/* TOC Sidebar */
.toc-sidebar {
    width: 280px;
    min-width: 280px;
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border);
    padding: 2rem 1.5rem;
    overflow-y: auto;
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
}

.toc-header {
    margin-left: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.toc-toggle {
    display: none;
}

.toc-list {
    list-style: none;
}

.toc-item {
    margin-bottom: 0.25rem;
    position: relative;
    border-radius: 4px;
    transition: background 0.3s;
}

.toc-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        #ff0080, 
        #ff8c00, 
        #40e0d0, 
        #9b59b6,
        #ff0080
    );
    background-size: 200% 100%;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 0;
}

.toc-item:hover::before {
    opacity: 0.2;
    animation: rainbow-flow 2s linear infinite;
}

@keyframes rainbow-flow {
    0% {
        background-position: 200% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Make sure the link appears above the rainbow background */
.toc-item .toc-link {
    position: relative;
    z-index: 1;
}

.toc-link {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 0.9rem;
    line-height: 1.4;
    cursor: pointer;
}

.toc-link:hover {
    /* background-color: var(--bg-card); */
    color: var(--text-primary);
}

.toc-link.active {
    /* background-color: var(--accent); */
    color: #ffffff;
}

/* Indent levels */
.toc-link[data-level="1"] {
    padding-left: 0.75rem;
    font-weight: 600;
}

.toc-link[data-level="2"] {
    padding-left: 0.75rem;
    font-weight: 500;
}

.toc-link[data-level="3"] {
    padding-left: 1.5rem;
}

.toc-link[data-level="4"] {
    padding-left: 2.25rem;
    font-size: 0.85rem;
}

/* Adjust main content to make room for TOC */
.main-content {
    margin-right: 280px;
}

/* Mobile styles */
@media (max-width: 1024px) {
    .main-content {
        margin-right: 0;
    }

    .toc-sidebar {
        position: fixed;
        right: -280px;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transition: right 0.3s;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
    }

    .toc-sidebar.active {
        right: 0;
    }

    .toc-toggle {
        display: block;
        position: fixed;
        bottom: 2rem;
        right: 2rem;
        z-index: 999;
        background-color: var(--bg-secondary);
        border: none;
        color: #ffffff;
        border-radius: 50%;
        width: 56px;
        height: 56px;
        font-size: 1.5rem;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .toc-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .toc-overlay.active {
        display: block;
    }
}