/* Mobile Menu Fix - Global Styles for All Pages */

/* Mobile menu button improvements */
.site-header__mobile-menu-button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 0.375rem;
    background-color: transparent;
    border: none;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    position: relative;
    z-index: 60;
}

.site-header__mobile-menu-button:hover {
    background-color: #f3f4f6;
    color: #1f2937;
}

.site-header__mobile-menu-button:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Mobile menu icon animation */
.site-header__mobile-menu-button i {
    font-size: 1.25rem;
    transition: transform 0.3s ease;
}

.site-header__mobile-menu-button[aria-expanded="true"] i.fa-bars {
    transform: rotate(90deg);
}

.site-header__mobile-menu-button[aria-expanded="true"] i.fa-times {
    transform: rotate(0deg);
}

/* Mobile navigation styles */
.site-header__nav {
    transition: all 0.3s ease-in-out;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: #ffffff;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    z-index: 50;
    width: 100%;
    max-height: calc(100vh - 88px);
    overflow-y: auto;
}

/* Phase 1: Mobile Menu Spacing Gap Fix - Enhanced Solution */
@media (max-width: 767px) {
    .site-header__nav {
        /* Override Tailwind mt-4 class to eliminate spacing gap */
        margin-top: 0 !important;
        /* Remove visual separator border for seamless connection */
        border-top: none !important;
        /* Chrome Edge-to-Edge Safe Area Support */
        top: calc(100% - env(safe-area-inset-top, 0px));
        /* Ensure seamless connection with no transform offset */
        transform: translateY(0) !important;
    }
    
    /* Remove problematic margin when menu is hidden */
    .site-header__nav.hidden {
        margin-top: 0 !important;
    }
    
    /* Override any remaining Tailwind spacing on navigation container */
    .site-header__nav.w-full.md\\:w-auto.mt-4.md\\:mt-0 {
        margin-top: 0 !important;
    }
}

/* Mobile menu hidden state */
@media (max-width: 767px) {
    .site-header__nav.hidden {
        display: none !important;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-10px);
    }
    
    .site-header__nav:not(.hidden) {
        display: block !important;
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
    
    .site-header__nav.flex {
        display: block !important;
    }
}

/* Desktop navigation - ensure it's always visible */
@media (min-width: 768px) {
    .site-header__nav {
        position: static !important;
        display: flex !important;
        background-color: transparent !important;
        border-top: none !important;
        box-shadow: none !important;
        max-height: none !important;
        overflow-y: visible !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
        width: auto !important;
    }
    
    .site-header__mobile-menu-button {
        display: none !important;
    }
}

/* Mobile navigation list styles */
.site-header__nav-list {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 1rem;
    margin: 0;
    list-style: none;
}

@media (min-width: 768px) {
    .site-header__nav-list {
        flex-direction: row;
        align-items: center;
        padding: 0;
        gap: 1.5rem;
    }
}

/* Mobile navigation items */
.site-header__nav-item {
    border-bottom: 1px solid #f3f4f6;
    margin: 0;
}

.site-header__nav-item:last-child {
    border-bottom: none;
}

@media (min-width: 768px) {
    .site-header__nav-item {
        border-bottom: none;
        margin: 0;
    }
}

/* Mobile navigation links */
.site-header__nav-link {
    display: block;
    padding: 0.75rem 0;
    color: #374151;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease-in-out;
    border-radius: 0.375rem;
}

.site-header__nav-link:hover {
    color: #3b82f6;
    background-color: #f8fafc;
}

@media (min-width: 768px) {
    .site-header__nav-link {
        padding: 0.5rem 0;
        background-color: transparent !important;
    }
}

/* Search toggle button in mobile menu */
.search-toggle-btn {
    display: flex;
    align-items: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.75rem 0;
    color: #374151;
    font-weight: 500;
    transition: color 0.2s ease-in-out;
    width: 100%;
    text-align: left;
}

.search-toggle-btn:hover {
    color: #3b82f6;
}

@media (min-width: 768px) {
    .search-toggle-btn {
        padding: 0.5rem 0.75rem;
        width: auto;
    }
}

/* Register button in mobile menu */
.site-header__nav .btn {
    margin-top: 1rem;
    width: 100%;
    text-align: center;
}

/* Phase 2: Register Button Width Fix - Enhanced Multi-Browser Solution */
@media (max-width: 767px) {
    /* High specificity selectors for register button width fix */
    .site-header__nav .btn,
    .site-header__nav button.btn,
    .site-header__nav .btn.btn--accent.btn--small,
    .site-header__nav button.btn.btn--accent.btn--small {
        /* Force 100% width with high specificity */
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        
        /* Chrome Android specific fixes */
        -webkit-box-sizing: border-box !important;
        box-sizing: border-box !important;
        flex: 1 1 100% !important;
        
        /* Safari Mobile fallback */
        display: block !important;
        
        /* Chrome Edge-to-Edge safe area consideration */
        margin-left: env(safe-area-inset-left, 0px);
        margin-right: env(safe-area-inset-right, 0px);
        
        /* Ensure button spans full container width */
        margin-top: 1rem;
        text-align: center;
    }
    
    /* Container must support full width */
    .site-header__nav-item:has(button.btn),
    .site-header__nav-item:has(.btn) {
        width: 100% !important;
        flex: 1 1 100% !important;
        display: block !important;
    }
    
    /* Fallback for browsers that don't support :has() */
    .site-header__nav-item.mt-2.md\\:mt-0.md\\:ml-4 {
        width: 100% !important;
        flex: 1 1 100% !important;
        display: block !important;
    }
}

