/* ==========================================================================
   Home header — mobile navigation drawer
   --------------------------------------------------------------------------
   Below 992px the header's #navbarNav stops being a Bootstrap collapse that
   pushes the page down and becomes a sheet that slides in from the leading
   edge. Above 992px nothing here applies and the bar is untouched.

   Paired with public/js/home-nav-drawer.js, which owns the open state.
   ========================================================================== */

:root {
    --qnav-width: min(88vw, 340px);
    --qnav-radius: 26px;
    /* Fast out of the gate, long settle — reads as weight rather than speed. */
    --qnav-ease: cubic-bezier(.32, .72, 0, 1);
    --qnav-in: 420ms;
    --qnav-out: 300ms;
    --qnav-green: #165D31;
}

/* ==========================================================================
   Burger
   ========================================================================== */

.qnav-burger {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 14px;
    background: #F5F7F5;
    color: #1F2A23;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 200ms ease, transform 200ms var(--qnav-ease);
}

.qnav-burger:focus,
.qnav-burger:focus-visible {
    box-shadow: none;
    outline: 2px solid var(--qnav-green);
    outline-offset: 2px;
}

.qnav-burger:active { transform: scale(.93) }

/* Bars are drawn here rather than shipped as an icon so they can morph. */
.qnav-burger-icon {
    display: block;
    position: relative;
    width: 20px;
    height: 14px;
    pointer-events: none;
}

.qnav-burger-icon > span {
    position: absolute;
    inset-inline: 0;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    transition: transform var(--qnav-out) var(--qnav-ease),
                opacity 150ms linear;
}

.qnav-burger-icon > span:nth-child(1) { top: 0 }
.qnav-burger-icon > span:nth-child(2) { top: 6px; width: 68% }
.qnav-burger-icon > span:nth-child(3) { top: 12px }

/* Open: the outer bars cross, the middle one dissolves. */
.qnav-burger[aria-expanded="true"] {
    background: var(--qnav-green);
    color: #fff;
}
.qnav-burger[aria-expanded="true"] .qnav-burger-icon > span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}
.qnav-burger[aria-expanded="true"] .qnav-burger-icon > span:nth-child(2) {
    opacity: 0;
    transform: scaleX(.2);
}
.qnav-burger[aria-expanded="true"] .qnav-burger-icon > span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

.active-dark-mode .qnav-burger {
    background: #2A2A2A;
    color: #E8E8E8;
}

/* ==========================================================================
   Scrim
   ========================================================================== */

.qnav-scrim {
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(10, 22, 15, .5);
    -webkit-backdrop-filter: blur(3px) saturate(.9);
    backdrop-filter: blur(3px) saturate(.9);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--qnav-out) ease, visibility 0s linear var(--qnav-out);
}

.qnav-scrim.is-visible {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--qnav-in) ease, visibility 0s;
}

@media (min-width: 992px) {
    /* Desktop never opens the drawer, so the scrim must not be in the way. */
    .qnav-scrim { display: none }
}

/* Chrome/Safari keep scrolling the page under a fixed drawer without this. */
html.qnav-open,
html.qnav-open body {
    overscroll-behavior: none;
}

/* `.rbt-header` is `z-index: 99`, which makes it a stacking context: the
   drawer lives inside it and so cannot out-stack a scrim that sits outside.
   Lifting the whole header above the scrim while the drawer is open is what
   puts the two in the right order — and it keeps the burger tappable, so a
   second tap still closes. */
html.qnav-open .rbt-header {
    z-index: 1050;
}

/* ==========================================================================
   The sheet
   ========================================================================== */

