/* The member top bar: the ONE primary navigation, at every width. It is brand chrome: charcoal in light AND dark
   appearance, with off-white text. Same markup, links and order as before; only CSS decides how it looks.

   Composition (left to right):
     - the LOGO ZONE: the badge and wordmark on a slightly lighter charcoal, flush with the left edge, its right edge
       slanted like a forward slash (drawn in brand_mark.css);
     - the STRIPE: the bold three-band stripe (brand_stripe.css) running through the vertical middle of the bar, from
       the slanted edge to the right edge of the viewport;
     - the NAV BOX: one raised, bordered box near the right edge that sits on top of the stripe and holds the page
       links, Quick add and the account item. Because the box masks the stripe, the number and width of its items never
       needs a change to the stripe.
   The bar has restrained depth: a slight gradient, a darker 2px bottom edge and a soft shadow, no gloss.

   Quick add is the ONE coloured thing in the bar (the brand's primary-action mustard). The current page is quiet: brighter
   text and a thin underline under its label (aria-current="page" carries it for assistive technology; the underline is
   not the only cue).

   Collapse in steps as the window narrows (the ladder is spelled out at the bottom of this file) so nothing ever wraps
   or overlaps. The three page links are the last thing to go: the stripe, which is decoration, yields first. Where the
   steps fall comes from measuring the real items in the real fonts (Alfa Slab One, Atkinson Hyperlegible Next).

   Sticky: the bar sticks on every member page except the chart page, where the chart's own sticky header and the
   reading surface matter more (that page embeds this same navigation inside its header and lets it scroll away).
   The stickiness is on the header element (the nav inside it is only as tall as itself, so it can never stick).
   Scoped to body.member-shell; screen only (print hides the navigation). */
:root {
  --member-bar-height: 3.75rem;
  /* The height of the items inside the nav box (their hit area grows to 44px on touch layouts, nav_icons.css). */
  --member-nav-item-height: 2.125rem;
}

/* Bar plus anything drawn under it that a sticky element on the page must clear. The stripe now runs inside the bar, so
   there is nothing extra (brand_stripe.css leaves --stripe-height unset). */
.member-shell {
  --member-header-height: calc(var(--member-bar-height) + var(--stripe-height, 0px));
  --member-zone-pad-start: 22px;
  --member-zone-pad-end: 30px;
  --member-box-margin: 28px;
}

