/* ============================================
   HEADER & NAVIGATION
   Version: 5.8.0 - SAFARI BACKDROP-FILTER FIX & BREAKPOINT FIX
   Updated: March 2026
   For: imagelab.co.za
   WCAG 2.2 AA Compliant

   FIXES IN v5.8.0:
   ✅ CRITICAL FIX: Moved backdrop-filter off .site-header onto .site-header::before
      In Safari, backdrop-filter (including -webkit-backdrop-filter) on a parent
      creates a containing block for position:fixed children — identical to the
      effect of transform or filter. The mobile .main-nav uses position:fixed to
      escape the header stacking context, but Safari was re-trapping it inside
      the header's bounds. Moving blur to ::before leaves the header element
      itself filter-free, so position:fixed children resolve to the viewport.

   ✅ FIXED: Mobile breakpoint unified — was max-width:768px / min-width:769px,
      leaving a 1px gap at exactly 768px (iPad Mini portrait) that got mobile
      styles. Now max-width:767px / min-width:768px — consistent with the
      48em breakpoint used elsewhere in the codebase.

   PREVIOUS FIXES v5.7.1:
   ✅ Mobile dropdown position: static → relative + z-index: 10

   PREVIOUS FIXES v5.7.0:
   ✅ Mobile menu escapes header stacking context via position: fixed
   ✅ Site header z-index reduced to 900
   ✅ Menu toggle z-index: 10000 for interaction priority

   Z-INDEX HIERARCHY:
   Global context:
     10000: Menu toggle (interaction layer)
      9999: Mobile navigation menu
      9998: Menu overlay (body.menu-open::before)
       900: Site header (sticky)
        10: Dropdown menus (within mobile nav), logo
         1: Base page content

   DEPENDENCIES:
   - css/01-variables.css
   - js/navigation.js v2.6.0+

   WCAG 2.2 AA Compliant | Production-Ready
   ============================================ */

/* ============================================
   SITE HEADER
   NOTE: background and backdrop-filter are on ::before, NOT here.
   Keeping the header element itself filter-free is what allows the
   mobile nav (position:fixed) to escape to the viewport in Safari.
   ============================================ */
.site-header {
    position: sticky;
    top: 0;
    z-index: 900;
    /* No background or backdrop-filter here — see ::before below */
    border-bottom: 1px solid rgba(183, 148, 246, 0.15);
    box-shadow: var(--shadow-dark, 0 8px 32px rgba(0, 0, 0, 0.6));
    transition: border-color var(--transition-normal, 0.3s);
}

/*
 * SAFARI FIX v5.8.0: Backdrop-filter is applied here on the pseudo-element,
 * NOT on .site-header itself. This preserves the frosted-glass visual while
 * keeping .site-header free of filter/backdrop-filter, which would otherwise
 * create a containing block for position:fixed children in Safari.
 */
.site-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--glass-dark-charcoal, rgba(21, 29, 45, 0.65));
    backdrop-filter: var(--glass-blur-heavy, blur(8px));
    -webkit-backdrop-filter: var(--glass-blur-heavy, blur(8px));
    z-index: -1;
    pointer-events: none;
}

@supports not (backdrop-filter: blur(8px)) {
    .site-header::before {
        background: rgba(21, 29, 45, 0.98);
    }
}

.site-header .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-lg, 1.5rem);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 80px;
    gap: var(--space-lg, 1.5rem);
}

/* ============================================
   LOGO
   ============================================ */
.logo {
    flex-shrink: 0;
    z-index: 10;
    position: relative; /* needed for z-index to apply */
}

.logo a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    transition: opacity var(--transition-fast, 0.15s);
}

