/* Workspace docs — /resources/docs/. Laid out like a product docs site:
   a slim sticky bar under the navbar, a sticky sidebar tree, the article
   with its own title, and an "On this page" rail on wide screens. Reuses the
   main.css tokens; callouts come from
   safety-doc.css. */

:root {
    --docs-bar-h: 46px;
    /* navbar (64px) + docs bar */
    --docs-top: calc(64px + var(--docs-bar-h));
}

/* ---- docs bar: one slim navy strip, sticky under the site navbar ---- */
.docs-bar {
    position: sticky;
    top: 64px;
    z-index: 40;
    margin-top: 64px;
    height: var(--docs-bar-h);
    background: var(--navy);
    border-bottom: 1px solid var(--navy-line);
    color: var(--snow);
}

.docs-bar::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -5px;
    height: 5px;
    background: repeating-conic-gradient(var(--navy) 0 25%, transparent 0 50%) 0 0/10px 10px;
    pointer-events: none;
}

.docs-bar-inner {
    max-width: 1440px;
    height: 100%;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    font-family: var(--font-mono);
    font-size: 0.74rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.docs-bar-title {
    color: #ffffff;
    font-weight: 600;
    text-decoration: none;
}

.docs-bar-sep {
    width: 1px;
    height: 16px;
    background: var(--navy-line);
}

.docs-bar-section {
    color: var(--blue-hi);
}

.docs-bar-repos {
    margin-left: auto;
    display: flex;
    gap: 1.4rem;
}

.docs-bar-repos a {
    color: var(--mist);
    text-decoration: none;
}

.docs-bar-repos a:hover {
    color: #ffffff;
}

/* ---- shell: tree, article, rail; the rail drops out below 1200px ---- */
.docs-layout {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 1.5rem 4rem;
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr) 216px;
    gap: 3.5rem;
    align-items: start;
}

/* ---- sidebar: sticky, scrolls on its own when longer than the window ---- */
.docs-side {
    position: sticky;
    top: var(--docs-top);
    align-self: start;
    max-height: calc(100vh - var(--docs-top));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1.6rem 0.75rem 2rem 0;
    min-height: calc(100vh - var(--docs-top));
    border-right: 1px solid var(--line);
    font-size: 0.9rem;
    scrollbar-width: thin;
}

.docs-nav a {
    text-decoration: none;
}

.docs-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.docs-nav li {
    margin: 0;
}

.docs-nav-home {
    display: block;
    padding: 0.35rem 0.6rem;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: var(--heading);
    border-radius: 3px;
}

/* Categories: a labelled block with a rule above, so each one reads as its own group. */
.docs-nav-cat {
    margin-top: 0.9rem;
    padding-top: 0.9rem;
    border-top: 1px solid var(--line);
}

.docs-nav-cat-title {
    margin: 0 0 0.35rem;
    padding: 0 0.6rem;
}

.docs-nav-cat-title a {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--faint);
}

.docs-nav-cat-title a:hover,
.docs-nav-cat-title a[aria-current="page"] {
    color: var(--link-ink);
}

.docs-nav-link {
    display: block;
    flex: 1;
    padding: 0.3rem 0.6rem;
    line-height: 1.4;
    color: var(--ink);
    border-radius: 3px;
}

.docs-nav-link:hover,
.docs-nav-home:hover {
    background: var(--wash);
    color: var(--heading);
}

.docs-nav-link[aria-current="page"],
.docs-nav-home[aria-current="page"] {
    background: color-mix(in srgb, var(--blue) 10%, transparent);
    color: var(--link-ink);
    font-weight: 600;
}

/* A topic with subtopics: link plus an arrow button. Plain topics have no arrow. */
.docs-nav-row {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

.docs-nav-toggle {
    flex: none;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: var(--faint);
    cursor: pointer;
}

.docs-nav-toggle:hover {
    background: var(--wash);
    color: var(--heading);
}

.docs-nav-toggle svg {
    transition: transform 0.15s;
}

.docs-nav-toggle[aria-expanded="true"] svg {
    transform: rotate(90deg);
}

.docs-nav-sub {
    margin: 0.1rem 0 0.3rem 0.85rem;
    padding-left: 0.4rem;
    border-left: 1px solid var(--line);
}

.docs-nav-sub .docs-nav-link {
    font-size: 0.87rem;
    color: var(--muted);
}

/* The current page's own headings. */
.docs-nav-toc {
    margin: 0.15rem 0 0.4rem 0.6rem;
}

.docs-nav-toc a {
    display: block;
    padding: 0.18rem 0.6rem;
    border-left: 2px solid var(--line);
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--faint);
}

