/* ==========================================================================
   Layout shell
   ========================================================================== */
.kb-main { min-height: calc(100vh - 12rem); }
.kb-page-shell {
    display: grid;
    grid-template-columns: var(--rail) minmax(0, 1fr) var(--rail);
    gap: 2rem;
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 2rem 1.5rem;
}
@media (max-width: 960px) {
    .kb-page-shell { grid-template-columns: 1fr; }
    .kb-page-shell .kb-left, .kb-page-shell .kb-right { order: 2; }
    .kb-page-shell .kb-article { order: 1; }
}
.kb-left, .kb-right { position: sticky; top: 5rem; height: fit-content; align-self: start; }

/* ==========================================================================
   Header
   ========================================================================== */
.kb-header {
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 50;
    box-shadow: var(--shadow-sm);
}
.kb-header__inner {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 1.5rem;
}
/* Nav toggle checkbox is a mobile-only implementation detail; hide it visually
   but keep it focusable for keyboard users via its associated label. */
.kb-nav-toggle {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
}
.kb-header__burger { display: none; }
.kb-brand { display: flex; align-items: center; gap: 0.6rem; color: var(--ink); font-weight: 700; text-decoration: none; }
.kb-brand:hover { color: var(--ink); text-decoration: none; }
.kb-brand__name { font-size: 0.98rem; letter-spacing: -0.01em; }

.kb-search {
    display: flex; align-items: center;
    background: var(--bg-alt);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.3rem 0.4rem 0.3rem 0.9rem;
    max-width: 32rem; width: 100%;
    justify-self: center;
}
.kb-search input {
    background: transparent; border: 0; flex: 1;
    padding: 0.4rem 0.25rem; font-size: var(--step--1);
    color: var(--ink); outline: none;
    font-family: inherit;
}
.kb-search button {
    background: var(--brand); color: white; border: 0; border-radius: var(--radius-sm);
    padding: 0.4rem 0.55rem; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.kb-search button svg { flex-shrink: 0; }
.kb-search button:hover { background: var(--brand-hover); }
.kb-search--large { max-width: 48rem; padding: 0.5rem 0.6rem 0.5rem 1.1rem; }
.kb-search--large input { font-size: var(--step-0); padding: 0.55rem 0.25rem; }

.kb-nav { display: flex; align-items: center; gap: 1rem; }
.kb-nav a { color: var(--ink-2); font-size: var(--step--1); font-weight: 500; }
.kb-nav a:hover { color: var(--brand); text-decoration: none; }
.kb-nav__admin { padding: 0.25rem 0.65rem; border: 1px solid var(--line); border-radius: var(--radius-sm); }

.kb-user-menu { position: relative; }
.kb-user-menu summary {
    list-style: none; cursor: pointer;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: var(--step--1);
}
.kb-user-menu summary::-webkit-details-marker { display: none; }
.kb-user-menu > div {
    position: absolute; right: 0; top: calc(100% + 4px);
    background: var(--bg); border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem; min-width: 12rem;
    display: flex; flex-direction: column; gap: 0.5rem;
}
.kb-user-menu__role { font-size: var(--step--1); color: var(--ink-3); }

.kb-linkbtn {
    background: none; border: 0; color: var(--brand); cursor: pointer;
    font-family: inherit; font-size: inherit; padding: 0; text-align: left;
}

/* ---- Mobile header: burger + stacked nav ------------------------------- */
@media (max-width: 720px) {
    .kb-header__inner {
        grid-template-columns: auto 1fr auto;
        grid-template-areas:
            "brand   search  burger"
            "nav     nav     nav";
        gap: 0.6rem 0.75rem;
        padding: 0.65rem 1rem;
    }
    .kb-brand { grid-area: brand; }
    .kb-brand__name { display: none; }
    .kb-search {
        grid-area: search;
        max-width: none;
        justify-self: stretch;
    }
    .kb-header__burger {
        grid-area: burger;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.5rem;
        height: 2.5rem;
        border: 1px solid var(--line);
        border-radius: var(--radius-sm);
        background: var(--bg);
        color: var(--ink);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .kb-header__burger:hover { background: var(--bg-alt); }
    .kb-nav-toggle:focus-visible + .kb-header__burger {
        outline: 2px solid var(--brand);
        outline-offset: 2px;
    }
    .kb-header__burger-close { display: none; }
    .kb-nav-toggle:checked ~ .kb-header__burger { background: var(--bg-alt); }
    .kb-nav-toggle:checked ~ .kb-header__burger .kb-header__burger-open { display: none; }
    .kb-nav-toggle:checked ~ .kb-header__burger .kb-header__burger-close { display: inline; }

    /* Nav is hidden by default on mobile; shown when the toggle is checked. */
    .kb-nav {
        grid-area: nav;
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        margin: 0.35rem -1rem -0.65rem;
        padding: 0.5rem 0;
        border-top: 1px solid var(--line);
        background: var(--bg);
    }
    .kb-nav-toggle:checked ~ .kb-nav { display: flex; }
    .kb-nav > a,
    .kb-nav > .kb-user-menu > summary,
    .kb-nav > .kb-btn {
        display: flex;
        align-items: center;
        padding: 0.75rem 1rem;
        border: 0;
        border-radius: 0;
        font-size: var(--step-0);
        color: var(--ink);
        min-height: 2.75rem;
    }
    .kb-nav > a:hover { background: var(--bg-alt); color: var(--brand); }
    .kb-nav__admin { border: 0 !important; padding: 0.75rem 1rem !important; }
    .kb-nav > .kb-btn--outline {
        margin: 0.35rem 1rem;
        justify-content: center;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        min-height: 2.75rem;
    }
    .kb-user-menu { width: 100%; }
    .kb-user-menu summary {
        border: 0;
        border-radius: 0;
        padding: 0.75rem 1rem;
        justify-content: space-between;
    }
    .kb-user-menu > div {
        position: static;
        border: 0;
        border-top: 1px solid var(--line);
        box-shadow: none;
        border-radius: 0;
        padding: 0.6rem 1rem 0.8rem;
        background: var(--bg-alt);
    }
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.kb-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: var(--step--1);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
    font-family: inherit;
}
.kb-btn--primary { background: var(--brand); color: white; }
.kb-btn--primary:hover { background: var(--brand-hover); text-decoration: none; color: white; }
.kb-btn--outline { background: transparent; color: var(--ink); border-color: var(--line); }
.kb-btn--outline:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }

/* ==========================================================================
   Hero + landing
   ========================================================================== */
.kb-hero {
    background: linear-gradient(160deg, var(--bg-tint), var(--bg));
    border-bottom: 1px solid var(--line);
}
.kb-hero__inner {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 4rem 1.5rem 3rem;
}
.kb-eyebrow {
    text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem;
    font-weight: 600; color: var(--brand);
}
.kb-hero h1 { font-size: var(--step-5); max-width: 40ch; margin-top: 0.4rem; }
.kb-lede { font-size: var(--step-1); color: var(--ink-2); max-width: 48ch; margin-bottom: 1.5rem; }
.kb-hero__cta { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.kb-section { max-width: var(--wrap); margin: 3rem auto; padding: 0 1.5rem; }
.kb-section__title { font-size: var(--step-2); margin-bottom: 1.25rem; }
.kb-card-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
    gap: 1rem;
}
.kb-card {
    display: block;
    padding: 1.25rem 1.3rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--ink);
    transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
    text-decoration: none;
}
.kb-card:hover { border-color: var(--brand); box-shadow: var(--shadow); text-decoration: none; transform: translateY(-1px); }
.kb-card h3 { margin: 0.25rem 0 0.4rem; font-size: var(--step-1); }
.kb-card p { color: var(--ink-3); margin: 0; font-size: var(--step--1); }
.kb-card__type { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); font-weight: 600; }