@media screen {
  .member-shell:not(.member-shell--chart) > .member-header {
    position: sticky;
    z-index: 300;
    top: 0;
  }

  .member-shell .member-header {
    position: relative;
    isolation: isolate;
    box-sizing: border-box;
    height: var(--member-bar-height);
    border-bottom: 2px solid var(--chrome-edge);
    color: var(--chrome-ink);
    background: linear-gradient(var(--chrome-bar-top), var(--chrome-bg) 60%);
    box-shadow: 0 5px 12px -3px var(--chrome-shadow);
  }

  /* The nav is transparent so the stripe (behind it) shows between the zone and the box. */
  .member-shell .member-nav {
    position: static;
    height: 100%;
    min-height: 0;
    color: inherit;
    background: transparent;
  }

  .member-shell .member-nav__rail {
    display: flex;
    width: 100%;
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
    align-items: center;
    justify-content: space-between;
    /* The zone's slanted edge reaches 30px past the wordmark; 70px keeps at least 40px of stripe in view. The gap is only
       a minimum: the stripe yields (below 45rem the gap shrinks to what is left) before any link does. */
    gap: calc(var(--member-zone-pad-end) + 40px);
    margin: 0;
    padding: 0 0 0 var(--member-zone-pad-start);
  }

  /* The logo zone's content: the badge and the wordmark. The zone itself is two pseudo-elements in brand_mark.css, which
     extend past this link to the viewport's left edge and 30px to its right. */
  .member-shell .member-nav__brand {
    position: relative;
    flex: 0 0 auto;
    align-self: stretch;
    gap: 11px;
    width: auto;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border-radius: 0;
    overflow: visible;
    color: inherit;
    background: none;
    font-size: 1.375rem;
    font-weight: 400;
    letter-spacing: 0;
    line-height: 1;
    isolation: isolate;
  }

  /* THE NAV BOX: the links container, raised on the stripe. No overflow clipping, so focus rings are never cut off. */
  .member-shell .member-nav__links {
    flex: 0 0 auto;
    justify-content: flex-start;
    gap: 2px;
    box-sizing: border-box;
    height: 46px;
    margin-right: var(--member-box-margin);
    padding: 0 6px;
    border: 1px solid var(--chrome-box-border);
    border-radius: 10px;
    color: var(--chrome-ink-dim);
    background: var(--chrome-box);
    box-shadow: 0 2px 6px var(--chrome-shadow-box);
    font-size: 0.97rem;
    font-weight: 600;
  }

  .member-shell .member-nav__links > a:not(.member-nav__quick-add) {
    position: relative;
    display: inline-flex !important;
    min-height: var(--member-nav-item-height);
    height: var(--member-nav-item-height);
    padding: 0 13px;
    border-radius: 8px;
    color: var(--chrome-ink-dim);
    background: var(--chrome-box);
    font-size: inherit;
    text-decoration: none;
  }

  .member-shell .member-nav__links > a:not(.member-nav__quick-add):hover {
    color: var(--chrome-ink-strong);
    background: var(--chrome-nav-hover);
  }

  /* The current page: full-strength text, and a thin underline under the label (not a fill: the colour is saved for
     Quick add). Hover keeps the underline and brightens like the others. */
  .member-shell .member-nav__links > a[aria-current="page"]:not(.member-nav__quick-add),
  .member-shell .member-nav__links > a[aria-current="page"]:not(.member-nav__quick-add):hover {
    color: var(--chrome-ink);
    background: var(--chrome-box);
  }

  .member-shell .member-nav__links > a[aria-current="page"]:not(.member-nav__quick-add):hover {
    color: var(--chrome-ink-strong);
    background: var(--chrome-nav-hover);
  }

  .member-shell .member-nav__links > a[aria-current="page"] .member-nav__label {
    text-decoration: underline;
    text-decoration-color: var(--chrome-underline);
    text-decoration-skip-ink: none;
    text-decoration-thickness: 2px;
    text-underline-offset: 0.45rem;
  }

  /* Quick add: the one filled, coloured button in the bar. Plus icon and the words; below 56rem the words go (it keeps
     its accessible name, "Quick add", on the link). Mustard is the brand's "do this" colour; the owner decided Quick add
     is a primary action in the chrome. The older rules set the colour with !important, so these do too. */
  .member-shell .member-nav__quick-add {
    min-height: var(--member-nav-item-height) !important;
    height: var(--member-nav-item-height);
    margin: 0 6px 0 4px;
    padding: 0 13px;
    justify-content: center;
    gap: 0.45rem;
    border: 1px solid var(--primary);
    border-radius: 8px;
    overflow: visible;
    color: var(--on-primary) !important;
    background: var(--primary);
    font-size: inherit;
    font-weight: 700;
    text-decoration: none;
  }

  .member-shell .member-nav__quick-add:hover {
    border-color: var(--chrome-cta-hover);
    color: var(--on-primary) !important;
    background: var(--chrome-cta-hover);
  }

  .member-shell .member-nav__profile {
    margin-left: 6px;
    padding-left: 7px;
    background-image: linear-gradient(var(--chrome-divider), var(--chrome-divider));
    background-repeat: no-repeat;
    background-position: left center;
    background-size: 1px 24px;
  }

  .member-shell .member-nav__profile summary {
    min-height: var(--member-nav-item-height);
    height: var(--member-nav-item-height);
    max-width: 9rem;
    box-sizing: border-box;
    padding: 0 13px;
    border-radius: 8px;
    overflow: visible;
    color: var(--chrome-ink-dim);
    background: var(--chrome-box);
  }

  /* The summary no longer clips (its hit area reaches past it, nav_icons.css); a long name is cut short on the label. */
  .member-shell .member-nav__profile-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .member-shell .member-nav__profile summary::after {
    display: none;
  }

  /* The hamburger glyph belongs to the last-resort step only; the account button is the person icon until then. */
  .member-shell .member-nav__menu-icon {
    display: none;
  }

  .member-shell .member-nav__profile summary:hover,
  .member-shell .member-nav__profile[open] > summary {
    color: var(--chrome-ink-strong);
    background: var(--chrome-nav-hover);
  }

  /* The account menu opens DOWNWARD from the nav box, right-aligned under the account item: a dark raised panel, cream
     text, the bar's muted colour for secondary text, in light AND dark appearance. */
  .member-shell .member-nav__profile-menu {
    --menu-ink: var(--chrome-ink);
    --menu-muted: var(--chrome-muted);
    --menu-rule: var(--chrome-rule);
    --menu-edge: var(--chrome-outline);
    --menu-hover: var(--chrome-raised-hover);
    --menu-selected: var(--chrome-raised-hover);
    --menu-focus: var(--chrome-focus);
    top: calc(100% + (var(--member-bar-height) - var(--member-nav-item-height)) / 2 + 0.5rem);
    right: -7px;
    left: auto;
    min-width: 14rem;
    max-height: calc(100dvh - var(--member-header-height) - 1.5rem);
    border-color: var(--chrome-box-border);
    color: var(--chrome-ink);
    background: var(--chrome-raised);
    box-shadow: 0 10px 24px var(--chrome-shadow);
  }

  .member-shell .member-nav__profile-menu a,
  .member-shell .member-nav__sign-out {
    color: var(--chrome-ink);
    background: var(--chrome-raised);
  }

  .member-shell .member-nav__profile-menu a:hover,
  .member-shell .member-nav__sign-out:hover,
  .member-shell .member-nav__profile-menu a[aria-current="page"] {
    color: var(--chrome-ink);
    background: var(--chrome-raised-hover);
  }

  .member-shell .member-nav__profile-menu a:focus-visible,
  .member-shell .member-nav__sign-out:focus-visible {
    outline: 3px solid var(--chrome-focus);
    outline-offset: -3px;
  }

  /* Focus rings use off-white (11:1 on the box). The box has 6px of padding and the items sit 5px inside its border, so a
     2px ring at a 2px offset fits inside without clipping; the box never clips (no overflow). */
  .member-shell .member-nav__brand:focus-visible,
  .member-shell .member-nav__links > a:focus-visible,
  .member-shell .member-nav__profile > summary:focus-visible {
    outline: 2px solid var(--chrome-focus);
    outline-offset: 2px;
  }

  /* The logo link is as tall as the bar, so its ring sits inside it. */
  .member-shell .member-nav__brand:focus-visible {
    outline-offset: -4px;
  }

  /* The full chart page (not the library dialog, Stage or the shared page): the top bar lives inside the sticky chart
     chrome, so the chrome sticks at minus the bar's height. The bar scrolls off and the chart header pins at the top. */
  .member-shell--chart.chart-reading-page .chart-stage__chrome {
    top: calc(-1 * var(--member-header-height));
  }

  /* The notice sits under the sticky bar. */
  .member-shell .preview-notice--below-member-navigation {
    top: var(--member-header-height);
  }

  /* Page spacing under the bar: the title starts about 32px below it (the older rule gave 40 to 80px). The chart page
     keeps its own spacing. */
  .member-shell:not(.member-shell--chart) .member-main {
    padding-top: 2rem;
  }
}

