/* Konstrukt Docs — "Pine, rundat" in a docs variant.
   Tokens follow the Konstrukt design system; the docs variant uses smaller display sizes,
   a pine top bar and hairline structure so it reads as a separate reference surface. */
:root {
  --pine: #1D3A35;
  --pine-deep: #16302C;
  --paper: #FBFAF6;
  --stone: #F0ECE4;
  --stone-2: #E6E0D6;

  --bg: #FBFAF6;
  --surface: #FBFAF6;
  --inset: #F0ECE4;
  --inset-strong: #E6E0D6;
  --ink: #1B2A26;
  --text-2: #566661;
  --label: #57665F;
  --rule: #E2DDD3;
  --rule-soft: #EBE6DD;
  --link: #0A6D80;
  --link-hover: #1D3A35;
  --data: #0A6D80;
  --scenario: #5E8A4C;
  --negative: #8C3A28;
  --topbar: #1D3A35;
  --topbar-ink: #FBFAF6;
  --topbar-2: #B7C4BF;
  --topbar-rule: rgba(251, 250, 246, 0.18);
  --topbar-field: rgba(251, 250, 246, 0.08);
  --current-bg: #F0ECE4;
  --mark: #1D3A35;
  --shadow-panel: 0 30px 80px -40px rgba(12, 26, 23, 0.55);
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--pine);

  --font-display: "Petrona", Georgia, "Times New Roman", serif;
  --font-body: "Instrument Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-pill: 999px;
  --r-card: 14px;
  --r-inset: 10px;
  --r-bar: 4px;
  --topbar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16302C;
    --surface: #16302C;
    --inset: rgba(251, 250, 246, 0.06);
    --inset-strong: rgba(251, 250, 246, 0.1);
    --ink: #FBFAF6;
    --text-2: #B7C4BF;
    --label: #93A09B;
    --rule: rgba(251, 250, 246, 0.14);
    --rule-soft: rgba(251, 250, 246, 0.09);
    --link: #7FC4CE;
    --link-hover: #FBFAF6;
    --data: #7FC4CE;
    --scenario: #85B773;
    --negative: #D08C7A;
    --topbar: #1D3A35;
    --current-bg: rgba(251, 250, 246, 0.08);
    --mark: #C9D8CE;
    --focus: 0 0 0 2px var(--bg), 0 0 0 4px #7FC4CE;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16302C;
  --surface: #16302C;
  --inset: rgba(251, 250, 246, 0.06);
  --inset-strong: rgba(251, 250, 246, 0.1);
  --ink: #FBFAF6;
  --text-2: #B7C4BF;
  --label: #93A09B;
  --rule: rgba(251, 250, 246, 0.14);
  --rule-soft: rgba(251, 250, 246, 0.09);
  --link: #7FC4CE;
  --link-hover: #FBFAF6;
  --data: #7FC4CE;
  --scenario: #85B773;
  --negative: #D08C7A;
  --topbar: #1D3A35;
  --current-bg: rgba(251, 250, 246, 0.08);
  --mark: #C9D8CE;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px #7FC4CE;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 16px; top: -40px; background: var(--pine); color: var(--paper); padding: 6px 12px; border-radius: var(--r-pill); z-index: 50; }
.skip:focus { top: 8px; }
.mono { font-family: var(--font-mono); font-size: 12px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 30;
  background: var(--topbar);
  color: var(--topbar-ink);
  border-bottom: 1px solid var(--topbar-rule);
}
.topbar-in {
  max-width: 1480px; margin: 0 auto; height: var(--topbar-h);
  display: flex; align-items: center; gap: 20px;
  padding-inline: clamp(16px, 3vw, 32px);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--topbar-ink); flex: none; }
.brand:hover { text-decoration: none; color: var(--topbar-ink); }
.brand .logo { height: 20px; width: auto; display: block; }
.brand-docs {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--topbar-2); border-left: 1px solid var(--topbar-rule); padding-left: 12px; line-height: 20px;
}
.search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search input {
  width: 100%; height: 36px; border-radius: var(--r-pill);
  border: 1px solid var(--topbar-rule); background: var(--topbar-field); color: var(--topbar-ink);
  font: 14px var(--font-body); padding: 0 16px;
}
.search input::placeholder { color: var(--topbar-2); }
.results {
  position: absolute; top: 44px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--rule);
  border-radius: var(--r-card); box-shadow: var(--shadow-panel); max-height: 70vh; overflow: auto;
}
.results a { display: block; padding: 8px 10px; border-radius: var(--r-inset); color: var(--ink); }
.results a:hover, .results a.active { background: var(--inset); text-decoration: none; }
.results .r-sec { display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--label); }
.results .r-t { display: block; font-weight: 500; }
.results .r-d { display: block; font-size: 13px; color: var(--text-2); line-height: 1.45; }
.results .r-none { padding: 10px; color: var(--text-2); font-size: 13px; }
.toplinks { display: flex; gap: 18px; flex: none; font-size: 13px; }
.toplinks a { color: var(--topbar-2); }
.toplinks a:hover { color: var(--topbar-ink); }
.navtoggle { display: none; background: none; border: 1px solid var(--topbar-rule); border-radius: var(--r-pill); width: 36px; height: 36px; color: var(--topbar-ink); cursor: pointer; padding: 0; }
.navtoggle svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.75; fill: none; stroke-linecap: round; vertical-align: middle; }

