/**
 * Docs + help-center stylesheet.
 *
 * Why plain CSS (and not Tailwind `@apply`):
 * - Article body HTML is pre-rendered at build time by
 *   `scripts/build-docs.mjs` into `src/generated/docs-manifest.ts` as
 *   strings. Those strings are not a reliable scan surface for Tailwind's
 *   `@source` content detector — semantic class names on h2/h3/p/pre would
 *   need every possible variant explicitly enumerated.
 * - The sibling patterns in `build.js` (`buildTryStyles()`,
 *   `buildJoinStyles()`) are already plain PostCSS for the same reason.
 *
 * Consumed by:
 * - `src/ssr/docs/shell.ts` via `<link rel="stylesheet" href="/static/docs.css">`.
 * - The shell also inlines a small fallback copy of the critical rules
 *   below so the page is still legible if this file fails to load.
 *
 * Brand tokens (v3.6 dark-first — resolved at runtime via tokens.css + home.css):
 * - `var(--ink)`, `var(--ink-secondary)`, `var(--ink-tertiary)`, `var(--ink-faint)`
 * - `var(--paper)`, `var(--wash)`, `var(--surface)`
 * - `var(--border)`, `var(--border-light)`
 * - `var(--gradient)`, `var(--gradient-start)`, `var(--accent)`
 * - `var(--success)`, `var(--error)`
 * - `var(--font-sans)`, `var(--font-serif)`, `var(--font-mono)`
 *
 * The shell loads `tokens.css → home.css → docs.css`. home.css forces
 * dark mode on `:root` for every v3.6 surface, so any `var(--ink)` /
 * `var(--paper)` reference here inverts to warm-cream-on-deep-paper
 * automatically. Page-chrome (nav + footer) comes from site-shell.ts
 * + home.css — this file no longer owns `.docs-header` / `.docs-footer`.
 */

/*
 * Page-local tokens. Anything NOT derived from the shared dark palette stays
 * here. Backgrounds for code blocks and callouts are tuned for the dark paper.
 */
:root {
  --docs-warn: rgba(255, 217, 61, 0.08);
  --docs-code-bg: rgba(250, 246, 238, 0.10);
  --docs-pre-bg: rgba(250, 246, 238, 0.06);
  --docs-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --docs-radius-sm: 6px;
  --docs-radius-md: 8px;
  --docs-radius-lg: 12px;
  --docs-radius-pill: 999px;
}

* { box-sizing: border-box; }

/*
 * Body baseline + chrome (.nav, .footer) come from home.css. This file
 * does not declare body styling so home.css's dark paper cascade wins
 * without specificity wars.
 */
a { color: var(--ink); }

.docs-sidebar-toggle {
  display: none;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--docs-radius-md);
  padding: 8px 10px;
  cursor: pointer;
  color: var(--ink-secondary);
}

/* Layout
   ----------------------------------------------------------------- */
.docs-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 220px;
  gap: 40px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px;
}

@media (max-width: 1200px) {
  .docs-layout { grid-template-columns: 240px minmax(0, 1fr); }
  .docs-toc { display: none; }
}

@media (max-width: 900px) {
  .docs-layout { grid-template-columns: minmax(0, 1fr); padding: 20px; gap: 20px; }
  .docs-sidebar-toggle { display: inline-flex; align-items: center; gap: 6px; }
}

/* Sidebar
   ----------------------------------------------------------------- */
.docs-sidebar {
  position: sticky;
  top: 88px;
  align-self: start;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  /*
   * Symmetric horizontal padding is required: `.docs-sidebar-link` below
   * uses `margin: 2px -10px` to bleed the active-state pill to the
   * sidebar's edges, and `overflow-y: auto` establishes a clipping box
   * that also clips overflowing x. Without at least 10px of left
   * padding, the first character of every link gets cut off.
   */
  padding: 0 12px;
}

.docs-sidebar-group {
  margin-bottom: 24px;
}

.docs-sidebar-heading {
  display: block;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-secondary);
  margin-bottom: 8px;
  text-decoration: none;
}

.docs-sidebar-heading:hover { color: var(--ink); }

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

.docs-sidebar-link {
  display: block;
  padding: 6px 10px;
  margin: 2px -10px;
  border-radius: var(--docs-radius-sm);
  color: var(--ink-secondary);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.4;
  transition: background 120ms ease, color 120ms ease;
}

.docs-sidebar-link:hover {
  background: var(--paper);
  color: var(--ink);
}

.docs-sidebar-link--active {
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  border-left: 2px solid var(--accent);
  padding-left: 10px;
  margin-left: -2px;
}

/* Mobile drawer state: toggled via `.docs-body[data-drawer-open="true"]` by
   `client/docs.ts`. When closed on mobile the sidebar is hidden; when open
   it slides in as an overlay. */
@media (max-width: 900px) {
  .docs-sidebar {
    display: none;
    position: fixed;
    inset: 64px 0 0 0;
    background: var(--wash);
    padding: 20px 20px 40px;
    max-height: none;
    overflow-y: auto;
    z-index: 25;
    border-top: 1px solid var(--border);
  }
  body.docs-body[data-drawer-open='true'] .docs-sidebar {
    display: block;
  }
}