@media (max-width: 991.98px) {

    /* Bootstrap hides an un-shown .collapse outright, which would make the
       slide-in impossible. The panel is instead always laid out and parked
       off-canvas, with visibility keeping it out of the tab order. */
    #navbarNav.collapse:not(.show),
    #navbarNav {
        display: flex !important;
        position: fixed;
        top: 0;
        bottom: 0;
        z-index: 1041;
        flex-direction: column;
        align-items: stretch;
        width: var(--qnav-width);
        max-width: 100vw;
        height: 100%;
        margin: 0 !important;
        padding: 0 0 max(20px, env(safe-area-inset-bottom));
        overflow-y: auto;
        overflow-x: hidden;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        background: #fff;
        border-top: 0 !important;
        visibility: hidden;
        transition: transform var(--qnav-out) var(--qnav-ease),
                    visibility 0s linear var(--qnav-out);
        will-change: transform;
    }

    /* Only the edge facing the page is rounded. */
    html[dir="rtl"] #navbarNav {
        right: 0;
        left: auto;
        border-radius: var(--qnav-radius) 0 0 var(--qnav-radius);
        transform: translateX(calc(100% + 24px));
    }

    html[dir="ltr"] #navbarNav {
        left: 0;
        right: auto;
        border-radius: 0 var(--qnav-radius) var(--qnav-radius) 0;
        transform: translateX(calc(-100% - 24px));
    }

    /* `--qnav-drag` is what the swipe gesture writes to; it is 0 for a plain
       open, so one rule covers both. */
    html[dir="rtl"] #navbarNav.qnav-drawer-open,
    html[dir="ltr"] #navbarNav.qnav-drawer-open {
        transform: translateX(var(--qnav-drag, 0px));
        visibility: visible;
        box-shadow: 0 0 0 1px rgba(15, 35, 25, .04),
                    0 26px 64px -14px rgba(9, 30, 20, .34);
        transition: transform var(--qnav-in) var(--qnav-ease), visibility 0s;
    }

    /* While a finger is down the panel tracks it 1:1. */
    #navbarNav.is-dragging {
        transition: none !important;
    }

    #navbarNav::-webkit-scrollbar { width: 4px }
    #navbarNav::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, .14);
        border-radius: 4px;
    }

    /* ---- Sheet header (stays put while the body scrolls) ---------------- */
    .qnav-drawer-head {
        position: sticky;
        top: 0;
        z-index: 2;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: max(14px, env(safe-area-inset-top)) 18px 14px;
        background: rgba(255, 255, 255, .9);
        -webkit-backdrop-filter: blur(12px);
        backdrop-filter: blur(12px);
        border-bottom: 1px solid #EFF2EF;
    }

    .qnav-drawer-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        text-decoration: none;
    }

    .qnav-drawer-brand img {
        width: 42px;
        height: 42px;
        object-fit: contain;
    }

    .qnav-drawer-brand-text {
        display: flex;
        flex-direction: column;
        line-height: 1.3;
    }

    .qnav-drawer-brand-name {
        font-size: 15px;
        font-weight: 600;
        color: #16211A;
    }

    .qnav-drawer-brand-sub {
        font-size: 11px;
        font-weight: 300;
        color: #8C948F;
    }

    .qnav-drawer-close {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 38px;
        width: 38px;
        height: 38px;
        padding: 0;
        border: none;
        border-radius: 12px;
        background: #F2F4F2;
        color: #48524C;
        cursor: pointer;
        transition: background 180ms ease, transform 180ms var(--qnav-ease);
    }

    .qnav-drawer-close svg { width: 18px; height: 18px }

    .qnav-drawer-close:active {
        transform: scale(.92);
        background: #E7EAE7;
    }

    /* ---- Section labels -------------------------------------------------- */
    .qnav-label {
        display: block;
        margin: 22px 18px 10px;
        font-size: 11px;
        font-weight: 600;
        letter-spacing: .08em;
        text-transform: uppercase;
        color: #9AA39D;
    }

    /* ---- Audience switcher ---------------------------------------------- */
    .navbar-nav.qnav-tabs {
        flex-direction: column !important;
        gap: 6px !important;
        margin: 0 !important;
        padding: 0 14px;
    }

    /* The rows carry inline `height` and a pill `border-radius` from the
       desktop bar, so those two need !important to become list rows. */
    .qnav-tabs .user-type-tab,
    .qnav-tabs > a {
        width: 100%;
        height: auto !important;
        min-height: 48px;
        padding: 12px 14px !important;
        border-radius: 14px !important;
        font-size: 15px !important;
        justify-content: flex-start !important;
        background: transparent !important;
        transition: background 180ms ease, transform 180ms var(--qnav-ease);
    }

    .qnav-tabs .user-type-tab:active,
    .qnav-tabs > a:active {
        transform: scale(.985);
        background: #F2F6F3 !important;
    }

    /* The inline styles that the tab script writes are colour-only, so the
       selected row still needs its own treatment here. */
    .qnav-tabs .user-type-tab.active {
        position: relative;
        background: #EDF5F0 !important;
        color: var(--qnav-green) !important;
    }

    .qnav-tabs .user-type-tab.active span { color: var(--qnav-green) }

    .qnav-tabs .user-type-tab.active::before {
        content: "";
        position: absolute;
        inset-inline-start: 0;
        top: 50%;
        width: 3px;
        height: 20px;
        background: var(--qnav-green);
        border-radius: 3px;
        transform: translateY(-50%);
    }

    /* ---- Account actions --------------------------------------------------
       A two-column grid: the CTAs span it, the two utility tiles share the
       last row. Source order puts the theme toggle first, so `order` does
       the rearranging. */
    .navbar-nav.qnav-actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px !important;
        margin: 0 !important;
        padding: 0 14px;
    }

    .qnav-actions > * { min-width: 0 !important }

    .qnav-actions .subscribe-cta {
        grid-column: 1 / -1;
        order: 1;
        justify-content: center;
        width: 100%;
    }

    .qnav-actions .register-btn {
        grid-column: 1 / -1;
        order: 2;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .qnav-actions .login-btn {
        grid-column: 1 / -1;
        order: 3;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #fff;
    }

    /* Theme + language: matching tiles on the closing row. */
    .qnav-actions .qnav-theme { order: 4 }
    .qnav-actions .qnav-lang { order: 5 }

    .qnav-actions .qnav-theme,
    .qnav-actions .qnav-lang {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 6px;
        width: 100% !important;
        height: auto !important;
        min-height: 68px;
        padding: 12px 8px !important;
        border: 1px solid #E8ECE9 !important;
        border-radius: 16px;
        background: #FBFCFB !important;
        text-decoration: none;
    }

    .qnav-actions .qnav-theme img {
        width: 22px !important;
        height: 22px;
        object-fit: contain;
    }

    .qnav-tile-label {
        font-size: 12px;
        font-weight: 400;
        color: #5B655F;
    }

    /* ---- Dark mode ------------------------------------------------------- */
    .active-dark-mode #navbarNav { background: #1A1A1A }

    .active-dark-mode .qnav-drawer-head {
        background: rgba(26, 26, 26, .92);
        border-bottom-color: #2C2C2C;
    }

    .active-dark-mode .qnav-drawer-brand-name { color: #fff }
    .active-dark-mode .qnav-label { color: #7E867F }

    .active-dark-mode .qnav-drawer-close {
        background: #2C2C2C;
        color: #C7C7C7;
    }

    .active-dark-mode .qnav-tabs .user-type-tab:active,
    .active-dark-mode .qnav-tabs > a:active {
        background: #262626 !important;
    }

    .active-dark-mode .qnav-tabs .user-type-tab.active {
        background: #1E3227 !important;
        color: #8FD3AC !important;
    }

    .active-dark-mode .qnav-tabs .user-type-tab.active span { color: #8FD3AC }
    .active-dark-mode .qnav-tabs .user-type-tab.active::before { background: #8FD3AC }

    .active-dark-mode .qnav-actions .qnav-theme,
    .active-dark-mode .qnav-actions .qnav-lang {
        border-color: #2E2E2E !important;
        background: #242424 !important;
    }

    .active-dark-mode .qnav-tile-label { color: #B3B3B3 }
    .active-dark-mode .qnav-actions .login-btn { background: transparent !important }

    .active-dark-mode #navbarNav.qnav-drawer-open {
        box-shadow: 0 26px 64px -14px rgba(0, 0, 0, .65);
    }
}

/* The open and closed states still read without the motion. */
@media (prefers-reduced-motion: reduce) {
    #navbarNav,
    .qnav-scrim,
    .qnav-burger-icon > span {
        transition-duration: 1ms !important;
    }
}
