/* ============================================
   MOBILE USABILITY IMPROVEMENTS
   Enhanced mobile experience for phones and tablets
   ============================================ */

/* ============================================
   QUICK WINS - Critical Fixes
   ============================================ */

/* Hide Ghost floating member/portal trigger icon (bottom-right bubble) */
iframe.gh-portal-triggerbtn-iframe,
iframe[data-testid="portal-trigger-frame"],
.gh-portal-triggerbtn-iframe,
[class*="gh-portal-trigger"],
[id*="ghost-portal"],
div[style*="position: fixed"][style*="bottom"] iframe {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
}

/* Prevent iOS zoom on input focus */
input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
select,
textarea {
    font-size: 16px !important;
}

/* Prevent horizontal scroll globally */
body {
    overflow-x: hidden;
}

/* Safe area insets for iPhone notch/Dynamic Island */
.sticky-nav,
.gh-head {
    padding-top: env(safe-area-inset-top);
}

/* Safe area bottom for iPhone home indicator */
.mobile-filter-fab,
.menu-toggle,
.sticky-cta,
.fixed-bottom {
    padding-bottom: env(safe-area-inset-bottom);
    margin-bottom: env(safe-area-inset-bottom);
}

/* ============================================
   NAVIGATION IMPROVEMENTS
   Hide Home link and optimize for mobile/tablet
   ============================================ */

/* Hide Home link globally - not needed with logo */
.gh-head-menu .nav-home,
.gh-head-menu a[href="/"] {
    display: none !important;
}

/* ============================================
   TOUCH TARGET IMPROVEMENTS
   Minimum 44px for all interactive elements
   Applied to mobile and tablet (up to 1024px)
   ============================================ */