.kb-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.kb-list li { border-bottom: 1px solid var(--line); }
.kb-list a {
    display: grid;
    grid-template-columns: 6rem 1fr auto;
    gap: 1rem;
    padding: 0.75rem 0.5rem;
    align-items: center;
    color: var(--ink);
}
.kb-list a:hover { background: var(--bg-alt); text-decoration: none; }
.kb-list__type { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); font-weight: 600; }
.kb-list__date { font-size: var(--step--1); color: var(--ink-3); }

/* ==========================================================================
   Article prose
   ========================================================================== */
.kb-article { max-width: 42rem; }
.kb-article header { margin-bottom: 2rem; }
.kb-article header h1 { font-size: var(--step-4); }
.kb-article__footer { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--line); font-size: var(--step--1); color: var(--ink-3); }
.kb-article__source code { font-size: 0.75rem; }

.kb-prose { font-size: var(--step-0); }
.kb-prose h2 { margin: 2.5rem 0 0.75rem; font-size: var(--step-2); scroll-margin-top: 5rem; }
.kb-prose h3 { margin: 2rem 0 0.5rem; font-size: var(--step-1); scroll-margin-top: 5rem; }
.kb-prose img { border-radius: var(--radius-sm); border: 1px solid var(--line); margin: 1.5rem 0; }
.kb-prose ul, .kb-prose ol { padding-left: 1.5rem; }
.kb-prose li { margin: 0.25rem 0; }

/* ==========================================================================
   Technical excerpts — TAB algorithms, SQL, transcripts, and query results
   ========================================================================== */
.kb-body pre,
.kb-prose pre {
    margin: 1.25rem 0;
    padding: 1rem 1.1rem;
    overflow-x: auto;
    background: var(--bg-alt);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-size: 0.82em;
    line-height: 1.55;
    tab-size: 4;
}
.kb-body pre code,
.kb-prose pre code {
    display: block;
    width: max-content;
    min-width: 100%;
    padding: 0;
    background: transparent;
    color: inherit;
    font-family: var(--font-mono);
    font-size: inherit;
    white-space: pre;
}

/* Prism-compatible SQL palette: works immediately for tagged SQL blocks and
   applies token colours if Prism is enabled by a future loader enhancement. */
