/* ============================================================
   structam.sh: the generated documentation (/docs/ and /docs/<page>)
   Loaded after site.css on docs pages only; every rule is scoped to .docs-gen (the <main> of a generated page)
   or to classes only the docs use. Markup comes from tools/build_docs.py; behaviour from js/docs.js.
   ============================================================ */

/* Subpages mark the Docs link with aria-current="true" (the section, not the page itself). */
.nav-links > a[aria-current="true"] { color: var(--ink); background: var(--tint); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 8px 8px 2px 2px; }

/* ---------- Layout: menu | article | on this page ---------- */
.docs-gen { padding: 40px 0 96px; }
.docs-gen .docs-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr) 208px; gap: 48px; align-items: start; }
/* The sidebar is sticky and does not clip, so the search results can spread over the article; only the page list
   below the search box scrolls. */
.docs-sidebar {
  position: sticky; z-index: 10; top: calc(var(--header-h) + 24px); max-height: calc(100vh - var(--header-h) - 48px);
  display: flex; flex-direction: column;
}
.docs-nav-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 2px 8px 24px 2px;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.docs-gen .docs-nav { position: static; max-height: none; overflow: visible; padding-right: 0; }
.docs-gen .docs-nav ul, .docs-nav-list ul { display: grid; }
.docs-gen .docs-nav a[aria-current="page"] { color: var(--ink); border-left-color: var(--accent); font-weight: 500; }
.docs-nav-mobile { display: none; }
.docs-article { min-width: 0; max-width: 800px; }
.docs-gen .docs-title { font-size: clamp(30px, 3.6vw, 42px); margin-bottom: 12px; text-wrap: balance; }
.docs-gen .docs-lede { font-size: 17.5px; margin-bottom: 28px; text-wrap: pretty; }
.docs-gen .docs-meta { margin: -8px 0 32px; }

/* Breadcrumb */
.docs-crumbs { margin-bottom: 14px; }
.docs-crumbs ol { display: flex; flex-wrap: wrap; gap: 4px 0; font-size: 13.5px; color: var(--ink-subtle); }
.docs-crumbs li + li::before { content: "/"; margin: 0 8px; color: var(--line-strong); }
.docs-crumbs a { color: var(--ink-subtle); text-decoration: underline; text-decoration-color: var(--link-line); text-underline-offset: 3px; }
.docs-crumbs a:hover { color: var(--ink); }
.docs-crumbs [aria-current] { color: var(--ink-muted); }

/* ---------- Search (built by js/docs.js) ---------- */
.docs-search { position: relative; flex: none; margin: 0 8px 18px 2px; }
.docs-search label { display: block; margin-bottom: 6px; font-family: var(--font-display); font-size: 11.5px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-subtle); }
.docs-search-field { position: relative; }
.docs-search input {
  width: 100%; height: 40px; padding: 0 64px 0 12px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14.5px;
}
.docs-search input::placeholder { color: var(--ink-subtle); opacity: 1; }
.docs-search input:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: transparent; }
.docs-search input::-webkit-search-cancel-button { display: none; }
.docs-search-key {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%); padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line); color: var(--ink-subtle); font-family: var(--font-mono); font-size: 11px; pointer-events: none;
}
.docs-search-results {
  position: absolute; z-index: 20; left: 0; top: calc(100% + 6px); width: min(420px, calc(100vw - 40px));
  max-height: min(70vh, 520px); overflow-y: auto; padding: 6px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-lg);
}
.docs-search-results li a { display: block; padding: 9px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.docs-search-results li[aria-selected="true"] a, .docs-search-results li a:hover { background: var(--surface-overlay); }
.docs-result-title { display: block; font-size: 14px; font-weight: 500; line-height: 1.4; }
.docs-result-excerpt { display: block; margin-top: 2px; color: var(--ink-muted); font-size: 13px; line-height: 1.5; }
/* Parchment highlight: ink on it 10.4:1. */
.docs-search-results mark, .docs-search-empty mark { background: var(--selection); color: var(--ink); border-radius: 2px; }
.docs-search-empty { margin-top: 8px; color: var(--ink-subtle); font-size: 13.5px; }

/* ---------- On this page (right column) ---------- */
.docs-toc {
  position: sticky; top: calc(var(--header-h) + 24px); max-height: calc(100vh - var(--header-h) - 48px);
  overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; font-size: 13.5px;
}
.docs-toc-title { margin-bottom: 8px; font-family: var(--font-display); font-size: 11.5px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-subtle); }
.docs-toc ul { display: grid; }
.docs-toc ul ul { margin-left: 12px; }
.docs-toc a {
  display: block; padding: 4px 0 4px 12px; border-left: 1px solid var(--line);
  color: var(--ink-subtle); line-height: 1.4; text-decoration: none; transition: color 0.15s ease, border-color 0.15s ease;
}
.docs-toc a:hover { color: var(--ink); }
.docs-toc a[aria-current="true"] { color: var(--ink); border-left-color: var(--accent); }

