/* ============================================================
   Floating TOC — lives in the reserved right gutter
   Width (--toc-width 220px) and right offset must match
   the padding-right set in custom-theme.css.
   ============================================================ */

.floating-toc {
    position: fixed;
    top: 80px;
    right: 20px;
    width: 200px;
    max-height: calc(100vh - 100px);
    background: transparent;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    z-index: 900;
    overflow: visible;
}

.floating-toc.collapsed {
    width: 32px;
    height: 32px;
    overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────── */
.floating-toc-header {
    background: transparent;
    padding: 0 0 6px 0;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #bbbbbb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    margin-bottom: 4px;
    border-bottom: 1px solid #e4e4e4;
}

.floating-toc-title { color: #aaaaaa; }

.floating-toc-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    color: #aaaaaa;
    display: flex;
    align-items: center;
    border-radius: 2px;
    transition: color 0.12s;
}
.floating-toc-toggle:hover { color: #555555; }
.floating-toc-toggle svg { width: 12px; height: 12px; }

/* ── Content ─────────────────────────────────────────────── */
.floating-toc-content {
    max-height: calc(100vh - 145px);
    overflow-y: auto;
    padding: 2px 0 0 0;
}

.floating-toc ul { list-style: none; margin: 0; padding: 0; }
.floating-toc li { margin: 0; padding: 0; }

/* ── Links ───────────────────────────────────────────────── */
.floating-toc a {
    display: block;
    padding: 2px 4px;
    margin: 0;
    color: #888888;
    text-decoration: none;
    border-left: 2px solid transparent;
    font-size: 14px;
    line-height: 1.5;
    font-weight: 400;
    transition: color 0.12s, border-color 0.12s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.floating-toc a:hover {
    color: #0055d4;
    border-left-color: #0055d4;
    text-decoration: none;
    background: none;
}

.floating-toc a.active {
    color: #0055d4;
    font-weight: 600;
    border-left-color: #0055d4;
}

/* ── Nesting ─────────────────────────────────────────────── */
.floating-toc ul ul a         { padding-left: 14px; font-size: 13px; color: #bbbbbb; }
.floating-toc ul ul ul a      { padding-left: 26px; font-size: 12px; color: #cccccc; }
.floating-toc ul ul ul ul a   { padding-left: 38px; font-size: 12px; color: #d8d8d8; }

/* ── Scrollbar ───────────────────────────────────────────── */
.floating-toc-content::-webkit-scrollbar       { width: 3px; }
.floating-toc-content::-webkit-scrollbar-track { background: transparent; }
.floating-toc-content::-webkit-scrollbar-thumb { background: #dddddd; border-radius: 2px; }

/* ── Collapsed button ────────────────────────────────────── */
.floating-toc.collapsed .floating-toc-header {
    padding: 7px;
    background: #0055d4;
    color: white;
    justify-content: center;
    width: 32px;
    height: 32px;
    box-sizing: border-box;
    border-radius: 3px;
    border-bottom: none;
}
.floating-toc.collapsed .floating-toc-content { display: none; }
.floating-toc.collapsed .floating-toc-title   { display: none; }
.floating-toc.collapsed .floating-toc-toggle  { color: white; padding: 0; background: none; }
.floating-toc.collapsed .floating-toc-toggle .hamburger-icon { display: none; }
.floating-toc.collapsed .floating-toc-toggle .toc-icon       { display: block !important; }
.floating-toc.collapsed .floating-toc-toggle:hover { background: rgba(255,255,255,0.15); }

/* ── Responsive ─────────────────────────────────────────── */

/* At ≤1200px the CSS gutter is removed, so TOC becomes a floating panel */
@media (max-width: 1200px) {
    .floating-toc:not(.collapsed) {
        background: #ffffff;
        border: 1px solid #e4e4e4;
        border-radius: 3px;
        padding: 10px 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        width: min(220px, calc(100vw - 24px));
        right: 12px;
        top: 72px;
        max-height: calc(100vh - 88px);
        overflow: hidden;
    }

    .floating-toc:not(.collapsed) .floating-toc-content {
        max-height: calc(100vh - 160px);
    }

    .floating-toc.collapsed {
        right: 12px;
        top: 12px;
    }
}

@media (max-width: 768px) {
    .floating-toc:not(.collapsed) {
        width: min(200px, calc(100vw - 20px)) !important;
        right: 10px !important;
        top: 60px !important;
    }
    .floating-toc.collapsed {
        right: 10px !important;
        top: 10px !important;
    }
}
