/* ==================================================================
   nav.css — shared mobile-nav styles for the unified <nav> partial.

   Loaded via <link rel="stylesheet" href="partials/nav.css"> on every
   page that uses partials/nav.html. Desktop nav rules still live in
   each page's inline <style> block (those are intentionally untouched
   for now — this file only adds the bits that didn't exist before).

   Adds:
     - .nav-toggle (hamburger button, hidden above 768)
     - mobile drop-down panel for .nav-links when [data-nav-open="true"]
     - mobile rendering for the partnerships sub-menu (always-visible
       flat list inside the panel)
     - body scroll lock while the panel is open

   Toggle is wired by site.js → wireMobileMenu().
   ================================================================ */

/* ===================================================================
   Desktop dropdown (Partnerships) — single source of truth for all pages.
   Mobile rules in the @media block below override these.
   =================================================================== */

.nav-dd { position: relative; }

.nav-dd > button {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 100px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color .18s ease, background .18s ease;
}
.nav-dd > button svg {
  width: 11px;
  height: 11px;
  transition: transform .25s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-dd:hover > button,
.nav-dd.is-open > button {
  color: var(--text-primary);
  background: var(--muted);
}
.nav-dd:hover > button svg,
.nav-dd.is-open > button svg {
  transform: rotate(180deg);
}

.nav-dd-menu {
  position: absolute;
  top: calc(100% + 8px);
  /* Align the menu's right edge to the trigger's right edge so it opens
     leftward — keeps it inside the viewport when the trigger is near the
     right edge of the nav (e.g. Partnerships). */
  right: 0;
  left: auto;
  min-width: 340px;
  background: var(--background);
  border: 1px solid var(--surface-border);
  border-radius: 14px;
  box-shadow:
    0 24px 48px -16px rgba(0, 0, 0, 0.14),
    0 4px 12px rgba(0, 0, 0, 0.04);
  padding: 14px 10px 10px;
  display: none;
  z-index: 51;
}

/* Invisible bridge that covers the 8px gap between the trigger and the menu
   so a mouse moving between them keeps the hover active. */
.nav-dd-menu::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  height: 12px;
}

.nav-dd:hover .nav-dd-menu,
.nav-dd:focus-within .nav-dd-menu,
.nav-dd.is-open .nav-dd-menu {
  display: block;
}

/* Small category label inside the menu (e.g. "Programmes"). */
.nav-dd-header {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  padding: 0 14px 8px;
  margin-bottom: 4px;
}

.nav-dd .nav-dd-menu a {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  text-decoration: none;
  transition: background .15s ease;
}
.nav-dd .nav-dd-menu a:hover { background: var(--muted); }

