/* --- The docs reader (docs.go, docsreader.go, docs.js), in Admin → Docs and
   the public docs at /docs/… (publicdocs.go): grouped menu, search,
   "On this page", folding ## sections. Phone first: everything stacks in one
   column, wide tables and code scroll inside their own box. --- */
.doc-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-4); }
.doc-crumbs { flex-basis: 100%; margin: 0; font-size: 13px; overflow-wrap: anywhere; }
.doc-search { display: flex; gap: var(--space-2); flex: 1 1 240px; max-width: 520px; margin: 0; }
.doc-search input { flex: 1; min-width: 0; }
.doc-drop > summary { display: inline-flex; align-items: center; gap: var(--space-2); height: var(--control-sm); padding: 0 var(--space-3); border-radius: var(--radius-sm); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong); font-size: 13px; font-weight: 600; cursor: pointer; list-style: none; user-select: none; }
.doc-drop > summary::-webkit-details-marker, .doc-sec > summary::-webkit-details-marker { display: none; }
.doc-drop > summary::after { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.doc-drop[open] > summary::after { transform: translateY(1px) rotate(-135deg); }
.doc-drop > summary:focus-visible, .doc-sec > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.doc-menu[open] { flex-basis: 100%; }
.doc-menu[open] .doc-groups { margin-top: var(--space-3); }
.doc-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-4); margin: var(--space-5) 0; }
.doc-group { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: var(--space-4); min-width: 0; }
.doc-group h2 { margin: 0 0 var(--space-2); font-size: var(--text-xs); line-height: 16px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); }
.doc-group ul { list-style: none; margin: 0; padding: 0; }
.doc-group li { margin: 0 0 var(--space-3); }
.doc-group li:last-child { margin-bottom: 0; }
.doc-group a { font-weight: 600; display: block; }
.doc-group a[aria-current] { color: var(--ink); box-shadow: inset 3px 0 0 var(--orange); padding-left: var(--space-2); }
.doc-group span { display: block; font-size: 13px; line-height: 19px; color: var(--ink-muted); }
/* A page's last change, under its title, and each menu line's date on
   Admin → Docs (docschanged.go): quiet secondary text. */
