/* =====================================================================
 * components/navbar.css — sticky navbar with Programs dropdown and a
 * mobile slide-in panel. No hex literals.
 *
 * State classes (toggled by app.js):
 *   .navbar--scrolled   when window.scrollY > 50
 *   .navbar--open       when mobile menu is open
 * ===================================================================== */

/* Navbar height, reserved as body padding-top below so fixed-position
 * content doesn't sit under the bar. Responsive: a bit taller on desktop
 * for the larger logo. */
:root {
    --navbar-h: 4.25rem;   /* mobile */
}
@media (min-width: 1024px) {
    :root { --navbar-h: 5rem; }   /* desktop */
}

/* The navbar is position:FIXED, not sticky. position:sticky silently fails
 * on this site because base.css sets `html, body { overflow-x: hidden }`
 * (kept, to prevent horizontal scroll); overflow-x:hidden makes <body> a
 * scroll container, so a sticky child sticks to body's scroll box and
 * scrolls away with the page. fixed is immune to ancestor overflow. The
 * bar's height is reserved via body padding-top so the hero/first section
 * starts BELOW it on load (not clipped underneath). */
body { padding-top: var(--navbar-h); }

/* So in-page anchor jumps (to the curriculum, facilities, … sections)
 * land below the fixed bar instead of hidden beneath it. */
html { scroll-padding-top: var(--navbar-h); }

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--z-sticky);
    width: 100%;
    /* Solid (opaque) background: the bar floats over scrolling content, so
     * nothing — hero imagery or page content — must bleed through. */
    background-color: var(--color-bg);
    border-bottom: 1px solid transparent;
    transition: background-color var(--transition-base),
                border-color var(--transition-base),
                box-shadow var(--transition-base);
}

.navbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-5);
    /* min-height drives the bar height (so it equals --navbar-h, which body
     * padding-top reserves); the small padding-block is just breathing room. */
    min-height: var(--navbar-h);
    padding-block: var(--space-2);
}

/* Brand is the horizontal logo image (icon + single-line wordmark; the
 * wordmark lives inside the PNG, so no adjacent text). The link is a flex
 * box so the logo sits centred in the bar. The explicit height keeps the
 * navbar from growing with the intrinsic 1280x720 image; width:auto + the
 * 16:9 HTML attrs reserve the box so there is no layout shift. */
.navbar__brand {
    display: inline-flex;
    align-items: center;
}

/* INTERIM SIZE — logo-horizontal.png has ~66% transparent VERTICAL padding
 * (the artwork fills only ~34% of the 1280x720 canvas height), so the box
 * must be large for the wordmark to read. Once the logo is re-exported
 * tightly cropped, this height can drop back to ~2.75rem. */
.navbar__logo {
    display: block;
    height: 3.25rem;
    width: auto;
}

@media (min-width: 1024px) {
    .navbar__logo { height: 4rem; }
}

.navbar__menu {
    list-style: none;
    margin: 0; padding: 0;
}

.navbar__cta-wrap {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* Hamburger button (mobile only) */
.navbar__toggle {
    width: 2.75rem;
    height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text);
    border-radius: var(--radius-md);
}

.navbar__toggle:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Belt-and-braces icon contrast: the SVG's stroke is locked to a
 * concrete token rather than left to flow through currentColor + the
 * button's inherited colour. On /home the navbar (96% opaque white)
 * sits over the near-solid midnight-navy start of the hero gradient;
 * without these explicit declarations the navy bleed-through could
 * match the icon's own navy stroke and erase the contrast (same class
 * of cascade-context bug as the .section--navy .btn fix). Setting
 * BOTH color and stroke to var(--color-text) leaves nothing to
 * inherit. */
.navbar__toggle svg {
    width: 1.5rem;
    height: 1.5rem;
    color: var(--color-text);
    stroke: var(--color-text);
}

/* Hamburger ↔ X icon swap. Default state shows the hamburger;
   when .navbar--open is on the header, the X shows instead. */
.navbar__toggle-icon--close { display: none; }
.navbar--open .navbar__toggle-icon--open  { display: none; }
.navbar--open .navbar__toggle-icon--close { display: block; }

.navbar__item        { position: relative; }
.navbar__link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    font-weight: var(--fw-medium);
    color: var(--color-text);
    border-radius: var(--radius-md);
    transition: color var(--transition-fast),
                background-color var(--transition-fast);
}

.navbar__link:hover,
.navbar__link[aria-expanded="true"] {
    color: var(--color-primary);
    background-color: var(--color-surface);
}