/* ---------- shell ---------- */
.shell {
  max-width: 1480px; margin: 0 auto;
  display: grid; grid-template-columns: 272px minmax(0, 1fr) 232px;
  padding-inline: clamp(16px, 3vw, 32px);
  gap: 0 40px;
}
.sidebar {
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h));
  height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding-block: 28px 40px; border-right: 1px solid var(--rule); padding-right: 20px;
}
.nav-group { margin-bottom: 22px; }
.nav-label {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--label); margin: 0 0 6px;
}
.sidenav ul { list-style: none; margin: 0; padding: 0; }
.sidenav a {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  color: var(--ink); font-size: 14px; line-height: 1.4; padding: 6px 10px; border-radius: var(--r-inset);
}
.sidenav a:hover { background: var(--inset); text-decoration: none; color: var(--ink); }
.sidenav a[aria-current="page"] { background: var(--current-bg); color: var(--ink); font-weight: 500; box-shadow: inset 2px 0 0 var(--mark); }
.nav-gap {
  font-family: var(--font-mono); font-size: 10px; min-width: 20px; height: 18px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-pill); color: var(--negative); border: 1px dashed var(--negative); flex: none;
}

.content { min-width: 0; padding-block: 36px 64px; }
.doc { max-width: 46rem; }
.eyebrow { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--label); margin: 0 0 10px; }
.doc h1, .doc h2, .doc h3, .doc h4 {
  font-family: var(--font-display); font-weight: 400; letter-spacing: -0.024em; text-wrap: balance; color: var(--ink);
}
.doc h1 { font-size: clamp(32px, 4vw, 42px); line-height: 1.08; margin: 0 0 14px; }
.doc h2 { font-size: 27px; line-height: 1.15; margin: 48px 0 12px; padding-top: 22px; border-top: 1px solid var(--rule); }
.doc h3 { font-size: 20px; line-height: 1.25; margin: 32px 0 8px; }
.doc h4 { font-family: var(--font-body); font-weight: 600; letter-spacing: 0; font-size: 15px; margin: 24px 0 6px; }
.doc .headerlink { visibility: hidden; margin-left: 8px; color: var(--label); font-family: var(--font-mono); font-size: 0.7em; }
.doc h2:hover .headerlink, .doc h3:hover .headerlink { visibility: visible; }
.lead { font-size: 17px; line-height: 1.6; color: var(--text-2); margin: 0 0 16px; max-width: 40rem; text-wrap: pretty; }
.doc p, .doc li { text-wrap: pretty; }
.doc p { margin: 0 0 14px; }
.doc ul, .doc ol { padding-left: 22px; margin: 0 0 16px; }
.doc li { margin-bottom: 4px; }
.doc ul > li::marker { color: var(--data); }
.doc strong { font-weight: 600; }
.doc hr { border: 0; border-top: 1px solid var(--rule); margin: 32px 0; }
.doc dl { margin: 0 0 16px; }
.doc dt { font-weight: 600; margin-top: 10px; }
.doc dd { margin: 2px 0 0 0; color: var(--text-2); }

.meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 28px; }
.pill {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: var(--r-pill);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; border: 1px solid var(--rule); color: var(--text-2);
}
a.pill:hover { text-decoration: none; background: var(--inset); color: var(--ink); }
.pill-review { color: var(--scenario); border-color: currentColor; }
.pill-draft { color: var(--label); }
.pill-stub { color: var(--negative); border-color: currentColor; }
.pill-gap { color: var(--negative); border: 1px dashed var(--negative); }
.status-line { display: flex; gap: 12px; align-items: center; }

/* code */
.doc code {
  font-family: var(--font-mono); font-size: 0.86em; background: var(--inset); padding: 1px 5px; border-radius: 5px;
  overflow-wrap: anywhere;
}
.doc pre {
  background: var(--inset); border: 1px solid var(--rule-soft); border-radius: var(--r-inset);
  padding: 14px 16px; overflow-x: auto; margin: 0 0 18px; line-height: 1.55;
}
.doc pre code { background: none; padding: 0; font-size: 13px; overflow-wrap: normal; white-space: pre; }

