/*
 * Navigation: desktop items with disclosure dropdowns, mobile menu panel, accordion (footer groups, mobile menu).
 * Dropdown: label link (no JS) is swapped for a toggle button by the dropdown module.
 */
@layer components {
  /* ---------- Desktop navigation ---------- */
  .nav__list {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .nav__item {
    position: relative;
  }

  .nav__link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-4);
    min-block-size: var(--component-control-height-s);
    padding: 0 var(--space-12);
    border: 0;
    background: none;
    color: var(--color-text-default);
    font-family: var(--font-family-base), system-ui, sans-serif;
    font-weight: var(--font-weight-medium);
    font-size: var(--type-label-s-size);
    line-height: var(--type-label-s-line-height);
    text-decoration: none;
    position: relative;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background-color var(--duration-fast) ease-out;
  }

  /*
   * States: hover and open dropdown show a soft pill behind the item (same tint as the dropdown entries); the current page
   * (aria-current, also the section a page belongs to) gets a short bar centred below the word and one weight step up.
   * The label reserves the width of its bold form (hidden copy in ::after), so the weight change never shifts neighbours.
   */
  .nav__label {
    position: relative;
    display: inline-grid;
    justify-items: center;
  }

  .nav__label::after {
    content: attr(data-label);
    block-size: 0;
    overflow: hidden;
    font-weight: var(--font-weight-semibold);
    visibility: hidden;
    pointer-events: none;
    user-select: none;
  }

  .nav__link:hover,
  .nav__toggle[aria-expanded='true'] {
    background-color: var(--color-nav-hover);
    color: var(--color-text-default);
  }

  .nav__link[aria-current] .nav__label {
    font-weight: var(--font-weight-semibold);
  }

  /* Indicator: short rounded bar in the text colour (16 x 3 px below the word; a 3 x 16 px bar left of the label in the mobile menu). */
  .nav__link[aria-current]::before,
  .mobile-menu__link[aria-current] .mobile-menu__label::before,
  .mobile-menu__sublink[aria-current] > span::before {
    content: "";
    border-radius: var(--radius-pill);
    background-color: var(--color-nav-indicator);
  }

  /* Centred under the whole item (word and chevron, i.e. under the hover pill); without a chevron that is the word. */
  .nav__link[aria-current]::before {
    position: absolute;
    inset-block-end: 2px;
    inset-inline-start: calc(50% - 8px);
    inline-size: 16px;
    block-size: 3px;
  }

  .mobile-menu__link[aria-current] .mobile-menu__label::before,
  .mobile-menu__sublink[aria-current] > span::before {
    display: inline-block;
    inline-size: 3px;
    block-size: 16px;
    margin-inline-end: var(--space-12);
    vertical-align: -0.2em;
  }

  .nav__toggle .icon {
    flex: none;
    transition: transform var(--duration-fast) ease-out;
  }

  .nav__toggle[aria-expanded='true'] .icon {
    transform: rotate(180deg);
  }

  .nav__panel {
    position: absolute;
    z-index: var(--z-popover);
    inset-block-start: calc(100% + var(--space-8));
    inset-inline-start: 0;
    inline-size: max-content;
    min-inline-size: 20rem;
    max-inline-size: calc(100vw - 2 * var(--layout-margin));
    padding: var(--space-16) var(--space-8);
    border: var(--border-width-thick) solid var(--color-action-primary-border);
    border-radius: var(--radius-m);
    background-color: var(--color-background-default);
  }

  /* 4 px between the entries so a tinted active entry and a hovered one never merge into one block. */
  .nav__sublist {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .nav__sublink {
    display: flex;
    align-items: center;
    gap: var(--space-12);
    min-block-size: var(--component-control-height-s);
    padding: var(--space-8) var(--space-16);
    border-radius: var(--radius-s);
    color: var(--color-text-default);
    font-size: var(--type-text-small-size);
    line-height: var(--type-text-small-line-height);
    text-decoration: none;
  }

  .nav__sublink .icon {
    flex: none;
  }

  .nav__sublink:hover,
  .nav__sublink[aria-current] {
    background-color: var(--color-nav-hover);
    color: var(--color-text-default);
  }

  .nav__sublink[aria-current],
  .nav__sublink--overview {
    font-weight: var(--font-weight-semibold);
  }

  /*
   * Fine divider (li, aria-hidden, presentational): after the overview entry and before the archive group. The 4 px list gap
   * plus 4 px margin give 8 px of air on each side; no fill, only a 1 px line in the divider colour.
   */
  .nav__divider {
    block-size: 0;
    margin: var(--space-4) var(--space-16);
    border-block-start: var(--border-width-thin) solid var(--color-border-default);
  }

  /* ---------- Mobile menu (below 1024 px) ---------- */
  .mobile-menu {
    position: absolute;
    z-index: var(--z-popover);
    inset-inline: 0;
    inset-block-start: 100%;
    block-size: calc(100vh - var(--layout-header-height));
    block-size: calc(100dvh - var(--layout-header-height));
    padding-block: var(--space-8) var(--space-32);
    overflow-y: auto;
    overscroll-behavior: contain;
    background-color: var(--color-background-default);
  }

  .mobile-menu__list,
  .mobile-menu__sublist {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .mobile-menu__item {
    border-block-end: var(--border-width-thin) solid var(--color-border-default);
  }

  .mobile-menu__heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-16);
    inline-size: 100%;
    padding-block: var(--space-16);
    color: var(--color-text-default);
    font-family: var(--font-family-heading), Georgia, serif;
    font-weight: var(--font-weight-bold);
    font-size: var(--type-heading-m-size);
    line-height: var(--type-heading-m-line-height);
    text-decoration: none;
  }

  .mobile-menu__link:hover {
    color: var(--color-text-default);
  }

  .mobile-menu__sublist {
    padding: 0 0 var(--space-8) var(--space-16);
  }

  .mobile-menu__sublink {
    display: flex;
    align-items: center;
    gap: var(--space-12);
    padding-block: var(--space-8);
    color: var(--color-text-default);
    font-size: var(--type-text-small-size);
    line-height: var(--type-text-small-line-height);
    text-decoration: none;
  }

  .mobile-menu__sublink .icon {
    flex: none;
  }

  .mobile-menu__sublink--overview {
    font-weight: var(--font-weight-semibold);
  }

  .mobile-menu__sublink[aria-current] {
    font-weight: var(--font-weight-bold);
  }

  .mobile-menu__divider {
    block-size: 0;
    margin-block: var(--space-8);
    border-block-start: var(--border-width-thin) solid var(--color-border-default);
  }

  @media (min-width: 1024px) {
    .mobile-menu {
      display: none;
    }
  }

  /* Page behind the open mobile menu does not scroll (the module also sets inert on main and footer). */
  html.menu-open {
    overflow: hidden;
  }

  /* ---------- Accordion (accordion module builds the button inside the heading) ---------- */
  .accordion__button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-16);
    inline-size: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
  }

  .accordion__icon {
    display: inline-flex;
    flex: none;
  }

  .accordion__plus,
  .accordion__minus {
    display: inline-flex;
  }

  .accordion__minus,
  .accordion__button[aria-expanded='true'] .accordion__plus {
    display: none;
  }

  .accordion__button[aria-expanded='true'] .accordion__minus {
    display: inline-flex;
  }

  @media (prefers-reduced-motion: reduce) {
    .nav__link,
    .nav__toggle .icon {
      transition: none;
    }
  }
}
