/* =================================================================
   TABLE OF CONTENTS (TOC) STYLES
   - Desktop: Sticky Sidebar (left side)
   - Tablet: Collapsible Sidebar
   - Mobile: Integrated in hamburger menu + Progress bar
   ================================================================= */

/* ==================== Desktop Sidebar TOC ==================== */
.toc-sidebar {
    position: fixed;
    top: 72px; /* Below sticky header (adjust based on actual header height) */
    left: 0;
    width: 280px;
    height: calc(100vh - 72px);
    background: white;
    border-right: 2px solid #e5e7eb;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    z-index: 40;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on touch devices */
}

/* Scrollbar styling for Webkit browsers (Chrome, Safari, Edge) */
.toc-sidebar::-webkit-scrollbar {
    width: 8px;
}

.toc-sidebar::-webkit-scrollbar-track {
    background: #f9fafb;
    border-radius: 4px;
}

.toc-sidebar::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.toc-sidebar::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Scrollbar styling for Firefox */
.toc-sidebar {
    scrollbar-width: thin;
    scrollbar-color: #d1d5db #f9fafb;
}

/* TOC Header */
.toc-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #10b981;
}

.toc-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* TOC List */
.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-item {
    margin-bottom: 0.5rem;
}

.toc-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    text-decoration: none;
    color: #4b5563;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    cursor: pointer;
}

.toc-link:hover {
    background-color: #f3f4f6;
    color: #1f2937;
    transform: translateX(4px);
}

.toc-link.active {
    background-color: #ecfdf5;
    color: #059669;
    border-left-color: #10b981;
    font-weight: 600;
}

/* TOC Item Icon */
.toc-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

/* TOC Item Content */
.toc-content {
    flex: 1;
}

.toc-item-title {
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.3;
}

/* ==================== Tablet Collapsible Sidebar ==================== */
@media (max-width: 1023px) and (min-width: 768px) {
    .toc-sidebar {
        width: 240px;
        height: calc(100vh - 72px);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        transform: translateX(-100%);
    }
    
    .toc-sidebar.open {
        transform: translateX(0);
    }
    
    /* Scrollbar for tablet */
    .toc-sidebar::-webkit-scrollbar {
        width: 6px;
    }
    
    .toc-sidebar::-webkit-scrollbar-track {
        background: #f9fafb;
    }
    
    .toc-sidebar::-webkit-scrollbar-thumb {
        background: #d1d5db;
        border-radius: 3px;
    }
    
    .toc-toggle-btn {
        position: fixed;
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        background: #10b981;
        color: white;
        border: none;
        border-radius: 0 0.5rem 0.5rem 0;
        padding: 1rem 0.5rem;
        cursor: pointer;
        z-index: 41;
        box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
        transition: all 0.3s ease;
    }
    
    .toc-toggle-btn:hover {
        background: #059669;
        padding-right: 0.75rem;
    }
    
    .toc-toggle-btn.open {
        left: 240px;
    }
}

/* ==================== Mobile Progress Bar ==================== */
@media (max-width: 767px) {
    /* Hide desktop sidebar */
    .toc-sidebar {
        display: none;
    }
    
    /* Mobile TOC in Hamburger Menu */
    .mobile-toc-section {
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 2px solid #e5e7eb;
    }
    
    .mobile-toc-header {
        font-size: 0.875rem;
        font-weight: 700;
        color: #6b7280;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 0.75rem;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    .mobile-toc-list {
        list-style: none;
        padding: 0;
        margin: 0;
    }
    
    .mobile-toc-item {
        margin-bottom: 0.25rem;
    }
    
    .mobile-toc-link {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.75rem;
        border-radius: 0.5rem;
        text-decoration: none;
        color: #4b5563;
        transition: all 0.2s ease;
        min-height: 44px; /* Touch-friendly */
    }
    
    .mobile-toc-link:hover,
    .mobile-toc-link:active {
        background-color: #f3f4f6;
    }
    
    .mobile-toc-link.active {
        background-color: #ecfdf5;
        color: #059669;
        font-weight: 600;
    }
    
    .mobile-toc-icon {
        font-size: 1.25rem;
        flex-shrink: 0;
    }
    
    .mobile-toc-text {
        flex: 1;
        font-size: 0.875rem;
    }
}

/* ==================== Content Offset (for sidebar) ==================== */
@media (min-width: 1024px) {
    /* Add padding to body when TOC exists to prevent content overlap */
    body.has-toc {
        padding-left: 280px;
    }
    
    body.has-toc .container {
        max-width: 100%;
    }
}



/* ==================== Smooth Scroll Behavior ==================== */
html {
    scroll-behavior: smooth;
}

/* ==================== Accessibility ==================== */
.toc-link:focus,
.mobile-toc-link:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .toc-sidebar {
        border-right-width: 3px;
    }
    
    .toc-link.active {
        border-left-width: 5px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .toc-sidebar,
    .toc-link,
    .toc-toggle-btn {
        transition: none;
    }
    
    html {
        scroll-behavior: auto;
    }
}
