/* Principle 5: external stylesheet, no inline styles anywhere. Brand tokens are
   CSS custom properties on :root so branding.ts values flow through one place.

   Aesthetic direction (frontend-design Step 2): "refined editorial newsroom" —
   an ink-on-warm-paper document surface, one restrained indigo accent, calm
   spacing, and a real type hierarchy. No emoji, no colored left-border stripes,
   no gradient heroes, no generic SaaS blue. Badge tones are the only spectrum
   color, used as tinted pills. */

:root {
  color-scheme: light;

  /* Neutrals */
  --ink: #09090b;
  --ink-soft: #27272a;
  --muted: #636369;
  --muted-2: #52525b;
  --line: #e4e4e7;
  --line-strong: #d4d4d8;
  --subtle: #f4f4f5;
  --surface: #ffffff;
  --surface-warm: #fafafa;
  --surface-dark: #0a0a0a;

  /* Brand tokens (--accent, --font, --brand-orb-*) are provided by the
     boot-generated, content-hashed /static/brand.css (Part IV), loaded before
     this stylesheet, so a tenant swap is env-only. The semantic tones and
     neutrals below are the app's fixed design system, not tenant brand. */

  /* Semantic tones (badges/chips) — reference-only spectrum from the spec. */
  --tone-blue: #2b7fff;
  --tone-amber: #fe9a00;
  --tone-indigo: #615fff;
  --tone-green: #00c950;
  --tone-emerald: #00bc7d;
  --tone-orange: #ff6900;
  --tone-red: #fb2c36;
  --tone-violet: #8e51ff;

  /* Radii */
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;

  --font-serif: "Iowan Old Style", "Palatino Linotype", "Palatino", Georgia, serif;

  /* 4px spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-8: 48px;
  --space-10: 64px;

  --shadow-sm: 0 1px 2px rgba(9, 9, 11, 0.05);
  --shadow-md: 0 8px 30px rgba(9, 9, 11, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--surface-warm);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
}

img {
  max-width: 100%;
}

/* Toggles use the hidden attribute, never inline display:none. */
[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------------------------------------------------------------- Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar__inner {
  max-width: 1120px;
  margin: 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-5);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.brand-logo {
  display: block;
  border-radius: var(--radius-xs);
  width: 28px;
  height: 28px;
}

/* Size classes passed to brandMark(); the ONE logo helper decides the mark,
   the placement decides the size. */
.brand-logo--xs { width: 20px; height: 20px; }
.brand-logo--sm { width: 28px; height: 28px; }
.brand-logo--md { width: 40px; height: 40px; }
.brand-emoji.brand-logo--xs { font-size: 16px; }
.brand-emoji.brand-logo--sm { font-size: 20px; }
.brand-emoji.brand-logo--md { font-size: 30px; }

.brand__name {
  font-size: 16px;
  white-space: nowrap;
}

/* Emoji logo fallback (Part IV, last resort only). */
.brand-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
}

/* Principle 25: a page's count is a small uppercase KICKER, never a bordered
   subtitle. Shared by the index count and any other count surface. */
.count-kicker {
  margin: 0 0 var(--space-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0 var(--space-4);
  font: 500 14px var(--font);
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.14s ease, background-color 0.14s ease, color 0.14s ease;
}

.iconbtn:hover {
  border-color: var(--line-strong);
  background: var(--subtle);
  color: var(--ink);
}

.iconbtn--primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

.iconbtn--primary:hover {
  background: var(--ink-soft);
  color: var(--surface);
}

/* ------------------------------------------------------------- Leaf layout */

.leaf__main {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-10) var(--space-5) var(--space-8);
}

.leaf__article {
  min-width: 0;
}

/* ------------------------------------------------------------- Metadata bar */

/* Principle 25: the page/metadata header carries NO bottom border — whitespace
   separates it from the body, never a stacked hairline (no divider soup). */
.meta {
  margin: 0 0 var(--space-8);
}

.meta__type {
  margin: 0 0 var(--space-3);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.meta__title {
  margin: 0 0 var(--space-4);
  font-size: clamp(30px, 4.6vw, 44px);
  font-weight: 640;
  line-height: 1.08;
  letter-spacing: -0.028em;
  text-wrap: balance;
}

.meta__desc {
  margin: 0 0 var(--space-5);
  font-size: 19px;
  line-height: 1.5;
  color: var(--muted-2);
  text-wrap: pretty;
}

.meta__badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
}

.meta__byline {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin: 0 0 var(--space-4);
  font-size: 14px;
  color: var(--muted);
}

.meta-byline__item {
  white-space: nowrap;
}

.meta-byline__k {
  color: var(--muted-2);
  font-weight: 500;
}

.meta__dates {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
  margin: 0 0 var(--space-4);
}

.meta__dates div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta__dates dt {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.meta__dates dd {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
}

.meta__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-2) 0 0;
  padding: 0;
  list-style: none;
}

