/* docs-browser design system */

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/Inter-Regular.woff2") format("woff2");
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/Inter-500.woff2") format("woff2");
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/Inter-600.woff2") format("woff2");
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/Inter-700.woff2") format("woff2");
}

:root {
    --bg: #FFFFFF;
    --bg-subtle: #F5F7F9;
    --text: #1F2328;
    --text-muted: #5A636E;
    --border: #E2E5E9;
    --accent: #007ACC;
    --accent-soft: rgba(0, 122, 204, .09);
    --code-bg: #F6F8FA;
    --surface-1: #FFFFFF;
    --surface-2: #F5F7F9;
    --surface-3: #EDF1F4;
    --text-strong: #14181D;
    --code-surface: #F6F8FA;
    --code-border: #E2E5E9;
    --code-text: #1F2328;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-1: 0 1px 2px rgba(16,24,40,.06);
    --shadow-2: 0 8px 24px rgba(16,24,40,.12);
    --diff-add: #E6FFEC;
    --diff-add-text: #2EA043;
    --diff-del: #FFEBE9;
    --diff-del-text: #CF222E;
    /* Fixed chrome height: the top bar stays put while the content column
       scrolls beneath it. */
    --topbar-h: 48px;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #0D1117;
    --bg-subtle: #11161D;
    --text: #E6EDF3;
    --text-muted: #9AA4B2;
    --border: #272E38;
    --accent: #2E9BFF;
    --accent-soft: rgba(46, 155, 255, .13);
    --code-bg: #161B22;
    --surface-1: #0D1117;
    --surface-2: #11161D;
    --surface-3: #161B22;
    --text-strong: #F0F6FC;
    --code-surface: #161B22;
    --code-border: #272E38;
    --code-text: #E6EDF3;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 8px 24px rgba(0,0,0,.5);
    --diff-add: #12261E;
    --diff-add-text: #3FB950;
    --diff-del: #2D1214;
    --diff-del-text: #F85149;
    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

/* Bound the page grid so child min-content widths cannot expand the viewport.
   The two rows are the fixed chrome: top bar and scrolling content. */
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    display: grid;
    grid-template-rows: var(--topbar-h) minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr);
    min-height: 100vh;
}

.topbar {
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: var(--topbar-h);
    padding: 0 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    z-index: 30;
}

.app-shell {
    grid-row: 2;
    min-height: 0;
    overflow: auto;
}

/* Brand */
.topbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    flex-shrink: 0;
}

.topbar-brand img,
.topbar-brand svg {
    width: 20px;
    height: 20px;
}

/* Search */
.topbar-search {
    position: relative;
    display: flex;
    align-items: center;
    flex: 0 1 320px;
    min-width: 180px;
}

.topbar-search input {
    width: 100%;
    height: 30px;
    padding: 0 2rem 0 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-subtle);
    color: var(--text);
    font: inherit;
    font-size: 14px;
}

.topbar-search input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg);
}

.search-hint {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 4px;
    line-height: 1.4;
    pointer-events: none;
}

.search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    max-height: 360px;
    overflow: auto;
    z-index: 40;
}

.search-dropdown mark {
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 2px;
    padding: 0 1px;
}

/* Result rows: title / breadcrumb / snippet stack; the first row carries a
   faint accent edge as a "press enter" affordance, echoing the sidebar's
   active marker. */
.search-row {
    display: block;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
}

.search-row:last-child {
    border-bottom: none;
}

.search-row:hover,
.search-row.is-active {
    background: var(--accent-soft);
}

.search-row:first-child {
    box-shadow: inset 2px 0 0 var(--accent);
}

.search-title {
    display: block;
    font-weight: 600;
    font-size: 14px;
    line-height: 1.4;
}