article.doc > h1:has(+ .doc-changed), .docs-site article.doc > h1:has(+ .doc-changed) { margin-bottom: var(--space-1); }
.doc-changed { margin: 0 0 var(--space-4); font-size: 13px; line-height: 19px; color: var(--ink-muted); overflow-wrap: anywhere; }
.doc-group .doc-date { display: block; font-size: 12px; line-height: 16px; color: var(--ink-subtle); }
.doc-layout { display: flex; flex-direction: column; gap: var(--space-3); }
.doc-toc { min-width: 0; }
.doc-toc ol { list-style: none; margin: var(--space-2) 0 0; padding: 0; font-size: 13px; line-height: 19px; }
.doc-toc ol ol { margin: 2px 0 var(--space-1) var(--space-3); }
.doc-toc li { margin: 2px 0; }
.doc-toc a { display: block; padding: 2px var(--space-2); color: var(--ink-muted); border-radius: var(--radius-xs); }
.doc-toc a:hover { color: var(--ink); background: var(--surface-sunken); text-decoration: none; }
.doc-toc a[aria-current] { color: var(--ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--orange); }
.doc-toc details[open] > ol { max-height: 60vh; overflow-y: auto; background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-pop); padding: var(--space-2); }
.doc-openall { margin-left: auto; }
.doc-sec > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: var(--space-2); border-top: 1px solid var(--line); margin-top: var(--space-5); padding-top: var(--space-3); }
.doc-sec > summary::before { content: ""; flex: none; width: 8px; height: 8px; border-right: 2px solid var(--ink-subtle); border-bottom: 2px solid var(--ink-subtle); transform: translateY(-4px) rotate(-45deg); transition: transform 150ms ease; }
.doc-sec[open] > summary::before { transform: translateY(-6px) rotate(45deg); }
article.doc .doc-sec > summary h2 { margin: 0; scroll-margin-top: var(--space-4); }
article.doc h3, article.doc h4 { scroll-margin-top: var(--space-4); }
.doc-anchor { margin-left: var(--space-2); font-size: 0.8em; font-weight: 500; color: var(--ink-subtle); opacity: 0; text-decoration: none; }
.doc-anchor::before { content: "#"; }
.doc-anchor.copied::before { content: "Link copied"; font-family: var(--font-sans); font-size: 12px; }
:hover > .doc-anchor, .doc-anchor:focus-visible, .doc-anchor.copied { opacity: 1; }
@media (hover: none) { .doc-anchor { opacity: 0.6; } }
.doc-diagram { margin: var(--space-3) 0 var(--space-5); }
.doc-diagram iframe { display: block; width: 100%; height: min(88vh, 960px); border: 1px solid var(--line); border-radius: var(--radius-md); }
.doc-diagram figcaption { margin-top: var(--space-2); font-size: 13px; color: var(--ink-muted); }
.doc-table { max-width: 100%; overflow-x: auto; margin: var(--space-2) 0 var(--space-5); border-radius: var(--radius-md); }
article.doc pre.has-copy { position: relative; padding-top: var(--space-6); }
.doc-copy { position: absolute; top: var(--space-1); right: var(--space-1); height: 24px; padding: 0 var(--space-2); font-size: 12px; font-weight: 500; background: transparent; color: var(--code-ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.doc-copy:hover { filter: none; background: var(--code-bg); }
.doc-pager { display: flex; flex-wrap: wrap; gap: var(--space-3); justify-content: space-between; max-width: 760px; margin: var(--space-7) 0 0; padding-top: var(--space-4); border-top: 1px solid var(--line); }
.doc-pager a { display: flex; flex-direction: column; font-weight: 600; max-width: 48%; }
.doc-pager a.next { margin-left: auto; text-align: right; }
.doc-pager span { font-size: 12px; font-weight: 500; color: var(--ink-muted); }
.doc-hits { list-style: none; margin: var(--space-4) 0; padding: 0; max-width: 760px; }
.doc-hits li { padding: var(--space-3) 0; border-bottom: 1px solid var(--line); }
.doc-hits a { font-weight: 600; }
.doc-hit-page { display: block; font-size: 12px; color: var(--ink-muted); }
.doc-hit-line { display: block; font-size: 13px; line-height: 20px; color: var(--ink-muted); overflow-wrap: anywhere; }
mark { background: var(--orange-soft); color: var(--ink); border-radius: var(--radius-xs); padding: 0 1px; }
@media (min-width: 1101px) {
  .doc-layout { display: grid; grid-template-columns: minmax(0, 760px) 240px; gap: var(--space-7); align-items: start; }
  .doc-toc { grid-column: 2; grid-row: 1; position: sticky; top: var(--space-4); max-height: calc(100vh - var(--space-7)); overflow-y: auto; }
  .doc-toc details[open] > ol { max-height: none; overflow: visible; background: none; box-shadow: none; padding: 0; }
  .doc-toc .doc-drop > summary { background: none; box-shadow: none; padding: 0; font-size: var(--text-xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); }
  article.doc { grid-column: 1; grid-row: 1; }
}
@media print { .doc-bar, .doc-toc, .doc-pager, .doc-copy, .doc-anchor { display: none; } }

/* --- The public docs (site_doc*.html): the reader on the site's tokens. The
   text column reads like .prose; the search box matches the site's forms. --- */
.docs-site { padding-top: var(--space-7); }
.docs-site .doc-search input { height: 40px; padding: 0 var(--space-3); border: 0; border-radius: var(--radius-sm); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong); font: inherit; font-size: 15px; color: var(--ink); }
.docs-site .doc-crumbs { color: var(--ink-muted); }
.docs-site .doc-drop > summary { height: 40px; }
.docs-site article.doc { max-width: 760px; min-width: 0; overflow-wrap: break-word; }
.docs-site article.doc :is(p, li, h2, h3, h4) > code { overflow-wrap: anywhere; }
.docs-site .doc-sec > summary h2 { min-width: 0; }
.docs-site article.doc > h1 { font-size: 40px; line-height: 46px; margin: 0 0 var(--space-4); }
.docs-site .doc-table table { display: table; margin: 0; }
.docs-site .doc-search-title { margin: 0 0 var(--space-5); }
.docs-site .doc-hits-count { color: var(--ink-muted); }
@media (max-width: 640px) {
  .docs-site article.doc > h1 { font-size: 30px; line-height: 36px; }
}

.doc-more { max-width: 760px; color: var(--ink-muted); margin: 0 0 var(--space-5); }
.docs-site .doc-toc a, .docs-site .doc-group a, .docs-site .doc-pager a { text-decoration: none; }
.docs-site .doc-openall { height: 40px; padding: 0 var(--space-3); border: 0; border-radius: var(--radius-sm); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--ink); font-size: 13px; font-weight: 600; }
.docs-site .doc-copy { border: 0; border-radius: var(--radius-xs); }