.kb-body pre code.language-sql,
.kb-prose pre code.language-sql { color: #15334d; }
.kb-body pre code.language-sql .token.keyword,
.kb-prose pre code.language-sql .token.keyword { color: #125a8c; font-weight: 700; }
.kb-body pre code.language-sql .token.string,
.kb-prose pre code.language-sql .token.string { color: #a14b00; }
.kb-body pre code.language-sql .token.comment,
.kb-prose pre code.language-sql .token.comment { color: var(--ink-3); font-style: italic; }

.kb-body pre:has(code.language-warning),
.kb-prose pre:has(code.language-warning) {
    background: #fff4f2;
    border-color: #f2c6bf;
    border-left: 4px solid var(--error);
}
.kb-body pre code.language-warning,
.kb-prose pre code.language-warning { color: #7b271e; }

/* Cross-ref styling */
.kb-ref { color: var(--brand); }
.kb-ref--external::after {
    content: " ↗"; font-size: 0.8em; color: var(--ink-3);
}
.kb-ref--unresolved {
    color: var(--error);
    background: #FDECEA;
    padding: 0.05em 0.35em;
    border-radius: 3px;
    text-decoration: line-through wavy var(--error);
}
.kb-ref__warn { color: var(--error); font-weight: 600; }

/* ==========================================================================
   TOC + meta pill
   ========================================================================== */
.kb-toc { font-size: var(--step--1); }
.kb-toc__title {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--ink-3); font-weight: 600; margin-bottom: 0.5rem;
}
.kb-toc ul { list-style: none; padding: 0; margin: 0; border-left: 1px solid var(--line); }
.kb-toc li { padding: 0.2rem 0 0.2rem 0.9rem; }
.kb-toc li.kb-toc__l3 { padding-left: 1.6rem; font-size: 0.85em; }
.kb-toc a { color: var(--ink-2); }
.kb-toc a:hover { color: var(--brand); text-decoration: none; }

.kb-meta-pill {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    background: var(--bg-alt);
    font-size: var(--step--1);
}
.kb-meta-pill dl { margin: 0; }
.kb-meta-pill__row { display: grid; grid-template-columns: 5.5rem 1fr; gap: 0.5rem; padding: 0.3rem 0; border-bottom: 1px dashed var(--line); }
.kb-meta-pill__row:last-child { border-bottom: 0; }
.kb-meta-pill dt { color: var(--ink-3); font-weight: 500; }
.kb-meta-pill dd { margin: 0; color: var(--ink); font-weight: 500; }

/* Priority chips */
.kb-chip {
    display: inline-block;
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}
.kb-chip--p1 { background: var(--p1-bg); color: var(--p1); }
.kb-chip--p2 { background: var(--p2-bg); color: var(--p2); }
.kb-chip--p3 { background: var(--p3-bg); color: var(--p3); }
.kb-chip--p4 { background: var(--p4-bg); color: var(--p4); }

/* ==========================================================================
   Search results
   ========================================================================== */
.kb-search-page { max-width: var(--wrap-narrow); margin: 2rem auto; padding: 0 1.5rem; }
.kb-search-page__meta { color: var(--ink-3); font-size: var(--step--1); margin-top: 0.5rem; }
.kb-hits { list-style: none; padding: 0; margin: 2rem 0 0; }
.kb-hits li { border-bottom: 1px solid var(--line); padding: 1rem 0; }
.kb-hits a { display: block; color: var(--ink); }
.kb-hits a:hover { text-decoration: none; }
.kb-hits__type { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--brand); font-weight: 700; margin-right: 0.6rem; }
.kb-hits__title { font-size: var(--step-1); color: var(--ink); }
.kb-hits a:hover .kb-hits__title { color: var(--brand); }
.kb-hits__sub { display: block; color: var(--ink-3); font-size: var(--step--1); margin-top: 0.15rem; }
.kb-hits__snip { color: var(--ink-2); font-size: var(--step--1); margin: 0.4rem 0 0; }

/* ==========================================================================
   Auth
   ========================================================================== */
.kb-auth { display: grid; place-items: center; padding: 4rem 1.5rem; min-height: 60vh; }
.kb-auth__card {
    max-width: 24rem; width: 100%;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 2.25rem 2rem;
    box-shadow: var(--shadow);
}
.kb-auth__card h1 { font-size: var(--step-2); margin-bottom: 1rem; }
.kb-form { display: flex; flex-direction: column; gap: 1rem; }
.kb-form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: var(--step--1); color: var(--ink-2); font-weight: 500; }
.kb-form input {
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: var(--step-0);
    font-family: inherit;
    color: var(--ink);
    background: var(--bg);
}
.kb-form input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.kb-muted { color: var(--ink-3); font-size: var(--step--1); text-align: center; margin-top: 1rem; }
.kb-alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: var(--step--1); }
.kb-alert--error { background: #FDECEA; color: var(--error); border: 1px solid #F5CBC5; }

/* ==========================================================================
   Admin
   ========================================================================== */
.kb-admin { max-width: var(--wrap); margin: 2rem auto; padding: 0 1.5rem; }
.kb-admin__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 1rem; margin: 1.5rem 0 2rem; }
.kb-admin__card { border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.kb-admin__card h2 { font-size: var(--step-4); color: var(--brand); margin: 0; }
.kb-admin__card p { color: var(--ink-3); font-size: var(--step--1); margin: 0 0 0.75rem; }
.kb-admin__actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.kb-table { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

/* ==========================================================================
   Breadcrumbs + errors + empty
   ========================================================================== */
.kb-crumbs ol { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; gap: 0.4rem; font-size: var(--step--1); color: var(--ink-3); }
.kb-crumbs li + li::before { content: "/"; padding-right: 0.4rem; color: var(--ink-3); }
.kb-empty { color: var(--ink-3); font-style: italic; padding: 1rem 0; }
.kb-error { max-width: var(--wrap-narrow); margin: 5rem auto; padding: 0 1.5rem; text-align: center; }
.kb-error h1 { font-size: var(--step-4); }

/* ==========================================================================
   Course
   ========================================================================== */
.kb-course-actions { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }

/* ==========================================================================
   Footer
   ========================================================================== */
.kb-footer {
    background: var(--bg-alt);
    border-top: 1px solid var(--line);
    padding: 2rem 0;
    margin-top: 5rem;
    font-size: var(--step--1);
    color: var(--ink-3);
}
.kb-footer__inner {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}
.kb-footer__meta a { color: var(--ink-3); }
.kb-footer__meta a:hover { color: var(--brand); text-decoration: none; }

/* ==========================================================================
   Docs shell — 3-col layout with persistent left sidebar
   ========================================================================== */
.kb-docs-shell {
    display: grid;
    grid-template-columns: 17rem minmax(0, 1fr);
    gap: 3.5rem;
    max-width: 80rem;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    align-items: start;
}

.kb-sidebar {
    position: sticky;
    top: 4.75rem;
    align-self: start;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    font-size: var(--step--1);
    padding-right: 0.5rem;
    scrollbar-width: thin;
}
.kb-sidebar::-webkit-scrollbar { width: 8px; }
.kb-sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.kb-sidebar__section + .kb-sidebar__section {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--line);
}
.kb-sidebar h3 {
    margin: 0 0 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.kb-sidebar ul,
.kb-sidebar__tree { list-style: none; padding: 0; margin: 0; }

/* Rows — both leaves (<li>) and branch heads (<summary>) share this look */
.kb-sidebar__item {
    display: flex;
    align-items: flex-start;
    gap: 0.3rem;
    border-left: 2px solid transparent;
    padding: 0.3rem 0.6rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    line-height: 1.35;
}
.kb-sidebar__item > a {
    color: var(--ink-2);
    text-decoration: none;
    flex: 1 1 auto;
    min-width: 0;
}
.kb-sidebar__item:hover { background: var(--bg-alt); }
.kb-sidebar__item:hover > a { color: var(--ink); }
.kb-sidebar__item.is-active {
    border-left-color: var(--brand);
    background: var(--brand-tint);
    font-weight: 600;
}
.kb-sidebar__item.is-active > a { color: var(--ink); }

/* Branch nodes */
.kb-sidebar__branch { list-style: none; }
.kb-sidebar__node > summary {
    cursor: pointer;
    list-style: none;
}
.kb-sidebar__node > summary::-webkit-details-marker { display: none; }
.kb-sidebar__node > summary::marker { content: ""; }
.kb-sidebar__chev {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1.15rem;
    flex: 0 0 auto;
    color: var(--ink-3);
    transition: transform 0.15s ease;
}
.kb-sidebar__node[open] > summary .kb-sidebar__chev { transform: rotate(90deg); }

.kb-sidebar__nest {
    padding-left: 0.85rem;
    margin-left: 0.35rem;
    border-left: 1px solid var(--line);
}

/* Group headings (Management Controls / Technical Controls / Threats / …) */
.kb-sidebar__group { margin-bottom: 0.35rem; }
.kb-sidebar__group > summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--ink);
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.kb-sidebar__group > summary:hover { background: var(--bg-alt); }
.kb-sidebar__count {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--ink-3);
    background: var(--bg-alt);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.05rem 0.4rem;
}
.kb-sidebar__group[open] > summary .kb-sidebar__count { color: var(--brand); }

