/* Self-hosted fonts (specs/fonts/typography.kmd — no Google Fonts/CDNs).
   Same latin-400 subsets the KDS ships; heavier weights synthesize. */
@font-face {
  font-family: 'Inter';
  src: url('/_assets/fonts/inter-latin-400.woff2?v=9cf1c67b3f55') format('woff2');
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/_assets/fonts/jetbrains-mono-400.woff2?v=9cf1c67b3f55') format('woff2');
  font-weight: 100 800; font-style: normal; font-display: swap;
}

/* Palette/typography tokens come from the shared Verge Web export
   (kds.koder.dev/tokens/verge-web.css, vendored at _assets/tokens/ —
   META-DOCS-171). The portal only maps its local var names onto the
   shared --kw-* tokens; values are byte-identical to what shipped
   before the adoption (zero visual change by construction). */
:root {
  color-scheme: light;
  --bg: var(--kw-bg);
  --bg-soft: var(--kw-surface);
  --text: var(--kw-text);
  --text-soft: var(--kw-text-soft);
  --text-muted: var(--kw-text-muted);
  --border: var(--kw-border);
  --accent: var(--kw-accent);
  --accent-strong: var(--kw-accent-strong);
  --code-bg: var(--kw-code-bg);
  --font-sans: var(--kw-font-sans);
  --font-mono: var(--kw-font-mono);
  --max-content: 760px;
}

[data-theme="dark"] {
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-sans); background: var(--bg); color: var(--text); line-height: 1.6; }

/* Skip link (WCAG 2.4.1 Bypass Blocks) — visually hidden until keyboard focus. */
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 200; padding: 8px 12px;
  background: var(--text); color: var(--bg); border-radius: 8px; text-decoration: none;
  font-weight: 600; transition: top .15s; }
.skip-link:focus { top: 8px; outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent-strong); text-decoration: none; border-bottom: 1px solid var(--border); }
a:hover { border-bottom-color: var(--accent); }
code { font-family: var(--font-mono); background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 3px; font-size: 0.92em; }
pre { background: var(--code-bg); padding: 1em; border-radius: 6px; overflow-x: auto; }
pre code { background: none; padding: 0; }

.docs-nav { position: sticky; top: 0; z-index: 100; background: rgba(255,255,255,0.85); backdrop-filter: blur(16px); border-bottom: 1px solid var(--border); }
[data-theme="dark"] .docs-nav { background: rgba(5,8,15,0.85); }
.nav-inner { max-width: 1200px; margin: 0 auto; padding: 0.75rem 1.5rem; display: flex; align-items: center; justify-content: space-between; }
.nav-brand { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; border: none; }
.nav-brand img { width: 24px; height: 24px; }
.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a { border: none; color: var(--text-soft); font-weight: 500; }
.nav-links a:hover { color: var(--text); }
.theme-toggle { background: transparent; border: none; cursor: pointer; color: var(--text-soft); font-size: 1.1rem; padding: 0.25rem 0.5rem; border-radius: 4px; }
.nav-toggle { display: none; background: transparent; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; color: var(--text-soft); font-size: 1.1rem; padding: 0.25rem 0.6rem; }

main { max-width: 1200px; margin: 0 auto; padding: 2.5rem 1.5rem; }

/* 3-column layout (doc page only): sidebar | main | TOC */
.doc-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr) 200px; gap: 2rem; max-width: 1400px; margin: 0 auto; padding: 2rem 1.5rem; align-items: start; }
.doc-layout > main { padding: 0; margin: 0; max-width: none; min-width: 0; }
.doc-layout > main article { max-width: var(--max-content); }

