/* The header's links. On one row while they fit comfortably beside the
   logo. When they do not, the script in base.njk adds .nav-collapsed to
   <html>, and they move into a side menu that slides in from the right,
   opened by an icon button. Without the script, they wrap. */

.site-header {
  position: relative;
}

/* with the script, the logo and the links share one row, so it can tell
   when the links stop fitting; without it, they wrap */
.js-nav .site-header__inner {
  flex-wrap: nowrap;
}

/* the button is taller than the 32 px logo; trim the header's padding so
   it stays 64 px tall. The logo still has 16 px of clear space, half the
   mark's width (section 03). */
.nav-collapsed .site-header__inner {
  padding-top: var(--doppla-space-3);
  padding-bottom: var(--doppla-space-3);
}

.site-nav {
  display: flex;
  flex: 1 1 auto;
  justify-content: flex-end;
  min-width: 0;
  font-size: var(--doppla-text-small);
}

.site-nav__list {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--doppla-space-2) var(--doppla-space-6);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* with the script, keep one row, so it can tell when they stop fitting */
.js-nav .site-nav__list {
  flex-wrap: nowrap;
}

/* Every item, links and groups alike, in the text colour, turning Slate
   on hover. The .site-nav prefix outranks site.css's dark-mode rule for
   all links, so the menu looks the same in both modes. */
.site-nav .site-nav__list a {
  white-space: nowrap;
  color: var(--doppla-ink);
  text-decoration: none;
  transition: color var(--doppla-duration-fast) var(--doppla-ease);
}

.site-nav .site-nav__list a:hover {
  color: var(--doppla-slate);
}

/* the current page: text colour, with Blue for the current state
   (section 11) as its underline */
.site-nav .site-nav__list a[aria-current="page"] {
  color: var(--doppla-ink);
  text-decoration: underline;
  text-decoration-color: var(--doppla-blue);
  text-underline-offset: 0.4em;
}

/* Icons: Material Symbols, shown at 20 or 24 px (section 14) */

.icon {
  display: block;
  flex: none;
}

/* The menu button: the icon alone, with its label for screen readers.
   It swaps between the menu and close icons as the menu opens. */

.site-nav__toggle {
  display: none;
  align-items: center;
  justify-content: center;
  /* a 40 px target around the 24 px icon */
  padding: var(--doppla-space-2);
  margin-right: calc(-1 * var(--doppla-space-2));
  border: 0;
  border-radius: var(--doppla-radius-control);
  background: transparent;
  color: var(--doppla-ink);
  cursor: pointer;
}

.site-nav__toggle .icon {
  width: var(--doppla-space-6);
  height: var(--doppla-space-6);
}

.site-nav__toggle[aria-expanded="true"] .icon--menu,
.site-nav__toggle[aria-expanded="false"] .icon--close {
  display: none;
}

.nav-collapsed .site-nav__toggle {
  display: inline-flex;
}

/* While the menu is open, the close button stays in its top-right corner
   however far the page is scrolled: it is pinned to the screen, at the
   place the button takes in the header with the page at the top (12 px
   down; 16 px in, its 8 px of padding lining the icon up with the page's
   24 px margin). */
.nav-collapsed.nav-open .site-nav__toggle {
  position: fixed;
  top: var(--doppla-space-3);
  right: var(--doppla-space-4);
  z-index: 41;
  margin-right: 0;
}

/* A group: a button that opens its links. Set like the links around it,
   with a 20 px chevron that turns over while it is open. */

.site-nav__group {
  position: relative;
}

.site-nav__group-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--doppla-space-1);
  padding: 0;
  border: 0;
  background: none;
  color: var(--doppla-ink);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--doppla-duration-fast) var(--doppla-ease);
}

.site-nav__group-toggle:hover {
  color: var(--doppla-slate);
}

.site-nav__group-toggle .icon {
  width: 20px;
  height: 20px;
  transition: transform var(--doppla-duration-default) var(--doppla-ease);
}

.site-nav__group-toggle[aria-expanded="true"] .icon {
  transform: rotate(180deg);
}

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

/* with the script, a group's links show only while it is open */
.js-nav .site-nav__sub {
  display: none;
}

