/* ============================================================================
   ipconfig.is - the /api reference (design v5 "Signal"). Loaded after /styles.css, which supplies
   the tokens, nav, footer, buttons, terminal and code windows and the JSON colours. This file adds
   the docs layout: a sticky contents column, then each topic as text beside its request and response.
   The page CSP allows no inline styles: everything lives here.
   ========================================================================== */

/* The docs run wider than the 1200px site column, and the header follows them. */
.docs-page { --docs-w: 1440px; --hdr-w: var(--docs-w); --hdr-pad: 32px; }
body.docs-page { position: relative; isolation: isolate; }
body.docs-page::before {
    content: ""; position: absolute; left: 0; right: 0; top: 0; height: 560px; z-index: -1; pointer-events: none;
    background: radial-gradient(circle at 1px 1px, var(--dot-grid) 1px, transparent 1.5px) 0 0 / 24px 24px;
    -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent);
    mask-image: linear-gradient(to bottom, #000 30%, transparent);
}

.docs {
    max-width: var(--docs-w); margin: 0 auto; padding: 0 32px;
    display: grid; grid-template-columns: 212px minmax(0, 1fr); gap: 0 52px;
}

/* ----- Contents column (the whole map fits a 1440 x 900 screen) ----------------------------------- */
.docs-side {
    position: sticky; top: var(--nav-h); align-self: start;
    max-height: calc(100vh - var(--nav-h)); overflow-y: auto; overscroll-behavior: contain;
    padding: 28px 6px 24px 0; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
}
.side-group + .side-group { margin-top: 18px; }
.side-h {
    margin: 0 0 4px 14px; font-family: var(--mono); font-size: 0.6875rem; font-weight: 700;
    letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3);
}
.side-group ul { list-style: none; margin: 0; padding: 0; }
.side-group a {
    position: relative; display: block; padding: 4px 10px 4px 14px; border-radius: 8px;
    font-size: 0.875rem; font-weight: 500; line-height: 1.45; color: var(--text-2);
    transition: color .15s ease, background-color .15s ease;
}
.side-group a:hover { color: var(--text); background: var(--surface-3); text-decoration: none; }
.side-group a:focus-visible { outline-offset: -2px; }
/* the section in view: bold, with a short rule at the list's edge (no dot) */
.side-group a.on { color: var(--text); font-weight: 600; }
.side-group a.on::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 2px; border-radius: 1px; background: var(--text); }

/* the same list in a bar under the nav, for screens too narrow for the column */
.docs-toc { display: none; }

/* ----- Sections: text on the left, the request and response on the right ---------------------- */
.docs-main { min-width: 0; padding-bottom: 8px; }
.doc-sec {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.06fr); gap: 0 44px; align-items: start;
    padding: 52px 0 56px; border-top: 1px solid var(--line);
}
.doc-intro { border-top: 0; padding-top: 52px; }
.doc-text { min-width: 0; font-size: 0.9375rem; line-height: 1.7; color: var(--text-2); }
.doc-text p { margin: 0 0 14px; text-wrap: pretty; }
.doc-text strong, .doc-text b { color: var(--text); font-weight: 650; }
.doc-text a:not(.doc-anchor) { text-decoration: underline; text-decoration-color: var(--accent-line); text-underline-offset: 3px; }
.doc-text a:not(.doc-anchor):hover { text-decoration-color: currentColor; }
/* inline code is told apart by its typeface and ink, not a box */
.doc-text code { font-size: 0.8438rem; font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.doc-text a code { color: var(--accent-ink); }
/* the code column stays in view while its text scrolls past */
.doc-code { min-width: 0; display: flex; flex-direction: column; gap: 14px; position: sticky; top: calc(var(--nav-h) + 20px); }

.doc-title {
    margin: 14px 0 0; color: var(--text); text-wrap: balance;
    font-size: clamp(2.25rem, 3.4vw, 3rem); font-weight: 750; letter-spacing: -0.036em; line-height: 1.05;
}
.doc-text .doc-lede { margin: 18px 0 0; font-size: 1.125rem; line-height: 1.6; color: var(--text-2); }
.doc-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); margin: 28px 0 0; border-top: 1px solid var(--line); }
.doc-facts > div { display: contents; }
.doc-facts dt, .doc-facts dd { padding: 10px 0; border-bottom: 1px solid var(--line); }
.doc-facts dt {
    display: flex; align-items: center; padding-right: 28px; font-family: var(--mono); font-size: 0.6875rem; font-weight: 600;
    letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3);
}
.doc-facts dd { margin: 0; color: var(--text); font-weight: 550; }
.doc-facts dd code { font-size: 0.875rem; font-weight: 600; }
.doc-text .doc-aside { margin: 20px 0 0; font-size: 0.875rem; color: var(--text-3); }

