:root {
  /* Define this in :root because it also needs to be referenced outside this file. */
  --subheader-height: 60px;
}

.subheader {
  /* Layout */
  --subheader-item-gap: 4em;
  --subheader-searchbar-width: 300px;
  /* Typography */
  --subheader-font-size: 0.8rem;
  /* Colors */
  --color-subheader-bg: var(--color-primary-purple);
  --color-subheader-text: hsl(0 0% 100% / 1);
  --color-subheader-submenu-bg: var(--color-primary-purple);
}

.subheader {
  position: sticky; z-index: 50; top: 0;
  height: var(--subheader-height);
  font-size: var(--subheader-font-size);
  color: var(--color-subheader-text);
  background: var(--color-subheader-bg);
  @media (width < 800px) { display: none; }
}

.subheader-content {
  /* site name | menu | hours pill | search.
     The pill only renders on the Miller Library subsite; everywhere else there
     are three children and the trailing auto column collapses to zero width, so
     this is safe for all 77 sites. */
  display: grid; grid-template-columns: auto 1fr auto auto;
  width: 100%; height: 100%; max-width: 100vw;
  padding-left: 0; padding-right: 36px;
}

.subheader-site-name {
  display: flex; justify-content: center; align-items: center;
  padding: 2px 2.5rem 0 2.12rem;
  background: var(--color-primary-teal);
  color: hsl(0 0% 100% / 1);
  border-radius: 0 100px 100px 0;
  font-weight: bold;
}

.subheader-nav {
  width: 100%; height: 100%;
  max-width: calc(100vw - var(--subheader-searchbar-width));
  /* Pin the 1fr grid column to its share so items don't widen the layout
     before the overflow script runs. */
  min-width: 0;
}

.subheader ul {
  margin: 0; padding: 0;
}

.subheader li {
  /* outline: 1px solid hsl(0 100% 50% / 1); */
  display: flex; justify-content: center; align-items: center;
  position: relative;
  padding: 0 calc(var(--subheader-item-gap) / 2);
  list-style-type: none;
  cursor: pointer;
  transition: backdrop-filter ease-out 200ms;
}

.subheader li.menu-item-has-children:after {
  content: url(/wp-content/themes/wnmu/assets/imgs/icons/caret-down.svg);
  transform: scale(0.8) translate(0, 3px); filter: invert(1);
  transition: transform ease-out 200ms;
}

.subheader li:hover { backdrop-filter: brightness(1.3); }

.subheader a {
  text-decoration: none;
  color: var(--color-subheader-text);
  cursor: pointer;
}

/* Group headings ("#" parents) render as <button> — see Subheader_Walker.
   Strip the native button chrome so it reads exactly like the links beside
   it, and keep a clear keyboard focus ring (WCAG 2.4.7). */
.subheader .subheader-group-label {
  appearance: none;
  margin: 0; padding: 0;
  background: none; border: 0;
  font: inherit;
  color: var(--color-subheader-text);
  cursor: pointer;
}
.subheader .subheader-group-label:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.subheader-nav > ul {
  width: 100%; height: 100%;
  display: flex; flex-wrap: nowrap; justify-content: flex-start; align-items: center;
}

.subheader-nav > ul > li {
  --padding: 1.5%;
  height: 100%;
  padding-left: var(--padding); padding-right: var(--padding);
  flex-shrink: 0;
  white-space: nowrap;
}

/* Stretch the link's click target over the whole row, not just the text,
   so the hit area matches the li:hover highlight. The li is the
   positioning context.

   Safe for server-rendered dropdown rows because the walker flattens them:
   items with children are self-closed at depth >= 1, so every sub-menu item
   is a sibling <li>, never nested inside another. A parent's stretched
   target therefore cannot cover its own children. Top-level items keep
   their sub-menu clickable too — it is absolutely positioned below the li
   box, outside the inset:0 area. */
.subheader-nav > ul > li > a::after,
.subheader-nav > ul > li > .subheader-group-label::after,
.subheader .sub-menu li > a::after {
  content: '';
  position: absolute;
  inset: 0;
}

/* ...except inside "More". That flattening only holds for the markup PHP
   emits. When the menu is too wide for the viewport, overflow.js moves
   whole top-level items into the More dropdown carrying their own
   sub-menus, which render inline there (.sub-menu .sub-menu is static and
   always visible). A moved item therefore genuinely contains its children,
   and anything applied to that li covers the whole group: the stretched
   target swallows the children's clicks, and li:hover — which fires on
   every ancestor of whatever you point at — lights up every link in the
   group at once.

   So inside More the affordances belong to the individual link instead of
   the containing li. The group is also stacked explicitly: .subheader li
   is a row-direction flex container, which would otherwise lay a moved
   item's link and its nested <ul> side by side rather than one above the
   other. Leaf items are untouched — with no children, their li is their
   own row. */
.subheader-more .sub-menu li > a::after,
.subheader-more .sub-menu li > .subheader-group-label::after {
  content: none;
}
.subheader-more .sub-menu li.menu-item-has-children {
  flex-direction: column;
  align-items: stretch;
}
.subheader-more .sub-menu li.menu-item-has-children:hover {
  backdrop-filter: none;
}
.subheader-more .sub-menu li.menu-item-has-children > a:hover,
.subheader-more .sub-menu li.menu-item-has-children > .subheader-group-label:hover {
  backdrop-filter: brightness(1.3);
}

.subheader .sub-menu {
  display: none;
  position: absolute;
  left: 0; top: var(--subheader-height);
  width: fit-content; min-width: 240px;
  padding-top: 12px; padding-bottom: 12px;
  white-space: nowrap;
  background: var(--color-subheader-submenu-bg);
  border-top: 1px solid hsl(0 0% 100% / 0.5);
  border-radius: 0 0 10px 10px;
}

/*
   :focus-within, not :focus.

   An <li> has no tabindex, so it can never be the focused element and
   `li:focus` matched nothing — the dropdowns opened on hover only. Because the
   closed sub-menu is display:none, its links were not merely hard to reach by
   keyboard, they were not focusable at all: every second-level item in the
   subheader was unreachable without a mouse (WCAG 2.1.1, Level A).

   :focus-within matches the li while focus is on the parent link OR anything
   inside the open sub-menu, so tabbing into a group opens it and tabbing
   through the children keeps it open. It matches a strict superset of what
   `li:focus` matched (which was nothing), so this cannot regress hover.
*/
.subheader li:hover .sub-menu,
.subheader li:focus-within .sub-menu { display: block; }

.subheader li.menu-item-has-children:hover:after,
.subheader li.menu-item-has-children:focus-within:after {
  transform: scale(0.8) translate(0, 10px);
}

.subheader .sub-menu li {
  justify-content: flex-start;
  padding-top: 7px; padding-bottom: 7px;
}

/* Flatten nested sub-menus — always visible inline, no flyout */
.subheader .sub-menu .sub-menu {
  position: static;
  display: block;
  background: none;
  border: none;
  border-radius: 0;
  padding: 0;
  min-width: 0;
  width: auto;
}

/* Hide caret for nested parents since children are always visible */
.subheader .sub-menu li.menu-item-has-children::after { display: none; }

/* Depth-based indentation */
.subheader .sub-menu li.menu-depth-2 { padding-left: calc(var(--subheader-item-gap) / 2 + 1rem); }
.subheader .sub-menu li.menu-depth-3 { padding-left: calc(var(--subheader-item-gap) / 2 + 2rem); }