@media (max-width: 1024px) {
    /* Improve navigation layout on mobile/tablet */
    .gh-head-menu {
        gap: 4px;
    }

    /* Reduce padding on nav items for more space */
    .gh-head-menu a,
    .gh-head-btn {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 10px 12px;
        white-space: nowrap;
        font-size: 0.9rem;
    }

    /* Make Ghost's dropdown more touch-friendly */
    .gh-dropdown {
        min-height: 44px;
    }

    .gh-dropdown-trigger {
        min-height: 44px;
        padding: 10px 12px;
    }

    /* Improve dropdown menu */
    .gh-dropdown-menu {
        min-width: 200px;
    }

    .gh-dropdown-menu a {
        padding: 12px 16px;
        min-height: 44px;
    }

    /* Burger menu — 44px touch target, no extra padding (icon positioned by sticky-nav) */
    .gh-burger {
        width: 44px !important;
        height: 44px !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Filter options - larger touch targets */
    .filter-options label {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 8px 12px;
        cursor: pointer;
        user-select: none;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    /* Radio buttons and checkboxes */
    .filter-options input[type="radio"],
    .filter-options input[type="checkbox"] {
        width: 22px;
        height: 22px;
        margin-right: 12px;
        flex-shrink: 0;
    }

    /* Buttons */
    .btn,
    .ghost-btn,
    .modal-cta-button {
        min-height: 44px;
        padding: 12px 20px;
    }
}

/* Ensure Cohorts content starts below fixed active-filters bar on mobile/tablet */
@media (max-width: 1024px) {
    .cohort-container {
        padding-top: 140px; /* extra space for nav + chips bar */
    }
}

/* ============================================
   TEXT SIZE IMPROVEMENTS
   Better readability on mobile and tablet
   ============================================ */

@media (max-width: 1024px) {
    /* Ensure minimum readable text sizes */
    body {
        font-size: 16px;
        line-height: 1.6;
    }

    .stat-label {
        font-size: 0.875rem; /* 14px */
        letter-spacing: 0.05em;
    }

    .detail-list a {
        font-size: 1rem; /* 16px for better tap targets */
        padding: 4px 0;
    }

    .bar-row span {
        font-size: 1rem; /* 16px */
    }

    /* Search input */
    .sidebar-search input,
    #company-search {
        font-size: 16px;
        padding: 12px;
    }
}

/* ============================================
   HORIZONTAL SCROLL PREVENTION
   Fix full-bleed sections
   ============================================ */

@media (max-width: 1024px) {
    .cohort-wrapper,
    .featured-video-section {
        width: 100% !important;
        max-width: 100vw !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        left: auto !important;
        right: auto !important;
        overflow-x: hidden !important;
    }

    /* Ensure content doesn't break out */
    .cohort-container,
    .overview-wrapper,
    .site-content {
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Grid layouts should respect viewport */
    .cohort-grid,
    .overview-panels,
    .funnel-grid {
        max-width: 100%;
        overflow-x: hidden;
    }
}

/* ============================================
   MOBILE-FIRST FILTER SYSTEM
   Bottom sheet pattern for filters
   Extended to include tablets (iPad Air = 820px)
   ============================================ */

@media (max-width: 1024px) {
    /* Hide the old desktop menu-toggle */
    .menu-toggle {
        display: none !important;
    }

    /* Transform sidebar into bottom sheet */
    #sidebar-wrapper {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        height: auto;
        max-height: 75vh;
        margin-left: 0 !important;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
        z-index: 1002;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Show sidebar when toggled */
    #wrapper.toggled #sidebar-wrapper {
        transform: translateY(0);
        margin-left: 0 !important;
    }

    /* Add backdrop overlay */
    #wrapper::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        z-index: 1001;
    }

    #wrapper.toggled::before {
        opacity: 1;
        pointer-events: auto;
    }

    /* Hide hardcoded menu-toggle buttons on mobile (prevents double burger) */
    .menu-toggle:not(.mobile-filter-fab) {
        display: none !important;
    }

    /* Floating filter button - mobile FAB */
    .mobile-filter-fab {
        position: fixed !important;
        bottom: calc(30px + env(safe-area-inset-bottom)) !important;  /* Account for iPhone home indicator */
        right: 30px !important;
        width: 64px !important;
        height: 64px !important;
        border-radius: 50% !important;
        background: linear-gradient(135deg, #0f172a 0%, #2563eb 100%) !important;
        color: white !important;
        border: none !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
        z-index: 9999 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 24px !important;
        cursor: pointer !important;
        transition: transform 0.2s ease, box-shadow 0.2s ease !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    .mobile-filter-fab:active {
        transform: scale(0.95) !important;
    }

    #wrapper.toggled .mobile-filter-fab {
        background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%) !important;
    }

    .mobile-filter-fab .fab-icon {
        display: block !important;
        font-size: 28px !important;
        line-height: 1 !important;
        transition: transform 0.2s ease !important;
    }

    #wrapper.toggled .mobile-filter-fab .fab-icon {
        transform: scale(1.2) !important; /* Make X slightly larger */
    }

    /* Hide sidebar header on mobile - not needed for bottom sheet */
    .sidebar-header {
        display: none !important;
    }

    /* Adjust sidebar content padding */
    .sidebar-content {
        padding-top: 0 !important;
        padding-bottom: 20px;
    }

    /* Remove left margin shift on wrapper */
    #wrapper.toggled {
        padding-left: 0 !important;
    }
}

/* ============================================
   ACTIVE FILTERS BAR
   Show current filters at top of page
   ============================================ */