/* Breadcrumbs, lede, meta
   ----------------------------------------------------------------- */
.docs-main { min-width: 0; }

.docs-breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--ink-tertiary);
}

.docs-crumb {
  text-decoration: none;
  color: var(--ink-secondary);
}
.docs-crumb[aria-current='page'] { color: var(--ink); font-weight: 600; }
.docs-crumb-sep { color: var(--border); }

.docs-article-meta {
  margin: 0 0 24px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.docs-article-lede {
  font-size: 18px;
  line-height: 1.6;
  color: var(--ink-secondary);
  margin: 0 0 24px;
}

/* Prose (article body)
   ----------------------------------------------------------------- */
.docs-prose h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(32px, 5vw, 44px);
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}

/*
 * H2 separates beats with the sunrise gradient hairline (mirrors policy.css
 * and home.css's `.sec::after`). Size + weight track the brand guide
 * `.sub-head` (28px / 600 / -0.02em).
 */
.docs-prose h2 {
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 64px 0 12px;
  padding-top: 36px;
  position: relative;
  scroll-margin-top: 100px;
}
.docs-prose h2::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1.5px;
  background: var(--gradient);
  opacity: 0.78;
}
.docs-prose h2:first-of-type { margin-top: 56px; }

.docs-prose h3 {
  font-weight: 700;
  font-size: 18px;
  line-height: 1.35;
  margin: 32px 0 10px;
  scroll-margin-top: 100px;
}

.docs-prose p,
.docs-prose li {
  line-height: 1.7;
  color: var(--ink-secondary);
  font-size: 16px;
}

.docs-prose p { margin: 0 0 18px; }

.docs-prose ul,
.docs-prose ol {
  margin: 0 0 20px;
  padding-left: 24px;
}

.docs-prose li + li { margin-top: 6px; }

.docs-prose a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color 120ms ease;
}

.docs-prose a:hover { color: var(--gradient-start); }

/* Heading anchors from `rehype-autolink-headings` (wrap behavior): the
   whole heading becomes an <a>. Strip the underline and add a subtle
   hover affordance. */
.docs-prose h2 a,
.docs-prose h3 a {
  color: inherit;
  text-decoration: none;
}

.docs-prose h2:hover a::after,
.docs-prose h3:hover a::after {
  content: ' §';
  color: var(--ink-tertiary);
  font-weight: 400;
}

.docs-prose code {
  background: var(--docs-code-bg);
  padding: 2px 6px;
  border-radius: var(--docs-radius-sm);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.docs-prose pre {
  background: var(--docs-pre-bg);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--docs-radius-md);
  overflow-x: auto;
  margin: 0 0 24px;
}

.docs-prose pre code {
  background: transparent;
  padding: 0;
  font-size: 14px;
}

.docs-prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 24px;
  font-size: 14px;
}

.docs-prose th,
.docs-prose td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.docs-prose th {
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
}

/* Callouts (admonitions)
   ----------------------------------------------------------------- */
.callout {
  border-left: 4px solid var(--gradient-start);
  background: var(--docs-warn);
  padding: 14px 18px;
  border-radius: var(--docs-radius-sm);
  margin: 24px 0;
}

.callout p { color: var(--ink); margin: 0; }
.callout p + p { margin-top: 10px; }
.callout--tip { border-left-color: var(--success); background: rgba(16, 185, 129, 0.08); }
.callout--warn { border-left-color: var(--error); background: rgba(220, 38, 38, 0.10); }

/* Right-rail TOC
   ----------------------------------------------------------------- */
.docs-toc {
  position: sticky;
  top: 88px;
  align-self: start;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  font-size: 14px;
}

.docs-toc-title {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-secondary);
  margin: 0 0 12px;
}

.docs-toc-list { list-style: none; padding: 0; margin: 0; }
.docs-toc-item { margin: 2px 0; }
.docs-toc-item--h3 { padding-left: 14px; }

.docs-toc-link {
  display: block;
  padding: 4px 10px;
  margin: 0 -10px;
  border-radius: var(--docs-radius-sm);
  color: var(--ink-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  line-height: 1.4;
  transition: color 120ms ease, border-color 120ms ease;
}

.docs-toc-link:hover { color: var(--ink); }

.docs-toc-link[data-active='true'] {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* Prev/next
   ----------------------------------------------------------------- */
.docs-prevnext {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 64px 0 0;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.docs-prevnext-link {
  display: flex;
  flex-direction: column;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--docs-radius-md);
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  transition: border-color 120ms ease, transform 120ms ease;
}

.docs-prevnext-link:hover {
  border-color: var(--ink-secondary);
  transform: translateY(-1px);
}

.docs-prevnext-link--next { text-align: right; }

.docs-prevnext-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
  margin-bottom: 4px;
}

.docs-prevnext-title { font-weight: 600; }

/* Related
   ----------------------------------------------------------------- */
.docs-related {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.docs-related h2 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
}

.docs-related-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.docs-related-list a {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--docs-radius-sm);
  background: var(--paper);
  text-decoration: none;
  color: var(--ink);
}