/* ------------------------------------------------------ Badges & chips */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  padding: 5px 10px;
  border-radius: 980px;
  background: var(--subtle);
  color: var(--ink-soft);
  white-space: nowrap;
}

.badge--muted {
  background: var(--subtle);
  color: var(--muted-2);
}
.badge--neutral {
  background: var(--subtle);
  color: var(--ink-soft);
}
.badge--blue {
  background: color-mix(in srgb, var(--tone-blue) 12%, transparent);
  color: color-mix(in srgb, var(--tone-blue) 78%, var(--ink));
}
.badge--amber {
  background: color-mix(in srgb, var(--tone-amber) 15%, transparent);
  color: color-mix(in srgb, var(--tone-amber) 62%, var(--ink));
}
.badge--indigo {
  background: color-mix(in srgb, var(--tone-indigo) 12%, transparent);
  color: color-mix(in srgb, var(--tone-indigo) 82%, var(--ink));
}
.badge--green {
  background: color-mix(in srgb, var(--tone-green) 15%, transparent);
  color: color-mix(in srgb, var(--tone-green) 55%, var(--ink));
}
.badge--emerald {
  background: color-mix(in srgb, var(--tone-emerald) 14%, transparent);
  color: color-mix(in srgb, var(--tone-emerald) 62%, var(--ink));
}
.badge--orange {
  background: color-mix(in srgb, var(--tone-orange) 14%, transparent);
  color: color-mix(in srgb, var(--tone-orange) 70%, var(--ink));
}
.badge--red {
  background: color-mix(in srgb, var(--tone-red) 12%, transparent);
  color: color-mix(in srgb, var(--tone-red) 82%, var(--ink));
}
.badge--violet {
  background: color-mix(in srgb, var(--tone-violet) 13%, transparent);
  color: color-mix(in srgb, var(--tone-violet) 80%, var(--ink));
}

.chip {
  display: inline-flex;
  align-items: center;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
  padding: 6px 11px;
  border-radius: 980px;
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  text-decoration: none;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

a.chip:hover {
  border-color: var(--line-strong);
  background: var(--subtle);
}

.chip--sm {
  font-size: 12px;
  padding: 4px 9px;
}

/* ------------------------------------------------------- Document body */

.doc-body {
  font-size: 17px;
  line-height: 1.72;
  color: var(--ink-soft);
}

.doc-body > *:first-child {
  margin-top: 0;
}

.doc-body p {
  margin: 0 0 var(--space-4);
  text-wrap: pretty;
}

.doc-body .doc-lede {
  font-size: 19px;
  line-height: 1.55;
  color: var(--ink);
  margin-bottom: var(--space-5);
}

.doc-body h2 {
  margin: var(--space-8) 0 var(--space-3);
  font-size: 23px;
  font-weight: 620;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--ink);
  text-wrap: balance;
}

.doc-body h3 {
  margin: var(--space-6) 0 var(--space-2);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.doc-body ul,
.doc-body ol {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-5);
}

.doc-body li {
  margin: 0 0 var(--space-2);
}

.doc-body a {
  color: var(--accent);
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.doc-body strong {
  font-weight: 640;
  color: var(--ink);
}

.doc-body blockquote {
  margin: var(--space-5) 0;
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.55;
  color: var(--ink);
}

.doc-body blockquote p:last-child {
  margin-bottom: 0;
}

.doc-body table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-5) 0;
  font-size: 15px;
}

