/* Hide the boxed title only when JS is off. The parse-time script in
   module.html sets data-ag-toc-js on <html> (before the nav) and on the
   nav itself; CSS hides the box only when both markers are absent. */
html:not([data-ag-toc-js]) .auto-table-of-contents:not([data-ag-toc-js]) {
  display: none;
}

.auto-table-of-contents {
  --auto-table-of-contents-item-height: 2rem;
  --auto-table-of-contents-wrap-height: 1.45rem;
  --auto-table-of-contents-text: inherit;
  --auto-table-of-contents-accent: currentColor;
  --auto-table-of-contents-border: color-mix(in srgb, currentColor 18%, transparent);
  --auto-table-of-contents-bg: color-mix(in srgb, currentColor 5%, transparent);
  --auto-table-of-contents-muted: color-mix(in srgb, currentColor 72%, transparent);
  --auto-table-of-contents-hover: color-mix(in srgb, currentColor 8%, transparent);
  --auto-table-of-contents-radius: 10px;
  --auto-table-of-contents-pill-bg: #fff;
  margin: 1.5rem 0;
  color: var(--auto-table-of-contents-text);
  font-size: 1rem;
  line-height: 1.45;
}

@supports not (background: color-mix(in srgb, currentColor 18%, transparent)) {
  .auto-table-of-contents {
    --auto-table-of-contents-border: #d9dde3;
    --auto-table-of-contents-bg: #f7f8fa;
    --auto-table-of-contents-muted: #4a5563;
    --auto-table-of-contents-hover: #eef0f3;
    --auto-table-of-contents-accent: currentColor;
  }
}

.auto-table-of-contents [data-ag-toc-list] {
  min-height: var(--auto-table-of-contents-list-min-height, 0px);
}
.auto-table-of-contents:not([data-ag-toc-ready]) {
  pointer-events: none;
}
.auto-table-of-contents:not([data-ag-toc-ready]) [data-ag-toc-list] {
  visibility: hidden;
}
/* Title stays in flow (visibility, not display) so reserved height is stable,
   but it is not painted until module.js marks the list ready. module.js is a
   single cached head script; without this, a cold Slow 4G load shows the
   title with an empty list while the script is in flight. */
.auto-table-of-contents:not([data-ag-toc-ready]) .auto-table-of-contents__title,
.auto-table-of-contents:not([data-ag-toc-ready]) .auto-table-of-contents__toggle,
.auto-table-of-contents:not([data-ag-toc-ready]) .auto-table-of-contents__close,
.auto-table-of-contents:not([data-ag-toc-ready]) .auto-table-of-contents__pill {
  visibility: hidden;
}
.auto-table-of-contents--boxed:not([data-ag-toc-ready]) .auto-table-of-contents__panel,
.auto-table-of-contents--boxed:not([data-ag-toc-ready]) {
  background-color: transparent;
  border-color: transparent;
}

.auto-table-of-contents__panel {
  min-width: 0;
}
.auto-table-of-contents--boxed .auto-table-of-contents__panel {
  border: 1px solid var(--auto-table-of-contents-border);
  border-radius: var(--auto-table-of-contents-radius);
  background: var(--auto-table-of-contents-bg);
  padding: 1rem 1.25rem;
}

.auto-table-of-contents__head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.5rem;
}
.auto-table-of-contents__title {
  margin: 0;
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
}
.auto-table-of-contents__toggle,
.auto-table-of-contents__close,
.auto-table-of-contents__pill {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--auto-table-of-contents-border);
  border-radius: 999px;
  cursor: pointer;
  padding: 0.2rem 0.7rem;
  line-height: 1.3;
}
.auto-table-of-contents__toggle:focus-visible,
.auto-table-of-contents__close:focus-visible,
.auto-table-of-contents__pill:focus-visible,
.auto-table-of-contents__link:focus-visible {
  outline: 2px solid var(--auto-table-of-contents-accent);
  outline-offset: 2px;
}
.auto-table-of-contents__close,
.auto-table-of-contents__pill,
.auto-table-of-contents__backdrop {
  display: none;
}