/* Mobile disclosure wrapper — chrome hidden on desktop */
.kb-sidebar__mobile-toggle { display: none; }

/* Content column */
.kb-content { min-width: 0; }
.kb-content .kb-article { max-width: 47rem; }
.kb-content .kb-toc { margin: 0 0 2rem; }
.kb-content .kb-meta-pill { margin: 0 0 1.5rem; }

@media (max-width: 960px) {
    .kb-docs-shell {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        padding: 1.25rem 1rem 3rem;
    }
    .kb-sidebar {
        position: static;
        max-height: none;
        overflow: visible;
        margin-bottom: 0.5rem;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: var(--bg-tint);
    }
    .kb-sidebar__mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        cursor: pointer;
        list-style: none;
        font-weight: 600;
        color: var(--ink);
        padding: 0.75rem 1rem;
    }
    .kb-sidebar__mobile-toggle::-webkit-details-marker { display: none; }
    .kb-sidebar__disclosure[open] > .kb-sidebar__mobile-toggle {
        border-bottom: 1px solid var(--line);
    }
    .kb-sidebar__disclosure[open] > .kb-sidebar__mobile-toggle svg { transform: rotate(180deg); }
    .kb-sidebar__body { padding: 0.75rem 1rem 1rem; max-height: 60vh; overflow-y: auto; }
    .kb-content .kb-article { max-width: none; }
}

/* ==========================================================================
   Right rail — sticky page details + on-this-page (3-col docs shell)
   ========================================================================== */
.kb-docs-shell--three {
    grid-template-columns: minmax(14rem, 16rem) minmax(0, 1fr) minmax(13rem, 15rem);
    gap: 2.5rem;
    max-width: 88rem;
}

.kb-rail-right {
    position: sticky;
    top: 4.75rem;
    align-self: start;
    max-height: calc(100vh - 6.5rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    min-width: 0;
    font-size: var(--step--1);
    color: var(--ink-2);
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
    padding-left: 1.25rem;
    border-left: 1px solid var(--line);
}
.kb-rail-right:empty { display: none; }
.kb-rail-right::-webkit-scrollbar { width: 8px; }
.kb-rail-right::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.kb-rail-section { min-width: 0; }

.kb-rail__title {
    margin: 0 0 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.kb-rail__note {
    margin: 0.75rem 0 0;
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--ink-3);
}

/* Compact definition table — no card chrome */
.kb-meta-table { margin: 0; }
.kb-meta-table > div {
    display: grid;
    grid-template-columns: minmax(0, 5.25rem) minmax(0, 1fr);
    gap: 0.15rem 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px dashed var(--line);
    align-items: baseline;
}
.kb-meta-table > div:last-child { border-bottom: 0; }
.kb-meta-table dt {
    margin: 0;
    color: var(--ink-3);
    font-weight: 500;
    font-size: 0.76rem;
    line-height: 1.4;
}
.kb-meta-table dd {
    margin: 0;
    color: var(--ink);
    font-weight: 500;
    font-size: 0.79rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
}
.kb-meta-table dd code {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background: var(--bg-alt);
    border-radius: 3px;
    padding: 0.05em 0.3em;
}
.kb-meta-table .kb-chip { font-family: var(--font-mono); }

/* Cross-link chips (threats ⇄ controls) */
.kb-threat-links { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.kb-threat-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.7rem;
    padding: 0.12rem 0.4rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--bg-alt);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-2);
    text-decoration: none;
    line-height: 1.5;
}
.kb-threat-chip:hover {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-tint);
    text-decoration: none;
}

/* TOC inside the rail */
.kb-rail-right .kb-toc ul { border-left: 2px solid var(--line); }
.kb-rail-right .kb-toc li { padding: 0.25rem 0 0.25rem 0.75rem; line-height: 1.35; }
.kb-rail-right .kb-toc li.kb-toc__l3 { padding-left: 1.4rem; }
.kb-rail-right .kb-toc li.is-current {
    border-left: 2px solid var(--brand);
    margin-left: -2px;
}
.kb-rail-right .kb-toc li.is-current > a { color: var(--brand); font-weight: 600; }