.doc-body th,
.doc-body td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.doc-body th {
  font-weight: 600;
  color: var(--ink);
}

/* --------------------------------------------------- Old-revision banner */

.revbanner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 0 var(--space-5);
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--tone-amber) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--tone-amber) 30%, var(--line));
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.revbanner p {
  margin: 0;
}

.revbanner__link {
  font-weight: 600;
  color: var(--ink);
}

/* --------------------------------------------------------- Sources block */

.sources {
  margin: var(--space-10) 0 0;
  padding: var(--space-6) 0 0;
  border-top: 1px solid var(--line);
}

.sources__heading {
  margin: 0 0 var(--space-4);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.sources__empty {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.sources__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.source {
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.source__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.source__title {
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  text-underline-offset: 2px;
}

.source__title:hover {
  text-decoration: underline;
}

.source__snippet {
  margin: var(--space-2) 0 0;
  font-size: 14.5px;
  color: var(--muted-2);
  line-height: 1.55;
}

.source__meta {
  margin: var(--space-2) 0 0;
  font-size: 12.5px;
  color: var(--muted);
  word-break: break-word;
}

.source__url {
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------ Structured metadata (SHELL-5) */

.struct-meta {
  margin: var(--space-6) 0 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.struct-meta__summary {
  cursor: pointer;
  padding: var(--space-3) var(--space-4);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  list-style: none;
}

.struct-meta__summary::-webkit-details-marker {
  display: none;
}

.struct-meta__summary::after {
  content: "+";
  float: right;
  color: var(--muted);
  font-weight: 400;
}

.struct-meta[open] .struct-meta__summary::after {
  content: "-";
}

.struct-meta__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-3) var(--space-5);
  margin: 0;
  padding: 0 var(--space-4) var(--space-4);
}

.struct-meta__grid div {
  min-width: 0;
}

.struct-meta__grid dt {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.struct-meta__grid dd {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--ink-soft);
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------- Site footer */

.sitefoot {
  max-width: 1120px;
  margin: var(--space-8) auto 0;
  padding: var(--space-6) var(--space-5) var(--space-8);
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  color: var(--muted);
  font-size: 13px;
}

.sitefoot__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.sitefoot__brand .brand-logo {
  width: 20px;
  height: 20px;
}

.sitefoot__ids {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* -------------------------------------------------------- Buttons (chrome) */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--space-5);
  font: 600 15px var(--font);
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.14s ease, border-color 0.14s ease;
}

.btn--primary {
  background: var(--ink);
  color: var(--surface);
}

.btn--primary:hover {
  background: var(--ink-soft);
}

/* --------------------------------------------------------------- Motion */

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---------------------------------------------------------- Responsive */

@media (max-width: 768px) {
  .topbar__inner {
    padding: 0 var(--space-4);
  }
  .leaf__main {
    padding: var(--space-6) var(--space-4);
  }
  .iconbtn__label {
    /* keep labels; they stay readable and touch targets remain 44px */
  }
  .meta__dates {
    gap: var(--space-5);
  }
}

@media (max-width: 480px) {
  body {
    font-size: 15px;
  }
  .doc-body {
    font-size: 16px;
  }
}

/* ============================================================ Phase 2 chrome */

/* --------------------------------------- In-document search overlay (SRCH-1) */

.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh var(--space-4) var(--space-4);
}

.search-overlay__scrim {
  position: absolute;
  inset: 0;
  background: rgba(9, 9, 11, 0.36);
}

.search-overlay__panel {
  position: relative;
  width: min(620px, 100%);
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  animation: search-in 0.16s ease;
}

@keyframes search-in {
  from {
    transform: translateY(-8px);
    opacity: 0.7;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.search-overlay__field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
}

.search-overlay__input {
  flex: 1 1 auto;
  min-height: 40px;
  border: none;
  outline: none;
  font: 400 16px var(--font);
  color: var(--ink);
  background: transparent;
}

.search-overlay__input::placeholder {
  color: var(--muted);
}

.search-overlay__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  cursor: pointer;
}

.search-overlay__close:hover {
  color: var(--ink);
  background: var(--subtle);
}

.search-overlay__hint {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  font-size: 13px;
  color: var(--muted);
}

.search-overlay__results {
  list-style: none;
  margin: 0;
  padding: var(--space-2);
  overflow-y: auto;
}

.search-result__btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-3) var(--space-3);
  font: 400 14px var(--font);
  line-height: 1.5;
  color: var(--muted-2);
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
}

