/* Universal TOC - Right edge semi-circle button */
.toc-btn {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #1976d2 60%, #42a5f5 100%);
    color: #fff;
    border: none;
    border-radius: 50px 0 0 50px;
    width: 50px;
    height: 80px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: -4px 0 20px rgba(25, 118, 210, 0.15);
    z-index: 1000;
    transition: all 0.3s ease;
    padding-left: 8px;
}

.toc-btn:hover {
    width: 60px;
    box-shadow: -6px 0 28px rgba(25, 118, 210, 0.25);
    background: linear-gradient(135deg, #1565c0 60%, #64b5f6 100%);
}

/* TOC panel */
.toc-panel {
    position: fixed;
    top: 50%;
    right: -400px;
    transform: translateY(-50%);
    background: #fff;
    border: none;
    border-radius: 16px 0 0 16px;
    box-shadow: -8px 0 32px rgba(25, 118, 210, 0.12);
    width: 350px;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 999;
    transition: right 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.toc-panel.open {
    right: 0;
}

/* Dark theme support for TOC panel */
body.dark-theme .toc-panel {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--border-color);
}

/* TOC header */
.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid #e3f2fd;
    background: linear-gradient(90deg, #e3f2fd 80%, #bbdefb 100%);
    border-radius: 16px 16px 0 0;
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 0.02em;
}

/* Close button */
.toc-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    transition: color 0.2s;
}

.toc-close:hover {
    color: #1976d2;
}

/* TOC list */
.toc-panel ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-panel li {
    margin: 0;
}

/* TOC links */
.toc-link {
    display: block;
    padding: 12px 24px;
    color: #1976d2;
    text-decoration: none;
    border-bottom: 1px solid #f5f5f5;
    transition: all 0.3s ease;
    font-weight: 500;
}

.toc-link:hover,
.toc-link:focus {
    background: linear-gradient(90deg, #e3f2fd 80%, #bbdefb 100%);
    color: #1565c0;
    padding-left: 32px;
}

/* Active state for TOC links */
.toc-link.active {
    background: linear-gradient(90deg, #1976d2 0%, #42a5f5 100%);
    color: white;
    font-weight: 600;
    border-left: 4px solid #1565c0;
    transform: translateX(-4px);
}

/* Dark theme support for TOC elements */
body.dark-theme .toc-header {
    background: linear-gradient(90deg, rgba(25, 118, 210, 0.2) 80%, rgba(66, 165, 245, 0.2) 100%);
    border-bottom: 1px solid var(--border-subtle);
}

body.dark-theme .toc-link {
    color: #64b5f6;
    border-bottom: 1px solid var(--border-subtle);
}

body.dark-theme .toc-link:hover,
body.dark-theme .toc-link:focus {
    background: linear-gradient(90deg, rgba(227, 242, 253, 0.1) 80%, rgba(187, 222, 251, 0.1) 100%);
    color: #90caf9;
}

body.dark-theme .toc-link.active {
    background: linear-gradient(90deg, #1565c0 0%, #1976d2 100%);
    color: white;
    border-left: 4px solid #42a5f5;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .toc-panel {
        width: 300px;
        max-height: 70vh;
    }
    
    .toc-btn {
        height: 70px;
        width: 45px;
    }
    
    .toc-btn:hover {
        width: 55px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .toc-panel {
        width: calc(100vw - 50px);
        right: -100vw;
    }
    
    .toc-panel.open {
        right: 50px;
    }
}