.logo a:hover {
    opacity: 0.85;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    color: var(--color-primary-500, #b794f6);
    flex-shrink: 0;
}

.logo-icon svg {
    width: 40px;
    height: 40px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.logo-text {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.logo-title {
    background: linear-gradient(135deg, var(--color-primary-400, #ddd6fe), var(--color-primary-600, #9333ea));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: var(--font-family-heading, 'Poppins', sans-serif);
    font-size: var(--font-size-xl, 1.25rem);
    font-weight: var(--font-weight-bold, 700);
    line-height: 1.2;
}

.logo-tagline {
    color: var(--color-primary-400, #ddd6fe);
    font-size: var(--font-size-sm, 0.875rem);
    font-weight: var(--font-weight-medium, 500);
    line-height: 1;
}

/* ============================================
   MAIN NAVIGATION - BASE STYLES
   ============================================ */
.main-nav {
    display: flex;
}

.main-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.main-nav a {
    display: block;
    padding: var(--space-sm, 0.5rem) var(--space-md, 1rem);
    color: var(--text-secondary, #e0e4ea);
    text-decoration: none;
    font-size: var(--font-size-base, 1rem);
    font-weight: var(--font-weight-medium, 500);
    border-radius: var(--radius-sm, 0.375rem);
    transition: all var(--transition-fast, 0.15s);
    white-space: nowrap;
}

.main-nav a:hover,
.main-nav a:focus {
    color: var(--color-primary-400, #ddd6fe);
    background: var(--glass-card-default, rgba(15, 22, 35, 0.6));
    transform: translateY(-1px);
}

.main-nav a.active {
    color: var(--color-primary-400, #ddd6fe);
    font-weight: var(--font-weight-semibold, 600);
    background: var(--glass-card-default, rgba(15, 22, 35, 0.6));
}

/* ============================================
   DESKTOP NAVIGATION
   FIXED v5.8.0: min-width:768px (was 769px — unified with breakpoint fix)
   ============================================ */
@media (min-width: 768px) {
    .main-nav {
        position: relative;
    }

    .main-nav > ul {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: var(--space-sm, 0.5rem);
    }

    .main-nav > ul > li {
        position: relative;
    }

    /* ==========================================
       DROPDOWN MENU - DESKTOP
       ========================================== */

    .main-nav .dropdown-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        min-width: 200px;
        flex-direction: column;
        gap: 0;
        align-items: stretch;
        background: var(--glass-card-default, rgba(15, 22, 35, 0.6));
        backdrop-filter: var(--glass-blur-medium, blur(6px));
        -webkit-backdrop-filter: var(--glass-blur-medium, blur(6px));
        border: 1px solid rgba(183, 148, 246, 0.15);
        border-radius: var(--radius-md, 0.5rem);
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
        padding: var(--space-sm, 0.5rem) 0;
        margin-top: 0.25rem;
        z-index: 1020;
    }

    @supports not (backdrop-filter: blur(6px)) {
        .main-nav .dropdown-menu {
            background: rgba(15, 22, 35, 0.98);
        }
    }

    .has-dropdown:hover > .dropdown-menu,
    .has-dropdown:focus-within > .dropdown-menu {
        display: flex;
    }

    .main-nav .dropdown-menu li {
        width: 100%;
    }

    .main-nav .dropdown-menu a {
        padding: var(--space-sm, 0.5rem) var(--space-lg, 1.5rem);
        border-radius: 0;
        white-space: nowrap;
    }

    .main-nav .dropdown-menu a:hover,
    .main-nav .dropdown-menu a:focus {
        background: var(--glass-card-hover, rgba(21, 29, 45, 0.75));
        color: var(--color-primary-400, #ddd6fe);
        transform: none;
    }

    .menu-toggle {
        display: none;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .main-nav > ul {
        gap: var(--space-xs, 0.25rem);
    }

    .main-nav a {
        padding: var(--space-sm, 0.5rem);
        font-size: var(--font-size-sm, 0.875rem);
    }
}

/* ============================================
   MOBILE MENU TOGGLE
   ============================================ */
.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-around;
    width: 48px;
    height: 48px;
    padding: 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 10;
    position: relative;
    flex-shrink: 0;
}

.menu-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-secondary, #e0e4ea);
    border-radius: 2px;
    transition: all var(--transition-fast, 0.15s);
    transform-origin: center;
}

.menu-toggle:hover span,
.menu-toggle:focus span {
    background: var(--color-primary-400, #ddd6fe);
}

/* Hamburger → X animation */
.menu-toggle[aria-expanded="true"] span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.menu-toggle[aria-expanded="true"] span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.menu-toggle[aria-expanded="true"] span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ============================================
   MOBILE NAVIGATION
   FIXED v5.8.0: max-width:767px (was 768px — see breakpoint fix note above)
   ============================================ */
@media (max-width: 767px) {
    .header-content {
        min-height: 60px;
        gap: var(--space-md, 1rem);
        padding: 0.5rem 0;
    }

    .site-header .container {
        padding: 0 var(--space-md, 1rem);
    }

    .menu-toggle {
        display: flex;
        z-index: 10000;
        position: relative;
    }

    /*
     * Mobile nav uses position:fixed to escape the header's stacking context.
     * This works correctly in Chrome/Firefox at all times, and in Safari
     * specifically BECAUSE we moved backdrop-filter off .site-header (see ::before
     * fix above). Without that fix, Safari would re-trap this element inside
     * the header bounds despite position:fixed.
     */
    .main-nav {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--glass-dark-charcoal, rgba(21, 29, 45, 0.98));
        backdrop-filter: var(--glass-blur-heavy, blur(10px));
        -webkit-backdrop-filter: var(--glass-blur-heavy, blur(10px));
        padding: 5rem var(--space-lg, 1.5rem) var(--space-xl, 2rem);
        overflow-y: auto;
        overflow-x: hidden;
        transform: translateX(-100%);
        transition: transform var(--transition-normal, 0.3s);
        z-index: 9999;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
        will-change: transform;
        -webkit-overflow-scrolling: touch;
    }

    @supports not (backdrop-filter: blur(10px)) {
        .main-nav {
            background: rgba(21, 29, 45, 0.98);
        }
    }

    .main-nav.active {
        transform: translateX(0);
        box-shadow: -8px 0 30px rgba(0, 0, 0, 0.5);
    }

    .main-nav ul {
        display: flex;
        flex-direction: column;
        gap: 0;
        width: 100%;
    }

    .main-nav > ul > li {
        width: 100%;
        border-bottom: 1px solid rgba(183, 148, 246, 0.1);
    }

    .main-nav > ul > li:last-child {
        border-bottom: none;
    }

    .main-nav a {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem 1.25rem;
        color: rgba(255, 255, 255, 0.9);
        font-size: 1.0625rem;
        border-radius: 0;
        min-height: 48px;
        min-width: 48px;
    }

    .main-nav a:hover,
    .main-nav a:focus {
        background: rgba(183, 148, 246, 0.1);
        color: #ffffff;
        padding-left: 1.5rem;
    }

    .main-nav a.active {
        background: rgba(183, 148, 246, 0.15);
        border-left: 3px solid #b794f6;
        color: #ddd6fe;
    }

    /* ==========================================
       DROPDOWN MENU - MOBILE
       ========================================== */

    .has-dropdown > a[aria-haspopup="true"]::after {
        content: '›';
        margin-left: auto;
        font-size: 1.5rem;
        line-height: 1;
        transition: transform 0.3s ease;
        color: rgba(183, 148, 246, 0.6);
    }

    .has-dropdown > a[aria-expanded="true"]::after,
    .has-dropdown[data-expanded="true"] > a::after {
        transform: rotate(90deg);
        color: #b794f6;
    }

    .main-nav .dropdown-menu {
        display: none;
        max-height: 0;
        opacity: 0;
        overflow: hidden;
        position: relative;
        z-index: 10;
        width: 100%;
        background: rgba(10, 14, 26, 0.6);
        border: none;
        border-left: 2px solid rgba(183, 148, 246, 0.3);
        border-radius: 0;
        box-shadow: none;
        margin: 0 0 0 1rem;
        padding: 0;
        flex-direction: column;
        transition: max-height 0.3s ease, opacity 0.2s ease;
    }

    .has-dropdown > a[aria-expanded="true"] + .dropdown-menu,
    .has-dropdown[data-expanded="true"] > .dropdown-menu,
    .has-dropdown > a[aria-expanded="true"] ~ .dropdown-menu,
    .has-dropdown[data-expanded="true"] .dropdown-menu {
        display: flex;
        max-height: 600px;
        opacity: 1;
        margin-top: 0.25rem;
    }

    .main-nav .dropdown-menu li {
        border-bottom: 1px solid rgba(183, 148, 246, 0.05);
    }

    .main-nav .dropdown-menu li:last-child {
        border-bottom: none;
    }

    .main-nav .dropdown-menu a {
        padding: 0.875rem 1.5rem;
        font-size: 0.9375rem;
        color: rgba(255, 255, 255, 0.85);
        background: rgba(15, 22, 35, 0.3);
        min-height: 48px;
    }

    .main-nav .dropdown-menu a::after {
        content: none;
    }

    .main-nav .dropdown-menu a:hover,
    .main-nav .dropdown-menu a:focus {
        background: rgba(183, 148, 246, 0.15);
        color: #ffffff;
        padding-left: 2rem;
    }

    .main-nav .dropdown-menu a.active {
        background: rgba(183, 148, 246, 0.2);
        color: #ddd6fe;
        border-left: 2px solid #b794f6;
    }

    /* ========================================
       MENU OVERLAY
       ======================================== */

    body.menu-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        animation: fadeIn 0.3s ease;
    }

    @keyframes fadeIn {
        from { opacity: 0; }
        to   { opacity: 1; }
    }

    /*
     * Scroll lock — navigation.js v2.6.0 saves window.scrollY before applying
     * this class and restores it on close via body.style.top + window.scrollTo().
     */
    body.menu-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }

    /* ========================================
       SAFE AREA SUPPORT (iOS Notch / Dynamic Island)
       ======================================== */
    @supports (padding: env(safe-area-inset-top)) {
        .main-nav {
            padding-top: calc(5rem + env(safe-area-inset-top));
            padding-bottom: env(safe-area-inset-bottom);
        }
    }

    /* Smaller logo on mobile to prevent overlap with toggle */
    .logo-icon {
        width: 36px;
        height: 36px;
    }

    .logo-icon svg {
        width: 28px;
        height: 28px;
    }

    .logo-title {
        font-size: 1rem;
    }

    .logo-tagline {
        font-size: 0.6875rem;
    }
}

/* ============================================
   VERY SMALL SCREENS (≤480px)
   ============================================ */
@media (max-width: 480px) {
    .header-content {
        min-height: 56px;
        gap: 0.5rem;
    }

    .logo-icon {
        width: 32px;
        height: 32px;
    }

    .logo-icon svg {
        width: 24px;
        height: 24px;
    }

    .logo-title {
        font-size: 0.9375rem;
    }

    .logo-tagline {
        display: none;
    }

    .main-nav a {
        white-space: normal;
        word-wrap: break-word;
        word-break: break-word;
    }

    .main-nav .dropdown-menu a {
        white-space: normal;
    }
}

/* ============================================
   EXTRA SMALL SCREENS (≤360px)
   ============================================ */
@media (max-width: 360px) {
    .logo-text {
        display: none;
    }
}

/* ============================================
   FOCUS STATES (WCAG 2.2 AA)
   ============================================ */
.menu-toggle:focus-visible {
    outline: 3px solid var(--color-accent-500, #f97316);
    outline-offset: 2px;
    border-radius: 4px;
}

.main-nav a:focus-visible,
.dropdown-menu a:focus-visible {
    outline: 3px solid var(--color-accent-500, #f97316);
    outline-offset: -3px;
    z-index: 1;
}

/* ============================================
   SKIP LINK (WCAG 2.2 AA)
   Canonical definition is in 02-base.css.
   This rule is intentionally omitted here to
   avoid duplication.
   ============================================ */

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */
@media (prefers-contrast: high) {
    @media (max-width: 767px) {
        .main-nav {
            background: rgba(0, 0, 0, 0.98);
            border-left: 2px solid #ffffff;
        }

        .main-nav a {
            border-bottom: 1px solid rgba(255, 255, 255, 0.3);
        }

        .dropdown-menu {
            border-left-width: 3px;
        }
    }
}

/* ============================================
   ACCESSIBILITY - REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .main-nav,
    .menu-toggle span,
    .logo a,
    .main-nav a,
    .dropdown-menu {
        transition: none !important;
    }

    .main-nav a:hover {
        transform: none !important;
    }

    .menu-toggle[aria-expanded="true"] span:nth-child(1),
    .menu-toggle[aria-expanded="true"] span:nth-child(3) {
        transition: none;
    }

    body.menu-open::before {
        animation: none;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .site-header {
        position: static;
        background: #ffffff;
        border-bottom: 2px solid #000000;
        box-shadow: none;
    }

    .site-header::before {
        display: none;
    }

    .menu-toggle {
        display: none;
    }

    .main-nav {
        position: static;
        transform: none;
    }

    .main-nav ul {
        display: flex;
        flex-direction: row;
        gap: 1rem;
    }

    .main-nav a {
        color: #000000;
    }

    .dropdown-menu {
        display: none !important;
    }
}