/* ===================================================================
   MOBILE-FIRST RESPONSIVE ENHANCEMENTS
   World-class mobile experience for Personal Injury Whiz
   =================================================================== */

/* =============================================================================
   MOBILE VIEWPORT OPTIMIZATIONS
   ============================================================================= */

/* Prevent horizontal scroll on mobile */
html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    position: relative !important;
}

/* Ensure proper text sizing on iOS */
body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Optimize font rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Prevent zoom on input focus */
@supports (-webkit-touch-callout: none) {
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* =============================================================================
   TOUCH-FRIENDLY INTERACTIONS
   ============================================================================= */

/* Increase touch target sizes for mobile */
@media (max-width: 768px) {
    /* Minimum 44x44px touch targets per Apple HIG */
    button, 
    a, 
    .btn, 
    .btn-primary, 
    .btn-secondary,
    .nav-link,
    input[type="button"],
    input[type="submit"],
    .option-card,
    .checkbox-card,
    .case-type-card {
        min-height: 44px !important;
        min-width: 44px !important;
    }

    /* Add padding for better touch accuracy */
    .btn, 
    .btn-primary, 
    .btn-secondary {
        padding: 12px 24px !important;
        font-size: 16px !important; /* Prevent iOS zoom on tap */
    }

    /* Increase spacing between clickable elements */
    .option-cards-group,
    .grid,
    .checkbox-grid {
        gap: 1rem !important;
    }
}

/* =============================================================================
   MOBILE NAVIGATION ENHANCEMENTS
   ============================================================================= */

@media (max-width: 768px) {
    /* Sticky header with reduced height and better performance */
    .header {
        position: sticky !important;
        top: 0 !important;
        z-index: 9999 !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        /* Hardware acceleration */
        transform: translateZ(0);
        will-change: transform;
    }

    .header-content {
        padding: 0.75rem 1rem !important;
        justify-content: space-between !important;
    }

    /* Mobile hamburger menu button */
    .mobile-menu-btn {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 44px !important;
        height: 44px !important;
        background: transparent !important;
        border: 2px solid var(--gray-300) !important;
        border-radius: 8px !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
    }

    .mobile-menu-btn:active {
        background: var(--gray-100) !important;
        transform: scale(0.95) !important;
    }

    /* Keep navigation visible but optimized for mobile */
    .nav {
        display: flex !important;
        gap: 0.375rem !important;
    }

    /* Mobile navigation overlay */
    .mobile-nav {
        position: fixed !important;
        top: 60px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        z-index: 9998 !important;
        display: none !important;
        padding: 1rem !important;
    }

    .mobile-nav.active {
        display: block !important;
    }

    .mobile-nav-link {
        display: block !important;
        padding: 1rem !important;
        margin-bottom: 0.5rem !important;
        background: var(--gray-50) !important;
        border-radius: 12px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        color: var(--gray-700) !important;
        text-decoration: none !important;
        transition: all 0.2s ease !important;
    }

    .mobile-nav-link:active {
        background: var(--primary-100) !important;
        transform: scale(0.98) !important;
    }
}

/* =============================================================================
   MOBILE HERO SECTION OPTIMIZATIONS
   ============================================================================= */

@media (max-width: 768px) {
    .hero {
        padding: 2rem 1rem !important;
        margin-bottom: 3rem !important;
        min-height: auto !important;
    }

    .hero h1 {
        font-size: clamp(1.5rem, 5vw, 2rem) !important;
        line-height: 1.25 !important;
        margin-bottom: 1rem !important;
        font-weight: 800 !important;
        letter-spacing: -0.02em !important;
    }

    .hero-description {
        font-size: 1rem !important;
        line-height: 1.5 !important;
        margin-bottom: 1.5rem !important;
    }

    /* Stack trust stats vertically on very small screens */
    @media (max-width: 480px) {
        .trust-stats {
            grid-template-columns: 1fr !important;
            gap: 1rem !important;
            max-width: 300px !important;
            margin: 1.5rem auto !important;
        }

        .trust-stat {
            width: 100% !important;
            max-width: none !important;
            padding: 1rem !important;
        }

        .trust-number {
            font-size: 2rem !important;
        }
    }
}

/* =============================================================================
   MOBILE FORM & INPUT OPTIMIZATIONS
   ============================================================================= */

@media (max-width: 768px) {
    /* Prevent zoom on input focus (iOS) */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Full-width inputs on mobile */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        width: 100% !important;
        padding: 12px !important;
        border-radius: 8px !important;
    }

    /* Stack form elements vertically */
    .form-group,
    .input-group {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    /* Full-width buttons in forms */
    .form-actions {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .form-actions .btn {
        width: 100% !important;
        justify-content: center !important;
    }
}

/* =============================================================================
   MOBILE CARD & GRID LAYOUTS
   ============================================================================= */

@media (max-width: 768px) {
    /* Single column layouts on mobile */
    .case-type-grid,
    .feature-grid,
    .option-cards-group {
        grid-template-columns: 1fr !important;
        gap: 0.875rem !important;
    }
    
    /* Optimize for small screens */
    @media (min-width: 400px) and (max-width: 767px) {
        .feature-grid {
            grid-template-columns: repeat(2, 1fr) !important;
            gap: 0.75rem !important;
        }
        
        .feature-card {
            padding: 1rem !important;
        }
    }

    /* Enhanced card styling for mobile */
    .case-type-card,
    .feature-card,
    .option-card {
        padding: 1.25rem !important;
        border-radius: 12px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
    }

    /* Active state for touch feedback */
    .case-type-card:active,
    .feature-card:active,
    .option-card:active {
        transform: scale(0.98) !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12) !important;
    }
}

/* =============================================================================
   MOBILE MODAL OPTIMIZATIONS
   ============================================================================= */

@media (max-width: 768px) {
    /* Full-screen modals on mobile */
    .modal,
    .modal-content {
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        max-height: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    .modal-overlay {
        padding: 0 !important;
    }

    /* Sticky modal header and footer */
    .modal-header {
        position: sticky !important;
        top: 0 !important;
        background: white !important;
        z-index: 10 !important;
        padding: 1rem !important;
        border-bottom: 1px solid var(--gray-200) !important;
    }

    .modal-footer {
        position: sticky !important;
        bottom: 0 !important;
        background: white !important;
        z-index: 10 !important;
        padding: 1rem !important;
        border-top: 1px solid var(--gray-200) !important;
    }

    .modal-body {
        padding: 1rem !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

/* =============================================================================
   MOBILE CTA & FLOATING ELEMENTS
   ============================================================================= */

@media (max-width: 768px) {
    /* Enhanced floating CTA for mobile */
    .floating-cta {
        bottom: 20px !important;
        left: 20px !important;
        right: 20px !important;
        width: calc(100% - 40px) !important;
        transform: none !important;
        border-radius: 12px !important;
        padding: 14px 20px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
    }

    .floating-cta.visible {
        transform: translateY(0) !important;
    }

    .floating-cta:active {
        transform: scale(0.98) !important;
    }

    /* Hide floating CTA when footer is visible */
    .floating-cta.near-footer {
        opacity: 0 !important;
        pointer-events: none !important;
        transform: translateY(100px) !important;
    }
}

/* =============================================================================
   MOBILE FAQ ACCORDION ENHANCEMENTS
   ============================================================================= */

@media (max-width: 768px) {
    .faq-question {
        padding: 1rem !important;
        font-size: 16px !important;
        border-radius: 12px !important;
        margin-bottom: 0.5rem !important;
        background: var(--gray-50) !important;
    }

    .faq-question:active {
        background: var(--gray-100) !important;
    }

    .faq-answer {
        padding: 0 1rem 1rem 1rem !important;
        font-size: 15px !important;
        line-height: 1.6 !important;
    }

    .faq-icon {
        width: 24px !important;
        height: 24px !important;
    }
}

/* =============================================================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ============================================================================= */

@media (max-width: 768px) {
    /* Reduce animation complexity on mobile */
    * {
        animation-duration: 0.2s !important;
    }

    /* Disable parallax effects on mobile */
    .parallax {
        background-attachment: scroll !important;
    }

    /* Optimize images for mobile */
    img {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Reduce shadow complexity for better performance */
    .case-type-card,
    .feature-card,
    .option-card {
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
    }
}

/* =============================================================================
   MOBILE FOOTER OPTIMIZATIONS
   ============================================================================= */

@media (max-width: 768px) {
    footer {
        padding: 2rem 1rem !important;
    }

    .footer-content {
        flex-direction: column !important;
        gap: 2rem !important;
        text-align: center !important;
    }

    .footer-links {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .footer-link {
        padding: 0.75rem !important;
        background: var(--gray-800) !important;
        border-radius: 8px !important;
        display: block !important;
    }

    .footer-link:active {
        background: var(--gray-700) !important;
    }
}

/* =============================================================================
   LANDSCAPE MOBILE OPTIMIZATIONS
   ============================================================================= */

@media (max-width: 896px) and (orientation: landscape) {
    /* Reduce vertical spacing in landscape */
    .hero {
        padding: 1.5rem 2rem !important;
    }

    .section {
        padding: 2rem !important;
    }

    /* Hide less important elements in landscape */
    .hero-decoration {
        display: none !important;
    }

    /* Adjust modal height for landscape */
    .modal-content {
        max-height: 90vh !important;
    }
}

/* =============================================================================
   TABLET OPTIMIZATIONS (iPad, etc.)
   ============================================================================= */

@media (min-width: 768px) and (max-width: 1024px) {
    /* 2-column layouts for tablets */
    .case-type-grid,
    .feature-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.5rem !important;
    }

    /* Adjust container padding */
    .container {
        padding: 0 2rem !important;
    }

    /* Optimize button sizes for tablets */
    .btn {
        padding: 12px 28px !important;
        font-size: 16px !important;
    }
}

/* =============================================================================
   HIGH DPI / RETINA DISPLAY OPTIMIZATIONS
   ============================================================================= */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Use higher quality images for retina displays */
    .logo img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }

    /* Thinner borders on high DPI screens */
    .case-type-card,
    .feature-card {
        border-width: 0.5px !important;
    }
}

/* =============================================================================
   ACCESSIBILITY ENHANCEMENTS FOR MOBILE
   ============================================================================= */

@media (max-width: 768px) {
    /* Ensure sufficient color contrast on mobile */
    .text-muted {
        color: var(--gray-600) !important;
    }

    /* Larger focus outlines for mobile */
    *:focus {
        outline: 3px solid var(--primary-500) !important;
        outline-offset: 2px !important;
    }

    /* Skip navigation link for mobile */
    .skip-to-content {
        position: absolute !important;
        top: -100vh !important;
        left: 1rem !important;
        background: var(--primary-600) !important;
        color: white !important;
        padding: 0.75rem 1.5rem !important;
        border-radius: 8px !important;
        text-decoration: none !important;
        font-weight: 600 !important;
        z-index: 10000 !important;
    }

    .skip-to-content:focus {
        top: 1rem !important;
    }
}

/* =============================================================================
   SMOOTH SCROLLING & SCROLL BEHAVIOR
   ============================================================================= */

@media (max-width: 768px) {
    /* Enable smooth scrolling with momentum on iOS */
    html {
        scroll-behavior: smooth !important;
    }

    /* Momentum scrolling for scrollable areas */
    .scrollable,
    .modal-body,
    .dropdown-content {
        -webkit-overflow-scrolling: touch !important;
        overflow-scrolling: touch !important;
    }

    /* Hide scrollbars on mobile for cleaner look */
    .scrollable::-webkit-scrollbar {
        display: none !important;
    }

    .scrollable {
        -ms-overflow-style: none !important;
        scrollbar-width: none !important;
    }
}

/* =============================================================================
   MOBILE-SPECIFIC BUG FIXES
   ============================================================================= */

@media (max-width: 768px) {
    /* Fix iOS Safari bottom safe area */
    .floating-cta {
        padding-bottom: calc(14px + env(safe-area-inset-bottom)) !important;
    }

    /* Fix Android Chrome address bar jump */
    .hero {
        min-height: calc(100vh - 60px) !important;
        min-height: calc(100dvh - 60px) !important;
    }

    /* Prevent text selection on buttons */
    button,
    .btn {
        -webkit-user-select: none !important;
        -moz-user-select: none !important;
        -ms-user-select: none !important;
        user-select: none !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    /* Fix iOS form zoom issue */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
        transform: scale(1) !important;
    }
}

/* =============================================================================
   PROGRESSIVE ENHANCEMENT FOR SLOW CONNECTIONS
   ============================================================================= */

@media (max-width: 768px) and (prefers-reduced-data: reduce) {
    /* Disable non-essential animations */
    * {
        animation: none !important;
        transition: none !important;
    }

    /* Use system fonts to reduce data */
    body {
        font-family: system-ui, -apple-system, sans-serif !important;
    }

    /* Reduce image quality */
    img {
        image-rendering: pixelated !important;
        filter: contrast(1.1) !important;
    }
}

/* =============================================================================
   SMALL DEVICE OPTIMIZATIONS (iPhone SE, etc.)
   ============================================================================= */

@media (max-width: 375px) {
    /* Optimize for very small screens */
    .container {
        padding: 0 0.875rem !important;
    }
    
    .hero h1 {
        font-size: 1.375rem !important;
    }
    
    .hero-description {
        font-size: 0.9375rem !important;
    }
    
    .btn-primary,
    .btn-secondary {
        font-size: 0.9375rem !important;
        padding: 0.75rem 1.25rem !important;
    }
    
    /* Stack all grids on very small screens */
    .trust-stats,
    .feature-grid,
    .case-type-grid {
        grid-template-columns: 1fr !important;
    }
}

/* =============================================================================
   NOTCH AND SAFE AREA HANDLING (iPhone X+)
   ============================================================================= */

@supports (padding: env(safe-area-inset-left)) {
    @media (max-width: 768px) {
        /* Handle landscape orientation with notch */
        .container,
        .header-content,
        .footer-content {
            padding-left: max(1rem, env(safe-area-inset-left)) !important;
            padding-right: max(1rem, env(safe-area-inset-right)) !important;
        }
        
        /* Bottom safe area for floating elements */
        .floating-cta,
        .cookie-banner {
            bottom: max(20px, env(safe-area-inset-bottom)) !important;
        }
    }
}

/* =============================================================================
   IMPROVED TOUCH FEEDBACK
   ============================================================================= */

@media (hover: none) and (pointer: coarse) {
    /* Better touch feedback for touch devices */
    button,
    a,
    .btn,
    .card,
    .option-card,
    .checkbox-card {
        transition: transform 0.1s ease, box-shadow 0.1s ease !important;
    }
    
    button:active,
    a:active,
    .btn:active,
    .card:active,
    .option-card:active,
    .checkbox-card:active {
        transform: scale(0.97) !important;
    }
    
    /* Remove hover effects on touch devices */
    button:hover,
    a:hover,
    .btn:hover {
        transform: none !important;
    }
}