/* =========================================================================
   Primary navigation: three levels.
   Enqueued AFTER main.css, so every navigation rule lives here, mobile ones
   included. Splitting them across files lets a base rule here override a
   mobile rule there and pin the menu open.
   ========================================================================= */

.nav { display: flex; align-items: center; gap: 26px; }

.nav__list {
  display: flex;
  align-items: center;
  gap: 26px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.nav__list > li { position: relative; }

.nav a {
  font-size: 0.93rem;
  font-weight: 400;
  color: var(--muted);
  transition: color .16s ease;
  white-space: nowrap;
}

/* Every top-level item shares one box model so the caret on a dropdown
   trigger cannot shift its baseline against the plain links. */
.nav__list > li > a { display: inline-flex; align-items: center; line-height: 1.4; }

.nav a:hover,
.nav a[aria-current="page"],
.nav .current-menu-item > a,
.nav .current-menu-parent > a,
.nav .current-menu-ancestor > a { color: var(--ink); }

.nav .btn { font-size: 0.9rem; padding: 12px 18px; color: #0D0D0D; }
.nav .btn:hover { color: #0D0D0D; }

/* ---------- Dropdowns ----------
   Open on hover and on keyboard focus via :focus-within, so every level is
   reachable by tab without any script. */
.menu-item-has-children > a { gap: 7px; }
.menu-item-has-children > a::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform .18s ease;
  flex: none;
}
.nav__list > .menu-item-has-children:hover > a::after,
.nav__list > .menu-item-has-children:focus-within > a::after {
  transform: translateY(1px) rotate(225deg);
}

.sub-menu {
  position: absolute;
  top: calc(100% + 16px);
  left: -14px;
  min-width: 214px;
  margin: 0;
  padding: 8px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  display: grid;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity .18s ease, transform .18s ease, visibility .18s;
  z-index: 70;
}

/* Keeps the pointer inside the menu while crossing the gap below the trigger. */
.sub-menu::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -16px;
  height: 16px;
}

.menu-item-has-children:hover > .sub-menu,
.menu-item-has-children:focus-within > .sub-menu {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.sub-menu li { position: relative; }
.sub-menu a {
  display: block;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
  color: var(--muted);
}
.sub-menu a:hover,
.sub-menu a:focus-visible { background: var(--panel); color: var(--ink); }

/* ---------- Third level: School opens sideways ---------- */
.sub-menu .menu-item-has-children > a {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
/* Caret points the way the panel travels. */
.sub-menu .menu-item-has-children > a::after {
  transform: translateY(0) rotate(-45deg);
}
.sub-menu .menu-item-has-children:hover > a::after,
.sub-menu .menu-item-has-children:focus-within > a::after {
  transform: translateY(0) rotate(-45deg) translate(2px, 2px);
}

.sub-menu .sub-menu {
  top: -9px;
  left: calc(100% + 7px);
  transform: translateX(-6px);
}
.sub-menu .menu-item-has-children:hover > .sub-menu,
.sub-menu .menu-item-has-children:focus-within > .sub-menu {
  transform: none;
}
/* Bridge sits on the side here, not above. */
.sub-menu .sub-menu::before {
  left: -7px;
  right: auto;
  top: 0;
  bottom: 0;
  width: 7px;
  height: auto;
}
/* Flipped by script when the panel would leave the viewport. */
.sub-menu .sub-menu.is-flipped {
  left: auto;
  right: calc(100% + 7px);
  transform: translateX(6px);
}
.sub-menu .menu-item-has-children:hover > .sub-menu.is-flipped,
.sub-menu .menu-item-has-children:focus-within > .sub-menu.is-flipped {
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .sub-menu { transition: none; }
  .menu-item-has-children > a::after { transition: none; }
}

/* ---------- Mobile ----------
   The bar collapses to a toggled panel and every dropdown becomes an indented
   stack that is always open, so no extra tap is needed to reach a category. */
@media (max-width: 1080px) {
  .nav { gap: 20px; }
  .nav__list { gap: 20px; }
  .nav a { font-size: 0.88rem; }
}

@media (max-width: 900px) {
  .nav-toggle { display: block; }

  .nav {
    position: absolute;
    top: 76px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--hairline);
    padding: var(--space-sm) var(--gutter) var(--space-md);
    display: none;
    max-height: calc(100svh - 76px);
    overflow-y: auto;
  }
  .nav.is-open { display: flex; }

  .nav__list {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
  }
  .nav__list > li { position: static; }
  .nav a { display: block; font-size: 0.95rem; padding: 13px 0; border-bottom: 1px solid var(--hairline); }
  .nav__list > li > a { display: flex; justify-content: space-between; }
  .nav .btn {
    margin-top: var(--space-sm);
    border-bottom: 0;
    justify-content: center;
    width: auto;
    display: inline-flex;
    font-size: 0.95rem;
    padding: 15px 20px;
  }

  .menu-item-has-children > a::after { transform: translateY(0) rotate(45deg); }
  .sub-menu .menu-item-has-children > a::after { transform: translateY(0) rotate(45deg); }

  .sub-menu,
  .sub-menu .sub-menu,
  .sub-menu .sub-menu.is-flipped {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    background: transparent;
    border: 0;
    border-left: 2px solid var(--panel);
    border-radius: 0;
    margin: 0 0 10px 8px;
    padding: 0 0 0 14px;
    gap: 0;
    min-width: 0;
    left: auto;
    right: auto;
    top: auto;
  }
  .sub-menu::before { display: none; }
  .sub-menu a { padding: 11px 0; border-bottom: 1px solid var(--hairline); }
  .sub-menu .sub-menu { border-left-color: var(--accent); }
  .sub-menu li:last-child > a { border-bottom: 0; }
}