/* tables */
.doc table {
  display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 4px 0 20px;
  font-size: 14px; line-height: 1.5; font-variant-numeric: tabular-nums;
}
.doc th {
  text-align: left; font-family: var(--font-mono); font-weight: 500; font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--label); border-bottom: 1px solid var(--rule-strong, var(--rule));
  padding: 8px 14px 8px 0; vertical-align: bottom; white-space: nowrap;
}
.doc td { border-bottom: 1px solid var(--rule-soft); padding: 8px 14px 8px 0; vertical-align: top; }
.doc td code { white-space: nowrap; }

/* callouts */
.admonition {
  border: 1px solid var(--rule); border-left: 3px solid var(--data); border-radius: var(--r-inset);
  padding: 12px 16px 2px; margin: 0 0 18px; background: var(--surface);
}
.admonition-title {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--data); margin: 0 0 6px !important;
}
.admonition.tip { border-left-color: var(--scenario); }
.admonition.tip .admonition-title { color: var(--scenario); }
.admonition.warning { border-left-color: var(--negative); }
.admonition.warning .admonition-title { color: var(--negative); }
.admonition.agent { border-left-color: var(--label); background: var(--inset); border-color: transparent; }
.admonition.agent .admonition-title { color: var(--label); }
.admonition.gap { border: 1px dashed var(--negative); background: transparent; }
.admonition.gap .admonition-title { color: var(--negative); }
.admonition.gap .admonition-title::before { content: "Gap · "; }

/* flow diagram */
.flow-wrap { margin: 6px 0 20px; display: grid; gap: 10px; overflow-x: auto; }
.flow { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 0; align-items: stretch; }
.flow li { display: flex; flex-direction: column; justify-content: center; margin: 0; padding: 8px 12px; border: 1px solid var(--rule); border-radius: var(--r-inset); background: var(--surface); position: relative; margin-right: 26px; min-width: 7.5rem; }
.flow li:not(:last-child)::after { content: "→"; position: absolute; right: -20px; top: 50%; transform: translateY(-50%); color: var(--data); font-size: 14px; }
.flow .flow-t { font-weight: 500; font-size: 14px; line-height: 1.3; }
.flow .flow-d { font-size: 12px; color: var(--text-2); line-height: 1.35; margin-top: 2px; font-family: var(--font-mono); }

/* cards on index */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 12px; margin: 8px 0 24px; }
.cards a { display: block; border: 1px solid var(--rule); border-radius: var(--r-card); padding: 14px 16px; color: var(--ink); background: var(--surface); }
.cards a:hover { border-color: var(--data); text-decoration: none; color: var(--ink); }
.cards .c-t { display: block; font-family: var(--font-display); font-size: 19px; letter-spacing: -0.02em; line-height: 1.2; margin-bottom: 4px; }
.cards .c-d { display: block; font-size: 13px; color: var(--text-2); line-height: 1.5; }

/* page toc */
.pagetoc {
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h));
  max-height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding-block: 36px; font-size: 13px;
}
.pagetoc ul { list-style: none; margin: 0; padding: 0; }
.pagetoc ul ul { padding-left: 12px; }
.pagetoc a { display: block; color: var(--text-2); padding: 3px 0 3px 10px; border-left: 1px solid var(--rule); line-height: 1.4; }
.pagetoc a:hover { color: var(--ink); text-decoration: none; }
.pagetoc a.active { color: var(--ink); border-left-color: var(--mark); }

/* prev / next + footer */
.prevnext { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 56px; }
.pn { border: 1px solid var(--rule); border-radius: var(--r-card); padding: 12px 16px; color: var(--ink); display: flex; flex-direction: column; gap: 2px; }
.pn:hover { border-color: var(--data); text-decoration: none; color: var(--ink); }
.pn.next { text-align: right; align-items: flex-end; }
.pn .nav-label { margin: 0; }
.foot { max-width: 46rem; margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--rule); font-size: 13px; color: var(--text-2); }
.foot p { margin: 0; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 252px minmax(0, 1fr); }
  .pagetoc { display: none; }
}
@media (max-width: 880px) {
  .shell { display: block; }
  .navtoggle { display: inline-block; flex: none; }
  .toplinks { display: none; }
  .brand-docs { display: none; }
  .sidebar {
    position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
    top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h)); height: auto;
    background: var(--bg); border-right: 0; padding: 20px 16px 40px;
    display: none;
  }
  body.nav-open .sidebar { display: block; }
  body.nav-open { overflow: hidden; }
  .content { padding-block: 24px 48px; }
  .prevnext { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .search { max-width: none; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
