/* espressostream docs. Design tokens (section 1) are copied from server/internal/web/static/site.css;
   keep them in sync (TestTokensMatchSite checks this when ../server is present). No inline styles (strict CSP). */

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: light;
  /* colours: light */
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --surface-3: #e7e7e3;
  --border: #deded9;
  --border-strong: #c9c9c3;
  --text: #18181b;
  --text-2: #3f3f46;
  --muted: #5f5f68;          /* 5.9:1 on --bg */
  --accent: #9a5200;         /* links/text: 5.6:1 on --surface */
  --accent-hover: #7d4200;
  --accent-bg: #b86a12;      /* filled buttons (with --on-accent) */
  --accent-bg-hover: #9a5200;
  --on-accent: #ffffff;
  --accent-soft: #fbefdf;
  --accent-line: #f0d2a8;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --danger-line: #f5c2bd;
  --success: #1f7a3a;
  --success-bg: #e8f5ec;
  --success-line: #bfe3c9;
  --info-bg: #eef1f6;
  --info-line: #d3dae6;
  --live: #d92d20;
  --mark-bg: #fde7c2;
  --term-bg: #16161a;        /* card previews look like a terminal in both themes */
  --term-fg: #d6d6dc;
  --term-dim: #8a8a94;
  --focus: #b86a12;
  --shadow-1: 0 1px 2px rgb(16 16 20 / .06), 0 1px 1px rgb(16 16 20 / .04);
  --shadow-2: 0 4px 16px rgb(16 16 20 / .08), 0 1px 3px rgb(16 16 20 / .06);
  --shadow-3: 0 12px 32px rgb(16 16 20 / .16), 0 2px 6px rgb(16 16 20 / .08);

  /* type */
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --fs-xs: .75rem;   /* 12 */
  --fs-sm: .8125rem; /* 13 */
  --fs-md: .9375rem; /* 15 */
  --fs-base: 1rem;   /* 16 */
  --fs-lg: 1.125rem; /* 18 */
  --fs-xl: 1.375rem; /* 22 */
  --fs-2xl: 1.75rem; /* 28 */
  --fs-3xl: 2.25rem; /* 36 */

  /* spacing (4 px grid) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px;
  --sp-8: 32px; --sp-10: 40px; --sp-12: 48px; --sp-16: 64px;

  /* radii */
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-pill: 999px;

  --header-h: 56px;
  --container: 1200px;
  --gutter: 16px;
}

/* dark: the system preference unless the visitor picked light */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e0e10;
    --surface: #161619;
    --surface-2: #1d1d21;
    --surface-3: #26262b;
    --border: #2a2a30;
    --border-strong: #3a3a41;
    --text: #ececef;
    --text-2: #c9c9cf;
    --muted: #9d9da7;        /* 7.4:1 on --bg */
    --accent: #f0ae55;       /* 9.6:1 on --bg */
    --accent-hover: #f7c77f;
    --accent-bg: #e89b3a;
    --accent-bg-hover: #f2ae55;
    --on-accent: #1a1206;
    --accent-soft: #2a1f12;
    --accent-line: #5a3f1c;
    --danger: #ff8a7d;
    --danger-bg: #2c1513;
    --danger-line: #5c2a24;
    --success: #7fd497;
    --success-bg: #12241a;
    --success-line: #24492f;
    --info-bg: #171c24;
    --info-line: #2a3342;
    --live: #ff5a4c;
    --mark-bg: #5a3f1c;
    --term-bg: #0b0b0d;
    --focus: #f0ae55;
    --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-2: 0 4px 16px rgb(0 0 0 / .35), 0 1px 3px rgb(0 0 0 / .3);
    --shadow-3: 0 12px 32px rgb(0 0 0 / .55), 0 2px 6px rgb(0 0 0 / .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0e10;
  --surface: #161619;
  --surface-2: #1d1d21;
  --surface-3: #26262b;
  --border: #2a2a30;
  --border-strong: #3a3a41;
  --text: #ececef;
  --text-2: #c9c9cf;
  --muted: #9d9da7;
  --accent: #f0ae55;
  --accent-hover: #f7c77f;
  --accent-bg: #e89b3a;
  --accent-bg-hover: #f2ae55;
  --on-accent: #1a1206;
  --accent-soft: #2a1f12;
  --accent-line: #5a3f1c;
  --danger: #ff8a7d;
  --danger-bg: #2c1513;
  --danger-line: #5c2a24;
  --success: #7fd497;
  --success-bg: #12241a;
  --success-line: #24492f;
  --info-bg: #171c24;
  --info-line: #2a3342;
  --live: #ff5a4c;
  --mark-bg: #5a3f1c;
  --term-bg: #0b0b0d;
  --focus: #f0ae55;
  --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-2: 0 4px 16px rgb(0 0 0 / .35), 0 1px 3px rgb(0 0 0 / .3);
  --shadow-3: 0 12px 32px rgb(0 0 0 / .55), 0 2px 6px rgb(0 0 0 / .4);
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 12px); }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--fs-base)/1.6 var(--font-ui); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
::selection { background: color-mix(in srgb, var(--accent-bg) 35%, transparent); }
.skip-link { position: absolute; left: var(--sp-2); top: var(--sp-2); transform: translateY(-200%); z-index: 100; padding: var(--sp-2) var(--sp-3); background: var(--surface); border-radius: var(--r-sm); box-shadow: var(--shadow-2); }
.skip-link:focus { transform: none; }

