/* ==========================================================================
   Slate — Client Documentation
   Shared stylesheet. Light and dark, minimal, print-friendly, self-contained.

   Theming: every colour is a custom property on :root (light) and is
   re-declared under [data-theme="dark"]. Nothing below hard-codes a colour,
   so the two themes cannot drift apart. The active theme is set on <html> by
   a tiny inline script in each page's <head>, before first paint, so there is
   no flash of the wrong theme.
   ========================================================================== */

:root {
  color-scheme: light;

  --ink: #16181d;
  --ink-2: #3d424d;
  --ink-3: #646b78;
  /* --ink-4 is the quietest text on the page (nav group labels, the doc-card
     numbers, the footer). It is pinned so that it still clears 4.5:1 on
     --bg-3, the darkest surface it ever lands on — not just on white. */
  --ink-4: #666d7b;
  --line: #e6e8ec;
  --line-2: #f1f2f5;
  --bg: #ffffff;
  --bg-2: #fafbfc;
  --bg-3: #f5f6f8;

  --accent: #2f5fe0;
  --accent-soft: #eef2fd;
  --accent-line: #d4defa;

  --ok: #147a4b;
  --ok-soft: #e9f6ef;
  --ok-line: #c9e8d8;

  --warn: #9a6206;
  --warn-soft: #fdf4e3;
  --warn-line: #f0dfba;

  --stop: #b3352f;
  --stop-soft: #fdeceb;
  --stop-line: #f4cdcb;

  /* The brand chip inverts between themes, so it needs its own pair rather
     than reusing --ink (which would put white on white in dark mode). */
  --brand-bg: #16181d;
  --brand-fg: #ffffff;

  --ring: rgba(47, 95, 224, 0.45);
  --shadow: 0 1px 2px rgba(16, 18, 24, 0.05), 0 6px 20px rgba(16, 18, 24, 0.05);

  --radius: 10px;
  --radius-lg: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

/* ── dark ───────────────────────────────────────────────────────────────── */

[data-theme="dark"] {
  color-scheme: dark;

  /* Deliberately not pure black: a long document needs a surface that is
     easier on the eye, with text that stays crisp rather than glaring. */
  --ink: #f1f4f9;
  --ink-2: #c2c9d5;
  --ink-3: #a2abba;
  /* See the note in the light block: --ink-4 has to clear 4.5:1 on --bg. */
  --ink-4: #939cab;
  --line: #272d37;
  --line-2: #1f242c;
  --bg: #0f1319;
  --bg-2: #161b23;
  --bg-3: #0a0d12;

  --accent: #82a9ff;
  --accent-soft: #16203a;
  --accent-line: #27385f;

  --ok: #5cc98d;
  --ok-soft: #10231a;
  --ok-line: #1f3d2d;

  --warn: #e2ab45;
  --warn-soft: #291f0d;
  --warn-line: #493a1b;

  --stop: #f07f78;
  --stop-soft: #2b1514;
  --stop-line: #4c2825;

  --brand-bg: #f1f4f9;
  --brand-fg: #0f1319;

  --ring: rgba(130, 169, 255, 0.5);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg-3);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* Only animate colours once the page has settled, so switching themes eases
   but the initial paint does not fade in. */
html.theme-ready body,
html.theme-ready .card,
html.theme-ready .note,
html.theme-ready .table-wrap,
html.theme-ready .side,
html.theme-ready .main,
html.theme-ready .doc-card,
html.theme-ready .kpi,
html.theme-ready .flow-step,
html.theme-ready .pill,
html.theme-ready .role-tag,
html.theme-ready thead th,
html.theme-ready tbody td,
html.theme-ready code {
  transition: background-color 0.18s ease, border-color 0.18s ease,
    color 0.18s ease;
}

::selection { background: var(--accent-soft); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── layout ─────────────────────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  max-width: 1280px;
  margin: 0 auto;
  gap: 0;
  align-items: start;
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 28px 20px 40px 28px;
  border-right: 1px solid var(--line);
  background: var(--bg);
}

.main {
  background: var(--bg);
  padding: 34px 56px 96px;
  min-height: 100vh;
  min-width: 0;
}

.wide .shell { grid-template-columns: 1fr; max-width: 1180px; }
.wide .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
.wide .main { padding: 40px 56px 96px; }

/* ── brand ──────────────────────────────────────────────────────────────── */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  margin-bottom: 4px;
}

.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--brand-bg);
  color: var(--brand-fg);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  flex: none;
}

.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub {
  font-size: 11.5px;
  color: var(--ink-3);
  margin: 0 0 16px 38px;
  letter-spacing: 0.02em;
}

/* ── theme switch ───────────────────────────────────────────────────────── */

.theme-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-3);
  /* Cap the width: in the wide (index) layout the sidebar is full width, and
     a switch stretched across 500px reads as a content block rather than a
     control. It still fills the narrow sidebar in the normal layout. */
  max-width: 220px;
  margin: 0 0 26px;
}
/* The placeholder is empty until theme.js builds the control, so suppress it
   entirely on the rare page where scripting is unavailable. */