.search-breadcrumb {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

.search-snippet {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 0.15rem;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.45;
}

.search-empty {
    padding: 0.75rem;
    font-size: 13px;
    color: var(--text-muted);
}

/* Links + right-hand controls. margin-left:auto pins this cluster to the far
   right of the bar; nowrap keeps it on a single 48px row. */
.topbar-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: nowrap;
    flex-shrink: 0;
    margin-left: auto;
}

.topbar-links a {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
}

.topbar-links a:hover {
    color: var(--text);
    background: var(--accent-soft);
}

.topbar-links .icon,
.topbar .icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.topbar .icon svg {
    display: block;
    width: 16px;
    height: 16px;
}

/* Theme toggle + version select */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-subtle);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
}

.theme-toggle:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.version-select {
    height: 30px;
    padding: 0 0.5rem;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-subtle);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

/* App grid / doc shell */
.doc-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 260px;
    min-height: 100%;
}

/* Sidebar: sticks to the top of the scrolling shell and keeps its own
   scrollbar, so the tree is always reachable while the article scrolls. */
.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: calc(100vh - var(--topbar-h));
    border-right: 1px solid var(--border);
    padding: 1rem;
    overflow-y: auto;
    scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.sidebar-tree {
    font-size: 14px;
}

/* The home entry sits above the tree and is separated from it by a hairline:
   it is the page itself, not one of the sections. */
.sidebar-home {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.tree-node--home > .tree-link {
    color: var(--text);
    font-weight: 600;
}

.tree-node--home > .tree-link:hover {
    color: var(--accent);
}

.tree,
.tree ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tree li {
    margin: 0;
}

.tree-link,
.tree-label {
    color: var(--text-muted);
    text-decoration: none;
    display: inline-block;
    padding: 0.15rem 0;
}

.tree-link:hover {
    color: var(--accent);
}

.tree-node.is-active > .tree-link {
    color: var(--accent);
    font-weight: 600;
}

/* Hierarchy: indent nested levels behind a faint guide so the tree's shape
   reads at a glance. */
.tree ul {
    padding-left: 1rem;
    margin-left: 0.15rem;
    border-left: 1px solid var(--border);
}

/* Containers (sections/categories) read as headers; leaf topics stay quiet. */
.tree-node--section > .tree-link,
.tree-node--section > .tree-label {
    color: var(--text);
    font-weight: 600;
}

.tree-node--category > .tree-link,
.tree-node--category > .tree-label {
    color: var(--text);
    font-weight: 500;
}

/* Keep hover feedback above the container treatments. */
.tree-node--section > .tree-link:hover,
.tree-node--category > .tree-link:hover {
    color: var(--accent);
}

/* Main content: the shell scrolls, so the column must not scroll on its own. */
.doc-main {
    padding: 2rem;
}

.doc-column {
    max-width: 820px;
    margin: 0 auto;
}

.doc-title {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.25;
    margin: 0 0 1rem;
}

.doc-body {
    font-size: 16px;
}

.doc-body h2,
.doc-body h3,
.doc-body h4 {
    margin-top: 1.75rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
    /* Anchor jumps stop just short of the content top instead of flush. */
    scroll-margin-top: 1rem;
}

.doc-body p {
    margin: 0 0 1rem;
}

.doc-body a {
    color: var(--accent);
    text-decoration: none;
}

.doc-body a:hover {
    text-decoration: underline;
}

.doc-body ul,
.doc-body ol {
    margin: 0 0 1rem;
    padding-left: 1.5rem;
}

.doc-body blockquote {
    margin: 0 0 1rem;
    padding: 0.5rem 1rem;
    border-left: 3px solid var(--border);
    color: var(--text-muted);
    background: var(--bg-subtle);
    border-radius: 0 6px 6px 0;
}

.doc-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 0 0 1rem;
}