/* Active link — applied via the active_class() helper in PHP. The
 * brand-primary colour matches the hover state, so a hovered active
 * link does not "revert" visually; it picks up the hover background
 * and stays primary-coloured. The semibold weight is what marks it
 * as the current page even when not hovered. Applies in both the
 * desktop top nav and the mobile slide-in (same .navbar__link class). */
.navbar__link.is-active {
    color: var(--color-primary);
    font-weight: var(--fw-semibold);
}

.navbar__link .chevron {
    width: 0.875rem;
    height: 0.875rem;
    transition: transform var(--transition-fast);
}

.navbar__link[aria-expanded="true"] .chevron { transform: rotate(180deg); }

/* --- Dropdown (default — hidden state is refined per breakpoint below) --- */
.navbar__dropdown {
    list-style: none;
    margin: 0; padding: var(--space-3);
    display: none;
    min-width: 13rem;
    background-color: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.navbar__dropdown a {
    display: block;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-weight: var(--fw-medium);
}

.navbar__dropdown a:hover {
    background-color: var(--color-surface);
    color: var(--color-primary);
}

/* Active dropdown item — same active treatment as the top-level
 * .navbar__link.is-active rule. Dropdown items render as bare <a>s
 * (no .navbar__link class), so the selector is scoped to the dropdown. */
.navbar__dropdown a.is-active {
    color: var(--color-primary);
    font-weight: var(--fw-semibold);
}

/* --- Scrolled state --------------------------------------------------
 * Adds the separating shadow + hairline border once the page scrolls (the
 * .navbar--scrolled class is toggled in app.js at scrollY > 50). The bar
 * stays a constant --navbar-h height (no padding change) so the reserved
 * body padding-top never mismatches. */
.navbar--scrolled {
    border-bottom-color: var(--color-border);
    box-shadow: var(--shadow-sm);
}

/* --- Desktop layout (>= 1024px) -------------------------------------- */
@media (min-width: 1024px) {
    .navbar__menu {
        display: flex;
        align-items: center;
        gap: var(--space-1);
    }

    /* Center the top-level nav label so longer BM labels that wrap to two
     * lines (e.g. "Mengapa Tahfiz Abroad") read tidily; single-line EN
     * labels are visually unchanged. The link is an inline-flex row, so
     * justify-content centers the label+chevron group and text-align
     * centers the wrapped lines within the label. Desktop only — mobile
     * and the dropdown panel items (.navbar__dropdown a) stay left. */
    .navbar__link {
        justify-content: center;
        text-align: center;
    }

    .navbar__toggle { display: none; }

    /* Desktop dropdown: opacity/visibility instead of the bare display
     * toggle so the CLOSE can be debounced (~220ms). Combined with the
     * invisible ::before bridge below, this prevents the snap-shut
     * behaviour when the cursor crosses diagonally from "Programs" to
     * the last dropdown item — there is no longer a non-hover surface
     * for the mouse to traverse, and even if there were, the panel
     * waits before fading. Open is fast (~120ms) so the menu still
     * feels responsive on hover. */
    .navbar__dropdown {
        display: block;
        position: absolute;
        top: calc(100% + var(--space-2));
        left: 0;
        z-index: var(--z-dropdown);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 220ms ease,
                    visibility 0s linear 220ms;
    }

    /* Invisible bridge filling the 0.5rem gap between trigger and
     * panel. Sized to var(--space-2) so it stays in lock-step with the
     * `top:` offset above; if either changes, update both. No
     * background — purely a hover/focus surface so the dropdown's
     * effective hover region includes the gap. */
    .navbar__dropdown::before {
        content: "";
        position: absolute;
        top: calc(-1 * var(--space-2));
        left: 0;
        right: 0;
        height: var(--space-2);
    }

    .navbar__item--has-dropdown:hover .navbar__dropdown,
    .navbar__item--has-dropdown:focus-within .navbar__dropdown {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition: opacity 120ms ease,
                    visibility 0s linear 0s;
    }
}

/* --- Mobile slide-in panel ------------------------------------------- */
/* Wide desktops: keep every top-level label on one line (Vietnamese
 * labels such as "Trang chủ" would otherwise break into two short lines).
 * Between 1024 and 1199px the wrapping rule above still applies. */
@media (min-width: 1200px) {
    .navbar__link {
        white-space: nowrap;
    }
}

@media (max-width: 1023.98px) {
    /* Keep the hamburger tappable above the slide-in menu. The menu
     * sits at var(--z-fixed) (200); the toggle lifts to 201 so the
     * X-icon swap remains visible and the button is clickable to
     * close the menu. position:relative is required for z-index to
     * apply on an otherwise-static element. */
    .navbar__toggle {
        position: relative;
        z-index: calc(var(--z-fixed) + 1);
    }

    /* Always display:flex on mobile — visibility/opacity/pointer-events
     * control the open/closed state. Using display: none → flex prevents
     * the transform transition from running because display is not an
     * animatable property; visibility is, and combined with opacity and
     * pointer-events it gives a real slide-in animation. The visibility
     * transition is delayed on close (0s linear var(--transition-base))
     * so the panel stays interactive until the slide-out finishes. */
    .navbar__menu {
        display: flex;
        position: fixed;
        inset: 0 0 0 auto;
        width: min(20rem, 85vw);
        padding: var(--space-9) var(--space-5) var(--space-5);
        background-color: var(--color-surface-elevated);
        border-left: 1px solid var(--color-border);
        box-shadow: var(--shadow-lg);
        transform: translateX(100%);
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
        transition: transform var(--transition-base),
                    opacity var(--transition-fast),
                    visibility 0s linear var(--transition-base);
        overflow-y: auto;
        flex-direction: column;
        gap: var(--space-2);
        z-index: var(--z-fixed);
    }

    .navbar--open .navbar__menu {
        transform: translateX(0);
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
        transition: transform var(--transition-base),
                    opacity var(--transition-fast),
                    visibility 0s linear 0s;
    }

    .navbar__link {
        width: 100%;
        padding: var(--space-3);
    }

    .navbar__dropdown {
        position: static;
        margin-left: var(--space-4);
        padding: var(--space-2);
        box-shadow: none;
        border: 0;
        background-color: transparent;
    }

    .navbar__item--has-dropdown .navbar__dropdown { display: none; }
    .navbar__item--has-dropdown[data-open="true"] .navbar__dropdown { display: block; }

    /* Hide the desktop Pre-register CTA on mobile. Three nowrap items
     * (brand + CTA + 44px hamburger) in one flex row at 375px would
     * overflow and push the hamburger off-screen. The CTA is preserved as
     * the full-width .navbar-cta--block item INSIDE the slide-in menu. */
    .navbar__cta-wrap .navbar-cta { display: none; }

    /* The in-menu CTA sits a little below the last nav link. */
    .navbar__item--cta { margin-top: var(--space-3); }

    /* Square logo at the top of the slide-in panel (mobile only — the
     * element carries u-hidden-desktop, which hides it on desktop). Centred,
     * with spacing below before the first nav link. */
    .navbar__menu-logo {
        display: flex;
        justify-content: center;
        margin-bottom: var(--space-4);
    }
    .navbar__menu-logo-link { display: inline-flex; }
    .navbar__menu-logo-img {
        display: block;
        width: auto;
        max-width: 4rem;   /* 64px square logo */
        height: auto;
    }

    /* When the mobile menu is open, the WhatsApp float (z-index var(--z-fixed),
     * same stacking layer as the menu now) would otherwise sit alongside the
     * panel and visually compete with it. Hide it for the duration the menu
     * is open; the toggle adds .has-menu-open to <body> in app.js. */
    body.has-menu-open .wa-float {
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-fast);
    }

    /* Dim the page behind the open mobile menu via a fixed pseudo-
     * element on the navbar header. Sized to cover the viewport,
     * positioned BELOW the menu panel in stacking order so the menu
     * stays bright and interactive. */
    .navbar--open::before {
        content: "";
        position: fixed;
        inset: 0;
        background-color: color-mix(in srgb, var(--color-ink) 50%, transparent);
        z-index: calc(var(--z-fixed) - 1);
        pointer-events: none;
    }
}