/* THE LADDER (the owner's priority: the three page links stay visible as text as long as physically possible; the stripe,
   which is decoration, yields before any link does). In the order things go as the window narrows:
     below 62rem (992px)  the link icons go (nav_icons.css);
     below 56rem (896px)  Quick add loses its words (icon only);
     below 52rem (832px)  the account item is the person icon only (the name goes);
     below 45rem (720px)  the logo zone is the badge only (the wordmark goes before any link);
     below 30rem (480px)  Quick add leaves the bar (it stays in the account menu) and the items tighten;
     below 22.5rem (360px) the items tighten again and the badge shrinks a little;
     below 20rem (320px)  last resort: the links fold into the menu button (the hamburger).
   The menu repeats the page links only in that last step, and Quick add only once it has left the bar. */

/* Touch layouts: 4px between the links' hit areas (they are 44px tall and sit 2px apart on a desktop). */
@media screen and (max-width: 68.74rem) {
  .member-shell .member-nav__links {
    gap: 4px;
  }
}

/* Quick add loses its words. */
@media screen and (max-width: 55.99rem) {
  .member-shell .member-nav__quick-add {
    width: 2.75rem;
    min-width: 2.75rem;
    padding: 0;
  }
}

/* The account item is the person icon: the name goes, the button stays 44px wide. */
@media screen and (max-width: 51.99rem) {
  .member-shell .member-nav__profile-label {
    display: none;
  }

  .member-shell .member-nav__profile summary {
    width: 2.75rem;
    min-width: 2.75rem;
    max-width: none;
    padding: 0;
    justify-content: center;
    border: 1px solid var(--chrome-outline);
  }

  .member-shell .member-nav__profile summary:hover,
  .member-shell .member-nav__profile[open] > summary {
    border-color: var(--chrome-ink-dim);
  }
}