.doc-sidebar { position: sticky; top: 5rem; max-height: calc(100vh - 6rem); overflow-y: auto; font-size: 0.92rem; padding-right: 0.5rem; }
.sidebar-header { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; padding-bottom: 0.5rem; margin-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.sidebar-cat { font-weight: 700; color: var(--text); border: none; font-size: 0.95rem; }
.sidebar-count { font-size: 0.75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sidebar-tree { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.25rem; }
.sidebar-tree a { display: block; padding: 0.35rem 0.5rem; border-radius: 4px; border: none; color: var(--text-soft); font-size: 0.88rem; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-tree a:hover { background: var(--bg-soft); color: var(--text); }
.sidebar-tree a.active { background: var(--code-bg); color: var(--text); font-weight: 600; }

.doc-toc { position: sticky; top: 5rem; max-height: calc(100vh - 6rem); overflow-y: auto; font-size: 0.85rem; padding-left: 0.5rem; border-left: 1px solid var(--border); }
.toc-label { text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.7rem; color: var(--text-muted); font-weight: 600; margin: 0 0 0.75rem; padding-left: 0.6rem; }
.doc-toc ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.25rem; }
.doc-toc a { display: block; padding: 0.25rem 0.6rem; border: none; color: var(--text-soft); border-left: 2px solid transparent; line-height: 1.35; }
.doc-toc a:hover { color: var(--text); }
.doc-toc a.active { color: var(--text); border-left-color: var(--accent-strong); font-weight: 600; }
.toc-h3 { padding-left: 0.75rem; font-size: 0.82rem; }

/* Home */
.docs-home .hero { text-align: center; padding: 3rem 0 2.5rem; max-width: var(--max-content); margin: 0 auto; }
.docs-home .eyebrow { text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.8rem; color: var(--accent); font-weight: 600; }
.docs-home h1 { font-size: 3rem; margin: 0.5rem 0 1rem; }
/* Accent-gradient headline word (spec §5.1) — brand cyan→orange signature. */
.docs-home h1 .grad { background: linear-gradient(90deg, #22d3ee, #fb923c); -webkit-background-clip: text; background-clip: text; color: transparent; }
.docs-home .lead { color: var(--text-soft); font-size: 1.15rem; }
.hero-ctas { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: center; margin-top: 1.75rem; }
.btn { display: inline-block; padding: 0.6rem 1.2rem; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-soft); color: var(--text); font-weight: 500; }
.btn:hover { border-color: var(--accent); background: var(--code-bg); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

/* Home intro — README.md rendered as the portal overview (koder-tools#063).
   .doc-body styles are scoped to .docs-doc, so the home intro needs its own. */
.docs-home .home-intro { max-width: var(--max-content); margin: 1rem auto 0; line-height: 1.6; }
.docs-home .home-intro h2 { font-size: 1.5rem; margin: 2.25rem 0 0.75rem; padding-bottom: 0.4rem; border-bottom: 1px solid var(--border); }
.docs-home .home-intro h3 { margin: 1.75rem 0 0.5rem; }
.docs-home .home-intro p { color: var(--text-soft); margin: 0.75rem 0; }
.docs-home .home-intro ul { color: var(--text-soft); padding-left: 1.25rem; }
.docs-home .home-intro li { margin: 0.3rem 0; }
.docs-home .home-intro a { color: var(--accent); }
.docs-home .home-intro blockquote { margin: 1rem 0; padding: 0.6rem 1rem; border-left: 3px solid var(--accent); background: var(--bg-soft); border-radius: 0 6px 6px 0; }
.docs-home .home-intro table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: 0.95rem; }
.docs-home .home-intro th, .docs-home .home-intro td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; text-align: left; vertical-align: top; }
.docs-home .home-intro th { background: var(--bg-soft); }
.docs-home .home-intro pre { background: var(--code-bg); padding: 1rem; border-radius: 6px; overflow-x: auto; margin: 1rem 0; }

/* Recently updated (spec §5.1) */
.recent { max-width: var(--max-content); margin: 3rem auto 0; }
.recent h2 { font-size: 1.3rem; margin-bottom: 1rem; }
.recent-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.recent-list li { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: 0.45rem 0.6rem; border-radius: 6px; min-width: 0; }
.recent-list li:hover { background: var(--bg-soft); }
.recent-list a { border: none; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-list time { color: var(--text-muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.category-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-top: 2.5rem; }
.category-card { display: block; padding: 1.5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-soft); transition: transform 0.15s, border-color 0.15s; }
.category-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.category-card h3 { margin: 0 0 0.5rem; }
.category-card p { color: var(--text-soft); margin: 0 0 0.75rem; }
.category-card .count { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }

/* Category listing */
.breadcrumbs { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.breadcrumbs a { border: none; color: var(--text-soft); }
.cat-header h1 { margin: 0 0 0.5rem; font-size: 2.25rem; }
.cat-header .lead { color: var(--text-soft); margin: 0; }
.cat-header .meta { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.5rem; }
.doc-list { list-style: none; padding: 0; margin: 2rem 0; display: grid; gap: 1.25rem; }
.doc-list li { padding: 1rem 1.25rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-soft); }
.doc-list .summary { color: var(--text-soft); margin: 0.5rem 0 0; }
.doc-list .slug { font-size: 0.85rem; color: var(--text-muted); margin: 0.5rem 0 0; }

/* Doc page */
.docs-doc article { max-width: var(--max-content); margin: 0 auto; }
.docs-doc .doc-header h1 { margin: 0 0 0.5rem; }
.docs-doc .doc-header .summary { color: var(--text-soft); font-size: 1.05rem; }
.docs-doc .doc-body { margin-top: 2rem; }
.docs-doc .doc-body h2 { margin-top: 2.5rem; padding-bottom: 0.4rem; border-bottom: 1px solid var(--border); }
.docs-doc .doc-body h3 { margin-top: 2rem; }
.docs-doc .doc-body table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
.docs-doc .doc-body th, .docs-doc .doc-body td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; text-align: left; }
.docs-doc .doc-body th { background: var(--bg-soft); }
.docs-doc .doc-footer { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); font-size: 0.9rem; color: var(--text-muted); }

.badge { display: inline-block; padding: 0.15em 0.6em; font-size: 0.75rem; font-weight: 600; border-radius: 999px; background: var(--code-bg); color: var(--text-soft); margin-right: 0.4em; text-transform: uppercase; letter-spacing: 0.05em; }
.badge.mandatory { background: rgba(239, 68, 68, 0.15); color: #b91c1c; }
[data-theme="dark"] .badge.mandatory { color: #fca5a5; }

/* Footer — dark multi-column per institutional.kmd §8 (same in both themes). */
.docs-footer { margin-top: 4rem; background: #070b14; color: #94a3b8; font-size: 0.9rem; }
.footer-grid { max-width: 1200px; margin: 0 auto; padding: 3rem 1.5rem 2rem; display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 2rem; }
.footer-brand .nav-brand { color: #f1f5f9; }
.footer-brand p { margin: 0.75rem 0 0; max-width: 36ch; line-height: 1.55; }
.footer-col { display: grid; gap: 0.45rem; align-content: start; }
.footer-col h3 { margin: 0 0 0.35rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: #cbd5e1; }
.docs-footer a { color: #94a3b8; border: none; }
.docs-footer a:hover { color: #f1f5f9; }
.footer-bar { border-top: 1px solid rgba(255,255,255,0.08); }
.footer-bar p { max-width: 1200px; margin: 0 auto; padding: 1.1rem 1.5rem; text-align: center; font-size: 0.82rem; opacity: 0.8; }
.footer-bar code { background: rgba(255,255,255,0.08); color: inherit; }
@media (max-width: 800px) { .footer-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .footer-grid { grid-template-columns: 1fr; } }

.docs-404 .not-found { text-align: center; padding: 4rem 0; max-width: var(--max-content); margin: 0 auto; }
.docs-404 .eyebrow { font-size: 5rem; font-weight: 700; color: var(--accent); line-height: 1; margin-bottom: 0.5rem; opacity: 0.4; }
.docs-404 h1 { font-size: 2.5rem; margin: 0 0 1rem; }
.docs-404 .lead { color: var(--text-soft); font-size: 1.1rem; }
.docs-404 .not-found-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: center; margin-top: 2.5rem; }
/* Doc footer: prev/next + search route */
.doc-prevnext { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1.25rem; }
.doc-prevnext a { border: none; color: var(--text-soft); font-weight: 500; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-prevnext a:hover { color: var(--text); }

.docs-search .search-input { width: 100%; max-width: var(--max-content); padding: 0.75rem 1rem; font-size: 1.05rem;
  font-family: var(--font-sans); color: var(--text); background: var(--bg-soft);
  border: 1px solid var(--border); border-radius: 8px; }
.docs-search .search-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.docs-search .search-status { color: var(--text-muted); margin: 0.75rem 0; }
.search-group h2 { font-size: 1.1rem; margin: 2rem 0 0.75rem; color: var(--text-soft); }
.search-group ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.9rem; }
.search-group li { padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-soft); }
.search-group .summary { color: var(--text-soft); margin: 0.4rem 0 0; font-size: 0.92rem; }
mark { background: rgba(251, 146, 60, 0.3); color: inherit; border-radius: 2px; padding: 0 0.1em; }

/* Responsive reflow (WCAG 1.4.10): wide tables and code blocks already ship in a
   wrapper — give those wrappers the scroll so they NEVER push the page wider than
   the viewport (was: .kmd-table-wrap up to 1293px wide on a 375px phone → the whole
   page had to be pinch-zoomed). Long unbroken slugs/paths wrap instead of widening. */
.kmd-table-wrap { max-width: 100%; overflow-x: auto; }
.kmd-code-block, .kmd-pre { max-width: 100%; overflow-x: auto; }
.doc-body, .doc-body td, .doc-body li, code, .doc-list li, .doc-list .slug, .doc-list .summary, .doc-list a { overflow-wrap: anywhere; }

@media (max-width: 1100px) {
  .doc-layout { grid-template-columns: 220px minmax(0, 1fr); gap: 1.5rem; }
  .doc-toc { display: none; }
}
@media (max-width: 800px) {
  .doc-layout { grid-template-columns: 1fr; padding: 1.5rem 1rem; }
  .doc-sidebar { position: static; max-height: none; border-bottom: 1px solid var(--border); padding-bottom: 1rem; margin-bottom: 1rem; }
  .sidebar-tree { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
@media (max-width: 640px) {
  /* Mobile nav = hamburger (spec §8): toggle reveals the links as a column.
     The links stay in the DOM (keyboard/SR reachable via the toggle). */
  .nav-toggle { display: inline-block; }
  .nav-inner { flex-wrap: wrap; row-gap: 0.5rem; }
  .nav-links { display: none; }
  .docs-nav.nav-open .nav-links { display: grid; width: 100%; order: 3; gap: 0.25rem; padding: 0.5rem 0 0.75rem; }
  .docs-nav.nav-open .nav-links a { padding: 0.5rem 0.25rem; font-size: 0.95rem; }
  .docs-home h1 { font-size: 2.25rem; }
  main { padding: 1.5rem 1rem; }
  .docs-404 .eyebrow { font-size: 3.5rem; }
}
