/* Developer API reference presentation, shared by the dashboard's
   Documentation tab and the public /docs page. Extends
   css/arctop-design-system.css (tokens only; load that first).

   The document arrives from GET /api/dev/v1/docs and is rendered by
   dev_docs_model.js into semantic tags; dev_docs_page.js adds the TOC and
   code-block chrome. All presentation lives here -- the renderer emits no
   styles and no layout.

   The .code-head / .code-title / .code-block / .btn-copy family also serves
   the Developers page key-reveal modal and the agent-prompt card, which is
   why those rules are unscoped. */

/* ----- code chrome (also used outside .md-doc) ----- */
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 8px; }
.code-title { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-fg-4); }
.code-block { background: var(--color-bg); border: 1px solid var(--color-hairline); border-radius: 10px; padding: 14px 16px; margin: 0; font-family: var(--font-mono); font-size: 12px; line-height: 1.65; color: var(--color-fg-2); white-space: pre; overflow-x: auto; }
.btn-copy { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border: 1px solid var(--color-hairline-strong); border-radius: 8px; background: transparent; color: var(--color-fg-2); font-family: var(--font-mono); font-size: 11px; cursor: pointer; }
.btn-copy:hover { background: var(--color-surface-3); color: var(--color-fg-1); }

/* A grouped block: chrome row (language label + copy) over the code. Built by
   dev_docs_page.js around the reference's runnable (bash) fences only. */
.code-group { margin: 14px 0 0; background: var(--color-bg); border: 1px solid var(--color-hairline); border-radius: 10px; overflow: hidden; }
.code-group .code-head { margin: 0; padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--color-hairline); }
.code-group .code-block { background: transparent; border: none; border-radius: 0; margin: 0; }

/* Syntax tokens, all theme-safe design-system colors. */
.hl-cmd { color: var(--color-synapse-on-wash); }
.hl-key { color: var(--color-synapse-on-wash); }
.hl-var { color: var(--color-synapse-on-wash); }
.hl-str { color: var(--color-signal); }
.hl-num { color: var(--state-warning); }
.hl-lit { color: var(--state-warning); }
.hl-com { color: var(--color-fg-4); }
.hl-flag { color: var(--color-fg-1); }

/* ----- the rendered reference ----- */
.md-doc h1 { margin: 0 0 6px; font-family: var(--font-display); font-size: 24px; font-weight: 400; letter-spacing: -0.02em; line-height: 1.15; color: var(--color-fg-1); }
.md-doc h1 + p { font-size: 15px; line-height: 1.6; color: var(--color-fg-2); }
.md-doc h2 { margin: 44px 0 10px; padding-top: 26px; border-top: 1px solid var(--color-hairline); font-family: var(--font-mono); font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-fg-3); }
.md-doc h3 { margin: 30px 0 4px; font-family: var(--font-mono); font-size: 13.5px; font-weight: 600; color: var(--color-fg-1); word-break: break-all; }
.md-doc h4 { margin: 18px 0 2px; font-size: 13px; font-weight: 600; color: var(--color-fg-2); }
.md-doc p { margin: 10px 0 0; font-size: 14px; line-height: 1.65; color: var(--color-fg-2); max-width: 70ch; }
.md-doc ul { margin: 10px 0 0; padding-left: 22px; }
.md-doc li { margin: 5px 0; font-size: 14px; line-height: 1.6; color: var(--color-fg-2); max-width: 70ch; }
.md-doc li::marker { color: var(--color-fg-4); }
.md-doc strong { font-weight: 600; color: var(--color-fg-1); }
.md-doc code { font-family: var(--font-mono); font-size: 12.5px; color: var(--color-fg-1); background: var(--color-surface-3); border-radius: 5px; padding: 1px 5px; }
/* Inline code in running text reads as accent, like the highlighted blocks;
   headings (.md-endpoint) and fenced blocks keep their own colors. */