.docs-nav-toc a:hover {
    color: var(--heading);
}

.docs-nav-toc a[aria-current="true"] {
    color: var(--link-ink);
    border-left-color: var(--blue);
}

.docs-nav-mobile {
    display: none;
}

/* With the rail showing, the tree lists pages only. */
@media (min-width: 1201px) {
    .docs-nav-desktop .docs-nav-toc {
        display: none;
    }
}

/* ---- "On this page" rail: sticky, scrolls on its own when long ---- */
.docs-rail {
    position: sticky;
    top: var(--docs-top);
    align-self: start;
    max-height: calc(100vh - var(--docs-top));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 2.4rem 0 2rem;
    font-size: 0.82rem;
    line-height: 1.4;
    scrollbar-width: thin;
}

.docs-rail-title {
    margin: 0 0 0.6rem;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--faint);
}

.docs-rail ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.docs-rail li {
    margin: 0;
}

.docs-rail a {
    display: block;
    padding: 0.25rem 0 0.25rem 0.75rem;
    border-left: 2px solid var(--line);
    color: var(--muted);
    text-decoration: none;
}

.docs-rail ul ul a {
    padding-left: 1.5rem;
    font-size: 0.78rem;
    color: var(--faint);
}

.docs-rail a:hover {
    color: var(--heading);
}

.docs-rail a[aria-current="true"] {
    color: var(--link-ink);
    border-left-color: var(--blue);
}

.docs-rail a code {
    font-family: var(--font-mono);
    font-size: 0.92em;
}

/* ---- article head: breadcrumb, title and summary sit in the article, not a hero ---- */
.docs-article {
    padding-top: 2rem;
}

.docs-article .docs-crumbs ol {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0 0 0.9rem;
    padding: 0;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    color: var(--faint);
}

.docs-crumbs li + li::before {
    content: '/';
    margin-right: 0.35rem;
    color: var(--line-2);
}

.docs-article .docs-crumbs a {
    color: var(--muted);
    text-decoration: none;
}

.docs-crumbs a:hover {
    color: var(--link-ink);
}

.docs-title {
    font-size: clamp(1.9rem, 3.4vw, 2.5rem);
    color: var(--heading);
    margin: 0 0 0.6rem;
}

.docs-summary {
    max-width: 62ch;
    margin: 0 0 2rem;
    font-size: 1.08rem;
    line-height: 1.6;
    color: var(--muted);
}

/* ---- source links: a path with one small plate per car repository ---- */
/* A long path may wrap; each car plate stays whole. */
.docs-article .src-ref code {
    white-space: normal;
    overflow-wrap: anywhere;
}

.src-car {
    white-space: nowrap;
}

.src-car {
    display: inline-block;
    margin-left: 0.25rem;
    padding: 0 0.32rem;
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    line-height: 1.5;
    vertical-align: 0.12em;
    color: var(--link-ink);
    border: 1px solid color-mix(in srgb, var(--blue) 40%, transparent);
    border-radius: 2px;
    text-decoration: none;
}

.docs-article a.src-car {
    text-decoration: none;
}

.src-car:hover {
    background: var(--blue);
    border-color: var(--blue);
    color: #ffffff;
}

/* ---- article ---- */
.docs-article {
    max-width: 760px;
    min-width: 0;
    color: var(--ink);
    font-size: 1rem;
    line-height: 1.75;
}

.docs-article > *:first-child {
    margin-top: 0;
}

.docs-article h2 {
    font-size: 1.75rem;
    color: var(--heading);
    margin: 3rem 0 0.9rem;
    padding-top: 1.4rem;
    border-top: 1px solid var(--line);
    scroll-margin-top: calc(var(--docs-top) + 16px);
}