/* the intro terminal: each answer sits under its command (the prompt and its gap are 2ch) */
.doc-term .terminal-body { font-size: 0.8438rem; padding: 18px 20px 20px; }
.doc-term .cli-line { gap: 1ch; white-space: normal; align-items: baseline; }   /* a long command wraps beside its prompt */
.doc-term .cli-line > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.doc-term .cli-out { margin: 2px 0 0 2ch; color: var(--term-text); overflow-wrap: anywhere; }
.doc-you { font-weight: 600; }

/* groups are labelled rules; the sections under them carry the headings */
.doc-group { padding: 72px 0 0; }
.doc-group-h {
    display: flex; align-items: center; gap: 14px; margin: 0;
    font-family: var(--mono); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-3);
}
.doc-group-h::after { content: ""; flex: 1; height: 1px; background: var(--line-2); }
.doc-group + .doc-sec { border-top: 0; padding-top: 30px; scroll-margin-top: 32px; }   /* a jump to a group's first section shows the label */
.doc-intro + .doc-group { padding-top: 40px; }

.doc-h { margin: 0 0 14px; color: var(--text); font-size: 1.5rem; font-weight: 700; letter-spacing: -0.024em; line-height: 1.25; }
.doc-anchor { color: inherit; }
.doc-anchor:hover { color: inherit; text-decoration: none; }
.doc-anchor::after { content: "#"; margin-left: 10px; font-weight: 500; color: var(--text-3); opacity: 0; transition: opacity .15s ease; }
.doc-anchor:hover::after, .doc-anchor:focus-visible::after { opacity: 1; }

/* the request line: method and path, set as type (a box here read as an empty input) */
.ep-lines { display: flex; flex-direction: column; gap: 4px; margin: 0 0 18px; }
.doc-text .ep-line { display: flex; align-items: baseline; gap: 10px; margin: 0; min-width: 0; }
.ep-line .ep-verb { flex: none; font-family: var(--mono); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; color: var(--accent-ink); }
.doc-text .ep-path { font-size: 0.9375rem; font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.ep-path .var { color: var(--warn); }

.doc-sub {
    margin: 24px 0 6px; font-family: var(--mono); font-size: 0.6875rem; font-weight: 700;
    letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-3);
}
.ptable { width: 100%; border-collapse: collapse; font-size: 0.875rem; line-height: 1.6; }
/* the parameter and field tables are labelled by the heading above them: their header row is for screen readers */
.doc-ep .ptable thead, .pfields thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.doc-ep .ptable tbody { border-top: 1px solid var(--line-2); }
.ptable th {
    text-align: left; padding: 0 14px 8px 0; border-bottom: 1px solid var(--line-2);
    font-family: var(--mono); font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3);
}
.ptable td { padding: 11px 14px 11px 0; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--text-2); text-wrap: pretty; }
.ptable th:last-child, .ptable td:last-child { padding-right: 0; }
.ptable .p-name { white-space: nowrap; }
.doc-text .p-name code { font-size: 0.8438rem; font-weight: 650; }
.p-req { display: block; margin-top: 1px; font-family: var(--mono); font-size: 0.6875rem; font-weight: 500; color: var(--warn); }
.p-type { font-family: var(--mono); font-size: 0.8125rem; color: var(--info); white-space: nowrap; }
.p-status { font-family: var(--mono); font-weight: 700; color: var(--warn); white-space: nowrap; }
.p-codes { font-family: var(--mono); font-size: 0.8125rem; line-height: 1.75; color: var(--text); }
/* lists of values read as one line of mono text, not a wall of chips */
.doc-text .vals, .doc-paths { font-family: var(--mono); font-size: 0.8125rem; color: var(--text); }
.doc-text .doc-paths code, .doc-text .doc-paths-foot code { font-size: 0.8125rem; white-space: nowrap; }
.doc-full { grid-column: 1 / -1; }
.docs .table-wrap { overflow-x: auto; background: none; border: 0; border-radius: 0; box-shadow: none; margin: 4px 0 0; }
.docs .doc-full.table-wrap { margin-top: 32px; }
.perr .p-status { width: 1%; padding-right: 28px; }
.perr .p-codes { width: 1%; white-space: nowrap; padding-right: 48px; }