.docs-related-title { font-weight: 600; }
.docs-related-summary {
  color: var(--ink-secondary);
  font-size: 13px;
  margin-top: 2px;
}

/* Landing hero + category grid
   -----------------------------------------------------------------
   v3.6: landing hero uses home.css's .sec + .sec-headline + .sec-sub
   primitives (rendered by docs/landing.ts as `.docs-landing-hero`).
   The legacy .docs-hero gradient billboard is gone — the gradient
   survives as the .sec::after hairline at the section bottom. */
.docs-landing-hero {
  padding-block: 64px 32px;
  margin-bottom: 32px;
}
.docs-landing-hero .sec-headline { max-width: 22ch; }
.docs-landing-hero .sec-sub { margin-top: 24px; }

.docs-category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/*
 * Category card structure (see `landing.ts#renderCategoryGrid`):
 *
 *   <div class="docs-category-card">                  ← outer box, relative
 *     <a class="docs-category-card-link" href="/…">   ← title/description link
 *       <h3>…</h3><p>…</p>
 *     </a>
 *     <ul class="docs-category-card-list">            ← real article anchors
 *       <li><a href="/…">…</a></li>
 *     </ul>
 *   </div>
 *
 * The outer card is a `<div>` on purpose: HTML5 forbids nested `<a>`, so if
 * the card itself were an anchor the parser would eject the inner
 * `<ul><a>` into the grid as a sibling cell — which caused the visible
 * "raw bulleted list in the right column" bug.
 *
 * The `::after` stretched-link on `.docs-category-card-link` preserves the
 * "whole card clickable" affordance. The inner article `<a>`s sit on top
 * via `position: relative; z-index: 1`.
 */
.docs-category-card {
  position: relative;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--docs-radius-lg);
  background: var(--paper);
  color: inherit;
  transition: border-color 120ms ease, transform 120ms ease;
}

.docs-category-card:hover {
  border-color: var(--ink-secondary);
  transform: translateY(-1px);
}

.docs-category-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.docs-category-card-link::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.docs-category-card h3 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
}

.docs-category-card p {
  margin: 0 0 10px;
  color: var(--ink-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.docs-category-card-list {
  position: relative;
  z-index: 1;
  list-style: none;
  padding: 0;
  margin: 0;
}

.docs-category-card-list li {
  margin-top: 4px;
  font-size: 14px;
  color: var(--ink-secondary);
}

.docs-category-card-list li a {
  color: inherit;
  text-decoration: none;
}

.docs-category-card-list li a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Category index
   ----------------------------------------------------------------- */
.docs-category-header h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(28px, 4vw, 40px);
  margin: 0 0 8px;
}

.docs-category-header p {
  color: var(--ink-secondary);
  font-size: 16px;
  margin: 0 0 32px;
}

.docs-article-list {
  list-style: none;
  counter-reset: docs-article;
  padding: 0;
  margin: 0;
}

.docs-article-row { margin: 12px 0; }

.docs-article-row-link {
  display: block;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--docs-radius-md);
  background: var(--paper);
  text-decoration: none;
  color: var(--ink);
  transition: border-color 120ms ease, transform 120ms ease;
}

.docs-article-row-link:hover {
  border-color: var(--ink-secondary);
  transform: translateY(-1px);
}

.docs-article-row h3 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 700;
}

.docs-article-row p {
  margin: 0 0 8px;
  color: var(--ink-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.docs-article-row-meta {
  font-size: 12px;
  color: var(--ink-tertiary);
  letter-spacing: 0.02em;
}

/* 404 list + empties
   ----------------------------------------------------------------- */
.docs-notfound-list,
.docs-empty {
  color: var(--ink-secondary);
}

.docs-notfound-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  display: grid;
  gap: 6px;
}

.docs-notfound-list a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Search overlay (Phase 4 wires behavior; Phase 3 scaffolds styles)
   ----------------------------------------------------------------- */
.docs-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 11, 16, 0.7);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 20px 20px;
}

.docs-search-overlay[data-open='true'] { display: flex; }

.docs-search-dialog {
  width: 100%;
  max-width: 600px;
  background: var(--paper);
  border-radius: var(--docs-radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.docs-search-input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 18px 20px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
}

.docs-search-results {
  max-height: 50vh;
  overflow-y: auto;
  padding: 8px;
}

.docs-search-result {
  display: block;
  padding: 12px 14px;
  border-radius: var(--docs-radius-sm);
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
}

.docs-search-result[aria-selected='true'],
.docs-search-result:hover {
  background: var(--wash);
}

.docs-search-result-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  font-weight: 600;
}

.docs-search-result-badge {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--docs-radius-pill);
  background: var(--docs-code-bg);
  color: var(--ink-secondary);
}

.docs-search-result-summary {
  display: block;
  color: var(--ink-secondary);
  font-size: 13px;
  margin-top: 2px;
}

.docs-search-empty {
  padding: 24px 20px;
  color: var(--ink-tertiary);
  text-align: center;
  font-size: 14px;
}

.docs-search-empty a { color: var(--ink); }

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