.js-nav .site-nav__group-toggle[aria-expanded="true"] + .site-nav__sub {
  display: block;
}

/* On one row, a group's links drop down in a floating panel. It floats
   over the page, so it takes the brand's one shadow (section 11: menus,
   dialogs, and toasts). */
.js-nav:not(.nav-collapsed) .site-nav__sub {
  position: absolute;
  top: calc(100% + var(--doppla-space-4));
  left: calc(-1 * var(--doppla-space-4));
  z-index: 30;
  min-width: 12rem;
  padding: var(--doppla-space-2) 0;
  /* a step lighter than the page on dark (section 11); --doppla-panel is
     only defined there, so light mode falls back to Paper */
  background: var(--doppla-panel, var(--doppla-paper));
  border: 1px solid var(--doppla-hairline);
  border-radius: var(--doppla-radius-card);
  box-shadow: var(--doppla-shadow-floating);
}

.js-nav:not(.nav-collapsed) .site-nav__sub a {
  display: block;
  padding: var(--doppla-space-2) var(--doppla-space-4);
}

/* The side menu: a full-height panel that slides in from the right, over a
   dimmed page. Its first link starts below the close button. */

.nav-collapsed .site-nav__list {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  width: min(20rem, 85vw);
  flex-direction: column;
  /* start at the top: the row's flex-end, turned into a column, would push
     the links to the bottom, and in a panel shorter than its links, off
     the top where nothing can scroll to them */
  justify-content: flex-start;
  gap: 0;
  padding: calc(var(--doppla-space-16) + var(--doppla-space-4)) var(--doppla-space-6) var(--doppla-space-8);
  /* a step lighter than the page on dark (section 11); --doppla-panel is
     only defined there, so light mode falls back to Paper */
  background: var(--doppla-panel, var(--doppla-paper));
  border-left: 1px solid var(--doppla-hairline);
  box-shadow: var(--doppla-shadow-floating);
  font-size: var(--doppla-text-body);
  overflow-y: auto;
  /* scrolling past the end of the menu does not move the page */
  overscroll-behavior: contain;
  visibility: hidden;
  transform: translateX(100%);
  transition: transform var(--doppla-duration-slow) var(--doppla-ease),
              visibility 0s linear var(--doppla-duration-slow);
}

.nav-collapsed .site-nav__toggle[aria-expanded="true"] + .site-nav__list {
  visibility: visible;
  transform: none;
  transition: transform var(--doppla-duration-slow) var(--doppla-ease);
}

.nav-collapsed .site-nav__list li + li {
  border-top: 1px solid var(--doppla-hairline);
}

.nav-collapsed .site-nav__list a {
  display: block;
  padding: var(--doppla-space-3) 0;
}

/* In the menu, a group is a full-width row, and its links open beneath it,
   set in from the left */

.nav-collapsed .site-nav__group-toggle {
  justify-content: space-between;
  width: 100%;
  padding: var(--doppla-space-3) 0;
}

.nav-collapsed .site-nav__sub {
  padding: 0 0 var(--doppla-space-2) var(--doppla-space-4);
}

.nav-collapsed .site-nav__sub a {
  padding: var(--doppla-space-2) 0;
}

.nav-collapsed .site-nav__sub li + li {
  border-top: 0;
}

/* The backdrop behind the side menu. The brand sets no backdrop colour, so
   this is its dark base, #17171A (section 11), at 60%. Tapping it closes
   the menu, and the page cannot scroll behind it. */

.nav-collapsed body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgb(23 23 26 / 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--doppla-duration-slow) var(--doppla-ease),
              visibility 0s linear var(--doppla-duration-slow);
}

.nav-collapsed.nav-open body::after {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--doppla-duration-slow) var(--doppla-ease);
}

.nav-collapsed.nav-open body {
  overflow: hidden;
}

/* set while the script measures whether the links fit (see base.njk) */
.nav-measuring .site-nav,
.nav-measuring .site-nav *,
.nav-measuring body::after {
  transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .site-nav__group-toggle .icon,
  .nav-collapsed .site-nav__list,
  .nav-collapsed .site-nav__toggle[aria-expanded="true"] + .site-nav__list,
  .nav-collapsed body::after,
  .nav-collapsed.nav-open body::after {
    transition: none;
  }
}