/* ---------- Article body ---------- */
.docs-body > * + * { margin-top: 14px; }
.docs-body h2 { margin-top: 52px; padding-top: 28px; border-top: 1px solid var(--line-soft); font-size: 25px; letter-spacing: -0.015em; scroll-margin-top: calc(var(--header-h) + 16px); }
.docs-body > h2:first-child { margin-top: 8px; padding-top: 0; border-top: 0; }
.docs-body h3 { margin-top: 32px; font-family: var(--font-sans); font-size: 18px; font-weight: 600; letter-spacing: 0; scroll-margin-top: calc(var(--header-h) + 16px); }
.docs-body h4 { margin-top: 24px; font-family: var(--font-sans); font-size: 15.5px; font-weight: 600; letter-spacing: 0; scroll-margin-top: calc(var(--header-h) + 16px); }
.docs-body h2 + *, .docs-body h3 + *, .docs-body h4 + * { margin-top: 12px; }
.heading-anchor {
  display: inline-block; margin-left: 8px; padding: 0 4px; border-radius: 4px;
  color: var(--ink-subtle); font-weight: 400; text-decoration: none; opacity: 0; transition: opacity 0.15s ease;
}
.docs-body :is(h2, h3, h4):hover .heading-anchor { opacity: 1; }
.heading-anchor:hover { color: var(--ink); }
@media (hover: none) { .heading-anchor { opacity: 0.6; } }
.docs-body p, .docs-body li { color: var(--ink-muted); font-size: 15.5px; line-height: 1.72; }
.docs-body strong { color: var(--ink); }
.docs-body ul, .docs-body ol { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; padding-left: 4px; }
.docs-body li { min-width: 0; }
.docs-body li > ul, .docs-body li > ol, .docs-body li > .code-block, .docs-body li > p, .docs-body li > .table-wrap, .docs-body li > .note { margin-top: 8px; }
.docs-body ul > li { position: relative; padding-left: 20px; }
.docs-body ul > li::before { content: ""; position: absolute; left: 2px; top: 0.66em; width: 6px; height: 6px; border-radius: 1.5px; background: var(--ink-subtle); }
.docs-body ol { counter-reset: n; }
.docs-body ol > li { position: relative; padding-left: 32px; counter-increment: n; }
.docs-body ol > li::before {
  content: counter(n); position: absolute; left: 0; top: 0.22em; width: 21px; height: 21px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface-overlay); color: var(--ink-muted); font-family: var(--font-sans); font-size: 11.5px; font-weight: 600;
}
.docs-body :not(pre) > code {
  padding: 1px 5px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface);
  color: var(--ink); font-size: 0.86em; overflow-wrap: anywhere;
}
.docs-body .code-block { position: relative; }
.docs-body pre {
  padding: 16px 18px; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--stage-bg);
  color: var(--ink); font-size: 13.5px; line-height: 1.65; tab-size: 2;
}
.docs-body .code-block pre { padding-top: 48px; }
.docs-body pre code { font-size: inherit; }
/* Inside the block: the ring is the Midnight zone's Parchment, 10.42:1 on the block and 1.25:1 on the page outside. */
.docs-body pre:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -4px; }

/* Tables: the wrapper scrolls sideways on narrow screens and can take focus for keyboard scrolling. */
.docs-body .table-wrap { margin-top: 16px; }
.docs-body .table-wrap:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.docs-body table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.docs-body th, .docs-body td { padding: 9px 14px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; color: var(--ink-muted); line-height: 1.55; }
.docs-body tr:last-child td { border-bottom: 0; }
.docs-body th { background: transparent; color: var(--ink-muted); font-size: 12px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; }
.docs-body td:first-child { color: var(--ink); }
.docs-body thead td { background: var(--surface); }
/* Code in cells never breaks mid-token (only at spaces and hyphens, and on phones not at all): a path split into
   four-letter pieces is unreadable, so the table widens and its .table-wrap scrolls instead. Prose code outside
   tables keeps overflow-wrap: anywhere. */
.docs-body td code { white-space: normal; overflow-wrap: normal; word-break: normal; }
.docs-body th code { font-size: 1em; }
.docs-body table.table-vars td:first-child { width: 46%; }
.docs-body table.table-vars td:first-child code { white-space: nowrap; overflow-wrap: normal; }
.docs-body table.table-vars td:nth-child(3) { color: var(--ink-subtle); font-size: 13.5px; }

/* Notes: Status (what was tested), Note, Caution */
.docs-body .note > * + * { margin-top: 8px; }
.docs-body .note p { font-size: 14.5px; line-height: 1.65; }
.docs-body .note code { padding: 0 4px; }
.note.caution { border-left-color: var(--crit); }