.auto-table-of-contents__progress {
  display: block;
  height: 3px;
  margin: 0 0 0.75rem;
  border-radius: 999px;
  background: var(--auto-table-of-contents-border);
  overflow: hidden;
}
.auto-table-of-contents__progress-fill {
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: var(--auto-table-of-contents-accent);
  pointer-events: none;
}
.auto-table-of-contents:not([data-ag-toc-ready]) .auto-table-of-contents__progress {
  visibility: hidden;
}

.auto-table-of-contents__list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.auto-table-of-contents__list .auto-table-of-contents__list {
  margin: 0.15rem 0 0.15rem 0.9rem;
  padding: 0;
}
.auto-table-of-contents__item {
  margin: 0;
}
.auto-table-of-contents__link {
  display: block;
  position: relative;
  color: var(--auto-table-of-contents-muted);
  text-decoration: none;
  padding: 0.22rem 0.4rem 0.22rem 0.7rem;
  border-radius: 6px;
  border-left: 2px solid transparent;
}
.auto-table-of-contents__link:hover {
  background: var(--auto-table-of-contents-hover);
  text-decoration: none;
  color: inherit;
}
.auto-table-of-contents__link[aria-current="location"] {
  color: var(--auto-table-of-contents-accent);
  font-weight: 600;
  border-left-color: var(--auto-table-of-contents-accent);
  background: var(--auto-table-of-contents-hover);
}

.auto-table-of-contents[data-ag-toc-numbered="true"] .auto-table-of-contents__list {
  counter-reset: ag-toc;
}
.auto-table-of-contents[data-ag-toc-numbered="true"] .auto-table-of-contents__item {
  counter-increment: ag-toc;
}
.auto-table-of-contents[data-ag-toc-numbered="true"] .auto-table-of-contents__link::before {
  content: counters(ag-toc, ".") ". ";
  font-weight: 600;
  color: var(--auto-table-of-contents-muted);
}
.auto-table-of-contents[data-ag-toc-numbered="true"] .auto-table-of-contents__link[aria-current="location"]::before {
  color: inherit;
}

.auto-table-of-contents[data-ag-toc-collapsed] [data-ag-toc-list],
.auto-table-of-contents[data-ag-toc-collapsed] .auto-table-of-contents__progress {
  display: none;
}

.auto-table-of-contents__empty {
  margin: 0;
  color: var(--auto-table-of-contents-muted);
  font-style: italic;
}
.auto-table-of-contents__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.auto-table-of-contents__target {
  scroll-margin-top: var(--auto-table-of-contents-offset, 0px);
}

/* Sticky sidebar: out of flow on wide screens so the article starts at the top. */
@media (min-width: 1100px) {
  .auto-table-of-contents[data-ag-toc-layout="sticky-sidebar"] {
    position: fixed;
    top: var(--auto-table-of-contents-offset, 1rem);
    right: 1rem;
    width: 16rem;
    max-height: calc(100vh - var(--auto-table-of-contents-offset, 1rem) - 2rem);
    margin: 0;
    z-index: 20;
    overflow: auto;
  }
}

/* Floating compact panel, out of flow from the first paint. */
.auto-table-of-contents[data-ag-toc-layout="floating"] {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: min(20rem, calc(100vw - 2.5rem));
  max-height: min(70vh, 32rem);
  margin: 0;
  z-index: 40;
  overflow: auto;
}

