@layer components {
  /* The homepage's nav (app/landing/homepage.css, .nav-bar), in the app's names: warm white
   * with a hairline under it, the logo on the left, the links in grey-green in the middle,
   * the outline button on the right. 62 px tall, as on the homepage. */
  .header {
    background: var(--color-ground);
    border-block-end: 1px solid var(--color-hairline);
    inset-block-start: 0;
    padding-block: 12px;
    position: sticky;
    z-index: 20;
  }

  .header__inner {
    align-items: center;
    display: grid;
    gap: 24px;
    grid-template-columns: 1fr auto 1fr;
    min-block-size: 37px;

    > .logo { justify-self: start; }

    @media (max-width: 880px) {
      gap: 16px;
      grid-template-columns: 1fr auto;
    }

    /* The logo with its symbol is 104px wide: a 360px phone has room for it, the button and the
     * menu icon with 8px between the logo and the button, as on the homepage. */
    @media (max-width: 366px) {
      gap: 8px;
    }
  }

  .header__nav {
    align-items: center;
    color: var(--color-muted);
    display: flex;
    font-size: 15px;
    gap: 28px;
    line-height: 1.4;

    > a {
      color: inherit;
      text-decoration: none;

      &:hover { color: var(--color-ink); }
    }

    @media (max-width: 880px) {
      display: none;
    }
  }

  .header__menu {
    position: relative;
  }

  .header__toggle {
    align-items: center;
    cursor: pointer;
    display: inline-flex;
    gap: 6px;

    &::after {
      background-color: currentColor;
      block-size: 11px;
      content: "";
      inline-size: 11px;
      mask: url("/assets/icons/chevron-down-bd074ae3.svg") center / contain no-repeat;
    }

    &:hover,
    .header__menu[open] > & {
      color: var(--color-ink);
    }

    .header__menu[open] > &::after {
      rotate: 180deg;
    }
  }

  .header__right {
    align-items: center;
    display: flex;
    gap: 14px;
    justify-self: end;

    /* A narrower phone shows the logo and the menu icon: the button's link is in the menu
     * ("All documents"), as on the homepage. */
    > .btn {
      @media (max-width: 359px) {
        display: none;
      }
    }
  }

  /* A menu floats over the page: warm white, a hairline, raised. */
  .header__panel {
    background: var(--color-ground);
    border: 1px solid var(--color-hairline);
    border-radius: var(--rounded-lg);
    box-shadow: var(--shadow-raised);
    inline-size: 272px;
    inset-block-start: calc(100% + 30px);
    inset-inline-start: -20px;
    padding: 8px;
    position: absolute;

    a {
      border-radius: var(--rounded-sm);
      color: var(--color-ink);
      display: block;
      font-size: 15px;
      font-weight: 500;
      line-height: 1.4;
      padding: 10px 12px;
      text-decoration: none;

      &:hover { background: var(--color-surface); }

      @media (max-width: 880px) { padding-block: 12px; }
    }
  }

  .header__all {
    .header__panel & { font-weight: 600; }
  }

  /* A hairline above a link starts the menu's next group. */
  .header__rule {
    margin-block-start: 17px;
    position: relative;

    &::before {
      border-block-start: 1px solid var(--color-hairline);
      content: "";
      inset-block-start: -9px;
      inset-inline: 4px;
      position: absolute;
    }
  }

  .header__group {
    color: var(--color-muted);
    font: var(--text-label);
    padding: 8px 12px 2px;
  }

  /* On a phone the links fold into a menu icon; the name and the button stay. */
  .header__fold {
    display: none;
    position: relative;

    @media (max-width: 880px) { display: block; }

    .header__panel {
      inline-size: min(272px, calc(100vw - 40px));
      inset-block-start: calc(100% + 28px);
      inset-inline: auto 0;
      max-block-size: calc(100vh - 96px);
      overflow-y: auto;
    }
  }

  .header__burger {
    block-size: 24px;
    cursor: pointer;
    display: block;
    inline-size: 24px;
    position: relative;

    &::before {
      background-color: var(--color-ink);
      content: "";
      inset: 0;
      mask: url("/assets/icons/menu-50248e66.svg") center / contain no-repeat;
      position: absolute;
    }

    &::after {
      content: "";
      inset: -10px;
      position: absolute;
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    .header__nav > a,
    .header__toggle {
      transition: color 150ms ease;
    }

    .header__panel a {
      transition: background-color 150ms ease;
    }
  }
}
