/**
 * Blog Table of Contents (TOC) Styles
 * Modern, responsive, and SEO-optimized design
 * Optimized for both desktop and mobile devices
 * 
 * @version 1.0.0
 * @author Ignis Trace Development Team
 */

/* ============================================
   TOC Container
   ============================================ */
.blog-toc {
    background: #ffffff;
    border: 1px solid #e8e8e8;
    border-left: 3px solid #ed2023 !important;
    border-radius: 4px;
    padding: 0;
    margin: 1.5rem 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.blog-toc:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* ============================================
   TOC Header
   ============================================ */
.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: #fafafa;
    border-bottom: 1px solid #e8e8e8;
    cursor: pointer;
    user-select: none;
    outline: none;
}

.toc-header:focus {
    outline: none;
}

.toc-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #333;
    letter-spacing: 0;
}

.toc-icon {
    width: 18px;
    height: 18px;
    color: #ed2023;
    stroke-width: 2;
    flex-shrink: 0;
}

.toc-toggle {
    background: transparent;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toc-toggle:hover {
    background: rgba(237, 32, 35, 0.08);
}

.toc-toggle:focus {
    outline: 1px solid #ed2023;
    outline-offset: 1px;
}

.toc-toggle-icon {
    width: 16px;
    height: 16px;
    color: #666;
    transition: transform 0.2s ease;
}

.blog-toc.toc-collapsed .toc-toggle-icon {
    transform: rotate(-90deg);
}

/* ============================================
   TOC Content
   ============================================ */
.toc-content {
    padding: 0.75rem 1rem;
    max-height: 500px;
    overflow-y: auto;
    transition: all 0.2s ease;
}

.blog-toc.toc-collapsed .toc-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
}

/* Custom scrollbar */
.toc-content::-webkit-scrollbar {
    width: 4px;
}

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

.toc-content::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 2px;
}

.toc-content::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

/* ============================================
   TOC Navigation
   ============================================ */
.toc-nav {
    position: relative;
}

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

.toc-item {
    margin: 0;
    padding: 0;
    position: relative;
}

/* ============================================
   TOC Links
   ============================================ */
.toc-link {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
    text-decoration: none;
    color: #555;
    border-radius: 3px;
    transition: all 0.15s ease;
    position: relative;
    line-height: 1.4;
    font-size: 0.875rem;
}

.toc-link:hover {
    background: #f5f5f5;
    color: #ed2023;
}

.toc-link.active {
    color: #ed2023;
    font-weight: 500;
}

.toc-link.active .toc-number {
    color: #ed2023;
    font-weight: 600;
}

/* ============================================
   TOC Numbers
   ============================================ */
.toc-number {
    color: #6c757d;
    font-weight: 500;
    font-size: 0.8rem;
    min-width: 2rem;
    flex-shrink: 0;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
}

.toc-text {
    flex: 1;
}

/* ============================================
   Hierarchical Structure (H2, H3, H4)
   ============================================ */

/* Level 2 (H2) - Main sections */
.toc-item-level-2 > .toc-link {
    font-weight: 500;
    font-size: 0.875rem;
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
}

.toc-item-level-2:not(:first-child) {
    margin-top: 0.25rem;
}

/* Level 3 (H3) - Subsections */
.toc-list-level-3 {
    margin-top: 0.15rem;
    margin-bottom: 0.15rem;
    padding-left: 1rem;
    border-left: 1px solid #e8e8e8;
    margin-left: 0.5rem;
}

.toc-item-level-3 > .toc-link {
    font-size: 0.825rem;
    font-weight: 400;
    padding-top: 0.3rem;
    padding-bottom: 0.3rem;
}

/* Level 4 (H4) - Sub-subsections */
.toc-list-level-4 {
    margin-top: 0.15rem;
    margin-bottom: 0.15rem;
    padding-left: 1rem;
    border-left: 1px solid #e8e8e8;
    margin-left: 0.5rem;
}