/* Mobile pill + drawer. In-flow box collapses so the article is not pushed. */
@media (max-width: 719px) {
  .auto-table-of-contents[data-ag-toc-mobile="drawer"] {
    margin: 0;
    height: 0;
    overflow: visible;
  }
  .auto-table-of-contents[data-ag-toc-mobile="drawer"] [data-ag-toc-list] {
    min-height: 0;
  }
  /* The collapse toggle is hidden in drawer mode, so the drawer always shows the list. */
  .auto-table-of-contents[data-ag-toc-mobile="drawer"][data-ag-toc-collapsed] [data-ag-toc-list] {
    display: block;
  }
  .auto-table-of-contents[data-ag-toc-mobile="drawer"] .auto-table-of-contents__pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 45;
    margin: 0;
    padding: 0.65rem 1rem;
    background: var(--auto-table-of-contents-pill-bg);
    color: inherit;
    box-shadow: 0 8px 24px color-mix(in srgb, currentColor 18%, transparent);
    border: 1px solid var(--auto-table-of-contents-border);
    font-weight: 600;
  }
  .auto-table-of-contents[data-ag-toc-mobile="drawer"] .auto-table-of-contents__panel {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 46;
    width: auto;
    max-height: 80vh;
    margin: 0;
    overflow: auto;
    border-radius: 16px 16px 0 0;
    padding: 1rem 1.25rem 1.5rem;
    background: var(--auto-table-of-contents-pill-bg);
    border: 1px solid var(--auto-table-of-contents-border);
    box-shadow: 0 -8px 32px color-mix(in srgb, currentColor 16%, transparent);
  }
  .auto-table-of-contents[data-ag-toc-mobile="drawer"][data-ag-toc-open] .auto-table-of-contents__panel,
  .auto-table-of-contents[data-ag-toc-mobile="drawer"][data-ag-toc-open] .auto-table-of-contents__backdrop {
    display: block;
  }
  .auto-table-of-contents[data-ag-toc-mobile="drawer"][data-ag-toc-open] .auto-table-of-contents__backdrop {
    position: fixed;
    inset: 0;
    z-index: 45;
    background: color-mix(in srgb, currentColor 35%, transparent);
  }
  .auto-table-of-contents[data-ag-toc-mobile="drawer"][data-ag-toc-open] .auto-table-of-contents__close {
    display: inline-flex;
  }
  .auto-table-of-contents[data-ag-toc-mobile="drawer"] .auto-table-of-contents__toggle {
    display: none;
  }
  .auto-table-of-contents[data-ag-toc-mobile="drawer"][data-ag-toc-open] .auto-table-of-contents__pill {
    display: none;
  }
  .auto-table-of-contents[data-ag-toc-layout="sticky-sidebar"][data-ag-toc-mobile="drawer"],
  .auto-table-of-contents[data-ag-toc-layout="floating"][data-ag-toc-mobile="drawer"] {
    position: static;
    width: auto;
    max-height: none;
    overflow: visible;
    right: auto;
    bottom: auto;
    top: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .auto-table-of-contents__progress-fill,
  .auto-table-of-contents__panel,
  .auto-table-of-contents__backdrop,
  .auto-table-of-contents__link {
    transition: none;
  }
}

@media (forced-colors: active) {
  .auto-table-of-contents {
    --auto-table-of-contents-border: ButtonText;
    --auto-table-of-contents-bg: Canvas;
    --auto-table-of-contents-text: CanvasText;
    --auto-table-of-contents-accent: LinkText;
    --auto-table-of-contents-hover: Highlight;
    --auto-table-of-contents-muted: GrayText;
    --auto-table-of-contents-pill-bg: Canvas;
  }
  .auto-table-of-contents--boxed .auto-table-of-contents__panel {
    forced-color-adjust: none;
    border: 1px solid ButtonText;
    background: Canvas;
    color: CanvasText;
  }
  .auto-table-of-contents__link,
  .auto-table-of-contents__title,
  .auto-table-of-contents__toggle,
  .auto-table-of-contents__close,
  .auto-table-of-contents__pill {
    color: CanvasText;
    border-color: ButtonText;
  }
  .auto-table-of-contents__link[aria-current="location"] {
    color: LinkText;
    border-left-color: LinkText;
  }
}