.doc-body th,
.doc-body td {
    border: 1px solid var(--border);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.doc-body th {
    background: var(--bg-subtle);
    font-weight: 600;
}

/* Embedded media never leaves the reading column. Screenshots are authored
   far wider than the column, so they scale down to its width and keep their
   aspect ratio instead of spilling over the neighbouring column. */
.doc-body img,
.doc-body video,
.doc-body iframe,
.doc-body svg {
    max-width: 100%;
}

.doc-body img {
    height: auto;
}

/* A zoomable image invites the click that opens the viewer. */
.doc-body img.is-zoomable {
    cursor: zoom-in;
}

/* An image that is all a paragraph holds is a standalone figure: it becomes a
   block with its own spacing and a quiet frame. An image that sits inside a
   sentence stays inline. */
.doc-body p > img:only-child,
.doc-body p > a:only-child > img {
    display: block;
    margin: 0 0 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
}

/* Raw-HTML pages may group an image and its caption in a figure. */
.doc-body figure {
    margin: 0 0 1rem;
}

.doc-body figure img {
    display: block;
    margin: 0 auto;
}

.doc-body figcaption {
    margin-top: 0.5rem;
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

/* Heading copy-link buttons (injected by JS). Hidden until the heading is
   hovered or the button itself takes keyboard focus. */
.doc-body h2,
.doc-body h3 {
    position: relative;
}

.heading-anchor {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    margin-left: 0.4rem;
    padding: 0;
    vertical-align: -0.25rem;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.doc-body h2:hover .heading-anchor,
.doc-body h3:hover .heading-anchor,
.heading-anchor:focus-visible {
    opacity: 1;
}

.heading-anchor:hover {
    color: var(--accent);
    background: var(--accent-soft);
}

.heading-anchor.is-copied {
    opacity: 1;
    color: var(--diff-add-text);
}

/* Touch devices have no hover; keep the button quietly visible. */
@media (hover: none) {
    .heading-anchor {
        opacity: 0.5;
    }
}

/* TOC: sticks to the top of the scrolling shell, like the sidebar, and keeps
   its own scrollbar for long tables of contents. */
.toc {
    position: sticky;
    top: 0;
    align-self: start;
    height: calc(100vh - var(--topbar-h));
    border-left: 1px solid var(--border);
    padding: 1rem;
    overflow-y: auto;
    scrollbar-width: thin;
    font-size: 13px;
}

/* The mobile disclosure replaces the rail where the two-column reading layout no longer fits. */
.toc-mobile {
    display: none;
    margin: 0 0 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
}

.toc-mobile summary {
    cursor: pointer;
    font-weight: 600;
    padding: 0.6rem 0.85rem;
}

.toc ul,
.toc-mobile ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc li,
.toc-mobile li {
    margin: 0.15rem 0;
}

/* The rail's active marker sits on the column border, with a clear gap
   before the label: the negative margin pulls the marker out to the rail and
   the matching padding pushes the text back to its original position. */
.toc a {
    color: var(--text-muted);
    text-decoration: none;
    display: block;
    padding: 0.15rem 0.5rem 0.15rem 12px;
    border-left: 2px solid transparent;
    margin-left: -14px;
    transition: color 0.15s ease, border-color 0.15s ease;
}

/* The mobile disclosure is a box, not a rail, so its marker stays inside. */
.toc-mobile-nav {
    padding: 0 0.75rem 0.75rem;
}

.toc-mobile a {
    color: var(--text-muted);
    text-decoration: none;
    display: block;
    padding: 0.15rem 0.5rem 0.15rem 12px;
    border-left: 2px solid transparent;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.toc a:hover,
.toc-mobile a:hover {
    color: var(--text);
}

/* Both the rail and the mobile disclosure mark the heading in view. */
.toc a.is-active,
.toc-mobile a.is-active {
    color: var(--accent);
    font-weight: 600;
    border-left-color: var(--accent);
}

.toc .toc-level-3,
.toc-mobile .toc-level-3 {
    padding-left: 24px;
}

.toc .toc-top,
.toc-mobile .toc-top {
    margin-top: 0.4rem;
    color: var(--accent);
}

/* Tree collapse (enhanced by JS) */
.js .tree-node.is-group > ul {
    display: none;
}

.js .tree-node.is-group.is-open > ul {
    display: block;
}

.tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    margin-right: 0.15rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    vertical-align: middle;
    transition: transform 0.15s ease;
}

.tree-toggle svg {
    display: block;
}

/* Open groups rotate the right chevron to point down. */
.tree-node.is-open > .tree-toggle {
    transform: rotate(90deg);
}

/* Code blocks */
pre {
    background: var(--code-surface);
    padding: 1rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-size: 14px;
    line-height: 1.65;
    margin: 0 0 1rem;
}

code {
    font-family: "JetBrains Mono", "Fira Code", Consolas, "Liberation Mono", monospace;
    font-size: 0.9em;
}

p code,
li code,
td code {
    background: var(--code-bg);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}

pre code {
    display: block;
    background: transparent;
    padding: 0;
    margin: 0;
    font-size: inherit;
    line-height: inherit;
}

/* Breadcrumbs */
.breadcrumbs {
    margin: 0 0 1rem;
    font-size: 13px;
    color: var(--text-muted);
}

.breadcrumb-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.breadcrumb-item + .breadcrumb-item::before {
    content: "/";
    margin-right: 0.35rem;
    color: var(--text-muted);
}

.breadcrumbs a {
    color: var(--text-muted);
    text-decoration: none;
}

.breadcrumbs a:hover {
    color: var(--accent);
}

/* Home */
.home {
    max-width: 820px;
    margin: 0 auto;
    padding: 3rem 2rem;
}

.home-title {
    font-size: 2.25rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
}

.home-tagline {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin: 0 0 0.5rem;
}

.home-version {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0 0 1.5rem;
}

.home-sections {
    margin-top: 1rem;
}

.home-empty {
    color: var(--text-muted);
}

/* Error page */
.error-page {
    max-width: 640px;
    margin: 4rem auto;
    padding: 0 2rem;
    text-align: center;
}

.error-code {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-muted);
    margin: 0;
}

.error-title {
    margin: 0.5rem 0;
}

.error-message {
    color: var(--text-muted);
}

.error-suggestions-list {
    list-style: none;
    padding: 0;
}

.error-suggestions-list a {
    color: var(--accent);
}

.button {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
}

/* Utilities */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.site-footer {
    display: none;
}

/* Focus */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 0.25rem;
    margin-right: 0.5rem;
}

.scrim {
    display: none;
}

/* Responsive */
@media (max-width: 1100px) {
    .doc-shell {
        grid-template-columns: 280px minmax(0, 1fr);
    }

    .toc {
        display: none;
    }

    .toc-mobile {
        display: block;
    }
}

@media (max-width: 860px) {
    .menu-toggle {
        display: inline-flex;
    }

    /* Keep the primary controls in the narrow bar and move external links to the drawer. */
    .topbar {
        gap: 0.5rem;
        padding: 0 0.6rem;
    }

    .topbar-links {
        display: none;
    }

    .topbar-search {
        flex: 1 1 auto;
        min-width: 0;
    }

    .search-hint {
        display: none;
    }

    .doc-shell {
        grid-template-columns: 1fr;
    }

    /* Let the app shell own mobile scrolling instead of nesting a second scroller. */
    .doc-main {
        /* The reading column supplies the only horizontal gutter, so the
           effective margin is 1rem (16px) per side at a 390px viewport. */
        padding: 1rem 0;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: var(--topbar-h);
        bottom: 0;
        width: 280px;
        height: auto;
        z-index: 25;
        background: var(--bg);
        transition: left 0.2s ease;
    }

    .sidebar.is-open {
        left: 0;
    }

    .scrim {
        display: none;
        position: fixed;
        inset: 0;
        top: var(--topbar-h);
        background: rgba(0, 0, 0, 0.4);
        z-index: 20;
    }

    .scrim.is-open {
        display: block;
    }

}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
.link-broken { text-decoration: line-through; color: var(--text-muted); }