.md-doc p code, .md-doc li code, .md-doc td code { color: var(--color-synapse-on-wash); }
.md-doc pre.code-block { font-size: 12.5px; line-height: 1.7; margin: 14px 0 0; }
.md-doc pre.code-block code { background: none; padding: 0; color: inherit; }
/* Response and frame examples (the non-bash fences) stay plain blocks with a
   quiet inset label naming the syntax: nobody pastes a response, so they
   carry no copy chrome. */
.md-doc pre.code-block[data-lang="json"] { position: relative; padding-top: 32px; }
.md-doc pre.code-block[data-lang="json"]::before { content: attr(data-lang); position: absolute; top: 11px; left: 16px; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-fg-4); }
.md-doc a { color: var(--color-synapse-on-wash); text-decoration: none; }
.md-doc a:hover { text-decoration: underline; text-underline-offset: 2px; }
.md-doc table { margin: 14px 0 0; width: 100%; border-collapse: collapse; }
/* dev_docs_page.js wraps every table in this; a table wider than the column
   (nowrap cells on a phone) pans inside it instead of widening the page. */
.md-doc .table-scroll { margin: 14px 0 0; overflow-x: auto; }
.md-doc .table-scroll table { margin: 0; }
.md-doc th { padding: 6px 12px 6px 0; text-align: left; font-family: var(--font-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-fg-4); border-bottom: 1px solid var(--color-hairline); }
.md-doc td { padding: 10px 12px 10px 0; vertical-align: top; font-size: 13px; line-height: 1.55; color: var(--color-fg-2); border-bottom: 1px solid var(--color-hairline); }
.md-doc td:first-child, .md-doc th:first-child { white-space: nowrap; }
.md-doc tr:last-child td { border-bottom: none; }
.md-doc td code { white-space: nowrap; }

/* Anchor targets clear the viewport top (and the public page's sticky bar). */
.md-doc [id] { scroll-margin-top: 28px; }

/* Hover permalink on every heading; the glyph is ours, not the document's. */
.h-anchor { margin-left: 8px; color: var(--color-fg-4); opacity: 0; transition: opacity var(--dur-fast); text-decoration: none; }
.h-anchor::before { content: "#"; font-family: var(--font-mono); font-size: 0.9em; font-weight: 400; }
.md-doc h1:hover .h-anchor, .md-doc h2:hover .h-anchor, .md-doc h3:hover .h-anchor, .md-doc h4:hover .h-anchor { opacity: 1; }
.h-anchor:hover { color: var(--color-synapse-on-wash); }

/* Endpoint headings: a method badge and the path as code. */
.md-method { display: inline-block; margin-right: 10px; padding: 3px 8px; border-radius: 6px; font-family: var(--font-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.08em; vertical-align: 2px; background: var(--color-surface-3); color: var(--color-fg-2); }
.md-method[data-method="get"] { background: var(--color-signal-wash); color: var(--color-signal); }
.md-method[data-method="post"] { background: var(--color-synapse-wash); color: var(--color-synapse-on-wash); }
.md-method[data-method="put"], .md-method[data-method="patch"] { background: var(--state-warning-wash); color: var(--state-warning); }
.md-method[data-method="delete"] { background: var(--state-error-wash); color: var(--state-error); }
.md-endpoint { font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--color-fg-1); background: none; padding: 0; }

/* ----- layout: content beside a sticky "On this page" rail ----- */
.docs-layout { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 24px; align-items: start; }
.docs-toc { position: sticky; top: 28px; max-height: calc(100vh - 56px); overflow-y: auto; padding: 2px 0; }
/* A button so narrow layouts can use it as the panel toggle; inert and
   rendered exactly like the old static label on the desktop rail. */
.toc-title { display: block; width: 100%; margin: 0 0 10px; padding: 0; background: none; border: none; text-align: left; pointer-events: none; font-family: var(--font-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-fg-4); }
.toc-link { display: block; padding: 4px 0 4px 12px; border-left: 2px solid transparent; font-family: var(--font-mono); font-size: 11px; line-height: 1.5; color: var(--color-fg-4); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color var(--dur-fast); }
.toc-link:hover { color: var(--color-fg-2); }
.toc-link.active { color: var(--color-fg-1); border-left-color: var(--color-synapse); }
.toc-link.lvl-3 { padding-left: 24px; }