/* The wordmark goes: the zone is the badge only (brand_mark.css), the zone's edges and the box's margin close up. */
@media screen and (max-width: 44.99rem) {
  .member-shell {
    --member-zone-pad-start: 14px;
    --member-zone-pad-end: 26px;
    --member-box-margin: 14px;
  }
}

/* Phones: the menu spans the width under the bar (anchored to the bar rather than to the account button). */
@media screen and (max-width: 33.99rem) {
  .member-shell .member-nav__profile {
    position: static;
  }

  .member-shell .member-nav__profile-menu {
    top: calc(var(--member-bar-height) + 0.4rem);
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    min-width: 0;
  }
}

/* Below 30rem: Quick add leaves the bar and the items tighten. The links keep a 44px wide, 44px tall hit area, 6px apart. */
@media screen and (max-width: 29.99rem) {
  .member-shell {
    --member-zone-pad-end: 22px;
    --member-box-margin: 10px;
  }

  .member-shell .member-nav__quick-add {
    display: none !important;
  }

  /* The stripe is what yields: the rail's minimum gap shrinks so the box is never pushed out of the window. */
  .member-shell .member-nav__rail {
    gap: 8px;
  }

  .member-shell .member-nav__links {
    gap: 6px;
    padding: 0 5px;
  }

  .member-shell .member-nav__links > a:not(.member-nav__quick-add) {
    min-width: 2.75rem;
    justify-content: center;
    padding: 0 8px;
  }

  .member-shell .member-nav__profile {
    margin-left: 0;
    padding-left: 0;
    background-image: none;
  }
}

/* Below 22.5rem (360px): tighter again, and a slightly smaller badge. */
@media screen and (max-width: 22.49rem) {
  .member-shell {
    --member-zone-pad-start: 10px;
    --member-zone-pad-end: 20px;
    --member-box-margin: 8px;
  }

  .member-shell .member-nav__links {
    gap: 4px;
    padding: 0 4px;
  }

  .member-shell .member-nav__links > a:not(.member-nav__quick-add) {
    padding: 0 6px;
  }

  .member-shell .member-nav__brand {
    --brand-badge-size: 36px;
    --brand-mark-height: 27px;
  }
}

/* Below 20rem (320px), only if three links, the badge and the account button cannot fit: the links fold into the menu. */
@media screen and (max-width: 19.99rem) {
  .member-shell .member-nav__links > a:not(.member-nav__quick-add) {
    display: none !important;
  }

  .member-shell .member-nav__quick-add {
    display: inline-flex !important;
    margin: 0 4px 0 0;
  }

  .member-shell .member-nav__profile summary {
    border: 1px solid var(--chrome-outline);
  }

  .member-shell .member-nav__account-icon {
    display: none;
  }

  .member-shell .member-nav__menu-icon {
    display: block;
    width: 1.35rem;
    height: 1.35rem;
  }
}