.search-result__btn:hover {
  background: var(--subtle);
  color: var(--ink-soft);
}

.search-result__btn mark {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--ink);
  border-radius: 3px;
  padding: 0 2px;
}

/* Transient highlight when a search result is jumped to. */
.search-hit {
  animation: hit-flash 1.6s ease;
}

@keyframes hit-flash {
  0%,
  30% {
    background: color-mix(in srgb, var(--accent) 16%, transparent);
  }
  100% {
    background: transparent;
  }
}

/* ------------------------------------------------- Table of contents (RESP-4/5) */

.toc {
  position: fixed;
  top: 96px;
  left: calc((100vw - 760px) / 2 - 236px);
  width: 208px;
  max-height: 70vh;
  overflow-y: auto;
  padding-right: var(--space-3);
}

.toc__title {
  margin: 0 0 var(--space-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toc__link {
  display: block;
  padding: 4px var(--space-2);
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted-2);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.toc__link:hover {
  color: var(--ink);
  border-left-color: var(--line-strong);
  background: var(--subtle);
}

.toc__link--sub {
  padding-left: var(--space-4);
  font-size: 12px;
  color: var(--muted);
}

/* Hide the fixed rail when the viewport is too narrow to hold it beside the
   column; the floating fab takes over there (RESP-4). */
@media (max-width: 1240px) {
  .toc {
    display: none;
  }
}

/* When collapsed on scroll, the inline rail hides and the fab is shown. */
.toc--collapsed {
  display: none;
}

/* Floating hamburger fab (RESP-4). */
.toc-fab {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 55;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--ink);
  border: none;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

.toc-fab__bars {
  position: relative;
  width: 18px;
  height: 2px;
  background: var(--surface);
  border-radius: 2px;
}

.toc-fab__bars::before,
.toc-fab__bars::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: var(--surface);
  border-radius: 2px;
}

.toc-fab__bars::before {
  top: -6px;
}

.toc-fab__bars::after {
  top: 6px;
}

/* Bottom sheet the fab opens (mobile / collapsed). */
.toc-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.toc-sheet__scrim {
  position: absolute;
  inset: 0;
  background: rgba(9, 9, 11, 0.36);
}

.toc-sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 70vh;
  overflow-y: auto;
  padding: var(--space-5);
  background: var(--surface);
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
  box-shadow: var(--shadow-md);
  animation: sheet-in 0.18s ease;
}