/* =====================================================================
 * Pre-register CTA — the prominent navbar call-to-action.
 *
 * Shared by BOTH the desktop right-hand cluster and the mobile slide-in
 * menu (same .navbar-cta wrapper + .navbar-cta__btn pill). A vibrant
 * teal→accent gradient pill with bold white text, a slow shine sweep
 * gliding across the surface, and two soft sparkle dots that drift around
 * the edge to draw the eye. All motion is CSS-only and transform/opacity
 * based (GPU-friendly); it is fully disabled under prefers-reduced-motion,
 * where the button stays gradient + prominent but static.
 *
 * No hex literals: every colour is a token or a color-mix() of tokens.
 * The gradient is primary-dominant (text sits over the darker deep-teal,
 * keeping white bold text AA-legible) and brightens to the turquoise
 * accent at the trailing edge for vibrancy.
 * ===================================================================== */

/* Wrapper: carries the orbiting sparkles (its ::before / ::after) OUTSIDE
 * the pill, so it must stay overflow-visible. isolation:isolate keeps the
 * sparkle/shine stacking contained to the CTA. */
.navbar-cta {
    position: relative;
    display: inline-flex;
    isolation: isolate;
}

.navbar-cta--block {
    display: flex;
    width: 100%;
}

/* The pill. overflow:hidden clips the shine sweep to the rounded shape. */
.navbar-cta__btn {
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-5);
    font-family: var(--font-sans);
    font-size: var(--fs-md);
    font-weight: var(--fw-bold);
    letter-spacing: 0.01em;
    line-height: 1;
    white-space: nowrap;
    color: var(--color-text-inverse);
    background-image: linear-gradient(120deg,
        var(--color-primary) 0%,
        var(--color-primary) 40%,
        var(--color-accent) 100%);
    border-radius: var(--radius-pill);
    box-shadow: 0 2px 10px color-mix(in srgb, var(--color-primary) 35%, transparent);
    text-shadow: 0 1px 2px color-mix(in srgb, var(--color-ink) 35%, transparent);
    transition: transform var(--transition-fast),
                box-shadow var(--transition-fast);
}