/* --- The Run box (docsrun.go, docs-run.js): a real call on the demo shop,
   on the quick start and the API reference's read calls. --- */
.run-box { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: var(--space-5); margin: var(--space-5) 0; min-width: 0; }
.run-head h3 { margin: 0 0 var(--space-1); font-size: 18px; line-height: 26px; }
.run-head p, .run-note { margin: 0 0 var(--space-4); color: var(--ink-muted); font-size: 14px; line-height: 21px; }
.run-note { margin: var(--space-4) 0 0; }
.run-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin: 0 0 var(--space-4); }
.run-form label { display: flex; flex-direction: column; gap: var(--space-1); font-size: 13px; font-weight: 600; color: var(--ink-muted); min-width: 0; }
.run-form label[hidden], .run-box [hidden] { display: none; }
.run-form select, .run-form input { height: var(--control-sm); padding: 0 var(--space-2); border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-weight: 400; }
.run-form input[name="count"] { width: 5.5em; }
.run-form input[name="context"] { width: 10em; font-family: var(--font-mono); }
.run-form :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.run-box .run-code { margin: 0 0 var(--space-3); }
.run-box .run-code pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.run-answer pre { max-height: 360px; overflow-y: auto; }
.run-status { margin: 0 0 var(--space-3); font-size: 14px; }
.run-status:empty { display: none; }
.run-box .run-cards { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3); margin: 0 0 var(--space-4); padding: 0; }
.run-box .run-card { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: var(--space-2); border-radius: var(--radius-md); background: var(--surface-sunken); min-width: 0; font-size: 13px; line-height: 18px; }
.run-tile { display: block; aspect-ratio: 1; border-radius: var(--radius-sm); background: var(--sky-soft); overflow: hidden; margin-bottom: var(--space-1); }
.run-tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
.run-name { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.run-price { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.run-why { color: var(--ink-muted); }
@media print { .run-box { display: none; } }

/* --- Glossary terms (glossary.go, docs.js): the first use of a word on a
   page is a dotted link; its meaning opens in place. --- */
a.term { color: inherit; text-decoration: underline dotted var(--sky-text); text-decoration-thickness: 1.5px; text-underline-offset: 3px; cursor: help; }
a.term:hover, a.term[aria-expanded="true"] { color: var(--sky-text); }
a.term:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-xs); }
.term-pop { position: absolute; z-index: 30; width: min(320px, calc(100vw - 16px)); padding: var(--space-3); border-radius: var(--radius-md); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); font-size: 14px; line-height: 20px; font-weight: 400; text-align: left; white-space: normal; }
.term-pop[hidden] { display: none; }
.term-pop a { display: inline-block; margin-top: var(--space-1); font-weight: 600; }
@media print { .term-pop { display: none; } a.term { text-decoration: none; } }

/* --- Diagrams (docs.js): a node with a "%% link" line opens its section;
   "Full screen" lays a diagram out at its own width over the page. --- */