@keyframes sheet-in {
  from {
    transform: translateY(16px);
    opacity: 0.7;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toc-sheet__title {
  margin: 0 0 var(--space-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.toc-sheet__list {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toc-sheet__link {
  display: block;
  padding: var(--space-2) var(--space-2);
  font-size: 15px;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: var(--radius-xs);
}

.toc-sheet__link:hover {
  background: var(--subtle);
  color: var(--ink);
}

.toc-sheet__link--sub {
  padding-left: var(--space-4);
  font-size: 14px;
  color: var(--muted-2);
}

.toc-sheet__top {
  display: inline-block;
  margin-top: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
}

.toc-sheet__top:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* --------------------------------------- Mobile collapsing header search (RESP-2) */

@media (max-width: 640px) {
  /* The label collapses to an icon-sized control; tapping expands the search
     into the full-width overlay (SRCH-1), so no inline row is needed. */
  .iconbtn--search-toggle .iconbtn__label {
    font-size: 0;
  }
  .iconbtn--search-toggle .iconbtn__label::before {
    content: "\1F50D";
    font-size: 16px;
  }
  .iconbtn--search-toggle {
    min-width: 44px;
    padding: 0 var(--space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .search-overlay__panel,
  .toc-sheet__panel {
    animation: none;
  }
}

/* ------------------------------------------------------- Versions list page */

.versions {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-4);
}

.versions__eyebrow {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 var(--space-2);
}

.versions__title {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 var(--space-3);
  text-wrap: balance;
}

.versions__sub {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 var(--space-6);
}

.versions__sub a {
  color: var(--ink);
  font-weight: 600;
}

.versions__empty {
  color: var(--muted);
}

.versions__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.version-row {
  padding: var(--space-4) 0;
  border-top: 1px solid var(--line);
}

.version-row:last-child {
  border-bottom: 1px solid var(--line);
}

.version-row__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.version-row__label {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}

.version-row--current .version-row__label {
  color: var(--accent);
}

.version-row__meta {
  margin: var(--space-1) 0 0;
  font-size: 13px;
  color: var(--muted);
}

.version-row__note {
  margin: var(--space-2) 0 0;
  font-size: 14px;
  color: var(--ink-soft, var(--ink));
}

/* ==========================================================================
   Phase 4 — export menu, chart lightbox, progressive reveal, print
   ========================================================================== */

/* --- Export menu (EXP-1..7) ---------------------------------------------- */

.export {
  position: relative;
}

.export-menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 40;
  min-width: 240px;
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

.export-menu[hidden] {
  display: none;
}

.export-menu__title {
  margin: var(--space-1) var(--space-2) var(--space-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.export-menu__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.export-menu__item[hidden] {
  display: none;
}

.export-menu__btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  background: none;
  border: 0;
  border-radius: var(--radius-xs);
  cursor: pointer;
  color: var(--ink);
  font: inherit;
}

.export-menu__btn:hover,
.export-menu__btn:focus-visible {
  background: var(--subtle);
  outline: none;
}

.export-menu__label {
  font-size: 15px;
  font-weight: 600;
}

.export-menu__hint {
  font-size: 12px;
  color: var(--muted);
}

/* --- Chart lightbox (CHART-2) -------------------------------------------- */

.chart--zoomable {
  cursor: zoom-in;
}

.chart-lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.chart-lightbox[hidden] {
  display: none;
}

.chart-lightbox__scrim {
  position: absolute;
  inset: 0;
  background: rgba(9, 9, 11, 0.72);
}

.chart-lightbox__panel {
  position: relative;
  z-index: 1;
  max-width: min(1100px, 96vw);
  max-height: 92vh;
  width: 100%;
  padding: var(--space-5);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: auto;
}

.chart-lightbox__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 36px;
  height: 36px;
  font-size: 22px;
  line-height: 1;
  background: var(--subtle);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
}

.chart-lightbox__close:hover,
.chart-lightbox__close:focus-visible {
  background: var(--line);
  outline: none;
}

.chart-lightbox__stage {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.chart-lightbox__canvas {
  max-width: 100%;
  height: auto;
}

.chart-lightbox__caption {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.chart-lightbox__caption[hidden] {
  display: none;
}

/* --- Progressive reveal (CHART-4) ---------------------------------------- */

.doc-body li[hidden] {
  display: none;
}

.reveal-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0 var(--space-5);
}

.reveal-btn {
  padding: var(--space-2) var(--space-4);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xs);
  cursor: pointer;
}

.reveal-btn:hover,
.reveal-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.reveal-btn[hidden] {
  display: none;
}

/* --- Print / PDF (EXP-2) -------------------------------------------------- */

@media print {
  .topbar,
  .sitefoot,
  .toc,
  .toc-fab,
  .toc-sheet,
  .search-overlay,
  .chart-lightbox,
  .export,
  .export-menu,
  .reveal-controls {
    display: none !important;
  }

  /* Print every list item, regardless of the reveal collapse state. */
  .doc-body li[hidden] {
    display: list-item !important;
  }

  body,
  .leaf__main,
  .leaf__article {
    margin: 0;
    padding: 0;
    background: #fff;
    color: #000;
  }

  .leaf__article {
    max-width: none;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #555;
    word-break: break-all;
  }

  /* Don't append the URL for in-page anchors or javascript-less controls. */
  a[href^="#"]::after {
    content: "";
  }

  .struct-meta {
    display: none;
  }

  h1, h2, h3 {
    break-after: avoid;
  }

  table, figure, blockquote {
    break-inside: avoid;
  }
}