/* ----- the public /docs page shell ----- */
body.devdocs-page { margin: 0; background: var(--color-bg); color: var(--color-fg-1); font-family: var(--font-sans); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.devdocs-page *, .devdocs-page *::before, .devdocs-page *::after { box-sizing: border-box; }

.devdocs-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px; height: 58px; padding: 0 24px; background: var(--color-surface-1); border-bottom: 1px solid var(--color-hairline); }
.devdocs-header .wordmark { height: 15px; display: block; }
:root[data-theme="light"] .devdocs-header .wordmark { filter: invert(1); }
.devdocs-header .head-eyebrow { font-family: var(--font-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-fg-4); padding-left: 14px; border-left: 1px solid var(--color-hairline-strong); }
.devdocs-header .head-spacer { flex: 1; }
.devdocs-header .head-link { font-size: 13px; font-weight: 600; color: var(--color-fg-2); text-decoration: none; padding: 7px 13px; border: 1px solid var(--color-hairline-strong); border-radius: 8px; transition: color var(--dur-fast), background var(--dur-fast); }
.devdocs-header .head-link:hover { color: var(--color-fg-1); background: var(--color-surface-3); }

.devdocs-main { max-width: 1060px; margin: 0 auto; padding: 40px 32px 80px; }
.devdocs-page .docs-toc { top: 86px; max-height: calc(100vh - 114px); }
.devdocs-page .md-doc [id] { scroll-margin-top: 78px; }
.devdocs-page .md-doc h1 { font-size: 30px; }
.devdocs-page .code-group, .devdocs-page .md-doc pre.code-block { background: var(--color-surface-1); }
.devdocs-page .code-group .code-block { background: transparent; }


.docs-loading, .docs-error { font-size: 14px; color: var(--color-fg-4); }
.docs-error { color: var(--state-error); }

/* ----- narrow layouts (kept last: these override the shell rules above) ----- */
@media (max-width: 1100px) {
    /* minmax(0, 1fr), not bare 1fr: 1fr floors the column at its min-content
       width, so the widest nowrap table would set the page width and put the
       whole page on a horizontal pan. */
    .docs-layout { grid-template-columns: minmax(0, 1fr); }

    /* The rail becomes a collapsed "On this page" box above the document;
       the title button (built in dev_docs_page.js) toggles .toc-open. */
    .docs-layout .docs-toc { order: -1; position: static; max-height: none; overflow: hidden; padding: 0; background: var(--color-surface-1); border: 1px solid var(--color-hairline); border-radius: 10px; }
    .docs-layout .toc-title { display: flex; align-items: center; justify-content: space-between; margin: 0; padding: 12px 14px; pointer-events: auto; cursor: pointer; }
    .docs-layout .toc-title::after { content: ""; width: 7px; height: 7px; margin-top: -4px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); transition: transform var(--dur-fast); }
    .docs-layout .docs-toc.toc-open .toc-title::after { margin-top: 2px; transform: rotate(-135deg); }
    .docs-layout .toc-link { display: none; padding: 7px 14px 7px 24px; }
    .docs-layout .toc-link.lvl-3 { padding-left: 36px; }
    .docs-layout .docs-toc.toc-open .toc-link { display: block; }
    .docs-layout .docs-toc.toc-open { padding-bottom: 8px; }
}

@media (max-width: 720px) {
    .devdocs-header { padding: 0 16px; }
    .devdocs-header .head-eyebrow { display: none; }
    .devdocs-main { padding: 20px 18px 64px; }
    .devdocs-page .md-doc h1 { font-size: 26px; }
    /* A long inline token (an endpoint path, a header value) may exceed the
       phone column; let it break rather than widen the page. */
    .md-doc p code, .md-doc li code { overflow-wrap: anywhere; }
}
