/* ==========================================================================
   Permedjat — shared navigation layer (Phase F-NAV)
   Additive stylesheet: scoped to the shared header/footer only. Existing
   site.css/legal.css tokens, fonts and components are preserved untouched —
   this file only styles the new .nav-* hooks and lays out the shared menu.
   Brand purple #6E4FCB (var(--teal)) on the existing papyrus/ink ground.
   No-JS contract: the mobile menu is a native checkbox + label and every
   dropdown is a native <details>/<summary>, so keyboard (Tab/Space, and
   Enter/Space on summaries), touch and mouse all work with scripting
   disabled. The small navigation.js module only ADDS Escape/outside-close
   behaviour; it never hides a menu on its own.
   ========================================================================== */

/* ---- Mobile menu toggle (checkbox + label, no-JS operable) ----
   A closed <details> cannot be forced visible by author CSS in Blink
   (verified: content sizes to zero), so the menu uses a native checkbox:
   Tab reaches it, Space toggles it, clicking the label toggles it — all
   with scripting disabled. Desktop hides the toggle and shows the bar. */

.nav-check {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
}

.nav-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  color: var(--papyrus);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 16px;
  border: 1px solid rgba(241, 223, 182, 0.35);
  border-radius: 999px;
  background: transparent;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.nav-menu-toggle::before {
  content: "";
  inline-size: 16px;
  block-size: 12px;
  flex: none;
  border-block-start: 2px solid currentColor;
  border-block-end: 2px solid currentColor;
  background:
    linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat;
}

.nav-menu-toggle:hover {
  border-color: rgba(241, 223, 182, 0.7);
}

.nav-check:focus-visible + .nav-menu-toggle {
  outline: 2px solid #ac9fd4;
  outline-offset: 2px;
}

/* ---- Shared nav list ---- */

.site-header .site-nav {
  gap: 8px 22px;
}

.site-header .site-nav > a,
.site-header .nav-group > summary {
  padding-block: 10px;
  line-height: 1.4;
}

/* Grouped dropdowns: native details, no ARIA menu semantics needed. */
.nav-group {
  position: relative;
}

.nav-group > summary {
  list-style: none;
  cursor: pointer;
  color: rgba(241, 223, 182, 0.72);
  font-size: 15px;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}

.nav-group > summary::-webkit-details-marker {
  display: none;
}

.nav-group > summary::marker {
  content: "";
}

.nav-group > summary::after {
  content: "";
  display: inline-block;
  inline-size: 7px;
  block-size: 7px;
  margin-inline-start: 7px;
  border-inline-end: 2px solid currentColor;
  border-block-end: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

html[dir="rtl"] .nav-group > summary::after {
  margin-inline-start: 7px;
}

.nav-group > summary:hover {
  color: var(--papyrus);
}

.nav-group > summary:focus-visible,
.site-header .site-nav > a:focus-visible {
  outline: 2px solid #ac9fd4;
  outline-offset: 2px;
  border-radius: 4px;
}

.nav-group-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.nav-group-panel a {
  padding-block: 7px;
  white-space: normal;
}

.nav-group[open] > summary {
  color: var(--papyrus);
}

/* Current page marker inside the shared nav. */
.site-header .site-nav a[aria-current="page"] {
  color: var(--papyrus);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 5px;
}

/* ---- Small screens: stacked menu panel, no horizontal overflow ---- */

@media (max-width: 900px) {
  .site-header .shell {
    flex-wrap: wrap;
    height: auto;
    min-height: 66px;
    padding-block: 8px;
    row-gap: 0;
  }

  /* The checkbox owns the row; the panel drops below it. */
  .nav-menu-toggle {
    order: 2;
    margin-inline-start: auto;
    padding: 8px 14px;
    font-size: 14px;
  }

  /* Closed menu: panel hidden. Open menu: full-width stacked list. */
  .nav-check:not(:checked) ~ .site-nav {
    display: none;
  }

  /* Closed-menu row stability: while the mobile menu is closed the
     header row must never wrap — a font-swap width transient otherwise
     grows the shell and shifts the page (measured 0.24 CLS on 390px).
     :has() applies from first paint (no JS timing shift) and keeps
     working without JS; the open menu keeps wrapping (its panel needs
     the full row). The brand text absorbs any overflow with an
     ellipsis; older browsers without :has keep the old wrapping. */
  .site-header .shell:has(> input.nav-check:not(:checked)) {
    flex-wrap: nowrap;
  }
  .site-header .shell:has(> input.nav-check:not(:checked)) .brand {
    flex-shrink: 1;
    min-width: 0;
  }
  .site-header .shell:has(> input.nav-check:not(:checked)) .brand span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  /* 44px minimum touch targets on the mobile menu controls (box-sizing
     is border-box globally, so this is the full rendered height). */
  .nav-menu-toggle {
    min-block-size: 44px;
  }

  .nav-check:checked ~ .site-nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    flex: 1 1 100%;
    order: 10;
    margin: 0;
    padding-block: 6px 10px;
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px);
    overflow-y: auto;
    overflow-x: hidden;
  }

  .nav-check:checked ~ .site-nav > a,
  .nav-group > summary {
    min-block-size: 44px;
    padding-block: 11px;
    border-block-start: 1px solid rgba(241, 223, 182, 0.14);
  }

  .nav-group-panel {
    padding-inline-start: 14px;
    border-inline-start: 2px solid rgba(172, 159, 212, 0.55);
    margin-block: 2px 8px;
  }

  .nav-group-panel a {
    min-block-size: 44px;
    padding-block: 8px;
  }
}

/* ---- Wide screens: inline bar with floating group panels ---- */

@media (min-width: 901px) {
  /* Toggle never shows on desktop; the bar is always visible, even
     with scripting disabled (no closed-details override needed). */
  .nav-check,
  .nav-menu-toggle {
    display: none;
  }

  .site-header .site-nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px 20px;
    margin-inline-start: auto;
    flex-wrap: wrap;
    row-gap: 2px;
  }

  .nav-group > .nav-group-panel {
    position: absolute;
    inset-block-start: calc(100% + 10px);
    inset-inline-start: 0;
    z-index: 60;
    min-width: 15rem;
    max-width: min(22rem, calc(100vw - 2rem));
    padding: 10px 14px;
    border-radius: 14px;
    border: 1px solid rgba(48, 26, 115, 0.35);
    background: var(--teal-abyss);
    box-shadow: 0 18px 44px rgba(34, 19, 78, 0.45);
  }

  .nav-group:not([open]) > .nav-group-panel {
    display: none;
  }
}

/* ---- Shared footer: four balanced groups, no overflow ---- */

.site-footer .footer-groups {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 28px 24px;
}

.site-footer .footer-group nav {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-start;
}

.site-footer .footer-group a {
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  .site-footer .footer-groups {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .site-footer .footer-groups {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---- Motion ---- */

@media (prefers-reduced-motion: reduce) {
  .site-header .site-nav a,
  .nav-group > summary,
  .nav-menu-toggle,
  .site-footer .footer-group a {
    transition: none;
  }

  html {
    scroll-behavior: auto;
  }
}
