/* Table of Contents Sidebar Styles */

/* ===============================================
   TOC Overlay Design (No Layout Disruption)
   =============================================== */

/* TOC as overlay - does not affect existing layout */
.toc-sidebar {
    position: fixed;
    top: 60px; /* Below navigation */
    left: -320px; /* Hidden by default */
    bottom: 0;
    width: 320px;
    height: calc(100vh - 60px);
    z-index: 1001; /* Match old working version */
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    visibility: visible; /* Always visible for proper animations */
    opacity: 1; /* Always opaque for proper animations */
}

.toc-sidebar.toc-open {
    left: 0 !important; /* Slide in from left with !important */
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
}

/* ===============================================
   TOC Sidebar Structure
   =============================================== */

.toc-header {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.toc-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toc-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    line-height: 1;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toc-close-btn:hover {
    background: rgba(var(--primary-color-rgb), 0.1);
    color: var(--primary-color);
    transform: scale(1.1);
}

.toc-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.toc-footer {
    padding: var(--spacing-sm) var(--spacing-md);
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.toc-count {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ===============================================
   TOC List Items
   =============================================== */

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

.toc-item {
    padding: 12px var(--spacing-md);
    border-bottom: 1px solid rgba(var(--primary-color-rgb), 0.05);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    background: var(--bg-primary);
}

.toc-item:hover {
    background: rgba(var(--primary-color-rgb), 0.08);
    border-left: 3px solid rgba(var(--primary-color-rgb), 0.3);
}

.toc-item.active {
    background: rgba(var(--primary-color-rgb), 0.12);
    border-left: 3px solid var(--primary-color);
    font-weight: 500;
}

.toc-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary-color);
    box-shadow: 0 0 8px rgba(var(--primary-color-rgb), 0.4);
}

/* Header level styling */
.toc-item[data-level="1"] {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.toc-item[data-level="2"] {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-primary);
    padding-left: calc(var(--spacing-md) + 1rem);
}

.toc-item[data-level="3"] {
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding-left: calc(var(--spacing-md) + 2rem);
}

.toc-item[data-level="4"] {
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding-left: calc(var(--spacing-md) + 3rem);
}

.toc-item-icon {
    font-size: 0.9rem;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.toc-item-text {
    flex: 1;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ===============================================
   TOC Toggle Button
   =============================================== */

.toc-toggle-btn {
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

.toc-toggle-btn:hover {
    background: var(--primary-hover) !important;
    color: white !important;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.toc-toggle-btn:active {
    transform: translateY(0);
}

.toc-toggle-btn i {
    font-style: normal;
}

.toc-toggle-text {
    font-size: 0.85rem;
    font-weight: 500;
}

/* ===============================================
   TOC Scrollbar Styling
   =============================================== */

.toc-content::-webkit-scrollbar {
    width: 6px;
}

.toc-content::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.toc-content::-webkit-scrollbar-thumb {
    background: rgba(var(--primary-color-rgb), 0.3);
    border-radius: 3px;
}

.toc-content::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--primary-color-rgb), 0.5);
}

/* ===============================================
   TOC Empty State
   =============================================== */

.toc-empty {
    padding: var(--spacing-md);
    text-align: center;
    color: var(--text-muted);
}

.toc-empty-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.toc-empty-text {
    font-size: 0.9rem;
    line-height: 1.4;
}

/* ===============================================
   TOC Loading State
   =============================================== */

.toc-loading {
    padding: var(--spacing-md);
    text-align: center;
    color: var(--text-muted);
}

.toc-loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(var(--primary-color-rgb), 0.3);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 0.5rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===============================================
   TOC Dark Theme Support
   =============================================== */

[data-theme="dark"] .toc-sidebar {
    background: var(--bg-primary) !important;
    border-right-color: var(--border-color);
}

[data-theme="dark"] .toc-header {
    background: var(--bg-secondary);
    border-bottom-color: var(--border-color);
}

[data-theme="dark"] .toc-header h3 {
    color: var(--text-primary);
}

[data-theme="dark"] .toc-footer {
    background: var(--bg-secondary);
    border-top-color: var(--border-color);
}

[data-theme="dark"] .toc-count {
    color: var(--text-muted);
}

[data-theme="dark"] .toc-item {
    background: var(--bg-primary);
    color: var(--text-primary);
}

[data-theme="dark"] .toc-item:hover {
    background: rgba(var(--primary-color-rgb), 0.15);
}

[data-theme="dark"] .toc-item.active {
    background: rgba(var(--primary-color-rgb), 0.2);
}

[data-theme="dark"] .toc-close-btn {
    color: var(--text-muted);
}

[data-theme="dark"] .toc-close-btn:hover {
    background: rgba(var(--primary-color-rgb), 0.2);
    color: var(--primary-color);
}

/* ===============================================
   TOC Responsive Design
   =============================================== */

@media (max-width: 1024px) {
    .main-container.toc-open {
        margin-left: 0; /* Prevent layout shift */
    }
    
    .toc-item {
        padding: 10px var(--spacing-sm);
    }
    
    .toc-header {
        padding: var(--spacing-sm);
    }
}

@media (max-width: 768px) {
    .toc-sidebar {
        width: 280px !important;
        left: -280px !important;
    }
    
    .toc-toggle-btn {
        padding: 0.4rem 0.6rem;
    }
    
    .toc-toggle-text {
        display: none; /* Hide text on mobile */
    }
}

@media (max-width: 480px) {
    .toc-sidebar.mobile-overlay {
        width: 100vw !important;
        left: -100vw !important;
    }
    
    .toc-item {
        padding: 12px var(--spacing-sm);
    }
    
    .toc-item[data-level="2"] {
        padding-left: calc(var(--spacing-sm) + 0.5rem);
    }
    
    .toc-item[data-level="3"] {
        padding-left: calc(var(--spacing-sm) + 1rem);
    }
    
    .toc-item[data-level="4"] {
        padding-left: calc(var(--spacing-sm) + 1.5rem);
    }
}

/* ===============================================
   TOC Animations
   =============================================== */

.toc-item-enter {
    animation: tocItemEnter 0.3s ease-out;
}

@keyframes tocItemEnter {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toc-highlight-pulse {
    animation: tocHighlightPulse 0.6s ease-in-out;
}

@keyframes tocHighlightPulse {
    0%, 100% {
        background: rgba(var(--primary-color-rgb), 0.12);
    }
    50% {
        background: rgba(var(--primary-color-rgb), 0.25);
    }
}

.toc-flash {
    animation: tocFlash 1s ease-in-out;
}

@keyframes tocFlash {
    0%, 100% {
        background: var(--bg-primary);
    }
    25%, 75% {
        background: rgba(var(--primary-color-rgb), 0.15);
    }
    50% {
        background: rgba(var(--primary-color-rgb), 0.25);
    }
}

/* ===============================================
   TOC Accessibility
   =============================================== */

.toc-item:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    background: rgba(var(--primary-color-rgb), 0.1);
}

.toc-close-btn:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.toc-toggle-btn:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ===============================================
   TOC Reduced Motion Support
   =============================================== */

@media (prefers-reduced-motion: reduce) {
    .toc-sidebar,
    .toc-item,
    .toc-toggle-btn,
    .toc-close-btn {
        transition: none;
    }
    
    .toc-item-enter,
    .toc-highlight-pulse,
    .toc-flash {
        animation: none;
    }
    
    .main-container {
        transition: none;
    }
}

/* Removed conflicting TOC styles - using main .toc-sidebar class instead */ 