/* ---------- 3. Header ---------- */
.docs-header { position: sticky; top: 0; z-index: 10; height: var(--header-h); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.docs-header-inner { height: 100%; max-width: var(--container); margin: 0 auto; padding: 0 var(--gutter); display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); }
.brand { display: flex; align-items: center; gap: var(--sp-2); color: var(--text); text-decoration: none; font-weight: 650; letter-spacing: -.01em; }
.brand:hover { color: var(--text); }
.brand img { display: block; }
.brand-sub { color: var(--muted); font-weight: 500; }
.header-actions { display: flex; align-items: center; gap: var(--sp-3); }
.header-link { font-size: var(--fs-sm); color: var(--text-2); text-decoration: none; }
.header-link:hover { color: var(--accent); }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--text-2); cursor: pointer; }
.theme-toggle:hover { border-color: var(--border-strong); color: var(--text); }
.theme-toggle[hidden] { display: none; }

/* ---------- 4. Layout ---------- */
.docs-layout { max-width: var(--container); margin: 0 auto; padding: var(--sp-4) var(--gutter) var(--sp-12); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
.docs-nav, .toc-side { display: none; }
.docs-main { min-width: 0; }
@media (min-width: 768px) { :root { --gutter: 24px; } }
@media (min-width: 960px) {
  .docs-layout { grid-template-columns: 200px minmax(0, 1fr); gap: var(--sp-8); padding-top: var(--sp-8); }
  .docs-nav { display: block; position: sticky; top: calc(var(--header-h) + var(--sp-6)); align-self: start; }
  .nav-mobile { display: none; }
}
@media (min-width: 1240px) {
  :root { --gutter: 32px; }
  .docs-layout { grid-template-columns: 200px minmax(0, 1fr) 220px; }
  .toc-side { display: block; position: sticky; top: calc(var(--header-h) + var(--sp-6)); align-self: start; max-height: calc(100vh - var(--header-h) - var(--sp-12)); overflow: auto; }
  .toc-mobile { display: none; }
}

.docs-nav ul, .nav-mobile ul, .toc-side ul, .toc-mobile ul { list-style: none; margin: 0; padding: 0; }
.docs-nav a, .nav-mobile a { display: block; padding: 6px var(--sp-3); border-radius: var(--r-sm); color: var(--text-2); text-decoration: none; font-size: var(--fs-md); }
.docs-nav a:hover, .nav-mobile a:hover { background: var(--surface-2); color: var(--text); }
.docs-nav a[aria-current], .nav-mobile a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

details.nav-mobile, details.toc-mobile { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
details.toc-mobile { margin-bottom: var(--sp-6); }
details.nav-mobile > summary, details.toc-mobile > summary { cursor: pointer; padding: var(--sp-3) var(--sp-4); font-weight: 600; font-size: var(--fs-md); list-style: none; display: flex; align-items: center; gap: var(--sp-2); }
details.nav-mobile > summary::-webkit-details-marker, details.toc-mobile > summary::-webkit-details-marker { display: none; }
details.nav-mobile > summary::after, details.toc-mobile > summary::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; }
details[open].nav-mobile > summary::after, details[open].toc-mobile > summary::after { transform: rotate(-135deg); }
.nav-current { color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.nav-mobile > ul, details.toc-mobile > ul { padding: 0 var(--sp-2) var(--sp-3); }

.toc-title { margin: 0 0 var(--sp-2); font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.toc-side a, .toc-mobile a { display: block; padding: 3px 0; color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); line-height: 1.4; }
.toc-mobile a { padding: 5px var(--sp-3); }
.toc-side a:hover, .toc-mobile a:hover { color: var(--accent); }
.toc-l3 a { padding-left: var(--sp-3); }
.toc-mobile .toc-l3 a { padding-left: var(--sp-6); }

/* ---------- 5. Prose ---------- */
.prose { max-width: 78ch; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose h1 { font-size: var(--fs-2xl); line-height: 1.2; letter-spacing: -.02em; margin: 0 0 var(--sp-4); font-weight: 700; }
.prose h2 { font-size: var(--fs-xl); line-height: 1.3; margin: var(--sp-10) 0 var(--sp-3); padding-top: var(--sp-4); border-top: 1px solid var(--border); font-weight: 650; letter-spacing: -.01em; }
.prose h3 { font-size: var(--fs-lg); margin: var(--sp-8) 0 var(--sp-2); font-weight: 650; }
@media (min-width: 768px) { .prose h1 { font-size: var(--fs-3xl); } }
.prose h2, .prose h3 { position: relative; }
.h-anchor { position: absolute; left: -1.1em; width: 1em; color: var(--muted); text-decoration: none; opacity: 0; font-weight: 400; }
.prose h2 .h-anchor { top: var(--sp-4); }
.prose h2:hover .h-anchor, .prose h3:hover .h-anchor { opacity: 1; }
@media (max-width: 767px) { .h-anchor { display: none; } }
.prose p, .prose ul, .prose ol { margin: 0 0 var(--sp-4); }
.prose ul, .prose ol { padding-left: var(--sp-6); }
.prose li { margin: var(--sp-1) 0; }
.prose li > p { margin: 0; }
.prose strong { font-weight: 650; }
.prose blockquote { margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--accent-line); border-left: 4px solid var(--accent-bg); border-radius: var(--r-md); background: var(--accent-soft); color: var(--text); }
.prose blockquote p:last-child { margin: 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-8) 0; }
.prose code { font-family: var(--font-mono); font-size: .875em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: .05em .35em; overflow-wrap: anywhere; }
.prose pre { margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4); background: var(--term-bg); color: var(--term-fg); border: 1px solid var(--border); border-radius: var(--r-md); overflow-x: auto; font: var(--fs-sm)/1.55 var(--font-mono); -webkit-overflow-scrolling: touch; }
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; overflow-wrap: normal; white-space: pre; }
.table-wrap { margin: 0 0 var(--sp-4); overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.prose table { border-collapse: collapse; width: 100%; font-size: var(--fs-md); }
.prose th, .prose td { text-align: left; vertical-align: top; padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); }
.prose th { background: var(--surface-2); font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; }
.prose tr:last-child td { border-bottom: 0; }
.prose td code { white-space: nowrap; overflow-wrap: normal; }
@media (max-width: 600px) { .prose td code { white-space: normal; overflow-wrap: anywhere; } }

/* ---------- 6. Pager, footer ---------- */
.pager { max-width: 78ch; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); margin-top: var(--sp-12); }
.pager a { display: block; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); text-decoration: none; color: var(--text); font-weight: 600; }
.pager a:hover { border-color: var(--accent-line); color: var(--accent); }
.pager span { display: block; font-size: var(--fs-xs); font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.pager-next { grid-column: 2; text-align: right; }
.docs-footer { border-top: 1px solid var(--border); padding: var(--sp-6) var(--gutter); text-align: center; color: var(--muted); font-size: var(--fs-sm); }
