/* ==========================================================================
   Table of Contents Styles - Fixed
   ========================================================================== */

.table-of-contents {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    margin: 2rem 0;
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
}

.theme-dark .table-of-contents {
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Sticky positioning - fixed for no flicker */
.table-of-contents.toc-sticky {
    position: fixed;
    top: 80px;
    right: 2rem;
    width: 360px;
    max-height: calc(100vh - 120px);
    z-index: 30;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    /* Prevent flickering */
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
}

.theme-dark .table-of-contents.toc-sticky {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #1F5FBD 0%, #174A94 100%);
    color: white;
    border: none;
}

/* Ensure TOC title is white in both light and dark modes */
.toc-title,
.theme-light .toc-title,
.theme-dark .toc-title {
    color: white !important;
}

.theme-dark .toc-header {
    background: linear-gradient(135deg, #174A94 0%, #06474a 100%);
}

.toc-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Override post-content h3 styles for TOC in sticky mode */
.table-of-contents.toc-sticky .toc-title {
    margin: 0 !important;
    font-size: 0.875rem !important;
}

.toc-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toc-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.toc-toggle-icon {
    transition: transform 0.2s ease;
}

.table-of-contents.toc-expanded .toc-toggle-icon {
    transform: rotate(180deg);
}

.toc-nav {
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem;
    transition: all 0.3s ease;
    background: #ffffff;
}

.theme-dark .toc-nav {
    background: #1a1a1a;
}

.table-of-contents:not(.toc-expanded) .toc-nav {
    max-height: 0;
    padding: 0 1rem;
    overflow: hidden;
}

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

.toc-sublist {
    list-style: none;
    margin: 0.25rem 0;
    padding-left: 1.25rem;
    border-left: 2px solid var(--color-border);
}

.theme-dark .toc-sublist {
    border-left-color: rgba(255, 255, 255, 0.1);
}

.toc-item {
    margin: 0.25rem 0;
}

.toc-link {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    color: var(--color-base-600);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.theme-dark .toc-link {
    color: rgba(255, 255, 255, 0.7);
}

.toc-link:hover {
    background: rgba(31, 95, 189, 0.1);
    color: var(--color-primary);
    transform: translateX(4px);
}

.theme-dark .toc-link:hover {
    background: rgba(31, 95, 189, 0.15);
    color: var(--color-primary-light);
}

.toc-link.active {
    background: linear-gradient(135deg, #1F5FBD 0%, #174A94 100%);
    color: white;
    font-weight: 500;
}

.toc-text {
    flex: 1;
    font-size: 0.8125rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Level-specific styling */
.toc-level-1 .toc-link {
    font-weight: 600;
    font-size: 0.875rem;
}

.toc-level-2 .toc-link {
    font-weight: 500;
}

.toc-level-3 .toc-link,
.toc-level-4 .toc-link,
.toc-level-5 .toc-link,
.toc-level-6 .toc-link {
    font-size: 0.75rem;
    opacity: 0.9;
}

/* Hide on screens that are too small for sticky */
@media (max-width: 1400px) {
    .table-of-contents.toc-sticky {
        display: none;
    }
}

/* Mobile responsive */
@media (max-width: 1200px) {
    .table-of-contents {
        position: static !important;
        width: auto !important;
        max-height: none !important;
        box-shadow: none !important;
        margin: 2rem 0;
    }
    
    .table-of-contents.toc-sticky {
        display: block;
    }
}

@media (max-width: 768px) {
    .table-of-contents {
        margin: 1.5rem 0;
    }
    
    .toc-header {
        padding: 0.875rem 1rem;
    }
    
    .toc-nav {
        padding: 0.75rem;
    }
    
    .toc-sublist {
        padding-left: 1rem;
    }
    
    .toc-link {
        padding: 0.375rem 0.5rem;
    }
}

/* Print styles */
@media print {
    .table-of-contents {
        display: none;
    }
}

/* Focus states */
.toc-link:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

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

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

.toc-nav::-webkit-scrollbar-thumb {
    background: rgba(31, 95, 189, 0.3);
    border-radius: 2px;
}

.toc-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(31, 95, 189, 0.5);
}

/* Dark theme scrollbar */
.theme-dark .toc-nav::-webkit-scrollbar-thumb {
    background: rgba(31, 95, 189, 0.4);
}

.theme-dark .toc-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(31, 95, 189, 0.6);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .table-of-contents,
    .toc-nav,
    .toc-link,
    .toc-toggle-icon {
        transition: none !important;
    }
    
    .table-of-contents.toc-sticky {
        animation: none !important;
    }
}

/* Remove progress bars that were causing issues */
.toc-progress {
    display: none;
}