/* Documentation navigation: the sidebar, outline, and space they need. */

.sidebar {
  /* The index spans the article's row and the footer's, so the area a sticky
     box is held inside reaches the end of the page. Ending it with the
     article would let the footer push the index up under the header. An item
     with a definite row is placed before the auto-placed article, so the
     rails name their columns too, or one of them takes the article's. */
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: start;
  position: sticky;
  top: 4.2rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  padding: 1.6rem 0;
}

.docs-nav-toggle {
  display: none;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.65rem 0.75rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  cursor: pointer;
}

.docs-nav-toggle::after {
  content: "+";
  color: var(--teal-ink);
  font-size: 1.1rem;
  line-height: 1;
}

.docs-nav-toggle[aria-expanded="true"]::after {
  content: "−";
}

/* "On this page". Built from the page's own headings by the base template, and
   only shown when there is a third column to spare and enough headings to be
   worth one. A wide screen keeps that column on every page, filled or not, so
   the index and the reading column sit in the same place from page to page. */
.toc {
  display: none;
}

@media (min-width: 84rem) {
  .shell {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 13rem;
    max-width: 92rem;
  }

  /* A page with no outline centers its content and footer across both columns,
     at the width the two-column frame gives them. */
  body:not(.has-toc) :is(main, .site-footer) {
    grid-column: 2 / -1;
    justify-self: center;
    width: min(100%, calc(84rem - 2 * var(--header-inset) - var(--sidebar-w) - var(--shell-gap)));
  }

  body.has-toc .toc {
    display: block;
    grid-column: 3;
    grid-row: 1 / span 2;
    align-self: start;
    position: sticky;
    top: 4.2rem;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    padding: 2.2rem 0 2rem;
    padding-left: 1rem;
  }
}

.toc-links {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  /* The rail the whole list hangs from. The section you are in lights up its
     own segment of it, so position is shown by the rail itself rather than by a
     marker floating beside the text. */
  border-left: 1px solid var(--rule);
}

.toc-links a {
  position: relative;
  padding: 0.26rem 0.5rem 0.26rem 0.85rem;
  border-radius: 0 var(--radius-chip) var(--radius-chip) 0;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--ink-soft);
  text-wrap: balance;
}

.toc-links a:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  text-decoration: none;
}

.toc-links .toc-sub {
  padding-left: 1.6rem;
  font-size: 0.8rem;
}

/* The section you are in. Its segment of the rail turns teal: a real 2px
   element with square ends, not an inset shadow, which would bend around the
   corner radius and read as a bevel rather than a bar.

   Colour alone marks it. Bolding the active entry changes its text metrics, so
   a two-line heading re-wraps the moment you scroll into it and the list jumps
   under the cursor. */
.toc-links a.is-current {
  color: var(--teal-ink);
}

.toc-links a.is-current::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--teal);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.nav-heading {
  margin: 1.1rem 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.nav-heading:first-child {
  margin-top: 0;
}

.nav-link,
.nav-sub a {
  display: block;
  padding: 0.32rem 0.7rem;
  border-radius: var(--radius-chip);
  color: var(--ink);
  /* A link that takes two lines splits them evenly rather than leaving one
     word on the second. */
  text-wrap: balance;
}

.nav-link:hover,
.nav-sub a:hover {
  text-decoration: none;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.nav-sub {
  display: flex;
  flex-direction: column;
  margin: 0.1rem 0 0.2rem 0.5rem;
  padding-left: 0.55rem;
  border-left: 1px solid var(--rule);
  font-size: 0.92rem;
}

.nav-sub a {
  color: var(--ink-soft);
  padding-top: 0.26rem;
  padding-bottom: 0.26rem;
}

/* The page you are on. Colour and a tinted ground carry it, plus a rail on the
   leading edge drawn as a positioned element so it takes no space in the flow.

   Nothing here changes the text's metrics. Going bold on the active item, or
   indenting it to make room for a marker, re-wraps that one item and nudges the
   whole list, so the nav twitches every time you move between pages. The state
   has to be visible without the layout moving at all. */
.nav .is-current {
  background: color-mix(in srgb, var(--teal) 14%, transparent);
  color: var(--teal-ink);
  position: relative;
}

.nav .is-current::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  translate: 0 -50%;
  width: 3px;
  height: 1.15em;
  border-radius: 0 3px 3px 0;
  background: var(--teal);
}

.nav-sub a.is-current {
  background: color-mix(in srgb, var(--teal) 12%, transparent);
  color: var(--teal-ink);
}

.nav-sub a.is-current::before {
  height: 0.95em;
}

/* Keep the shared ring inside each scrolling navigation box. */
.nav a:focus-visible,
.toc-links a:focus-visible {
  outline-offset: -2px;
}

/* Forced colors strip the teal wash and bar that mark the current page, so
   the marker moves to a border the system palette keeps. */
@media (forced-colors: active) {
  .nav .is-current,
  .nav-sub a.is-current {
    border-left: 3px solid SelectedItem;
  }
  .toc-links a.is-current::before {
    background: none;
    border-left: 2px solid SelectedItem;
  }
}