.docs-article h3 {
    font-family: var(--font-body);
    font-size: 1.12rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: none;
    color: var(--heading);
    margin: 2rem 0 0.6rem;
    scroll-margin-top: calc(var(--docs-top) + 16px);
}

.docs-article h4 {
    font-family: var(--font-mono);
    font-size: 0.76rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 1.6rem 0 0.5rem;
}

.docs-article p,
.docs-article ul,
.docs-article ol {
    margin: 0 0 1.1rem;
}

.docs-article ul,
.docs-article ol {
    padding-left: 1.4rem;
}

.docs-article li {
    margin-bottom: 0.35rem;
}

.docs-article a {
    color: var(--link-ink);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.docs-article :not(pre) > code {
    font-family: var(--font-mono);
    font-size: 0.86em;
    padding: 0.05em 0.28em;
    background: var(--wash);
    border: 1px solid var(--line);
    border-radius: 3px;
    overflow-wrap: anywhere;
}

.docs-article .h-anchor {
    margin-left: 0.4rem;
    color: var(--faint);
    text-decoration: none;
    opacity: 0;
}

.docs-article h2:hover .h-anchor,
.docs-article h3:hover .h-anchor,
.docs-article .h-anchor:focus {
    opacity: 1;
}

/* ---- code blocks with a copy button ---- */
.docs-article .highlight {
    position: relative;
    margin: 1.2rem 0 1.5rem;
    max-width: 100%;
}

.docs-article .highlight pre {
    margin: 0;
    padding: 1rem 1.1rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.84rem;
    line-height: 1.65;
    border-left: 4px solid var(--blue);
}

.docs-copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem 0.65rem;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #c9d4e5;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.22);
    cursor: pointer;
}

.docs-copy:hover,
.docs-copy:focus-visible {
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.5);
}

/* ---- tables ---- */
.docs-article table {
    display: block;
    overflow-x: auto;
    width: 100%;
    border-collapse: collapse;
    margin: 1.3rem 0 1.6rem;
    font-size: 0.9rem;
    line-height: 1.55;
}

.docs-article th,
.docs-article td {
    text-align: left;
    vertical-align: top;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--line);
}

.docs-article thead th {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 2px solid var(--line-2);
    white-space: nowrap;
}

/* Car 1 / Car 2 comparison */
.cars-table-wrap {
    margin: 1.3rem 0 1.6rem;
    border: 1px solid var(--line-2);
    overflow-x: auto;
}

.docs-article .cars-table {
    display: table;
    margin: 0;
}

.cars-table caption {
    text-align: left;
    padding: 0.6rem 0.85rem;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    background: var(--wash);
    border-bottom: 1px solid var(--line);
}

.cars-table tbody th {
    font-weight: 600;
    color: var(--heading);
    white-space: nowrap;
}

.cars-table tbody tr:last-child th,
.cars-table tbody tr:last-child td {
    border-bottom: none;
}

.car-plate {
    display: inline-block;
    padding: 0.15rem 0.6rem 0.15rem 0.5rem;
    background: var(--navy);
    color: #ffffff;
    letter-spacing: 0.12em;
    clip-path: polygon(0 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}

/* ---- maths ---- */
.docs-article .katex-display {
    margin: 1.2rem 0 1.5rem;
    padding: 0.9rem 1rem;
    background: var(--wash);
    border-left: 4px solid var(--line-2);
    overflow-x: auto;
    overflow-y: hidden;
}

.docs-article .katex {
    font-size: 1.06em;
}

/* ---- figures (inline SVG from the page bundle) ---- */
.docs-figure {
    margin: 1.6rem 0 1.9rem;
    padding: 1.2rem;
    border: 1px solid var(--line);
    background: var(--paper);
}

.docs-figure svg {
    display: block;
    width: 100%;
    height: auto;
    max-height: 520px;
    color: var(--ink);
}

.docs-figure figcaption {
    margin-top: 0.8rem;
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--muted);
}

/* Shared SVG vocabulary. Diagrams use these classes instead of fixed colours
   so they read in both themes. */