.navbar-cta__btn--block { width: 100%; }

.navbar-cta__btn:hover {
    color: var(--color-text-inverse);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px color-mix(in srgb, var(--color-primary) 45%, transparent);
}

.navbar-cta__btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
}

/* Shine sweep: a soft diagonal highlight gliding across the pill, then a
 * long pause. Pseudo-element translated on X (GPU-friendly), clipped by
 * the button's overflow:hidden so it never spills past the rounded edge. */
.navbar-cta__btn::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 60%;
    height: 100%;
    background-image: linear-gradient(100deg,
        transparent 0%,
        color-mix(in srgb, var(--color-white) 55%, transparent) 50%,
        transparent 100%);
    transform: translateX(-180%) skewX(-18deg);
    animation: navbar-cta-shine 4.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes navbar-cta-shine {
    0%   { transform: translateX(-180%) skewX(-18deg); }
    35%  { transform: translateX(240%)  skewX(-18deg); }
    100% { transform: translateX(240%)  skewX(-18deg); }
}

/* Orbiting sparkles: two soft dots on the wrapper (overflow-visible),
 * each drifting in a small loop near the pill edge and twinkling out of
 * sync. Kept small, low-opacity and close to the pill so they never
 * reach a viewport edge or trigger horizontal scroll. */
.navbar-cta::before,
.navbar-cta::after {
    content: "";
    position: absolute;
    border-radius: var(--radius-pill);
    background-color: var(--color-white);
    pointer-events: none;
    z-index: 1;
}

.navbar-cta::before {
    width: 5px;
    height: 5px;
    top: -3px;
    right: 14%;
    box-shadow: 0 0 6px color-mix(in srgb, var(--color-white) 80%, transparent);
    animation: navbar-cta-sparkle-a 5s ease-in-out infinite;
}

.navbar-cta::after {
    width: 4px;
    height: 4px;
    bottom: -3px;
    left: 16%;
    box-shadow: 0 0 5px color-mix(in srgb, var(--color-white) 80%, transparent);
    animation: navbar-cta-sparkle-b 6s ease-in-out infinite;
}

@keyframes navbar-cta-sparkle-a {
    0%, 100% { transform: translate(0, 0)      scale(0.6); opacity: 0; }
    25%      { transform: translate(4px, 2px)  scale(1);   opacity: 0.9; }
    50%      { transform: translate(7px, 5px)  scale(0.7); opacity: 0.35; }
    75%      { transform: translate(2px, 3px)  scale(1);   opacity: 0.8; }
}

@keyframes navbar-cta-sparkle-b {
    0%, 100% { transform: translate(0, 0)        scale(0.6); opacity: 0; }
    30%      { transform: translate(-4px, -2px)  scale(1);   opacity: 0.85; }
    60%      { transform: translate(-7px, -4px)  scale(0.7); opacity: 0.35; }
    85%      { transform: translate(-2px, -3px)  scale(1);   opacity: 0.8; }
}

/* Motion-sensitive users: stop the sweep + sparkles and the hover lift;
 * the gradient pill stays prominent and static. */
@media (prefers-reduced-motion: reduce) {
    .navbar-cta__btn::before { animation: none; opacity: 0; }
    .navbar-cta::before,
    .navbar-cta::after { animation: none; opacity: 0; }
    .navbar-cta__btn:hover { transform: none; }
}