@media (max-width: 1024px) {
    .active-filters-bar {
        position: fixed;
        /* Fixed just below sticky nav; always visible when filters are active */
        top: calc(80px + env(safe-area-inset-top));
        left: 0;
        right: 0;
        background: var(--color-white, white);
        padding: 12px 16px;
        border-bottom: 1px solid var(--color-light-gray, #e2e8f0);
        display: flex;
        gap: 8px;
        overflow-x: auto;
        z-index: 1000;
        -webkit-overflow-scrolling: touch;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .active-filters-bar:empty {
        display: none;
    }

    .filter-chip {
        background: var(--color-lighter-gray, #f1f5f9);
        border-radius: 16px;
        padding: 6px 12px;
        font-size: 14px;
        white-space: nowrap;
        display: flex;
        align-items: center;
        gap: 8px;
        border: 1px solid var(--color-light-gray, #e2e8f0);
        color: var(--color-primary-text, inherit);
    }

    .filter-chip button {
        background: none;
        border: none;
        padding: 0;
        font-size: 18px;
        line-height: 1;
        cursor: pointer;
        color: var(--color-secondary-text, #64748b);
        display: flex;
        align-items: center;
        justify-content: center;
        width: 20px;
        height: 20px;
    }
}

/* ============================================
   MODAL IMPROVEMENTS
   Better mobile and tablet modal experience
   ============================================ */

@media (max-width: 1024px) {
    .detail-modal {
        padding: 20px 12px !important;
        align-items: flex-end;
    }

    .detail-modal__dialog {
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 24px 20px;
    }

    /* Better video sizing - maintain aspect ratio */
    .detail-video iframe {
        height: calc(100vw * 9 / 16);
        max-height: 280px;
    }

    /* Scrollable body with better padding */
    .detail-modal__body {
        max-height: 50vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-right: 8px;
    }

    /* Close button positioning */
    .detail-modal__close {
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 50%;
    }
}

/* Modal for company details (larger modals) */
@media (max-width: 1024px) {
    .modal-overlay {
        padding: 0 !important;
    }

    .modal-content {
        border-radius: 20px 20px 0 0 !important;
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-header {
        position: sticky;
        top: 0;
        background: var(--color-white, white);
        z-index: 10;
        padding-bottom: 16px;
        border-bottom: 1px solid var(--color-light-gray, #e2e8f0);
    }
}

/* ============================================
   DESKTOP BEHAVIOR (>1024px)
   Preserve original desktop sidebar behavior
   ============================================ */

@media (min-width: 1025px) {
    /* Desktop sidebar - always visible, no burger toggle */
    #wrapper {
        padding-left: 250px;
    }

    #sidebar-wrapper {
        margin-left: 0;
    }

    /* No mobile FAB on desktop */
    .mobile-filter-fab {
        display: none !important;
    }

    /* No desktop burger; sidebar is static */
    .menu-toggle:not(.mobile-filter-fab) {
        display: none !important;
    }
}

/* ============================================
   TABLET SPECIFIC (769px - 1024px)
   iPad Air and similar tablets
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    /* Tablets get bottom sheet like mobile but with adjustments */

    /* Slightly taller bottom sheet for tablets */
    #sidebar-wrapper {
        max-height: 65vh;
    }

    /* Larger FAB for tablets */
    .mobile-filter-fab {
        width: 72px;
        height: 72px;
        bottom: 36px; /* 50% more inset vs 24px */
        right: 36px;
    }

    .mobile-filter-fab span {
        font-size: 28px;
    }

    /* Increase touch targets for tablet */
    .gh-head-menu a,
    .gh-head-btn,
    .filter-options label {
        min-height: 48px;
        padding: 12px 16px;
    }

    /* Larger checkboxes for tablet */
    .filter-options input[type="radio"],
    .filter-options input[type="checkbox"] {
        width: 24px;
        height: 24px;
    }
}

/* ============================================
   LANDSCAPE MOBILE
   Optimize for landscape orientation
   ============================================ */

@media (max-width: 896px) and (orientation: landscape) {
    /* Reduce modal height to accommodate keyboard */
    .detail-modal__dialog {
        max-height: 70vh;
    }

    /* Sidebar takes less height in landscape */
    #sidebar-wrapper {
        max-height: 60vh;
    }

    /* Reduce vertical padding */
    .cohort-container {
        padding: 12px;
    }

    .overview-wrapper {
        padding: 20px 16px;
    }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

@media (max-width: 1024px) {
    /* Better focus indicators for keyboard navigation */
    a:focus-visible,
    button:focus-visible,
    input:focus-visible {
        outline: 2px solid #2563eb;
        outline-offset: 2px;
    }

    /* Reduce motion for users who prefer it */
    @media (prefers-reduced-motion: reduce) {
        #sidebar-wrapper,
        .menu-toggle,
        #wrapper::before {
            transition: none;
        }
    }

    /* High contrast mode support */
    @media (prefers-contrast: high) {
        .filter-chip {
            border-width: 2px;
        }

        .menu-toggle {
            border: 2px solid white;
        }
    }
}

/* ============================================
   VERY SMALL SCREENS (<400px)
   ============================================ */

@media (max-width: 400px) {
    /* Reduce padding further */
    .cohort-container {
        padding: 12px;
    }

    .overview-wrapper {
        padding: 20px 12px;
    }

    /* Stack stats vertically if needed */
    .overview-stats {
        grid-template-columns: 1fr;
    }

    /* Smaller floating button on tiny screens */
    .menu-toggle {
        width: 48px;
        height: 48px;
        bottom: 16px;
        right: 16px;
    }
}

/* ============================================
   HOTFIX OVERRIDES (loaded after sticky-nav.css)
   Navbar density + portrait hero video sizing
   ============================================ */

@media (max-width: 1024px) {
    /* Kill .gh-outer side-padding Ghost injects via --gap (2rem/32px each side).
       .is-head-open is on <body>, #gh-head is a child — need descendant selector. */
    .is-head-open #gh-head {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .is-head-open #gh-head .gh-head-brand {
        padding: 0.5rem 0.75rem !important;
    }

    /* Override Ghost screen.css: #gh-head .gh-head-menu sets justify-content:center
       and .gh-head-menu sets align-items:center — these center nav content vertically
       and prevent links from stretching to full panel width */
    .is-head-open #gh-head .gh-head-menu {
        padding: 0.5rem 0.75rem !important;
        justify-content: flex-start !important;
        align-items: stretch !important;
        background: #171717 !important;
    }

    .is-head-open #gh-head .gh-head-actions {
        padding: 0.5rem 0.75rem 0.625rem !important;
    }

    .is-head-open #gh-head .gh-head-members {
        gap: 0.5rem !important;
    }

    .is-head-open #gh-head .gh-head-btn,
    .is-head-open #gh-head .gh-btn {
        min-height: 44px !important;
        width: 100% !important;
        justify-content: center !important;
        padding: 0.65rem 0.85rem !important;
        margin: 0.2rem 0 !important;
        font-size: 13px !important;
        border-radius: 2px !important;
    }

    .is-head-open #gh-head .sb-nav-root {
        width: 100% !important;
        align-items: stretch !important;
        gap: 0.625rem !important;
    }

    .is-head-open #gh-head .sb-nav-groups {
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem !important;
        padding: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
    }

    .is-head-open #gh-head .sb-nav-group {
        width: 100% !important;
        padding: 0.15rem 0.1rem !important;
        border-top: 1px solid rgba(82, 82, 82, 0.35) !important;
    }

    .is-head-open #gh-head .sb-nav-group:first-child {
        border-top: 0 !important;
        padding-top: 0 !important;
    }

    .is-head-open #gh-head .sb-nav-group-trigger {
        width: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        text-align: left !important;
        min-height: 34px !important;
        padding: 0.15rem 0.25rem !important;
    }

    .is-head-open #gh-head .sb-nav-group-title {
        font-size: 0.86rem !important;
        line-height: 1.15 !important;
    }

    .is-head-open #gh-head .sb-nav-dropdown {
        position: static !important;
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        margin-top: 0.25rem !important;
        left: auto !important;
        right: auto !important;
        box-shadow: none !important;
    }

    .is-head-open #gh-head .sb-nav-link {
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        align-items: center !important;
        min-height: 42px !important;
        padding: 0.55rem 0.7rem !important;
        margin-bottom: 3px !important;
        border-radius: 2px !important;
        border: 1px solid #404040 !important;
        background: #0f0f10 !important;
    }

    .is-head-open #gh-head .sb-nav-link-name {
        width: 100% !important;
        font-size: 0.9rem !important;
        line-height: 1.2 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
    }

    .is-head-open #gh-head .sb-nav-link:hover,
    .is-head-open #gh-head .sb-nav-link:active,
    .is-head-open #gh-head .sb-nav-link:focus-visible {
        border-color: #3b82f6 !important;
        background: #111827 !important;
    }

    .is-head-open #gh-head .sb-nav-link-description {
        display: none !important;
    }
}