/* Below 1200px: drop the rail, keep sidebar + content */
@media (max-width: 1200px) {
    .kb-docs-shell--three {
        grid-template-columns: 16rem minmax(0, 1fr);
        gap: 2.5rem;
    }
    .kb-docs-shell--three .kb-rail-right { display: none; }
}

@media (max-width: 960px) {
    .kb-docs-shell--three {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

/* ==========================================================================
   COURSES / REFERENCES / DOCUMENTS
   Sectioned layout + pill row + file rows, mirroring the reference KB.
   Uses only existing Nexus tokens — no new colours.
   ========================================================================== */

/* Pill row under a page title */
.kb-pill-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.9rem; }
.kb-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg-alt);
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--ink-2);
    line-height: 1.6;
    white-space: nowrap;
}
.kb-badge--level-beginner { background: var(--p4-bg); color: var(--p4); border-color: transparent; }
.kb-badge--level-intermediate { background: var(--p3-bg); color: var(--warn); border-color: transparent; }
.kb-badge--level-advanced { background: var(--p1-bg); color: var(--p1); border-color: transparent; }

.kb-chip--optional { background: var(--bg-alt); color: var(--ink-3); }
.kb-chip--primary { background: var(--brand-tint); color: var(--brand); margin-left: 0.4rem; }

.kb-duration { font-size: 0.74rem; font-weight: 600; color: var(--ink-3); white-space: nowrap; }

/* Sectioned body — small caps rule heading, like the reference detail page */
.kb-doc-section { margin: 2.5rem 0; }
.kb-doc-section__title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    font-weight: 700;
    color: var(--ink-3);
    padding-bottom: 0.5rem;
    margin: 0 0 1rem;
    border-bottom: 1px solid var(--line);
}
.kb-prose--compact p { margin: 0 0 0.8rem; }

.kb-empty { color: var(--ink-3); font-size: var(--step--1); font-style: italic; margin: 0; }

/* ---------- Course lessons list ---------- */
.kb-course-lessons {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.kb-course-lessons__item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--line);
    margin: 0;
}
.kb-course-lessons__item:last-child { border-bottom: 0; }
.kb-course-lessons__item:hover { background: var(--bg-tint); }
.kb-course-lessons__link {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
    color: var(--ink);
    text-decoration: none;
}
.kb-course-lessons__link:hover { text-decoration: none; }
.kb-course-lessons__link:hover .kb-course-lessons__title { color: var(--brand); }
.kb-course-lessons__num {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--ink-3);
    flex: 0 0 auto;
}
.kb-course-lessons__title { font-size: var(--step-0); font-weight: 500; }
.kb-course-lessons__meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
}

.kb-prereq-list { margin: 0; padding-left: 1.2rem; color: var(--ink-2); font-size: var(--step-0); }
.kb-prereq-list li { margin: 0.3rem 0; }

.kb-course-actions { margin: 2.5rem 0 0; display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ---------- Reference / course card grid ---------- */
.kb-ref-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.9rem;
}
.kb-ref-card {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 1rem 1.1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--ink);
    text-decoration: none;
}
.kb-ref-card:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--ink);
}
.kb-ref-card h3 { margin: 0.1rem 0 0.2rem; font-size: var(--step-0); line-height: 1.3; }
.kb-ref-card p { margin: 0; color: var(--ink-3); font-size: var(--step--1); }
.kb-ref-card__kind {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--ink-3);
}
.kb-ref-card__foot {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 0.6rem;
    font-size: var(--step--1);
    color: var(--ink-3);
}
.kb-ref-card--missing { background: var(--bg-alt); border-style: dashed; }
.kb-ref-card--missing:hover { border-color: var(--line); box-shadow: none; }

/* ---------- Document file rows ---------- */
.kb-doc-files { display: flex; flex-direction: column; gap: 0.5rem; }
.kb-doc-file-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
}
.kb-doc-file-row:hover { border-color: var(--brand); }
.kb-doc-file-row__icon { font-size: 1.1rem; line-height: 1; flex: 0 0 auto; }
.kb-doc-file-row__name {
    flex: 1;
    min-width: 0;
    font-size: var(--step--1);
    font-weight: 500;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kb-doc-file-row__size {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--ink-3);
}
.kb-doc-file-row__actions { display: flex; gap: 0.4rem; flex: 0 0 auto; }

.kb-btn--sm { padding: 0.3rem 0.7rem; font-size: 0.76rem; }
.kb-btn--block { display: flex; width: 100%; justify-content: center; }

.kb-backlink-list { list-style: none; margin: 0; padding: 0; }
.kb-backlink-list li { border-bottom: 1px solid var(--line); }
.kb-backlink-list li:last-child { border-bottom: 0; }
.kb-backlink-list a { display: block; padding: 0.55rem 0.2rem; font-size: var(--step--1); }
.kb-backlink-list a:hover { text-decoration: none; color: var(--brand); }

/* ---------- Prev / next lesson footer ---------- */
.kb-prev-next {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin: 3rem 0 0;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
}
.kb-prev-next__link {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.8rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
}
.kb-prev-next__link:hover { border-color: var(--brand); text-decoration: none; }
.kb-prev-next__link:hover .kb-prev-next__title { color: var(--brand); }
.kb-prev-next__link--next { text-align: right; align-items: flex-end; }
.kb-prev-next__dir {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--ink-3);
}
.kb-prev-next__title { font-size: var(--step--1); font-weight: 500; }

/* ---------- Preview lightbox ---------- */
html.kb-lightbox-open { overflow: hidden; }
.kb-lightbox {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    background: rgba(23, 22, 26, 0.92);
}
.kb-lightbox[hidden] { display: none; }
.kb-lightbox__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    flex: 0 0 auto;
}
.kb-lightbox__name {
    margin: 0;
    font-size: var(--step--1);
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kb-lightbox__actions { display: flex; align-items: center; gap: 0.6rem; flex: 0 0 auto; }
.kb-lightbox__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
}
.kb-lightbox__close:hover { background: var(--bg-alt); color: var(--ink); }
.kb-lightbox__stage {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.kb-lightbox__frame {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--bg);
}
.kb-lightbox__img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    background: var(--bg);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}