.nav-dd-menu .ic {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.nav-dd-menu .ic svg {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
}
.nav-dd-menu .title {
  font-size: 14.5px;
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  letter-spacing: -0.1px;
  line-height: 1.3;
}
.nav-dd-menu .sub {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 3px;
  line-height: 1.4;
}

/* Hamburger button — hidden by default; revealed under the nav-mobile breakpoint. */
.nav-toggle {
  display: none;
  width: 36px;
  height: 36px;
  margin-left: 4px;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: var(--background);
  color: var(--text-primary);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
.nav-toggle:hover { background: var(--muted); }
.nav-toggle svg { width: 18px; height: 18px; display: block; }

@media (max-width: 768px) {
  .nav-toggle { display: inline-flex; }

  /* Make the nav-inner a positioning context so the panel anchors to it. */
  .nav .nav-inner { position: relative; }

  /* Push the toggle to the right side of the nav-inner. */
  .nav .nav-toggle { margin-left: auto; }

  /* Hide the auth CTAs from the mobile navbar — they're available inside
     the menu instead. The selector targets .nav-right ONLY when it's a
     direct child of .nav-inner; once site.js moves it into .nav-links the
     selector stops matching and the in-panel rules below take over. */
  .nav .nav-inner > .nav-right { display: none; }

  /* The mobile panel: turn .nav-links into a full-width drop-down below the nav. */
  .nav .nav-links {
    /* override the per-page inline rule that hides this on mobile */
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 6px 18px 14px;
    background: var(--background);
    border-top: 1px solid var(--surface-border);
    border-bottom: 1px solid var(--surface-border);
    box-shadow: 0 18px 36px -18px rgba(0, 0, 0, 0.18);
    z-index: 50;
    max-height: calc(100dvh - 64px);
    overflow-y: auto;
  }
  .nav[data-nav-open="true"] .nav-links { display: flex; }

  /* Each top-level link in the panel becomes a tappable row. */
  .nav .nav-links > a {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 14px 8px;
    border-radius: 0;
    border-bottom: 1px solid var(--surface-border);
    font-size: var(--text-md);
    color: var(--text-primary);
  }
  .nav .nav-links > a:hover { background: var(--muted); }

  /* Partnerships becomes a click-toggleable accordion inside the panel. */
  .nav .nav-links .nav-dd {
    display: flex;
    flex-direction: column;
    width: 100%;
  }
  .nav .nav-links .nav-dd > button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 8px;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--surface-border);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--text-md);
    font-weight: var(--font-weight-normal);
    text-transform: none;
    letter-spacing: normal;
    cursor: pointer;
    text-align: left;
  }
  .nav .nav-links .nav-dd > button:hover { background: var(--muted); }
  .nav .nav-links .nav-dd > button svg {
    display: block;
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
    transition: transform .2s;
    flex-shrink: 0;
  }
  .nav .nav-links .nav-dd > button[aria-expanded="true"] svg {
    transform: rotate(180deg);
  }

  /* Default the sub-menu to collapsed and override desktop's
     :hover/:focus-within rules so they don't reveal it on touch. */
  .nav .nav-links .nav-dd .nav-dd-menu,
  .nav .nav-links .nav-dd:hover .nav-dd-menu,
  .nav .nav-links .nav-dd:focus-within .nav-dd-menu {
    display: none;
    flex-direction: column;
    position: static;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    min-width: 0;
  }
  /* Reveal sub-menu only when the section has been clicked open. */
  .nav .nav-links .nav-dd.is-open .nav-dd-menu { display: flex; }

  /* Hide the floating-menu spacer pseudo-element (it bridges the hover gap on desktop). */
  .nav .nav-links .nav-dd-menu::before { display: none; }

  /* Hide the desktop category label inside the mobile accordion. */
  .nav .nav-links .nav-dd-header { display: none; }

  .nav .nav-links .nav-dd-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 8px 12px 20px;
    border-radius: 0;
    border-bottom: 1px solid var(--surface-border);
  }
  .nav .nav-links .nav-dd-menu a:hover { background: var(--muted); }
  .nav .nav-links .nav-dd-menu .ic { width: 24px; height: 24px; flex-shrink: 0; }
  .nav .nav-links .nav-dd-menu .ic svg { width: 14px; height: 14px; }
  .nav .nav-links .nav-dd-menu .title { font-size: 14px; }
  .nav .nav-links .nav-dd-menu .sub { font-size: var(--text-xs); }

  /* When the menu opens, site.js moves .nav-right INTO .nav-links so the
     buttons sit beneath the links (rather than overlapping the panel).
     Render the moved cluster as a stacked vertical button group with a
     subtle separator above it. */
  .nav .nav-links > .nav-right {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: 100%;
    margin: 0;
    padding-top: 14px;
  }
  .nav .nav-links > .nav-right .btn {
    width: 100%;
    height: 42px;
    align-self: stretch;
    justify-content: center;
    border-radius: 10px;
  }
  /* Each page's inline mobile CSS hides .nav-right .btn-ghost (the Log in
     button) — override that override now that .nav-right lives inside the
     panel and should show every CTA. */
  .nav .nav-links > .nav-right .btn-ghost { display: inline-flex; }

  /* Toggle icon swap based on aria-expanded. */
  .nav-toggle .icon-close { display: none; }
  .nav-toggle[aria-expanded="true"] .icon-open { display: none; }
  .nav-toggle[aria-expanded="true"] .icon-close { display: block; }

  /* Lock body scroll while menu is open. */
}

/* Body scroll lock — applied via JS by adding .nav-open class on <body>. */
body.nav-open { overflow: hidden; }

/* Desktop safety: ensure the nav-toggle never appears above the breakpoint,
   even if data-nav-open lingers from a resize. */
@media (min-width: 769px) {
  .nav .nav-toggle { display: none; }
  /* When site.js moves .nav-right back to its original spot above 768, the
     stacked-button overrides above don't apply anymore (selector requires
     .nav-right to be a child of .nav-links). Nothing else to undo here. */
}