@media (max-width: 768px) and (orientation: portrait) {
    .featured-video-section {
        padding-top: 60px !important;
        background: #000 !important;
    }

    .video-container,
    .is-home .video-container {
        height: clamp(220px, 38vh, 360px) !important;
        max-height: clamp(220px, 38vh, 360px) !important;
        min-height: 220px !important;
        aspect-ratio: 16 / 9 !important;
        background: #000 !important;
        overflow: hidden !important;
    }

    .featured-video,
    .is-home .featured-video {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        object-position: center center !important;
    }

    .video-overlay {
        bottom: 0 !important;
        padding: 12px 10px !important;
    }

    .video-title {
        margin-bottom: 0.3rem !important;
        font-size: 1.15rem !important;
        line-height: 1.15 !important;
    }

    .video-tagline {
        font-size: 0.78rem !important;
        margin-bottom: 0.5rem !important;
        line-height: 1.2 !important;
    }

    .video-cta {
        padding: 7px 14px !important;
        font-size: 0.78rem !important;
    }
}

/* ============================================
   PORTRAIT PHONE NAV MENU DENSITY
   Tighten gaps and padding so the dropdown menu
   doesn't overflow the viewport on phones.
   ============================================ */
@media (max-width: 768px) and (orientation: portrait) {
    /* Tighter section padding for portrait phones */
    .is-head-open #gh-head .gh-head-brand {
        padding: 0.4rem 0.6rem !important;
    }

    .is-head-open #gh-head .gh-head-menu {
        padding: 0.4rem 0.6rem !important;
    }

    .is-head-open #gh-head .gh-head-actions {
        padding: 0.4rem 0.6rem 0.5rem !important;
    }

    /* Tighter root and group gaps */
    .is-head-open #gh-head .sb-nav-root {
        gap: 0.35rem !important;
    }

    .is-head-open #gh-head .sb-nav-groups {
        gap: 0.3rem !important;
    }

    /* Reduce group section padding */
    .is-head-open #gh-head .sb-nav-group {
        padding: 0.1rem 0 !important;
    }

    .is-head-open #gh-head .sb-nav-group-trigger {
        min-height: 30px !important;
        padding: 0.1rem 0.15rem !important;
    }

    .is-head-open #gh-head .sb-nav-group-title {
        font-size: 0.8rem !important;
    }

    /* Compact nav link items */
    .is-head-open #gh-head .sb-nav-link {
        min-height: 36px !important;
        padding: 0.4rem 0.6rem !important;
        margin-bottom: 2px !important;
    }

    .is-head-open #gh-head .sb-nav-link-name {
        font-size: 0.85rem !important;
    }

    /* Compact dropdown gap */
    .is-head-open #gh-head .sb-nav-dropdown {
        margin-top: 0.15rem !important;
    }

    /* Compact action buttons */
    .is-head-open #gh-head .gh-head-btn,
    .is-head-open #gh-head .gh-btn {
        min-height: 40px !important;
        padding: 0.5rem 0.75rem !important;
        margin: 0.15rem 0 !important;
        font-size: 13px !important;
    }

    .is-head-open #gh-head .gh-head-members {
        gap: 0.35rem !important;
    }
}
