/**
 * Table of Contents Styles for News Articles
 */

/* TOC Container */
#article-toc {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    position: relative;
    transition: all 0.3s ease;
}

#article-toc.toc-generated {
    display: block !important;
}

/* TOC Header */
.toc-header {
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.toc-header h6 {
    color: #212529;
    font-size: 1rem;
}

.toc-toggle {
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.toc-toggle:hover {
    opacity: 0.7;
}

/* TOC Content */
.toc-content {
    overflow: hidden;
    transition: max-height 0.3s ease;
    max-height: 1000px;
}

.toc-content.collapsed {
    max-height: 0 !important;
    margin: 0;
}

/* TOC List */
.toc-list {
    margin: 0;
    padding: 0;
}

.toc-item {
    margin-bottom: 0.5rem;
}

.toc-level-2 {
    font-weight: 500;
}

.toc-level-3 {
    font-size: 0.9rem;
}

.toc-sublist {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

/* TOC Links */
.toc-link {
    color: #495057;
    text-decoration: none;
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    width: 100%;
}

.toc-link:hover {
    color: #0d6efd;
    background: rgba(13, 110, 253, 0.1);
    border-left-color: #0d6efd;
    padding-left: 0.75rem;
}

.toc-link.active {
    color: #0d6efd;
    background: rgba(13, 110, 253, 0.15);
    border-left-color: #0d6efd;
    font-weight: 600;
}

/* Heading Anchors */
.heading-anchor {
    opacity: 0;
    transition: opacity 0.2s ease;
    text-decoration: none;
    font-size: 0.8em;
}

h2:hover .heading-anchor,
h3:hover .heading-anchor {
    opacity: 1;
}

.heading-anchor:hover {
    color: #0d6efd !important;
}

/* Sticky TOC (Desktop) */
@media (min-width: 992px) {
    .toc-sticky-wrapper {
        position: sticky;
        top: 100px;
        max-height: calc(100vh - 120px);
        overflow-y: auto;
    }

    #article-toc {
        margin-bottom: 0;
    }

    /* Custom scrollbar for TOC */
    .toc-sticky-wrapper::-webkit-scrollbar {
        width: 6px;
    }

    .toc-sticky-wrapper::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }

    .toc-sticky-wrapper::-webkit-scrollbar-thumb {
        background: #888;
        border-radius: 3px;
    }

    .toc-sticky-wrapper::-webkit-scrollbar-thumb:hover {
        background: #555;
    }
}

/* Mobile Responsive */
@media (max-width: 991px) {
    #article-toc {
        margin-top: 1rem;
        margin-bottom: 1.5rem;
    }

    .toc-content {
        max-height: 400px;
        overflow-y: auto;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    #article-toc {
        background: #212529;
        border-color: #495057;
    }

    .toc-header {
        border-bottom-color: #495057;
    }

    .toc-header h6 {
        color: #f8f9fa;
    }

    .toc-link {
        color: #adb5bd;
    }

    .toc-link:hover {
        color: #0d6efd;
        background: rgba(13, 110, 253, 0.2);
    }

    .toc-link.active {
        color: #0d6efd;
        background: rgba(13, 110, 253, 0.25);
    }
}

/* Print Styles */
@media print {
    #article-toc {
        page-break-inside: avoid;
        border: 1px solid #000;
        padding: 1rem;
    }

    .toc-toggle {
        display: none;
    }

    .heading-anchor {
        display: none;
    }
}

/* Animation for TOC appearance */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#article-toc.toc-generated {
    animation: fadeInUp 0.3s ease-out;
}

/* Progress indicator (optional enhancement) */
.toc-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #0d6efd, #0dcaf0);
    z-index: 9999;
    transition: width 0.1s ease;
}

/* Highlight current section in article */
.article-content h2.toc-active,
.article-content h3.toc-active {
    position: relative;
}

.article-content h2.toc-active::before,
.article-content h3.toc-active::before {
    content: '';
    position: absolute;
    left: -1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 70%;
    background: #0d6efd;
    border-radius: 2px;
}

/* Compact mode for mobile */
@media (max-width: 576px) {
    #article-toc {
        padding: 1rem;
    }

    .toc-header h6 {
        font-size: 0.9rem;
    }

    .toc-link {
        font-size: 0.85rem;
        padding: 0.2rem 0.4rem;
    }

    .toc-level-3 {
        font-size: 0.8rem;
    }
}