@media (min-width: 768px) {
    .site-header__nav .btn {
        margin-top: 0;
        width: auto;
        margin-left: 1rem;
    }
}

/* Ensure mobile menu appears above other content */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background-color: #ffffff;
    border-bottom: 1px solid #e5e7eb;
}

/* Body padding adjustments for fixed header */
body {
    padding-top: 88px;
}

body.has-banner {
    padding-top: calc(88px + 80px);
}

@media (max-width: 767px) {
    body {
        padding-top: 76px;
    }
    
    body.has-banner {
        padding-top: calc(76px + 100px);
    }
}

/* Prevent body scroll when mobile menu is open */
@media (max-width: 767px) {
    body.mobile-menu-open {
        overflow: hidden;
    }
}

/* Mobile menu overlay for better UX */
.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

@media (max-width: 767px) {
    .mobile-menu-overlay.active {
        display: block;
        opacity: 1;
    }
}

/* Smooth animations for mobile menu */
@media (max-width: 767px) {
    .site-header__nav {
        transform: translateY(-100%);
        transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
    }
    
    .site-header__nav:not(.hidden) {
        transform: translateY(0);
    }
}

/* Accessibility improvements */
.site-header__mobile-menu-button:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.site-header__nav-link:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .site-header__nav {
        border: 2px solid;
    }
    
    .site-header__nav-link {
        border: 1px solid transparent;
    }
    
    .site-header__nav-link:hover,
    .site-header__nav-link:focus {
        border-color: currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .site-header__nav,
    .site-header__mobile-menu-button i,
    .mobile-menu-overlay {
        transition: none;
    }
}

/* Phase 3: Chrome Android Edge-to-Edge Compatibility */
@media (max-width: 767px) {
    /* Support for Chrome 135+ edge-to-edge mode */
    @supports (padding: env(safe-area-inset-bottom)) {
        .site-header__nav {
            /* Ensure proper positioning in edge-to-edge mode */
            padding-bottom: env(safe-area-inset-bottom, 0px);
            max-height: calc(100vh - 88px - env(safe-area-inset-bottom, 0px));
        }
        
        /* Enhanced register button positioning for edge-to-edge */
        .site-header__nav .btn,
        .site-header__nav button.btn {
            margin-bottom: env(safe-area-inset-bottom, 0px);
        }
    }
    
    /* Viewport fit cover support */
    @supports (padding: env(safe-area-inset-left)) {
        .site-header__nav {
            padding-left: env(safe-area-inset-left, 0px);
            padding-right: env(safe-area-inset-right, 0px);
        }
    }
}

/* Phase 4: Additional Browser-Specific Optimizations */
@media (max-width: 767px) {
    /* Webkit-specific optimizations for Safari Mobile */
    @supports (-webkit-appearance: none) {
        .site-header__nav .btn {
            -webkit-appearance: none;
            -webkit-border-radius: 0.375rem;
        }
    }
    
    /* Chrome/Blink specific optimizations */
    @supports (display: -webkit-box) {
        .site-header__nav .btn {
            -webkit-box-flex: 1;
        }
    }
    
    /* Firefox mobile optimizations */
    @supports (-moz-appearance: none) {
        .site-header__nav .btn {
            -moz-appearance: none;
        }
    }
    
    /* Performance optimizations to prevent layout thrashing */
    .site-header__nav {
        will-change: transform, opacity;
        contain: layout style paint;
    }
    
    .site-header__nav .btn {
        will-change: auto;
        contain: layout style;
    }
}

/* ═══ Phase 5: Scalable Language Switcher — 37 Languages ═══ */

/* ── Desktop trigger button ── */
.lang-switcher {
    position: relative;
    display: flex;
    align-items: center;
}

.lang-switcher__btn {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    background: none;
    border: 1.5px solid #e5e7eb;
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 0.8125rem;
    font-weight: 700;
    color: #003366;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color 0.15s, background-color 0.15s;
}

.lang-switcher__btn:hover {
    border-color: #003366;
    background-color: #f0f4ff;
}

.lang-switcher__btn .fa-globe {
    font-size: 0.75rem;
    opacity: 0.7;
}

.lang-switcher__btn .lang-switcher__caret {
    font-size: 0.6rem;
    line-height: 1;
    opacity: 0.6;
}

/* ── Desktop panel ── */
.lang-switcher__panel {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 5px;
    width: 296px;
    max-width: calc(100vw - 2rem);
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 9999;
    overflow: hidden;
}

.lang-switcher__panel[hidden] {
    display: none;
}

/* ── Search input ── */
.lang-switcher__search-wrap {
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    position: relative;
}

