/* Shared disclosure navigation: mouse, keyboard, touch and pen use one state. */
#navigation {
  z-index: var(--ui-layer-navigation);
  box-sizing: border-box;
  width: 100%;
  padding-inline-end: env(safe-area-inset-right);
  padding-inline-start: env(safe-area-inset-left);
  background: var(--color-nav-background);
  -webkit-user-select: none;
  user-select: none;
}

#navigation .first_level {
  overflow: auto;
  scrollbar-width: none;
}

#navigation .first_level::-webkit-scrollbar {
  display: none;
}

#navigation .first_level > ul {
  display: flex;
  box-sizing: border-box;
  width: max-content;
  min-width: 100%;
  margin: 0;
  /* The first item and its menu touch the bar's start edge. */
  padding-block: 0;
  padding-inline: 0 var(--ui-space-2);
  list-style: none;
}

/* DPG's navigation: compact, lowercase and flat; the current section keeps
   the raised surface. Menus still open on hover, click, tap and keyboard. */
#navigation .first_level button,
#navigation .second_level a {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  min-height: var(--ui-nav-height);
  padding: var(--ui-space-2) var(--ui-nav-item-inline);
  color: var(--color-nav-text);
  font: inherit;
  font-size: var(--ui-font-size-label);
  line-height: 18px;
  text-align: start;
  text-decoration: none;
  text-transform: lowercase;
  background: transparent;
  border: 0;
  cursor: pointer;
}

#navigation .first_level button {
  white-space: nowrap;
}

#navigation .first_level button[aria-current],
#navigation .first_level button[aria-expanded='true'],
#navigation .first_level button:hover {
  color: var(--color-nav-text-hover);
  background: var(--color-nav-surface);
}

@media (any-pointer: coarse) {
  #navigation .second_level a {
    min-height: var(--ui-touch-target);
  }
}

#navigation .second_level > ul {
  --navigation-menu-surface: var(--color-nav-surface);

  position: fixed;
  /* The menu may be a popover (initialiser.js): its position comes from the
     top and start the script sets, not the popover's centring defaults. */
  inset: auto;
  inset-block-start: var(--navigation-menu-top);
  inset-inline-start: var(--navigation-menu-start);
  z-index: var(--ui-layer-navigation);
  display: none;
  box-sizing: border-box;
  width: max-content;
  /* As wide as its longest item, and never narrower than its tab. */
  min-width: min(var(--navigation-trigger-width, 0px), calc(100vw - 16px));
  max-width: min(360px, calc(100vw - 16px));
  height: auto;
  /* At most the window's remaining height. */
  max-height: var(--navigation-available-height, 60dvh);
  margin: 0;
  padding: 0;
  overflow: auto;
  color: inherit;
  background: var(--navigation-menu-surface);
  border: 1px solid var(--color-nav-background);
  /* Open, the item and its menu are one surface: no edge between them. */
  border-block-start: 0;
  box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
  list-style: none;
  overscroll-behavior: contain;
}

#navigation .second_level > ul.is-open {
  display: block;
}

/* A long menu shows an arrow bar at each edge with more items beyond it
   (initialiser.js sets can-scroll-up and can-scroll-down). The bars stick to
   the edges and overlay the items without adding to the scroll height. */
#navigation .second_level > ul::before,
#navigation .second_level > ul::after {
  position: sticky;
  z-index: 1;
  display: block;
  visibility: hidden;
  height: var(--ui-nav-height);
  color: var(--color-nav-text-hover);
  font: var(--ui-icon-weight) var(--ui-font-size-small)/var(--ui-nav-height) var(--ui-icon-font-family);
  text-align: center;
  background: var(--navigation-menu-surface);
  pointer-events: none;
}

#navigation .second_level > ul::before {
  inset-block-start: 0;
  margin-block-end: calc(-1 * var(--ui-nav-height));
  border-block-end: 1px solid var(--color-nav-background);
  content: var(--ui-icon-chevron-up) var(--ui-icon-alt,);
}

#navigation .second_level > ul::after {
  inset-block-end: 0;
  margin-block-start: calc(-1 * var(--ui-nav-height));
  border-block-start: 1px solid var(--color-nav-background);
  content: var(--ui-icon-chevron-down) var(--ui-icon-alt,);
}

#navigation .second_level > ul.can-scroll-up::before,
#navigation .second_level > ul.can-scroll-down::after {
  visibility: visible;
}

/* Phones: a menu opens as a full-width sheet under the navigation with
   centred rows (initialiser.js leaves its start unset). */
@media (width <= 768px) {
  #navigation .second_level > ul {
    inset-inline-end: 0;
    inset-inline-start: 0;
    width: auto;
    min-width: 0;
    --navigation-menu-surface: var(--color-nav-surface-overlay);

    max-width: none;
    border-inline: 0;
  }

  #navigation .second_level a {
    justify-content: center;
    text-align: center;
  }
}

#navigation .second_level a {
  overflow-wrap: anywhere;
}

#navigation .second_level a:hover,
#navigation .second_level a[aria-current='page'] {
  color: var(--color-nav-text-hover);
  background: var(--color-nav-background);
}

#navigation button:focus-visible,
#navigation a:focus-visible {
  outline: 2px solid var(--color-nav-text-hover);
  outline-offset: -3px;
}
