/* ========================================
   MOBILE OPTIMIZATION - iOS & Android
   SPAiD Q&A System
   ======================================== */

/* Mobile-first touch targets (min 44x44px for iOS, 48x48px for Android) */
@media (max-width: 768px) {
    /* Larger buttons for touch */
    .btn-sm {
        min-height: 44px;
        padding: 0.5rem 1rem;
        font-size: 1rem;
    }
    
    .btn {
        min-height: 48px;
        font-size: 1.05rem;
    }
    
    /* Stack buttons vertically on mobile */
    #answerActions .d-flex {
        flex-direction: column !important;
    }
    
    #answerActions .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Larger touch targets for checkboxes */
    #captchaCheck {
        width: 2rem !important;
        height: 2rem !important;
    }
    
    /* Better form spacing */
    .card-body {
        padding: 1.5rem !important;
    }
    
    /* Larger text for readability */
    .faq-question-text {
        font-size: 1rem !important;
    }
    
    .form-text, .text-muted {
        font-size: 0.9rem !important;
    }
    
    /* Full-width modals on small screens */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
    }
    
    .modal-content {
        border-radius: 0;
        min-height: 100vh;
    }
    
    /* Better FAQ browser on mobile */
    #faqBrowserCollapse .accordion-body {
        max-height: 300px !important;
    }
    
    .faq-question-item {
        padding: 1rem !important;
        margin: 0.5rem 0 !important;
    }
    
    /* Larger icons */
    .bi {
        font-size: 1.1em;
    }
    
    /* Prevent zoom on input focus (iOS) */
    input[type="text"],
    input[type="email"],
    textarea {
        font-size: 16px !important;
    }
    
    /* Better scroll indicators */
    .accordion-body::-webkit-scrollbar {
        width: 12px !important;
    }
    
    /* Touch feedback */
    .btn:active,
    .faq-question-item:active {
        transform: scale(0.97);
        transition: transform 0.1s;
    }
    
    /* Better spacing for satisfied section buttons */
    #satisfiedSection .d-flex {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    #satisfiedSection .btn {
        width: 100% !important;
    }
    
    /* Feedback modal buttons on mobile */
    .feedback-category-btn {
        font-size: 0.9rem !important;
        padding: 0.6rem 0.8rem !important;
    }
}

@media (max-width: 576px) {
    /* Extra small devices */
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    h1, .h1 {
        font-size: 1.5rem;
    }
    
    h5, .h5 {
        font-size: 1.1rem;
    }
    
    /* Simplify FAQ browser */
    .accordion-button {
        font-size: 0.95rem !important;
    }
    
    /* Better modal close button */
    .btn-close {
        width: 2rem;
        height: 2rem;
    }
    
    /* Reduce padding in tight spaces */
    .modal-body {
        padding: 1rem !important;
    }
    
    /* Make answer text more readable */
    #answerText {
        font-size: 1.05rem;
        line-height: 1.6;
    }
}

/* iOS-specific optimizations */
@supports (-webkit-touch-callout: none) {
    * {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    .btn, input, textarea {
        -webkit-appearance: none;
        appearance: none;
    }
}

/* Landscape mode optimizations */
@media (max-height: 500px) and (orientation: landscape) {
    .card-body {
        padding: 0.75rem !important;
    }
    
    .mb-3, .my-3 {
        margin-bottom: 0.75rem !important;
    }
    
    h1, .h1 {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }
}

/* High-DPI displays (Retina) */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .card {
        border-width: 0.5px;
    }
}

/* Inline Question Editor */
. inline-editor {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #ffc107;
    animation: fadeIn 0.3s ease-in;
}

.inline-editor textarea {
    width: 100%;
    border-radius: 6px;
    border: 1px solid #dee2e6;
    padding: 0.75rem;
    font-size: 1rem;
    margin-bottom: 0.75rem;
    min-height: 80px;
}

.inline-editor-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
    color: #856404;
}

.inline-editor-header i {
    font-size: 1.25rem;
    margin-right: 0.5rem;
}

@media (max-width: 576px) {
    .inline-editor {
        padding: 0.75rem;
    }
    
    .inline-editor textarea {
        font-size: 16px; /* Prevent iOS zoom */
    }
}

/* Proactive Help System */
.proactive-help {
    position: fixed;
    bottom: 20px;
    right: 20px;
    max-width: 350px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 1.5rem;
    z-index: 1050;
    animation: slideInUp 0.4s ease-out;
    border-left: 4px solid #dc3545;
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.proactive-help-header {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    color: #dc3545;
    font-weight: 600;
    font-size: 1.1rem;
}

.proactive-help-header i {
    font-size: 1.5rem;
    margin-right: 0.75rem;
}

.proactive-help-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #6c757d;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.proactive-help-close:hover {
    color: #343a40;
}

.proactive-help-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.proactive-help-actions .btn {
    width: 100%;
}

@media (max-width: 576px) {
    .proactive-help {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

/* Frustration indicator (for admins/debugging) */
.frustration-indicator {
    position: fixed;
    top: 10px;
    right: 10px;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    z-index: 1060;
    display: none; /* Hidden by default */
}

.frustration-indicator.low {
    background: #d4edda;
    color: #155724;
}

.frustration-indicator.medium {
    background: #fff3cd;
    color: #856404;
}

.frustration-indicator.high {
    background: #f8d7da;
    color: #721c24;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}
