/* Mobile Responsive Enhancements */
/* This file ensures proper mobile responsiveness and overrides any desktop-forcing styles */

/* Reset any forced minimum widths */
html {
    min-width: initial !important;
    width: 100% !important;
    overflow-x: hidden !important; /* Prevent page-level horizontal scroll on mobile */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

body {
    min-width: initial !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important; /* Contain wide children (tables/code) within their own scroll containers */
    overflow-y: auto !important; /* Ensure vertical scroll works */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Ensure proper box-sizing */
* {
    box-sizing: border-box;
}

/* Container and wrapper adjustments - but NOT sections */
.container,
.wrapper,
.content,
main {
    min-width: initial !important;
    width: 100% !important;
    max-width: 100% !important;
}

/* Sections should be scrollable */
section {
    min-width: initial !important;
    width: 100% !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
}

/* Mobile-specific styles */
@media screen and (max-width: 768px) {
    /* Reset any forced desktop layouts */
    body {
        min-width: initial !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* Ensure containers are responsive */
    .container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 15px !important;
        margin: 0 auto !important;
    }
    
    /* Make navigation mobile-friendly and visible */
    nav, .nav {
        width: 100% !important;
        padding: 10px 15px !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: white !important; /* Solid background for visibility */
        z-index: 99999 !important; /* Highest z-index to stay on top */
        box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    }
    
    /* Ensure nav container is visible — flex row with gap for legacy pages */
    .nav-container {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        align-items: center !important;
        gap: 10px !important;
        width: 100% !important;
        padding: 0 14px !important;
    }

    /* Logo image — explicit small size to defeat global `img{height:auto}` rule */
    nav.nav .logo-image,
    .nav-container .logo-image {
        width: 32px !important;
        height: 32px !important;
        max-width: 32px !important;
        min-width: 32px !important;
        flex-shrink: 0 !important;
        object-fit: contain !important;
    }
    /* Brand text — single line, no subtitle on small screens */
    nav.nav .logo,
    .nav-container .logo {
        gap: 8px !important;
        min-width: 0 !important;
        flex: 0 1 auto !important;
    }
    nav.nav .logo-text-container {
        min-width: 0 !important;
    }
    nav.nav .logo-text {
        font-size: 15px !important;
        line-height: 1.15 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    nav.nav .tagline {
        display: none !important;
    }
    
    /* Hamburger menu button (legacy non-React pages).
       Defeats the global `button{display:block;width:100%;max-width:300px;margin:10px auto}`
       rule above and places the icon top-left (flex order:-1). */
    .hamburger-menu {
        order: -1 !important;
        display: inline-flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        max-width: 44px !important;
        margin: 0 !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
        background: #fff !important;
        border: 1px solid #E5E7EB !important;
        border-radius: 8px !important;
        cursor: pointer !important;
        z-index: 100000 !important; /* Higher than nav to ensure clickability */
        position: relative !important;
    }

    .hamburger-menu span {
        display: block !important;
        width: 20px !important;
        height: 2px !important;
        background-color: #1F2937 !important;
        margin: 2.5px 0 !important;
        border-radius: 1px !important;
        transition: 0.3s !important;
    }
    
    /* Hamburger animation when active */
    .hamburger-menu.active span:nth-child(1) {
        transform: rotate(-45deg) translate(-5px, 6px) !important;
    }
    
    .hamburger-menu.active span:nth-child(2) {
        opacity: 0 !important;
    }
    
    .hamburger-menu.active span:nth-child(3) {
        transform: rotate(45deg) translate(-5px, -6px) !important;
    }
    
    /* Mobile menu styles */
    .nav-links {
        display: none !important;
        position: absolute !important;
        top: 100% !important;
        left: 0 !important;
        right: 0 !important;
        background: white !important;
        flex-direction: column !important;
        padding: 20px !important;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1) !important;
        z-index: 99998 !important; /* Just below hamburger button */
        max-height: calc(100vh - 80px) !important;
        overflow-y: auto !important; /* Allow scrolling if menu is long */
    }
    
    /* Show menu when active */
    .nav-links.active {
        display: flex !important;
    }
    
    .nav-links li {
        margin: 10px 0 !important;
        width: 100% !important;
    }
    
    .nav-links a {
        display: block !important;
        padding: 10px !important;
        width: 100% !important;
        text-align: left !important;
    }
    
    /* Add padding to body to account for fixed nav */
    body {
        padding-top: 80px !important; /* Increased padding */
    }
    
    /* Push down any other fixed/absolute elements that might overlap */
    .hero, .hero-section, header, .header {
        margin-top: 60px !important;
        z-index: 1 !important; /* Ensure they're below nav */
    }
    
    /* Ensure all sections are below navigation */
    section:first-of-type {
        padding-top: 20px !important;
    }
    
    /* Responsive text */
    h1 {
        font-size: 2rem !important;
        line-height: 1.2 !important;
    }
    
    h2 {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
    }
    
    h3 {
        font-size: 1.25rem !important;
        line-height: 1.4 !important;
    }
    
    p, li {
        font-size: 1rem !important;
        line-height: 1.6 !important;
    }
    
    /* Make images responsive */
    img {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Responsive tables — table itself becomes a scroll container so wide tables
       don't push the whole page sideways. */
    table {
        display: block !important;
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    /* Allow cell content to wrap, but preserve the explicit table scroll above
       for tables that genuinely need to remain wide (e.g., comparison tables). */
    td, th {
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
    }
    /* Long URLs / code / pre — break to fit narrow screens */
    pre, code, kbd, samp {
        white-space: pre-wrap !important;
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
        max-width: 100% !important;
    }
    /* Images and embeds never push past viewport */
    img, video, iframe, embed, object {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Responsive forms */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    textarea,
    select {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Button responsiveness */
    button,
    .btn,
    .button {
        width: 100% !important;
        max-width: 300px !important;
        margin: 10px auto !important;
        display: block !important;
    }
    
    /* Fix overflow issues while allowing scroll */
    .section,
    .hero,
    .content-section {
        overflow-x: auto !important; /* Allow horizontal scroll if needed */
        overflow-y: visible !important; /* Allow vertical content to be visible */
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    /* Responsive grid */
    .grid,
    .row {
        display: block !important;
        width: 100% !important;
    }

    .col,
    .column {
        width: 100% !important;
        margin-bottom: 20px !important;
    }

    /* Force ALL multi-column grids to single column */
    .feature-grid,
    .benefits-grid,
    .teams-grid,
    .category-grid,
    .use-cases-grid,
    .footer-grid,
    .contact-grid,
    .stats-grid,
    [class*="grid"] {
        display: block !important;
        grid-template-columns: 1fr !important;
    }

    /* Force inline style grids to single column */
    div[style*="display: grid"],
    div[style*="display:grid"] {
        display: block !important;
    }

    div[style*="display: grid"] > *,
    div[style*="display:grid"] > * {
        width: 100% !important;
        margin-bottom: 15px !important;
    }

    /* Fix flex layouts that might overflow */
    div[style*="display: flex"],
    div[style*="display:flex"] {
        flex-wrap: wrap !important;
    }

    div[style*="display: flex"] > *,
    div[style*="display:flex"] > * {
        flex: 1 1 100% !important;
        min-width: 0 !important;
    }

    /* Fix any element with inline width styles */
    [style*="width:"][style*="px"],
    [style*="min-width:"][style*="px"] {
        width: 100% !important;
        min-width: unset !important;
        max-width: 100% !important;
    }

    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }

    /* Show mobile-only elements */
    .mobile-only {
        display: block !important;
    }
}

/* Small mobile devices */
@media screen and (max-width: 480px) {
    /* Even smaller font sizes for very small screens */
    h1 {
        font-size: 1.75rem !important;
    }
    
    h2 {
        font-size: 1.25rem !important;
    }
    
    h3 {
        font-size: 1.1rem !important;
    }
    
    p, li {
        font-size: 0.9rem !important;
    }
    
    /* Tighter padding on small screens */
    .container {
        padding: 0 10px !important;
    }
}

/* Tablet styles */
@media screen and (min-width: 768px) and (max-width: 1024px) {
    .container {
        max-width: 100% !important;
        padding: 0 30px !important;
    }
    
    /* Two-column layout for tablets */
    .grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
    }
}

/* Ensure scrollability */
@media screen and (max-width: 1024px) {
    /* Fix any position fixed elements that might cause issues */
    .fixed-element {
        position: relative !important;
    }

    /* Ensure footer is visible */
    footer {
        position: relative !important;
        width: 100% !important;
    }

    /* Force all grid layouts to single column on mobile */
    [style*="grid-template-columns: repeat(3"],
    [style*="grid-template-columns: repeat(2"],
    [style*="grid-template-columns:repeat(3"],
    [style*="grid-template-columns:repeat(2"] {
        grid-template-columns: 1fr !important;
    }

    /* Fix any fixed-width elements */
    [style*="width: 1200px"],
    [style*="width: 1400px"],
    [style*="width: 1000px"],
    [style*="min-width: 1200px"],
    [style*="min-width: 1400px"],
    [style*="min-width: 1000px"] {
        width: 100% !important;
        min-width: unset !important;
        max-width: 100% !important;
    }
}

/* Accessibility improvements for touch devices */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    a, button, input, select, textarea {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on touch devices */
    a:hover,
    button:hover {
        background: inherit;
        color: inherit;
    }
}

/* Desktop styles - ensure normal navigation */
@media screen and (min-width: 769px) {
    /* Hide hamburger on desktop */
    .hamburger-menu {
        display: none !important;
    }
    
    /* Show normal navigation */
    .nav-links {
        display: flex !important;
        position: static !important;
        flex-direction: row !important;
        padding: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
    }
    
    .nav-links li {
        margin: 0 15px !important;
        width: auto !important;
    }
    
    .nav-links a {
        padding: 5px 10px !important;
        width: auto !important;
    }
    
    /* Reset body padding on desktop */
    body {
        padding-top: 0 !important;
    }
}

/* Print styles */
@media print {
    * {
        min-width: initial !important;
        max-width: 100% !important;
    }
}

/* ===========================================================
   REACT v2 NAV — mobile overrides (homepage uses .v2-nav-*)
   These selectors are MORE specific than the global
   `button{display:block...}` and `img{height:auto}` rules
   above, so they win without needing extra !important storms.
   =========================================================== */
@media screen and (max-width: 768px) {
    /* Sticky nav row — single horizontal bar */
    nav .v2-nav-container,
    .v2-nav-container {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 10px 14px !important;
        min-height: 60px !important;
    }

    /* Hamburger — top-left, fixed 44x44 tap target.
       Overrides the global `button{display:block;width:100%;margin:10px auto}` rule. */
    .v2-nav-container .v2-nav-toggle,
    button.v2-nav-toggle {
        order: -1 !important;
        display: inline-flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        max-width: 44px !important;
        margin: 0 !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
        background: #fff !important;
        border: 1px solid #E5E7EB !important;
        border-radius: 8px !important;
        cursor: pointer !important;
    }
    .v2-nav-container .v2-nav-toggle span,
    button.v2-nav-toggle span {
        display: block !important;
        width: 20px !important;
        height: 2px !important;
        background: #1F2937 !important;
        margin: 2.5px 0 !important;
        border-radius: 1px !important;
        transition: transform 200ms ease, opacity 200ms ease !important;
    }
    /* Hamburger -> X when menu open */
    .v2-nav-container .v2-nav-toggle[aria-expanded="true"] span:nth-child(1) {
        transform: translateY(7px) rotate(45deg) !important;
    }
    .v2-nav-container .v2-nav-toggle[aria-expanded="true"] span:nth-child(2) {
        opacity: 0 !important;
    }
    .v2-nav-container .v2-nav-toggle[aria-expanded="true"] span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg) !important;
    }

    /* Brand link — sit right of hamburger, single row, no wrap */
    .v2-nav-container a[aria-label="AI Advisor Lab home"] {
        flex: 0 1 auto !important;
        min-width: 0 !important;
        gap: 10px !important;
        margin: 0 !important;
    }

    /* Logo image — explicit small size, defeat global `img{height:auto}` rule */
    .v2-nav-container a[aria-label="AI Advisor Lab home"] img {
        height: 32px !important;
        width: 32px !important;
        max-width: 32px !important;
        min-width: 32px !important;
        flex-shrink: 0 !important;
    }

    /* Brand text block — keep label, hide subtitle on small screens */
    .v2-nav-container a[aria-label="AI Advisor Lab home"] > span {
        min-width: 0 !important;
    }
    .v2-nav-container a[aria-label="AI Advisor Lab home"] > span > span:first-child {
        font-size: 15px !important;
        line-height: 1.15 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    .v2-nav-container a[aria-label="AI Advisor Lab home"] > span > span:last-child {
        display: none !important;
    }

    /* Closed mobile menu — hidden */
    .v2-nav-links {
        display: none !important;
    }
    /* Open mobile menu — full-width dropdown panel below nav.
       Mirrors index-v2.css `.v2-nav-links.v2-open` but with explicit
       overrides that beat the inline `display:flex` on the React div. */
    .v2-nav-links.v2-open {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        position: absolute !important;
        top: 100% !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0 !important;
        padding: 14px 18px 20px !important;
        background: #fff !important;
        border-top: 1px solid #E5E7EB !important;
        border-bottom: 1px solid #E5E7EB !important;
        box-shadow: 0 10px 28px rgba(0,0,0,0.10) !important;
        gap: 6px !important;
        max-height: calc(100vh - 64px) !important;
        overflow-y: auto !important;
        z-index: 60 !important;
    }
    .v2-nav-links.v2-open > a {
        display: block !important;
        width: 100% !important;
        padding: 12px 8px !important;
        font-size: 16px !important;
        border-bottom: 1px solid #F3F4F6 !important;
        max-width: none !important;
        margin: 0 !important;
        text-align: left !important;
    }
    /* Last item — the Start Free Trial CTA — keep its blue button style */
    .v2-nav-links.v2-open > a:last-child {
        margin-top: 10px !important;
        border-bottom: none !important;
        background: #0078D4 !important;
        color: #fff !important;
        text-align: center !important;
        border-radius: 6px !important;
        font-weight: 700 !important;
        padding: 14px 18px !important;
    }

    /* Body offset — nav is sticky/fixed and ~60px tall */
    body {
        padding-top: 60px !important;
    }
}

/* ≤480px — tighten further on small phones */
@media screen and (max-width: 480px) {
    .v2-nav-container {
        padding: 8px 12px !important;
        gap: 10px !important;
    }
    .v2-nav-container a[aria-label="AI Advisor Lab home"] img {
        height: 28px !important;
        width: 28px !important;
        max-width: 28px !important;
        min-width: 28px !important;
    }
    .v2-nav-container a[aria-label="AI Advisor Lab home"] > span > span:first-child {
        font-size: 14px !important;
    }
}

/* ===========================================================
   FORCE-DESKTOP OVERRIDES — defeat min-width:1200px rules in
   global-alignment.css and force-desktop.css so footer / body
   / sections fit the mobile viewport in portrait orientation.
   Without these, .footer { min-width: 1200px } from
   global-alignment.css:146 makes the footer extend off-screen.
   Range covers everything below 1200px: at 1025-1199 the body
   was still forced 1200px wide by global-alignment.css, which
   in turn pushed the nav row past the viewport edge on narrow
   laptops (1100-1199px) — fixed by extending this reset block
   from ≤1024 to ≤1199.
   =========================================================== */
@media screen and (max-width: 1199px) {
    html,
    body,
    nav,
    .nav,
    section,
    main,
    .main-content,
    .container,
    .nav-container,
    .footer-container,
    .footer,
    footer,
    .cta,
    .final-cta,
    .cta-section,
    .hero,
    .hero-section,
    .hero-content,
    .content,
    .section-content,
    .page-content {
        min-width: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Footer-specific: ensure interior content also fits */
    footer .container,
    .footer .container,
    .footer-container {
        max-width: 100% !important;
        padding-left: 20px !important;
        padding-right: 20px !important;
    }

    /* Footer grid collapses to single column with no minimum width */
    .footer-grid,
    .footer-bottom,
    .footer-content {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }

    /* Footer items — full width inside the column */
    .footer-section,
    .footer-column,
    .footer-links,
    .footer-bottom > * {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }
    .footer-section h4,
    .footer-section h5,
    .footer-section ul,
    .footer-section li,
    .footer-section a,
    .footer-section p {
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
    }
    /* Section heading top-margin so each footer column has air */
    .footer-section h4,
    .footer-section h5 {
        margin-top: 8px !important;
        margin-bottom: 12px !important;
    }

    /* Defeat `h1..h6 { max-width: 1200px; margin: auto }` from
       global-layout.css which centers footer headings off-axis. */
    footer h1, footer h2, footer h3, footer h4, footer h5, footer h6,
    .footer h1, .footer h2, .footer h3, .footer h4, .footer h5, .footer h6 {
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        text-align: left !important;
    }
    /* Same for p inside footer (global-layout has p { max-width: 900px; margin: auto }) */
    footer p,
    .footer p {
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}