/* Rail "Course contents" list reuses the TOC skin but links off-page */
.kb-rail-contents ul { border-left: 2px solid var(--line); }
.kb-rail-contents li { padding: 0.25rem 0 0.25rem 0.75rem; line-height: 1.35; }

@media (max-width: 720px) {
    .kb-prev-next { grid-template-columns: 1fr; }
    .kb-doc-file-row { flex-wrap: wrap; }
    .kb-doc-file-row__name { flex-basis: 60%; }
    .kb-doc-file-row__actions { margin-left: auto; }
    .kb-lightbox__stage { padding: 0.75rem; }
}

/* Rotate button for wiki figures (non-destructive per-image rotation) */
.kb-fig-rotatable {
  position: relative;
  display: block;
  margin: var(--space-6) 0;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.kb-fig-rotatable img {
  display: block;
  max-width: 100%;
  height: auto;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center center;
}
.kb-fig-rotatable.is-sideways {
  /* When rotated 90°/270°, wrapper height needs to accommodate the rotated image's real height (which becomes its width). */
  min-height: min(60vw, 620px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.kb-fig-rotatable__btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 2;
}
.kb-fig-rotatable:hover .kb-fig-rotatable__btn,
.kb-fig-rotatable:focus-within .kb-fig-rotatable__btn,
.kb-fig-rotatable[data-rot]:not([data-rot="0"]) .kb-fig-rotatable__btn {
  opacity: 1;
}
.kb-fig-rotatable__btn:hover {
  color: var(--text-1);
  background: var(--surface-2);
  border-color: var(--border-2);
}
.kb-fig-rotatable__caption {
  display: block;
  padding: 0.55rem 0.85rem;
  font-family: var(--font-body);
  font-size: var(--step--1);
  line-height: 1.4;
  color: var(--ink-2);
  background: var(--bg-tint);
  border-top: 1px solid var(--line);
  text-align: left;
}
/* When rotated 90°/270° the figure switches to flex+centered; keep the caption
   below the image rather than centered alongside it. */
.kb-fig-rotatable.is-sideways .kb-fig-rotatable__caption {
  align-self: stretch;
}

/* ---------- Admin: Users & Groups ---------- */
.kb-admin__header { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 1rem; }
.kb-crumb {
    font-size: var(--step--1);
    color: var(--ink-3);
    text-decoration: none;
    display: inline-block;
}
.kb-crumb:hover { color: var(--brand); }
.kb-admin__card--wide { padding: 1.5rem; margin-bottom: 1.5rem; }
.kb-admin__card--wide h2 {
    font-size: var(--step-2);
    color: var(--ink-1);
    margin: 0 0 1rem;
}

.kb-flash {
    padding: 0.75rem 1rem;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-left: 3px solid var(--brand);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: var(--step--1);
}
.kb-flash--warn {
    border-left-color: #d97706;
    background: #fff7ed;
}
.kb-flash__note {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--ink-3);
}
.kb-code-inline {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    background: var(--ink-1);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.95rem;
    user-select: all;
}

.kb-form__grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}
.kb-field { display: flex; flex-direction: column; gap: 0.35rem; font-size: var(--step--1); color: var(--ink-2); font-weight: 500; }
.kb-field input, .kb-field select {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm, 6px);
    font: inherit;
    color: var(--ink-1);
    background: #fff;
}
.kb-field input:focus, .kb-field select:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.kb-field--wide { grid-column: 1 / -1; }
.kb-field--check {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
    color: var(--ink-2);
}
.kb-field--check input { width: auto; }
.kb-form__actions { margin-top: 1rem; display: flex; gap: 0.75rem; }
.kb-form--inline {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}
.kb-form--inline input {
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm, 6px);
    font: inherit;
}

.kb-table--users { font-size: var(--step--1); }
.kb-table--users td { padding: 0.55rem 0.5rem; vertical-align: middle; }
.kb-table--users code { font-size: 0.85rem; }
.kb-cell-groups, .kb-cell-actions { white-space: nowrap; }
.kb-inline-form { display: inline-flex; align-items: center; gap: 0.35rem; margin-right: 0.35rem; }
.kb-inline-form select {
    padding: 3px 6px;
    font-size: 0.8rem;
    border: 1px solid var(--line);
    border-radius: 4px;
}