.docs-figure .fg { stroke: var(--ink); fill: none; }
.docs-figure .fg-fill { fill: var(--ink); }
.docs-figure .muted { stroke: var(--faint); fill: none; }
.docs-figure .muted-fill { fill: var(--muted); }
.docs-figure .accent { stroke: var(--blue); fill: none; }
.docs-figure .accent-fill { fill: var(--blue); }
.docs-figure .accent-soft { fill: color-mix(in srgb, var(--blue) 14%, transparent); }
.docs-figure .warn { stroke: var(--call-warning-band); fill: none; }
.docs-figure .warn-fill { fill: var(--call-warning-band); }
.docs-figure .warn-soft { fill: color-mix(in srgb, var(--call-warning-band) 16%, transparent); }
.docs-figure .box { fill: var(--wash); stroke: var(--line-2); }
.docs-figure .box-navy { fill: var(--navy); stroke: none; }
.docs-figure .on-navy { fill: #ffffff; }
.docs-figure text {
    font-family: var(--font-body);
    font-size: 13px;
    fill: var(--ink);
}
.docs-figure text.mono {
    font-family: var(--font-mono);
    font-size: 11.5px;
}
/* Small caps labels inside a navy box use the light mist, not the muted grey. */
.docs-figure text.label.on-navy { fill: var(--mist); }
.docs-figure text.label {
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.08em;
    fill: var(--muted);
}

/* ---- section listings, Stripe style: link, then one sentence ---- */
.docs-links {
    list-style: none;
    margin: 0.8rem 0 1.6rem;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.1rem 2rem;
}

.docs-article .docs-links li {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.docs-article .docs-links a {
    font-weight: 600;
    text-decoration: none;
}

.docs-article .docs-links a:hover {
    text-decoration: underline;
}

.docs-links span {
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--muted);
}

.docs-group h2 a {
    color: inherit;
    text-decoration: none;
}

/* ---- page foot ---- */
.docs-checked {
    margin-top: 3rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
    font-size: 0.82rem;
    color: var(--faint);
}

.docs-prevnext {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1.4rem;
}

.docs-article .docs-prevnext-link {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--line-2);
    color: var(--heading);
    font-weight: 600;
    text-decoration: none;
}

.docs-article .docs-prevnext-link:hover {
    border-color: var(--blue);
}

.docs-prevnext-next {
    text-align: right;
}

.docs-prevnext-dir {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--faint);
}

@media (max-width: 1200px) {
    .docs-layout {
        grid-template-columns: 264px minmax(0, 1fr);
    }

    .docs-rail {
        display: none;
    }
}

/* ---- narrow screens: one column, the sidebar becomes a menu ---- */
@media (max-width: 900px) {
    .docs-bar-section,
    .docs-bar-sep {
        display: none;
    }

    .docs-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
        padding: 0 1rem 3rem;
    }

    .docs-side {
        display: none;
    }

    .docs-article {
        padding-top: 1.25rem;
    }

    .docs-nav-mobile {
        display: block;
        margin-bottom: 1.4rem;
        border: 1px solid var(--line-2);
        padding: 0.7rem 0.9rem;
        font-size: 0.92rem;
    }

    .docs-nav-mobile summary {
        cursor: pointer;
        font-family: var(--font-mono);
        font-size: 0.74rem;
        font-weight: 600;
        letter-spacing: 0.14em;
        text-transform: uppercase;
        color: var(--heading);
    }

    .docs-nav-mobile[open] summary {
        margin-bottom: 0.6rem;
    }

    .docs-links,
    .docs-prevnext {
        grid-template-columns: minmax(0, 1fr);
    }

    .docs-prevnext-next {
        text-align: left;
    }
}

@media (max-width: 520px) {
    .docs-bar-repos {
        gap: 0.9rem;
    }
}

/* Dark grounds need a stronger tint for figure bands to read. */
:root[data-theme="dark"] .docs-figure .accent-soft { fill: color-mix(in srgb, var(--blue-hi) 24%, transparent); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .docs-figure .accent-soft { fill: color-mix(in srgb, var(--blue-hi) 24%, transparent); }
}

/* Parameter names in tables stay on one line; the table scrolls instead. */
.docs-article td code,
.docs-article th code {
    white-space: nowrap;
    overflow-wrap: normal;
}