.theme-switch:empty { display: none; }

.theme-switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  background: transparent;
  /* Must clear 4.5:1 on --bg-3, where the unselected option sits. */
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  /* 40px tall so the target is comfortable on a phone, where this control
     sits directly under the thumb. */
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.theme-switch button:hover { color: var(--ink); }
.theme-switch button[aria-pressed="true"] {
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.theme-switch button svg { width: 13px; height: 13px; flex: none; }
.theme-switch button span { white-space: nowrap; }

/* ── side nav ───────────────────────────────────────────────────────────── */

.nav-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-4);
  font-weight: 600;
  margin: 22px 0 8px;
}
.nav-label:first-of-type { margin-top: 0; }

.nav { list-style: none; margin: 0; padding: 0; }
.nav a {
  display: block;
  padding: 6px 10px;
  margin: 0 0 1px -10px;
  border-radius: 7px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 13.5px;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav a:hover { background: var(--bg-3); color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }

/* ── typography ─────────────────────────────────────────────────────────── */

h1 {
  font-size: 27px;
  line-height: 1.25;
  letter-spacing: -0.022em;
  font-weight: 600;
  margin: 0 0 10px;
}

h2 {
  font-size: 17px;
  letter-spacing: -0.01em;
  font-weight: 600;
  margin: 44px 0 14px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}
h2:first-of-type { margin-top: 34px; }

h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 28px 0 8px;
  letter-spacing: -0.005em;
}

h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 20px 0 6px;
  color: var(--ink-2);
}

p { margin: 0 0 14px; color: var(--ink-2); }
p.lead {
  font-size: 16px;
  color: var(--ink-2);
  line-height: 1.62;
  margin-bottom: 6px;
}

.kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 10px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

strong { font-weight: 600; color: var(--ink); }
em { font-style: italic; color: var(--ink-3); }

ul, ol { margin: 0 0 14px; padding-left: 22px; color: var(--ink-2); }
li { margin: 0 0 6px; }
li::marker { color: var(--ink-4); }

hr { border: 0; border-top: 1px solid var(--line); margin: 34px 0; }

code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--ink);
}

/* ── page header ────────────────────────────────────────────────────────── */

.page-head { margin-bottom: 8px; }
.page-head .lead { max-width: 74ch; }

.crumb {
  font-size: 12.5px;
  color: var(--ink-3);
  margin-bottom: 14px;
}
.crumb a { color: var(--ink-3); }
.crumb span { color: var(--ink-4); margin: 0 6px; }

/* ── cards ──────────────────────────────────────────────────────────────── */

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  background: var(--bg);
  box-shadow: var(--shadow);
  margin: 0 0 16px;
}
.card > :last-child { margin-bottom: 0; }
.card h3 { margin-top: 0; }
.card p:last-child { margin-bottom: 0; }

.grid { display: grid; gap: 14px; margin: 0 0 20px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ── tables ─────────────────────────────────────────────────────────────── */

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 0 0 20px;
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  background: var(--bg-2);
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-2);
  color: var(--ink-2);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: 0; }
tbody td:first-child { color: var(--ink); font-weight: 500; }
tbody tr:hover td { background: var(--bg-2); }

table.kv td:first-child { width: 210px; }

/* ── pills / badges ─────────────────────────────────────────────────────── */

.pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--ink-2);
  white-space: nowrap;
  line-height: 1.5;
}
.pill.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.pill.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.pill.stop { background: var(--stop-soft); border-color: var(--stop-line); color: var(--stop); }
.pill.info { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

/* ── callouts ───────────────────────────────────────────────────────────── */

.note {
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-4);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--bg-2);
  padding: 13px 18px;
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--ink-2);
}
.note > :last-child { margin-bottom: 0; }
.note .note-t {
  font-weight: 600;
  color: var(--ink);
  font-size: 13px;
  display: block;
  margin-bottom: 3px;
}
.note.rule { border-left-color: var(--stop); background: var(--stop-soft); }
.note.rule .note-t { color: var(--stop); }
.note.tip { border-left-color: var(--accent); background: var(--accent-soft); }
.note.tip .note-t { color: var(--accent); }
.note.good { border-left-color: var(--ok); background: var(--ok-soft); }
.note.good .note-t { color: var(--ok); }

/* ── steps ──────────────────────────────────────────────────────────────── */

.steps { list-style: none; margin: 0 0 20px; padding: 0; counter-reset: s; }
.steps > li {
  position: relative;
  padding: 0 0 18px 38px;
  counter-increment: s;
  border-left: 1px solid var(--line);
  margin-left: 12px;
}
.steps > li:last-child { border-left-color: transparent; padding-bottom: 0; }
.steps > li::before {
  content: counter(s);
  position: absolute;
  left: -13px; top: 0;
  width: 25px; height: 25px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
}
.steps > li > strong:first-child {
  display: block;
  font-size: 14.5px;
  color: var(--ink);
  margin-bottom: 2px;
}
.steps > li p { margin: 0 0 6px; font-size: 14px; }
.steps > li p:last-child { margin-bottom: 0; }