.doc-notes { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.doc-notes li { position: relative; padding-left: 18px; font-size: 0.875rem; line-height: 1.65; text-wrap: pretty; }
.doc-notes li::before { content: ""; position: absolute; left: 3px; top: 0.68em; width: 5px; height: 5px; border-radius: 50%; background: var(--line-3); }
.doc-paths-foot { margin: 16px 0 0 !important; font-size: 0.8438rem; line-height: 1.9; color: var(--text-3); }

.doc-defs { margin: 2px 0 0; }
.doc-defs dt { margin-top: 18px; font-size: 0.9375rem; font-weight: 650; color: var(--text); }
.doc-defs dt:first-child { margin-top: 0; }
.doc-defs dd { margin: 3px 0 0; font-size: 0.9063rem; line-height: 1.65; text-wrap: pretty; }

.doc-text .doc-try { margin: 22px 0 0; }
.doc-try a { display: inline-flex; align-items: center; gap: 6px; font-size: 0.875rem; font-weight: 600; }
.doc-try svg { width: 14px; height: 14px; }

/* the field reference takes the full width, in four bands */
.doc-wide { display: block; }
.doc-wide .doc-text { max-width: 980px; }
.pfields .p-name, .pfields .p-type { width: 1%; }
.pfields .pf-group th { padding: 28px 0 8px; border-bottom: 1px solid var(--line-2); }
.pfields tbody:first-of-type .pf-group th { padding-top: 4px; }

/* ----- Code windows: request (one snippet per language) and response ------------------------------ */
.docs .code-head { min-height: 40px; padding: 0 7px; }
.docs .code-tab { height: 40px; padding: 0 10px; border-radius: 0; }
.docs .code-tab.active { background: none; box-shadow: inset 0 -2px 0 var(--term-text); }   /* text on a rule, not a filled tab */
.code-label { flex: none; padding: 0 11px; font-family: var(--mono); font-size: 0.75rem; font-weight: 600; color: var(--term-text); }
.resp-meta {
    margin-left: auto; min-width: 0; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-family: var(--mono); font-size: 0.6875rem; color: var(--term-dim);
}
.resp-st { color: var(--term-text); font-weight: 600; }
.resp-st.err { color: var(--term-amber); }
.resp-meta.live .resp-kind { color: var(--term-green); }
.resp-meta.bad { color: var(--term-red); }
.docs .code-head .resp-meta + .term-btn { margin-left: 6px; }
.docs .code-body { padding: 16px 18px 18px; max-height: none; }
.docs .code-resp .code-body { max-height: min(460px, calc(100vh - 300px)); }
.docs .code-body .code, .docs .code-body .json { font-size: 0.8125rem; line-height: 1.72; }
.code-out { color: var(--term-text); }
.c-kw { color: var(--term-blue); }
.j-more { color: var(--term-faint); font-style: italic; }
.run-btn .spin { width: 12px; height: 12px; border-width: 1.5px; border-color: rgba(255, 255, 255, 0.2); border-top-color: var(--term-green); }

/* One span per line: a long line wraps under its own key (a hanging indent of its depth + 2ch) instead
   of running off the window. The newlines between the spans keep copying exact. */
.docs .ln-wrap { white-space: normal; }
.docs .ln-wrap > code { display: block; }
.ln { --d: 0; display: block; min-height: 1lh; white-space: pre-wrap; overflow-wrap: anywhere; padding-left: calc(var(--d) * 2ch + 2ch); text-indent: calc(var(--d) * -2ch - 2ch); }
.ln.d1 { --d: 1; } .ln.d2 { --d: 2; } .ln.d3 { --d: 3; } .ln.d4 { --d: 4; } .ln.d5 { --d: 5; } .ln.d6 { --d: 6; } .ln.d7 { --d: 7; } .ln.d8 { --d: 8; }

/* the "show all" bar exists only where the code follows the text (see the 960px block) */
.resp-more { display: none; }

/* one snippet per language; JavaScript turns the tabs on (and remembers the choice), otherwise curl */
.code-body pre[data-lang] { display: none; margin: 0; }
.code-body pre[data-lang="curl"] { display: block; }
:root[data-code="js"] .code-body pre[data-lang="curl"], :root[data-code="py"] .code-body pre[data-lang="curl"] { display: none; }
:root[data-code="js"] .code-body pre[data-lang="js"], :root[data-code="py"] .code-body pre[data-lang="py"] { display: block; }
.docs .code-tabs { display: none; }
.js .docs .code-tabs { display: flex; }
.js .code-label-nojs { display: none; }
.run-btn { display: none; }
.js .run-btn { display: inline-flex; }

/* ----- Responsive ------------------------------------------------------------------------- */
@media (max-width: 1180px) {
    .docs { grid-template-columns: minmax(0, 1fr); }
    .docs-side { display: none; }
    /* the contents become a bar under the nav that always says where you are */
    .docs-toc {
        display: block; position: sticky; top: var(--nav-h); z-index: 50; margin: 0 -32px;
        border-bottom: 1px solid var(--line);
        background: color-mix(in srgb, var(--bg) 92%, transparent);
        -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    }
    .docs-toc summary {
        display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 32px;
        font-size: 0.875rem; font-weight: 600; color: var(--text); cursor: pointer; list-style: none;
    }
    .docs-toc summary::-webkit-details-marker { display: none; }
    .toc-label { flex: none; }
    .toc-now { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-3); font-weight: 500; }
    .toc-now:not(:empty)::before { content: "/"; margin-right: 10px; color: var(--line-3); }
    .docs-toc summary svg { flex: none; width: 18px; height: 18px; color: var(--text-3); transition: transform .2s ease; }
    .docs-toc[open] summary svg { transform: rotate(180deg); }
    .docs-toc summary:focus-visible { outline-offset: -3px; }
    .docs-toc-nav {
        position: absolute; left: 0; right: 0; top: 100%; max-height: calc(100dvh - var(--nav-h) - 44px); overflow-y: auto; overscroll-behavior: contain;
        columns: 3 200px; column-gap: 24px; padding: 4px 24px 20px; background: var(--bg); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-md);
    }
    .docs-toc-nav .side-group { break-inside: avoid; margin: 14px 0 0; }
    .doc-sec, .doc-group { scroll-margin-top: 44px; }
    .doc-group + .doc-sec { scroll-margin-top: 76px; }
    .doc-code { top: calc(var(--nav-h) + 64px); }
    .doc-intro { padding-top: 40px; }
}
@media (max-width: 960px) {
    .doc-sec { grid-template-columns: minmax(0, 1fr); gap: 22px 0; padding: 44px 0 48px; }
    .doc-code { position: static; }
    .doc-group { padding-top: 60px; }
    /* the code follows the text here: a long example shows its first 8 lines and opens in place */
    .docs .code-resp .code-body { max-height: 196px; }
    .js .code-resp.has-more .code-body { overflow: hidden; }
    .js .code-resp.has-more.open .code-body { max-height: none; }
    .js .code-resp.has-more .resp-more {
        display: block; width: 100%; height: 36px; padding: 0 18px; text-align: left; cursor: pointer;
        border: 0; border-top: 1px solid var(--term-line); background: rgba(255, 255, 255, 0.025);
        font-family: var(--mono); font-size: 0.75rem; font-weight: 600; color: var(--term-dim);
    }
    .js .code-resp.has-more .resp-more:hover { color: var(--term-text); }
    .resp-more:focus-visible { outline: 2px solid var(--term-green); outline-offset: -2px; border-radius: 0 0 var(--r-lg) var(--r-lg); }
}
@media (max-width: 760px) {
    .docs { padding: 0 16px; }
    .docs-page { --hdr-pad: 16px; }
    .docs-toc { margin: 0 -16px; }
    .docs-toc summary { padding: 0 16px; }
    .docs-toc-nav { columns: 2 150px; padding: 4px 8px 20px; }
    .doc-sec { padding: 28px 0 32px; }
    .doc-group { padding-top: 40px; }
    .doc-title { font-size: 2.125rem; }
    .doc-text .doc-lede { font-size: 1.0625rem; }
    .doc-h { font-size: 1.3125rem; }
}
@media (max-width: 560px) {
    .doc-facts dt { padding-right: 16px; }
    /* parameter rows stack: name and type on one line, the description under them */
    .ptable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .ptable, .ptable tbody { display: block; }
    .ptable tr { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
    .ptable td { display: block; padding: 0; border: 0; min-width: 0; }
    .ptable td:last-child { grid-column: 1 / -1; }
    .ptable .p-name { display: flex; align-items: baseline; gap: 8px; }
    .p-req { display: inline; margin: 0; }
    .ptable .p-type { justify-self: end; }
    .perr .p-codes { width: auto; white-space: normal; padding-right: 0; }
    .ptable tr.pf-group { display: block; padding: 0; border: 0; }
    .pfields .pf-group th { display: block; padding: 24px 0 8px; }
    .docs .code-body { padding: 14px 14px 16px; }
    .resp-ct { display: none; }   /* the status and "example / live" stay; the content type is in the docs */
    .doc-term .terminal-body { padding: 16px 16px 18px; font-size: 0.8125rem; }
    .docs-toc-nav { columns: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .docs-toc summary svg { transition: none; }
}