.kb-role {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.kb-role--admin { background: #fef2f2; color: #b91c1c; }
.kb-role--staff { background: #eff6ff; color: #1e40af; }
.kb-role--customer { background: #f0fdf4; color: #166534; }

.kb-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}
.kb-status--active { background: #f0fdf4; color: #166534; }
.kb-status--disabled { background: #f3f4f6; color: #6b7280; }
.kb-status--invited { background: #fef3c7; color: #92400e; }

.kb-chip--group {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    padding: 2px 6px 2px 8px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 4px;
    font-family: ui-monospace, monospace;
    font-size: 0.75rem;
    margin-right: 0.25rem;
    margin-bottom: 0.25rem;
}
.kb-chip__x {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink-3);
    font-size: 1rem;
    line-height: 1;
    padding: 0 2px;
}
.kb-chip__x:hover { color: #b91c1c; }

.kb-btn--xs {
    padding: 3px 8px;
    font-size: 0.75rem;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink-2);
    border-radius: 4px;
    cursor: pointer;
}
.kb-btn--xs:hover { background: var(--surface-2); border-color: var(--ink-3); }
.kb-btn--xs:disabled { opacity: 0.4; cursor: not-allowed; }
.kb-btn--danger { color: #b91c1c; border-color: #fecaca; }
.kb-btn--danger:hover { background: #fef2f2; border-color: #fca5a5; }
.kb-btn--primary {
    background: var(--brand);
    color: #fff;
    border: 1px solid var(--brand);
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm, 6px);
    font-weight: 500;
    cursor: pointer;
}
.kb-btn--primary:hover { filter: brightness(1.08); }

.kb-group-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.kb-group-list li {
    padding: 4px 10px;
    background: var(--surface-2);
    border-radius: 4px;
    font-size: var(--step--1);
}
.kb-group-list li.kb-muted { background: transparent; padding: 0; }

@media (max-width: 720px) {
    .kb-form__grid { grid-template-columns: 1fr; }
    .kb-table--users { font-size: 0.75rem; }
    .kb-cell-actions { display: flex; flex-direction: column; gap: 0.25rem; }
}

/* ---------- Course page — reference lists ---------- */
.kb-outcome-list { list-style: none; padding-left: 0; margin: 1rem 0; }
.kb-outcome-list li {
    position: relative;
    padding-left: 1.75rem;
    margin-bottom: 0.75rem;
    line-height: 1.55;
}
.kb-outcome-list li::before {
    content: "✓";
    position: absolute;
    left: 0;
    top: 0;
    color: var(--brand);
    font-weight: 700;
    font-size: 1.05em;
}
.kb-muted-lede { color: var(--ink-3); font-size: var(--step--1); margin: 0.5rem 0 1rem; }

.kb-ref-group__title {
    font-size: var(--step-0);
    color: var(--ink-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin: 1.5rem 0 0.75rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--line);
}
.kb-ref-group__title:first-of-type { margin-top: 0; }

.kb-ref-list {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 1.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.kb-ref-list__item {
    display: grid;
    grid-template-columns: 8rem 1fr;
    gap: 0.5rem 1rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--line);
    align-items: baseline;
}
.kb-ref-list__item:last-child { border-bottom: none; }
.kb-ref-list__item:hover { background: var(--surface-2); }
.kb-ref-list__label {
    font-size: 0.75rem;
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    font-family: ui-monospace, monospace;
}
.kb-ref-list__title {
    color: var(--ink-1);
    text-decoration: none;
    font-weight: 500;
}
.kb-ref-list__title:hover { color: var(--brand); text-decoration: underline; }
.kb-ref-list__subtitle {
    display: block;
    grid-column: 2;
    color: var(--ink-3);
    font-size: var(--step--1);
    margin-top: 0.15rem;
}
.kb-ref-list__item--missing .kb-ref-list__title { color: var(--ink-3); }

@media (max-width: 640px) {
    .kb-ref-list__item { grid-template-columns: 1fr; }
    .kb-ref-list__subtitle { grid-column: 1; }
}

/* ---------- Related pages (auto-generated cross-links) ---------- */
.kb-related {
    margin: 3rem 0 1.5rem;
    padding: 1.75rem;
    background: var(--surface-2);
    border-radius: var(--radius);
    border: 1px solid var(--line);
}
.kb-related__head { margin-bottom: 1.25rem; }
.kb-related__title {
    font-size: var(--step-1);
    margin: 0;
    color: var(--ink-1);
    font-weight: 600;
    letter-spacing: -0.01em;
}
.kb-related__sub {
    color: var(--ink-3);
    font-size: var(--step--1);
    margin: 0.25rem 0 0;
}
.kb-related__list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.5rem;
}
.kb-related__item { margin: 0; }
.kb-related__link {
    display: flex;
    gap: 0.6rem;
    padding: 0.65rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) - 4px);
    text-decoration: none;
    color: var(--ink-1);
    transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
    height: 100%;
    align-items: flex-start;
}
.kb-related__link:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.kb-related__kind {
    display: inline-block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    background: var(--surface-2);
    color: var(--ink-2);
    flex-shrink: 0;
    margin-top: 2px;
}
.kb-related__kind--wiki { background: #eff4ff; color: #1e40af; }
.kb-related__kind--course { background: #fef3c7; color: #92400e; }
.kb-related__kind--lesson { background: #fef3c7; color: #92400e; }
.kb-related__kind--document { background: #dcfce7; color: #166534; }

.kb-related__body { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; flex: 1; }
.kb-related__name {
    font-weight: 500;
    color: var(--ink-1);
    line-height: 1.35;
    font-size: var(--step--1);
}
.kb-related__link:hover .kb-related__name { color: var(--brand); }
.kb-related__meta {
    display: flex;
    gap: 0.5rem;
    font-size: 0.7rem;
    color: var(--ink-3);
    font-family: ui-monospace, monospace;
}

/* ---------- Admin graph browser ---------- */
.kb-graph-filters {
    display: flex;
    gap: 1rem;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.kb-graph-filters label { display: flex; flex-direction: column; gap: 0.25rem; font-size: var(--step--1); color: var(--ink-2); }
.kb-graph-filters select,
.kb-graph-filters input {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--surface);
    font-family: inherit;
    font-size: var(--step--1);
    min-width: 200px;
}
.kb-graph-page {
    border: 1px solid var(--line);
    border-radius: 6px;
    margin-bottom: 0.5rem;
    background: var(--surface);
}
.kb-graph-page summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.9rem;
    cursor: pointer;
    list-style: none;
}
.kb-graph-page summary::marker,
.kb-graph-page summary::-webkit-details-marker { display: none; }
.kb-graph-page summary::before {
    content: "▸";
    color: var(--ink-3);
    transition: transform 120ms ease;
    display: inline-block;
    width: 1em;
}
.kb-graph-page[open] summary::before { transform: rotate(90deg); }
.kb-graph-page__title { font-weight: 500; color: var(--ink-1); text-decoration: none; }
.kb-graph-page__title:hover { color: var(--brand); }
.kb-graph-page__meta { margin-left: auto; display: flex; gap: 0.75rem; font-size: var(--step--1); }
.kb-graph-page__related {
    list-style: none;
    padding: 0.5rem 1rem 0.75rem 3rem;
    margin: 0;
    border-top: 1px solid var(--line);
}
.kb-graph-page__related li {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    padding: 0.25rem 0;
    font-size: var(--step--1);
}
.kb-graph-score {
    font-family: ui-monospace, monospace;
    font-size: 0.75rem;
    color: var(--ink-3);
    width: 3.5rem;
    text-align: right;
}

/* ---------------------------------------------------------------- TAB Subject Index (chapter 137) */

.tab-index-intro {
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin: 1rem 0 1.5rem;
    font-size: 0.9375rem;
}
.tab-index-intro ul { margin: 0.5rem 0; padding-left: 1.25rem; }
.tab-index-intro li { margin: 0.15rem 0; }
.tab-index-download {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-1);
    font-size: 0.9375rem;
}
.tab-index-download a {
    display: inline-block;
    background: var(--brand-teal, #0f766e);
    color: #fff;
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
}
.tab-index-download a:hover { filter: brightness(1.1); }

.tab-index-jumpnav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface-1);
    border: 1px solid var(--border-1);
    border-radius: 6px;
    margin-bottom: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 5;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.875rem;
}
.tab-index-jumpnav a {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    text-decoration: none;
    color: var(--ink-1);
    background: transparent;
}
.tab-index-jumpnav a:hover {
    background: var(--brand-teal, #0f766e);
    color: #fff;
}

.tab-index-letter {
    font-size: 1.5rem;
    color: var(--brand-teal, #0f766e);
    border-bottom: 2px solid var(--brand-teal, #0f766e);
    padding-bottom: 0.25rem;
    margin: 2rem 0 0.75rem;
}

.tab-index-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.tab-index-entry {
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border-1);
    border-radius: 6px;
    background: var(--surface-1);
    font-size: 0.9375rem;
}
.tab-index-entry__term {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 0.35rem;
}
.tab-index-entry__link {
    font-weight: 600;
    font-size: 1rem;
    text-decoration: none;
    color: var(--brand-teal, #0f766e);
}
.tab-index-entry__link:hover { text-decoration: underline; }
.tab-index-entry__nolink {
    font-weight: 600;
    font-size: 1rem;
    color: var(--ink-3);
}
.tab-index-entry__pages {
    font-size: 0.8125rem;
    color: var(--ink-3);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.tab-index-entry__type {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.75rem;
    color: var(--ink-3);
    text-transform: uppercase;
    padding: 0.05rem 0.35rem;
    border: 1px solid var(--border-1);
    border-radius: 3px;
    margin-right: 0.35rem;
}
.tab-index-entry__snip {
    color: var(--ink-2);
    line-height: 1.5;
}
.tab-index-entry__snip a {
    color: var(--ink-1);
    text-decoration: none;
    font-weight: 500;
}
.tab-index-entry__snip a:hover { text-decoration: underline; }
.tab-index-entry__snip--empty { color: var(--ink-3); font-style: italic; }
.tab-index-entry__all {
    margin-top: 0.35rem;
    font-size: 0.8125rem;
}
.tab-index-entry__all a {
    color: var(--brand-teal, #0f766e);
    text-decoration: none;
}
.tab-index-entry__all a:hover { text-decoration: underline; }
.tab-index-entry__fb {
    color: var(--ink-3);
    font-size: 0.75rem;
    margin-left: 0.5rem;
}
.tab-index-entry__fb code {
    background: var(--surface-2);
    padding: 0.05rem 0.3rem;
    border-radius: 3px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.7rem;
}

/* --- Technical note / document article extensions --- */
.kb-doc-subtitle { font-size: var(--step-1); color: var(--text-2); margin: 0 0 1.5rem; line-height: 1.5; }
.kb-doc-figure { margin: 1.5rem 0 2rem; }
.kb-doc-figure img { display: block; max-width: 100%; height: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); background: #fff; margin: 0 auto; }
.kb-doc-figure figcaption { font-size: var(--step-00); color: var(--text-2); margin-top: 0.5rem; text-align: center; font-style: italic; }
.kb-doc-glossary { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 1rem 0 0.5rem; padding: 1rem 1.25rem; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--line); }
.kb-doc-glossary dt { font-weight: 700; color: var(--text-1); font-family: var(--font-mono, ui-monospace, monospace); }
.kb-doc-glossary dd { margin: 0; color: var(--text-1); }
.kb-doc-glossary-note { font-size: var(--step-00); color: var(--text-2); margin: 0.25rem 0 1.5rem; }
.kb-doc-rules, .kb-doc-procedure { padding-left: 1.25rem; }
.kb-doc-rules li, .kb-doc-procedure li { margin: 0.5rem 0; }
.kb-doc-refs li { margin: 0.3rem 0; }
.kb-doc-signoff { font-size: var(--step-00); color: var(--text-2); border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 2rem; }

/* --- TAB subject index appendix (BM Global glossary) --- */
.tab-index-appendix { margin-top: 3rem; }
.tab-index-appendix-note { font-size: var(--step-0); color: var(--ink-2); background: var(--bg-tint); border-left: 3px solid var(--brand); padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin: 0.5rem 0 1rem; }

.tab-index-appendix-downloads { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; margin: 0 0 1.5rem; padding: 0.75rem 1rem; background: var(--bg-tint); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.tab-index-appendix-downloads__label { font-size: var(--step--1); color: var(--ink-2); font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }
.tab-index-appendix-downloads__link { font-size: var(--step-0); font-weight: 500; color: var(--brand); text-decoration: none; padding: 0.35rem 0.7rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); transition: background 0.15s, border-color 0.15s; }
.tab-index-appendix-downloads__link:hover { background: var(--bg-alt); border-color: var(--brand); }