/* ---------- Docs home: every page by group ---------- */
.docs-groups { margin-top: 48px; padding-top: 28px; border-top: 1px solid var(--line-soft); }
.docs-groups h2 { font-size: 25px; margin-bottom: 20px; scroll-margin-top: calc(var(--header-h) + 16px); }
.docs-group-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.docs-group { padding: 20px 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-sm); }
.docs-group h3 { margin-bottom: 10px; font-family: var(--font-display); font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-subtle); }
.docs-group ul { display: grid; gap: 12px; }
.docs-group li { scroll-margin-top: calc(var(--header-h) + 16px); }
.docs-group li:target { outline: 1px solid var(--accent); outline-offset: 6px; border-radius: 4px; }
.docs-group a { font-weight: 600; font-size: 15px; color: var(--ink); text-decoration: underline; text-decoration-color: var(--link-line); text-underline-offset: 3px; }
.docs-group a:hover { text-decoration-color: currentColor; }
.docs-group-desc { display: block; margin-top: 2px; color: var(--ink-muted); font-size: 13.5px; line-height: 1.55; }

/* ---------- Previous / next ---------- */
.docs-pager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 56px; }
.docs-pager a {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 18px; border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); text-decoration: none; transition: border-color 0.15s ease, background 0.15s ease;
}
.docs-pager a:hover { border-color: var(--line-strong); background: var(--surface); }
.docs-pager-next { grid-column: 2; text-align: right; }
.docs-pager-dir { color: var(--ink-subtle); font-size: 12px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.docs-pager-title { font-weight: 600; font-size: 15px; }
.docs-gen .docs-end { margin-top: 32px; }

/* ---------- Narrower screens ---------- */
@media (max-width: 1180px) {
  .docs-gen .docs-shell { grid-template-columns: 220px minmax(0, 1fr); gap: 40px; }
  .docs-toc { display: none; }
  .docs-gen .docs-toc-mobile { display: block; margin-bottom: 28px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
  .docs-gen .docs-toc-mobile summary { padding: 12px 18px; min-height: 44px; cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; align-items: center; }
  .docs-gen .docs-toc-mobile summary::-webkit-details-marker { display: none; }
  .docs-gen .docs-toc-mobile summary::after { content: "+"; color: var(--accent); font-size: 20px; line-height: 1; }
  .docs-gen .docs-toc-mobile[open] summary::after { content: "\2212"; }
  .docs-gen .docs-toc-mobile .toc-list { padding: 0 18px 14px; columns: 2; column-gap: 20px; }
  .docs-gen .docs-toc-mobile .toc-list a { display: block; padding: 5px 0; font-size: 14px; color: var(--ink-muted); break-inside: avoid; }
  .docs-gen .docs-toc-mobile .toc-list a:hover { color: var(--ink); }
}
@media (max-width: 980px) {
  .docs-gen .docs-shell { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .docs-sidebar { position: relative; top: auto; max-height: none; display: block; margin-bottom: 24px; }
  .docs-nav-scroll { display: none; }
  .docs-gen .docs-nav { display: none; }
  .docs-nav-mobile { display: block; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
  .docs-nav-mobile summary { padding: 12px 18px; min-height: 44px; cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; align-items: center; }
  .docs-nav-mobile summary::-webkit-details-marker { display: none; }
  .docs-nav-mobile summary::after { content: "+"; color: var(--accent); font-size: 20px; line-height: 1; }
  .docs-nav-mobile[open] summary::after { content: "\2212"; }
  .docs-nav-list { padding: 0 18px 14px; columns: 2; column-gap: 24px; }
  .docs-nav-list .docs-nav-label { margin: 14px 0 4px; break-after: avoid; }
  .docs-nav-list .docs-nav-label:first-child { margin-top: 0; }
  .docs-nav-list ul { break-inside: avoid; }
  .docs-nav-list a { display: block; padding: 6px 0; color: var(--ink-muted); font-size: 14.5px; text-decoration: none; }
  .docs-nav-list a:hover, .docs-nav-list a[aria-current="page"] { color: var(--ink); }
  .docs-nav-list a[aria-current="page"] { font-weight: 600; }
  .docs-search-results { width: 100%; }
  .docs-article { max-width: none; }
}
@media (max-width: 640px) {
  .docs-gen { padding-top: 24px; }
  .docs-nav-list, .docs-gen .docs-toc-mobile .toc-list { columns: 1; }
  .docs-nav-list a, .docs-gen .docs-toc-mobile .toc-list a { padding-block: 10px; }
  .docs-group-grid, .docs-pager { grid-template-columns: minmax(0, 1fr); }
  .docs-pager-next { grid-column: 1; }
  .docs-body .code-block pre { padding-top: 54px; padding-right: 18px; }
  .docs-body p, .docs-body li { font-size: 15px; }
  .docs-body th, .docs-body td { padding: 8px 10px; }
  .docs-body table.table-vars td:first-child { width: auto; }
  .docs-body table { min-width: 560px; }
  .docs-body td code { white-space: nowrap; }
  .docs-search-key { display: none; }
  .docs-search input { height: 44px; padding-right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .heading-anchor, .docs-toc a, .docs-pager a { transition: none; }
}
