/* ==========================================================================
   TABLE OF CONTENTS (TOC) STYLES
   Professional, collapsible navigation for blog articles
   ========================================================================== */

/* Container */
.toc-container {
    width: 100%;
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius-1, 8px);
    margin: 1.5rem 0 2rem 0;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Header */
.toc-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, var(--secondary-color-1, #2563eb) 0%, color-mix(in srgb, var(--secondary-color-1, #2563eb) 85%, #000) 100%);
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: filter 0.2s ease;
    text-align: left;
}

.toc-header:hover {
    filter: brightness(1.1);
}

.toc-header:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: -2px;
}

.toc-title {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.625rem;
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: -0.01em;
}

.toc-title {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: -0.01em;
}

.toc-icon {
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    opacity: 0.9;
}

.toc-toggle-main {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    transition: all 0.2s ease;
    color: #ffffff;
}

.toc-header:hover .toc-toggle-main {
    background: rgba(255, 255, 255, 0.25);
}

.toc-toggle-icon {
    width: 1rem;
    height: 1rem;
    transition: transform 0.3s ease;
}

.toc-header[aria-expanded="true"] .toc-toggle-icon {
    transform: rotate(0deg);
}

.toc-header[aria-expanded="false"] .toc-toggle-icon {
    transform: rotate(-90deg);
}

/* Content area */
.toc-content {
    padding: 0.75rem 0;
    max-height: 400px;
    overflow-y: auto;
    transition: max-height 0.35s ease, padding 0.35s ease, opacity 0.25s ease;
    opacity: 1;
}

.toc-content.toc-main-collapsed {
    max-height: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
}

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

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

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

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

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

.toc-sublist {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    max-height: 1000px;
    transition: max-height 0.35s ease, opacity 0.25s ease;
    opacity: 1;
}

.toc-sublist.toc-collapsed {
    max-height: 0;
    opacity: 0;
}

/* Items */
.toc-item {
    margin: 0;
}

.toc-item-wrapper {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0;
}

/* Level-based indentation */
.toc-level-2 > .toc-item-wrapper {
    padding-left: 1rem;
}

.toc-level-3 > .toc-item-wrapper {
    padding-left: 2rem;
}

.toc-level-4 > .toc-item-wrapper {
    padding-left: 3rem;
}

.toc-level-5 > .toc-item-wrapper {
    padding-left: 4rem;
}

.toc-level-6 > .toc-item-wrapper {
    padding-left: 5rem;
}

/* Toggle button (arrow) */
.toc-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    color: #64748b;
}

.toc-toggle:hover {
    background: #e2e8f0;
    color: var(--secondary-color-1, #2563eb);
}

.toc-toggle:focus {
    outline: 2px solid var(--secondary-color-1, #2563eb);
    outline-offset: 1px;
}

.toc-arrow {
    width: 0.875rem;
    height: 0.875rem;
    transition: transform 0.25s ease;
}

.toc-toggle[aria-expanded="true"] .toc-arrow {
    transform: rotate(90deg);
}

/* Links */
.toc-link {
    display: flex;
    align-items: center;
    flex: 1;
    padding: 0.5rem 0.75rem;
    text-decoration: none;
    color: #374151;
    border-radius: 6px;
    transition: all 0.2s ease;
    font-size: 0.9375rem;
    line-height: 1.4;
    margin-right: 0.75rem;
}

.toc-link:hover {
    background: #e2e8f0;
    color: var(--secondary-color-1, #2563eb);
}

.toc-link:focus {
    outline: 2px solid var(--secondary-color-1, #2563eb);
    outline-offset: 1px;
    background: #e2e8f0;
}

.toc-link:active {
    background: #cbd5e1;
}

.toc-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Level-specific text styles */
.toc-level-2 .toc-link {
    font-weight: 600;
    color: #1e293b;
}

.toc-level-3 .toc-link {
    font-weight: 500;
    font-size: 0.875rem;
    color: #475569;
}

.toc-level-4 .toc-link,
.toc-level-5 .toc-link,
.toc-level-6 .toc-link {
    font-weight: 400;
    font-size: 0.8125rem;
    color: #64748b;
}

/* Active state indicator */
.toc-link.active {
    background: color-mix(in srgb, var(--secondary-color-1, #2563eb) 10%, transparent);
    color: var(--secondary-color-1, #2563eb);
    font-weight: 600;
    position: relative;
}

.toc-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--secondary-color-1, #2563eb);
    border-radius: 0 2px 2px 0;
}

/* Empty state */
.toc-empty {
    padding: 1.5rem;
    text-align: center;
    color: #64748b;
    font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 768px) {
    .toc-container {
        margin: 1rem 0 1.5rem 0;
    }

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

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

    .toc-content {
        max-height: 300px;
    }

    .toc-level-2 > .toc-item-wrapper {
        padding-left: 0.75rem;
    }

    .toc-level-3 > .toc-item-wrapper {
        padding-left: 1.5rem;
    }

    .toc-level-4 > .toc-item-wrapper {
        padding-left: 2.25rem;
    }

    .toc-level-5 > .toc-item-wrapper {
        padding-left: 3rem;
    }

    .toc-level-6 > .toc-item-wrapper {
        padding-left: 3.75rem;
    }

    .toc-link {
        font-size: 0.875rem;
        padding: 0.4375rem 0.625rem;
    }

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

/* Print styles */
@media print {
    .toc-container {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }

    .toc-toggle,
    .toc-toggle-all {
        display: none;
    }

    .toc-sublist.toc-collapsed {
        max-height: none;
        opacity: 1;
    }

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