/* Universal TOC Component */

/* ==================== WIDE LAYOUT (>=1200px): Left Pane ==================== */

.universal-toc {
    display: none;
}

@media (min-width: 1200px) {
    body.toc-active .universal-toc {
        display: block;
        position: fixed;
        left: 0;
        top: 48px;
        width: 260px;
        height: calc(100vh - 48px);
        background: var(--brand-nav-bg);
        border-right: 1px solid var(--brand-border);
        z-index: 100;
        overflow-y: auto;
        padding: 16px 0;
        scrollbar-width: thin;
        scrollbar-color: var(--brand-scrollbar) transparent;
    }

    body.toc-active .universal-toc::-webkit-scrollbar {
        width: 4px;
    }
    body.toc-active .universal-toc::-webkit-scrollbar-track {
        background: transparent;
    }
    body.toc-active .universal-toc::-webkit-scrollbar-thumb {
        background: var(--brand-scrollbar);
        border-radius: 2px;
    }

    /* Push main content right */
    body.toc-wide {
        padding-left: 260px !important;
    }

    /* Collapse toggle */
    .toc-collapse-btn {
        position: absolute;
        top: 8px;
        right: 8px;
        background: rgba(255,255,255,0.06);
        border: none;
        color: var(--brand-muted);
        font-size: 0.75rem;
        cursor: pointer;
        padding: 4px 8px;
        border-radius: 4px;
        transition: all 0.2s;
        z-index: 2;
        font-family: var(--font-ui);
    }
    .toc-collapse-btn:hover {
        background: rgba(255,255,255,0.12);
        color: #fff;
    }

    body.toc-collapsed .universal-toc {
        width: 0;
        padding: 0;
        overflow: hidden;
        border-right: none;
    }
    body.toc-collapsed.toc-wide {
        padding-left: 0 !important;
    }
    .toc-expand-btn {
        display: none;
        position: fixed;
        left: 0;
        top: 48px;
        height: calc(100vh - 48px);
        background: var(--brand-nav-bg);
        border: none;
        border-right: 1px solid var(--brand-border);
        border-radius: 0;
        color: var(--brand-muted);
        font-size: 0.85rem;
        cursor: pointer;
        padding: 0 5px;
        z-index: 101;
        transition: all 0.2s;
        width: 20px;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0;
    }
    .toc-expand-btn:hover {
        background: rgba(var(--brand-accent-rgb), 0.08);
    }
    body.toc-collapsed .toc-expand-btn {
        display: flex;
    }
    body.toc-collapsed.toc-wide {
        padding-left: 20px !important;
    }

    /* Mini progress dots inside expand button */
    .toc-mini-dot {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: rgba(255,255,255,0.12);
        margin: 3px 0;
        transition: all 0.3s;
        flex-shrink: 0;
    }
    .toc-mini-dot.active {
        background: var(--brand-accent);
        box-shadow: 0 0 6px rgba(var(--brand-accent-rgb), 0.5);
    }
    .toc-mini-dot.passed {
        background: rgba(var(--brand-accent-rgb), 0.45);
    }
}

/* TOC heading */
.toc-heading {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--brand-muted);
    padding: 0 16px 10px;
    margin: 0;
    font-weight: 600;
    font-family: var(--font-ui);
}

/* TOC list */
.toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc-list li {
    margin: 0;
}

.toc-list a {
    display: block;
    padding: 8px 16px;
    font-size: 0.82rem;
    color: var(--brand-muted);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.2s;
    line-height: 1.4;
    font-family: var(--font-ui);
}

.toc-list a:hover {
    color: var(--brand-text);
    background: rgba(255,255,255,0.03);
}

.toc-list a.active {
    color: var(--brand-accent);
    border-left-color: var(--brand-accent);
    background: rgba(var(--brand-accent-rgb), 0.06);
    font-weight: 500;
}

/* ==================== NARROW LAYOUT (<1200px): Bottom Sheet ==================== */

@media (max-width: 1199px) {
    body.toc-active .universal-toc {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--brand-nav-bg);
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--brand-border);
        z-index: 1999;
        overflow: hidden;
        max-height: 45vh;
    }

    .toc-heading {
        display: none;
    }

    .toc-collapse-btn,
    .toc-expand-btn {
        display: none !important;
    }

    .toc-list {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: var(--brand-scrollbar) transparent;
        padding: 6px 0;
    }

    .toc-list::-webkit-scrollbar {
        width: 3px;
    }
    .toc-list::-webkit-scrollbar-track {
        background: transparent;
    }
    .toc-list::-webkit-scrollbar-thumb {
        background: var(--brand-scrollbar);
        border-radius: 2px;
    }

    .toc-list li {
        flex-shrink: 0;
    }

    .toc-list a {
        display: block;
        padding: 8px 16px;
        font-size: 0.8rem;
        color: var(--brand-muted);
        text-decoration: none;
        border-left: 3px solid transparent;
        transition: all 0.2s;
        line-height: 1.35;
    }

    .toc-list a:hover {
        color: var(--brand-text);
        background: rgba(255,255,255,0.04);
    }

    .toc-list a.active {
        color: var(--brand-accent);
        border-left-color: var(--brand-accent);
        background: rgba(var(--brand-accent-rgb), 0.08);
        font-weight: 500;
    }

    /* Bottom sheet padding on body to avoid content overlap */
    body.toc-active {
        padding-bottom: var(--toc-bottom-height, 200px) !important;
    }
}

/* Short/mobile screens: limit visible items */
@media (max-width: 1199px) and (max-height: 700px) {
    body.toc-active .universal-toc {
        max-height: 30vh;
    }
}

@media (max-width: 1199px) and (max-height: 500px) {
    body.toc-active .universal-toc {
        max-height: 25vh;
    }
}

/* ==================== Light Mode ==================== */

[data-theme="light"] .universal-toc {
    background: var(--brand-nav-bg) !important;
    border-right-color: var(--brand-border) !important;
    border-top-color: var(--brand-border) !important;
}

[data-theme="light"] .toc-heading {
    color: var(--brand-muted);
}

[data-theme="light"] .toc-list a {
    color: var(--brand-muted);
}

[data-theme="light"] .toc-list a:hover {
    color: #333;
    background: rgba(0,0,0,0.03);
}

[data-theme="light"] .toc-list a.active {
    color: var(--brand-accent);
    border-left-color: var(--brand-accent);
    background: rgba(var(--brand-accent-rgb), 0.06);
}

[data-theme="light"] .toc-collapse-btn {
    background: rgba(0,0,0,0.05);
    color: var(--brand-muted);
}
[data-theme="light"] .toc-collapse-btn:hover {
    background: rgba(0,0,0,0.1);
    color: #333;
}
[data-theme="light"] .toc-expand-btn {
    background: var(--brand-nav-bg);
    border-right-color: var(--brand-border);
    color: var(--brand-muted);
}
[data-theme="light"] .toc-expand-btn:hover {
    background: rgba(var(--brand-accent-rgb), 0.04);
}
[data-theme="light"] .toc-mini-dot {
    background: rgba(0,0,0,0.1);
}
[data-theme="light"] .toc-mini-dot.active {
    background: var(--brand-accent);
    box-shadow: 0 0 6px rgba(var(--brand-accent-rgb), 0.3);
}
[data-theme="light"] .toc-mini-dot.passed {
    background: rgba(var(--brand-accent-rgb), 0.35);
}

[data-theme="light"] .universal-toc::-webkit-scrollbar-thumb {
    background: var(--brand-scrollbar);
}