.toc-item-level-4 > .toc-link {
    font-size: 0.8rem;
    font-weight: 400;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    color: #666;
}

/* ============================================
   Mobile Responsive Styles
   ============================================ */
@media (max-width: 768px) {
    .blog-toc {
        margin: 1rem -15px;
        border-radius: 0;
        border-left: 3px solid #ed2023;
        border-right: none;
    }

    .toc-header {
        padding: 0.65rem 1rem;
    }

    .toc-title {
        font-size: 0.9rem;
    }

    .toc-icon {
        width: 16px;
        height: 16px;
    }

    .toc-content {
        padding: 0.65rem 1rem;
        max-height: 350px;
    }

    .toc-link {
        font-size: 0.825rem;
        padding: 0.3rem 0.4rem;
    }

    .toc-item-level-2 > .toc-link {
        font-size: 0.85rem;
    }

    .toc-item-level-3 > .toc-link {
        font-size: 0.8rem;
    }

    .toc-item-level-4 > .toc-link {
        font-size: 0.75rem;
    }

    .toc-list-level-3,
    .toc-list-level-4 {
        padding-left: 0.75rem;
    }

    .toc-number {
        min-width: 1.75rem;
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    .toc-header {
        padding: 0.6rem 0.875rem;
    }

    .toc-title {
        font-size: 0.875rem;
        gap: 0.4rem;
    }

    .toc-content {
        padding: 0.6rem 0.875rem;
        max-height: 280px;
    }

    .toc-link {
        gap: 0.4rem;
        font-size: 0.8rem;
    }

    .toc-number {
        min-width: 1.5rem;
        font-size: 0.7rem;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .blog-toc {
        border: 1px solid #000;
        box-shadow: none;
        page-break-inside: avoid;
        background: #fff;
    }

    .toc-toggle {
        display: none;
    }

    .toc-content {
        max-height: none !important;
        padding: 1rem !important;
    }

    .toc-link {
        color: #000 !important;
    }

    .toc-link:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* ============================================
   Accessibility Improvements
   ============================================ */
.blog-toc:focus-within {
    outline: none;
}

.toc-link:focus {
    outline: 2px solid #ed2023;
    outline-offset: -2px;
    background: rgba(237, 32, 35, 0.1);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .blog-toc {
        border-width: 3px;
    }

    .toc-link.active {
        border-left-width: 4px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .blog-toc,
    .toc-link,
    .toc-toggle-icon,
    .toc-content {
        transition: none;
    }
}

/* Dark mode support (if implemented) */
@media (prefers-color-scheme: dark) {
    .blog-toc {
        background: #ffffff;
        border-color: #e8e8e8;
    }

    .toc-header {
        background: #fafafa;
        border-bottom-color: #e8e8e8;
    }

    .toc-title {
        color: #333;
    }

    .toc-link {
        color: #555;
    }

    .toc-link:hover {
        background: #f5f5f5;
        color: #ed2023;
    }

    .toc-link.active {
        background: #fef5f5;
        color: #ed2023;
    }

    .toc-content::-webkit-scrollbar-thumb {
        background: #d0d0d0;
    }

    .toc-list-level-3 {
        border-left-color: #e8e8e8;
    }

    .toc-list-level-4 {
        border-left-color: #e8e8e8;
    }
}

/* ============================================
   Animation for initial load
   ============================================ */
@keyframes tocFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.blog-toc {
    animation: tocFadeIn 0.4s ease-out;
}

/* ============================================
   Special: Sticky TOC for desktop (optional)
   Uncomment if you want sticky behavior
   ============================================ */
/*
@media (min-width: 1200px) {
    .blog-toc {
        position: sticky;
        top: 100px;
        max-height: calc(100vh - 120px);
    }

    .toc-content {
        max-height: calc(100vh - 220px);
    }
}
*/