.lang-switcher__search-wrap .fa-search {
    position: absolute;
    left: 22px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: #9ca3af;
    pointer-events: none;
}

.lang-switcher__search {
    width: 100%;
    padding: 6px 10px 6px 28px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.lang-switcher__search:focus {
    border-color: #003366;
}

/* ── Language list ── */
.lang-switcher__grid {
    display: flex;
    flex-direction: column;
    max-height: 65vh;
    overflow-y: auto;
    padding: 6px;
    gap: 2px;
}

/* ── Individual language link ── */
.lang-switcher__lang {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    width: 100%;
    box-sizing: border-box;
    border-radius: 5px;
    text-decoration: none;
    font-size: 0.8125rem;
    color: #374151;
    font-weight: 500;
    transition: background-color 0.1s, color 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lang-switcher__lang:hover,
.lang-switcher__lang:focus {
    background-color: #f0f4ff;
    color: #003366;
    outline: none;
}

.lang-switcher__lang--active {
    background-color: #f0f4ff;
    color: #003366;
    font-weight: 700;
}

.lang-switcher__code {
    font-size: 0.6875rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    min-width: 22px;
    flex-shrink: 0;
}

.lang-switcher__lang--active .lang-switcher__code {
    color: #003366;
}

.lang-switcher__name {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Mobile: hide desktop button, show mobile trigger ── */
@media (max-width: 767px) {
    /* Move language switcher to top of mobile menu */
    .site-header__nav-item.lang-switcher-item {
        order: -10 !important;
        width: 100% !important;
        display: block !important;
        padding: 0 !important;
        margin-bottom: 0 !important;
        border-bottom: 1px solid #e5e7eb !important;
    }

    /* Hide desktop button + panel on mobile */
    .lang-switcher__btn,
    .lang-switcher__panel {
        display: none !important;
    }

    /* Mobile trigger row */
    .lang-switcher__mobile-trigger {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 12px 0;
        background: none;
        border: none;
        cursor: pointer;
        font-family: inherit;
        font-size: 0.875rem;
        color: #374151;
        font-weight: 500;
    }

    .lang-switcher__mobile-trigger .fa-globe {
        margin-right: 8px;
        color: #003366;
        font-size: 0.875rem;
    }

    .lang-switcher__mobile-trigger-label {
        flex: 1;
        text-align: left;
    }

    .lang-switcher__mobile-trigger-arrow {
        font-size: 0.75rem;
        color: #9ca3af;
        transition: transform 0.2s;
    }

    .lang-switcher__mobile-trigger[aria-expanded="true"] .lang-switcher__mobile-trigger-arrow {
        transform: rotate(90deg);
    }

    /* Mobile panel */
    .lang-switcher__mobile-panel {
        padding: 0 0 8px 0;
    }

    .lang-switcher__mobile-panel[hidden] {
        display: none !important;
    }

    .lang-switcher__mobile-panel .lang-switcher__search-wrap {
        padding: 8px 0;
        border-bottom: none;
    }

    .lang-switcher__mobile-panel .lang-switcher__search-wrap .fa-search {
        left: 10px;
    }

    .lang-switcher__mobile-panel .lang-switcher__grid {
        max-height: 45vh;
        padding: 4px 0;
    }

    .lang-switcher__mobile-panel .lang-switcher__lang {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .lang-switcher__mobile-panel .lang-switcher__code {
        font-size: 0.75rem;
        min-width: 28px;
    }
}

/* Desktop: hide mobile trigger */
@media (min-width: 768px) {
    .lang-switcher__mobile-trigger,
    .lang-switcher__mobile-panel {
        display: none !important;
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .lang-switcher__lang,
    .lang-switcher__btn,
    .lang-switcher__mobile-trigger-arrow {
        transition: none;
    }
}

/* Site-wide header height normalization */
:root {
    --ki-header-height-mobile: 76px;
    --ki-header-height-desktop: 88px;
}

.site-header {
    min-height: var(--ki-header-height-mobile);
}

.site-header > .container,
.site-header > .container > .flex.flex-wrap.justify-between.items-center {
    min-height: inherit;
}

.site-header__logo-link {
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .site-header {
        min-height: var(--ki-header-height-desktop);
    }

    .site-header > .container,
    .site-header > .container > .flex.flex-wrap.justify-between.items-center {
        min-height: var(--ki-header-height-desktop);
    }

    .site-header > .container > .flex.flex-wrap.justify-between.items-center {
        flex-wrap: nowrap !important;
    }

    .site-header__nav {
        min-width: 0;
        flex: 0 1 auto;
        align-self: center;
    }

    .site-header__nav-list {
        width: auto !important;
        flex-wrap: nowrap !important;
    }

    /* The desktop header already uses flex gap, so prevent Tailwind's
       space-x utility margins from double-spacing the nav items. */
    .site-header__nav-list > :not([hidden]) ~ :not([hidden]) {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .site-header__nav-link,
    .search-toggle-btn,
    .lang-switcher__btn,
    .site-header .btn.btn--small {
        white-space: nowrap;
    }
}