figure.diagram { margin: 0 0 var(--space-4); }
.diagram-zoom { margin-bottom: var(--space-2); }
.diagram-link { cursor: pointer; }
.diagram-link:hover rect, .diagram-link:hover polygon, .diagram-link:hover path.basic, .diagram-link:hover circle { stroke: var(--orange); stroke-width: 2px; }
.diagram-link:focus { outline: none; }
.diagram-link:focus-visible rect, .diagram-link:focus-visible polygon, .diagram-link:focus-visible circle { stroke: var(--focus); stroke-width: 3px; }
figure.diagram-full { position: fixed; inset: 0; z-index: 40; margin: 0; padding: var(--space-4); background: var(--surface); overflow: auto; overscroll-behavior: contain; }
figure.diagram-full svg { max-width: none !important; height: auto; }
/* Full screen: the whole figure pans both ways, not the drawing's own box. */
article.doc figure.diagram-full .mermaid { display: inline-block; min-width: 100%; margin: 0; overflow: visible; box-shadow: none; }
.diagram-open, .diagram-open body { overflow: hidden; }
@media print { .diagram-zoom { display: none; } }

/* Admin → Docs front page: a table of contents. One calm band to start
   from, the usual questions beside the week's changes, then one row per
   topic: its name, then its pages. */
.doc-lead { max-width: 64ch; margin: calc(-1 * var(--space-3)) 0 var(--space-4); }
.doc-start { position: relative; display: grid; gap: var(--space-2); margin: var(--space-5) 0 var(--space-6); padding: var(--space-5) var(--space-6); background: var(--sky-soft); border-radius: var(--radius-lg); }
/* The band is the start: its name stays for screen readers only. */
.doc-start > h2 { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.doc-start ul { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); grid-auto-flow: dense; gap: var(--space-3) var(--space-7); list-style: none; margin: 0; padding: 0; }
.doc-start li { display: grid; gap: 2px; align-content: start; }
.doc-start a { font-weight: 600; }
.doc-start span { font-size: 13px; line-height: 19px; color: var(--ink-muted); }
.doc-start .doc-date { font-size: 12px; line-height: 16px; color: var(--ink-subtle); }
.doc-start li { grid-column: 2; }
.doc-start .doc-start-main { grid-column: 1; grid-row: 1 / span 4; align-self: center; max-width: 62ch; }
.doc-start-main a { font-size: 24px; line-height: 32px; letter-spacing: -0.01em; }
.doc-start-main span { font-size: 15px; line-height: 23px; }
.doc-front { display: grid; gap: var(--space-6); margin: 0 0 var(--space-4); }
.doc-front .doc-group ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr)); gap: var(--space-3) var(--space-6); }
.doc-front .doc-group li { margin: 0; }
.doc-front .doc-group, .doc-topics .doc-group { background: none; box-shadow: none; border-radius: 0; padding: 0; }
.doc-front .doc-group h2, .doc-topics .doc-group h2 { margin: 0 0 var(--space-3); font-size: 17px; line-height: 24px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--ink); }
.doc-more { margin-top: var(--space-3); }
.doc-more > summary { cursor: pointer; width: max-content; font-size: 14px; font-weight: 500; color: var(--sky-text); }
.doc-more > ul { margin-top: var(--space-3); }
.doc-topics { padding-top: var(--space-3); border-top: 1px solid var(--line); }
.doc-topics { display: block; margin: 0; }
.doc-topics .doc-group { display: grid; grid-template-columns: 13rem minmax(0, 1fr); gap: var(--space-5); padding: var(--space-5) 0; border-top: 1px solid var(--line); }
.doc-topics .doc-group:first-child { border-top: 0; padding-top: var(--space-2); }
.doc-topics .doc-group h2 { margin: 0; font-size: 16px; line-height: 24px; color: var(--ink); }
.doc-topics .doc-group ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: var(--space-4) var(--space-6); }
.doc-topics .doc-group li { margin: 0; }
.doc-topics .doc-group span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-more > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-xs); }
@media (max-width: 900px) {
  .doc-front { gap: var(--space-5); }
  .doc-front .doc-group ul { grid-template-columns: minmax(0, 1fr); }
  .doc-topics .doc-group { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
  .doc-start { padding: var(--space-4); }
  .doc-start ul { grid-template-columns: minmax(0, 1fr); }
  .doc-start li, .doc-start .doc-start-main { grid-column: 1; grid-row: auto; }
  .doc-start-main a { font-size: 20px; line-height: 28px; }
}
