/**
 * Table of Contents - Sticky Sidebar Styles
 * 
 * Positioned in left viewport margin, follows scroll,
 * uses theme CSS variables for colors.
 */

.toc-sidebar {
    position: fixed;
    left: 20px;
    top: 120px;
    width: 200px;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
    z-index: 100;

    /* Subtle background */
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--theme_rounded, 12px);
    padding: 1.2em;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.toc-title {
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #999;
    margin-bottom: 1em;
    padding-bottom: 0.5em;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

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

.toc-item {
    margin: 0;
    padding: 0;
}

.toc-link {
    display: block;
    padding: 0.4em 0 0.4em 0.8em;
    font-size: 0.85em;
    line-height: 1.4;
    color: #666;
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all 0.2s ease-in-out;
}

.toc-link:hover {
    color: var(--theme_accent, #ed1e24);
    border-left-color: var(--theme_accent, #ed1e24);
}

.toc-link.active {
    color: var(--theme_accent, #ed1e24);
    border-left-color: var(--theme_accent, #ed1e24);
    font-weight: 600;
}

/* H3 items are indented */
.toc-h3 .toc-link {
    padding-left: 1.4em;
    font-size: 0.8em;
}

/* Scrollbar styling */
.toc-sidebar::-webkit-scrollbar {
    width: 4px;
}

.toc-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.toc-sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
}

/* ==========================================
   Responsive: Hide when margin disappears
   ========================================== */

/* Calculate when left margin is too small:
   Viewport < pagewidth (1160px) + TOC width (200px) + margins (40px) × 2 = ~1440px */

@media (max-width: 1440px) {
    .toc-sidebar {
        display: none;
    }
}

/* Dark mode support */
.tf_darkmode .toc-sidebar {
    background: rgba(30, 30, 30, 0.95);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.tf_darkmode .toc-title {
    color: #888;
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.tf_darkmode .toc-link {
    color: #aaa;
}

.tf_darkmode .toc-link:hover,
.tf_darkmode .toc-link.active {
    color: var(--theme_accent, #ed1e24);
}