/* ── hero / index ───────────────────────────────────────────────────────── */

.hero {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-2);
  padding: 30px 32px;
  margin: 0 0 26px;
}
.hero h1 { margin-bottom: 8px; }
.hero .lead { margin-bottom: 0; }

.toc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

.doc-card {
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  text-decoration: none;
  color: inherit;
  background: var(--bg);
  transition: border-color 0.14s ease, transform 0.14s ease;
}
.doc-card:hover { border-color: var(--ink-4); text-decoration: none; transform: translateY(-1px); }
.doc-card .n {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-4);
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 7px;
}
.doc-card .t {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  display: block;
  margin-bottom: 5px;
  letter-spacing: -0.01em;
}
.doc-card .d { font-size: 13px; color: var(--ink-3); line-height: 1.55; display: block; }

/* ── misc ───────────────────────────────────────────────────────────────── */

.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 22px; }
.kpi {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--bg-2);
}
.kpi .v { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; display: block; line-height: 1.2; }
.kpi .l { font-size: 11.5px; color: var(--ink-3); display: block; margin-top: 3px; }

.flow { margin: 0 0 20px; }
.flow-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 9px;
}
.flow-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--ink-2);
  font-weight: 500;
}
.flow-step.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.flow-arrow { color: var(--ink-4); font-size: 13px; }

.role-tag {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--ink-2);
  margin-right: 6px;
}

.footer {
  margin-top: 64px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-4);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.next-prev { display: flex; justify-content: space-between; gap: 14px; margin-top: 40px; }
.next-prev a {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 16px;
  font-size: 13.5px;
  color: var(--ink-2);
  font-weight: 500;
  flex: 1;
}
.next-prev a:hover { border-color: var(--ink-4); text-decoration: none; }
.next-prev a .dir { display: block; font-size: 11px; color: var(--ink-4); margin-bottom: 2px; font-weight: 600; letter-spacing: 0.06em; }
.next-prev a.nx { text-align: right; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: static; height: auto; border-right: 0;
    border-bottom: 1px solid var(--line); padding: 20px 22px;
  }
  .main { padding: 26px 22px 72px; min-height: 0; }
  .brand-sub { margin-left: 0; }
  /* On a phone the switch sits under the nav in a single row: stacking it
     above the whole menu pushes the actual content off the screen. */
  .theme-switch {
    margin: 22px 0 0;
    max-width: 190px;
  }
  .grid.three, .grid.four, .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toc-grid { grid-template-columns: 1fr; }
  h1 { font-size: 23px; }
}

@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .grid.two, .grid.three, .grid.four, .kpi-row { grid-template-columns: 1fr; }
  table { font-size: 12.5px; }
  thead th, tbody td { padding: 9px 10px; }
  .main { padding: 22px 16px 64px; }
}

/* ── print ──────────────────────────────────────────────────────────────── */

@media print {
  /* Force the light palette regardless of the reader's theme. The selector
     has to out-rank `[data-theme="dark"]` (0,1,0), so it is doubled up —
     html:root and html[data-theme] are both (0,1,1) and the later rule wins.
     Reset every colour token, not just the ones we happen to remember, so a
     newly added token cannot silently inherit a dark value here.

     Transitions are disabled outright. Without this the theme change animates
     over 180ms, which means the first frames of a print job can be captured
     mid-fade — dark ink on a white page, or worse, white on white. Print has
     no concept of a transition, so it should never wait on one. */
  html:root,
  html[data-theme="dark"],
  html[data-theme="light"] {
    color-scheme: light;
    --ink: #16181d; --ink-2: #3d424d; --ink-3: #646b78; --ink-4: #666d7b;
    --line: #e6e8ec; --line-2: #f1f2f5;
    --bg: #ffffff; --bg-2: #fafbfc; --bg-3: #ffffff;
    --accent: #2f5fe0; --accent-soft: #eef2fd; --accent-line: #d4defa;
    --ok: #147a4b; --ok-soft: #e9f6ef; --ok-line: #c9e8d8;
    --warn: #9a6206; --warn-soft: #fdf4e3; --warn-line: #f0dfba;
    --stop: #b3352f; --stop-soft: #fdeceb; --stop-line: #f4cdcb;
    --brand-bg: #16181d; --brand-fg: #ffffff;
    --ring: rgba(47, 95, 224, 0.45);
    --shadow: none;
  }
  html, body, html * {
    transition: none !important;
    animation: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  body { background: #fff; font-size: 11pt; }
  .shell { display: block; max-width: none; }
  .side, .next-prev, .footer, .theme-switch { display: none; }
  .main { padding: 0; }
  h2 { page-break-after: avoid; }
  .card, table, .note { page-break-inside: avoid; }
  a { color: inherit; }
}
