/**
 * Table of Contents Styles
 * Visual melhorado com scroll spy e animações
 */

/* Card do TOC */
.toc-card {
    border: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
}

[data-theme="dark"] .toc-card {
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Header do TOC */
.toc-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.25rem 1.5rem;
    border-bottom: none;
    position: relative;
}

[data-theme="dark"] .toc-header {
    background: linear-gradient(135deg, #5568d3 0%, #5e3a7d 100%);
}

/* Badge de contagem */
.toc-count-badge {
    position: absolute;
    top: 50%;
    right: 1.5rem;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.25);
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.3);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Ícone do TOC */
.toc-icon {
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    backdrop-filter: blur(10px);
}

.toc-icon i {
    color: white;
}

/* Título do TOC */
.toc-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: white;
}

.toc-header small {
    color: rgba(255,255,255,0.8);
    font-size: 0.85rem;
}

/* Body do TOC */
.toc-body {
    padding: 1rem 1.5rem;
    max-height: 400px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #667eea #f1f3f5;
}

[data-theme="dark"] .toc-body {
    scrollbar-color: #5568d3 #2d2d2d;
}

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

.toc-body::-webkit-scrollbar-track {
    background: #f1f3f5;
    border-radius: 10px;
}

[data-theme="dark"] .toc-body::-webkit-scrollbar-track {
    background: #2d2d2d;
}

.toc-body::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

.toc-body::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

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

/* Item do TOC */
.toc-item {
    margin: 0.5rem 0;
    position: relative;
    transition: all 0.2s ease;
}

/* Níveis de indentação */
.toc-level-1 {
    padding-left: 0;
}

.toc-level-2 {
    padding-left: 1rem;
}

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

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

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

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

/* Link do TOC */
.toc-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #495057;
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
}

[data-theme="dark"] .toc-link {
    color: #adb5bd;
}

/* Indicador de nível (H1, H2, etc) */
.toc-level-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 20px;
    background: #e9ecef;
    color: #6c757d;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 4px;
    padding: 0 0.3rem;
    flex-shrink: 0;
}

[data-theme="dark"] .toc-level-indicator {
    background: #495057;
    color: #adb5bd;
}

.toc-link:hover {
    background: #f8f9fa;
    color: #667eea;
    border-left-color: #667eea;
    padding-left: 1rem;
    transform: translateX(4px);
}

[data-theme="dark"] .toc-link:hover {
    background: #2d2d2d;
    color: #9c8dd6;
    border-left-color: #9c8dd6;
}

.toc-link:hover .toc-level-indicator {
    background: #667eea;
    color: white;
}

[data-theme="dark"] .toc-link:hover .toc-level-indicator {
    background: #9c8dd6;
    color: #1a1d23;
}

/* Link ativo (scroll spy) */
.toc-link.active {
    background: linear-gradient(135deg, rgba(102,126,234,0.1) 0%, rgba(118,75,162,0.1) 100%);
    color: #667eea;
    font-weight: 600;
    border-left: 3px solid #667eea;
    padding-left: 1rem;
    box-shadow: 0 2px 4px rgba(102,126,234,0.2);
}

[data-theme="dark"] .toc-link.active {
    background: linear-gradient(135deg, rgba(102,126,234,0.15) 0%, rgba(118,75,162,0.15) 100%);
    color: #9c8dd6;
    border-left-color: #9c8dd6;
    box-shadow: 0 2px 4px rgba(156,141,214,0.3);
}

.toc-link.active .toc-level-indicator {
    background: #667eea;
    color: white;
    font-weight: 700;
    transform: scale(1.05);
}

[data-theme="dark"] .toc-link.active .toc-level-indicator {
    background: #9c8dd6;
    color: #1a1d23;
}

.toc-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 100%;
    background: linear-gradient(to bottom, #667eea, #764ba2);
    border-radius: 0 2px 2px 0;
}

[data-theme="dark"] .toc-link.active::before {
    background: linear-gradient(to bottom, #9c8dd6, #8b6db3);
}

/* Animação de pulso no link ativo */
@keyframes toc-pulse {
    0%, 100% {
        box-shadow: 0 2px 4px rgba(102,126,234,0.2);
    }
    50% {
        box-shadow: 0 2px 8px rgba(102,126,234,0.4);
    }
}

.toc-link.active {
    animation: toc-pulse 2s ease-in-out infinite;
}

/* TOC Sticky (fixa no scroll) */
.toc-sticky {
    position: sticky;
    top: 20px;
    z-index: 100;
    animation: toc-stick 0.3s ease-out;
}

@keyframes toc-stick {
    from {
        transform: translateY(-10px);
        opacity: 0.8;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Badge de contagem */
.toc-header::after {
    content: attr(data-count);
    position: absolute;
    top: 1.25rem;
    right: 1.5rem;
    background: rgba(255,255,255,0.3);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

/* Efeito de gradient animado no header */
@keyframes gradient-flow {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.toc-header {
    background-size: 200% 200%;
    animation: gradient-flow 6s ease infinite;
}

/* Responsividade */
@media (max-width: 991px) {
    .toc-card {
        margin-bottom: 2rem;
    }
    
    .toc-sticky {
        position: relative;
        top: 0;
    }
}

@media (max-width: 576px) {
    .toc-header {
        padding: 1rem;
    }
    
    .toc-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
        margin-right: 0.75rem !important;
    }
    
    .toc-title {
        font-size: 1rem;
    }
    
    .toc-header small {
        font-size: 0.75rem;
    }
    
    .toc-body {
        padding: 0.75rem 1rem;
        max-height: 300px;
    }
    
    .toc-link {
        font-size: 0.9rem;
        padding: 0.4rem 0.6rem;
    }
    
    /* Reduzir indentação em mobile */
    .toc-level-2 { padding-left: 0.75rem; }
    .toc-level-3 { padding-left: 1.5rem; }
    .toc-level-4 { padding-left: 2.25rem; }
    .toc-level-5 { padding-left: 3rem; }
    .toc-level-6 { padding-left: 3.75rem; }
}

/* Indicador de progresso (opcional) */
.toc-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(to right, #667eea, #764ba2);
    transition: width 0.3s ease;
    border-radius: 0 0 12px 12px;
}

/* Estado vazio */
.toc-empty {
    text-align: center;
    color: #6c757d;
    padding: 2rem;
    font-style: italic;
}

[data-theme="dark"] .toc-empty {
    color: #adb5bd;
}

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

/* Efeito hover no card inteiro */
.toc-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

[data-theme="dark"] .toc-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* Separador visual entre níveis */
.toc-level-1 + .toc-level-1 {
    margin-top: 1rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e9ecef;
}

[data-theme="dark"] .toc-level-1 + .toc-level-1 {
    border-top-color: #495057;
}

/* Animação de entrada */
@keyframes toc-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toc-item {
    animation: toc-fade-in 0.3s ease-out;
    animation-fill-mode: both;
}

.toc-item:nth-child(1) { animation-delay: 0.05s; }
.toc-item:nth-child(2) { animation-delay: 0.1s; }
.toc-item:nth-child(3) { animation-delay: 0.15s; }
.toc-item:nth-child(4) { animation-delay: 0.2s; }
.toc-item:nth-child(5) { animation-delay: 0.25s; }
.toc-item:nth-child(n+6) { animation-delay: 0.3s; }

/* Tooltip para links longos */
.toc-link[title] {
    position: relative;
}

.toc-link[title]:hover::after {
    content: attr(title);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #212529;
    color: white;
    font-size: 0.85rem;
    border-radius: 6px;
    white-space: nowrap;
    z-index: 1000;
    opacity: 0;
    animation: tooltip-fade-in 0.3s ease-out forwards;
}

@keyframes tooltip-fade-in {
    to {
        opacity: 1;
    }
}

/* Loading state */
.toc-loading {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
}

.toc-loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Print styles */
@media print {
    .toc-card {
        box-shadow: none;
        border: 1px solid #dee2e6;
        page-break-inside: avoid;
    }
    
    .toc-sticky {
        position: relative;
        top: 0;
    }
    
    .toc-link {
        color: #000 !important;
    }
    
    .toc-link.active {
        font-weight: bold;
        background: none;
    }
}

/* Highlight effect for headings when clicked from TOC */
.heading-highlight {
    animation: heading-flash 2s ease-out;
    scroll-margin-top: 100px;
}

@keyframes heading-flash {
    0%, 100% {
        background: transparent;
        box-shadow: none;
    }
    10%, 30% {
        background: rgba(102,126,234,0.15);
        box-shadow: 0 0 0 4px rgba(102,126,234,0.2);
        border-radius: 8px;
        padding: 0.25rem 0.5rem;
        margin-left: -0.5rem;
    }
}

[data-theme="dark"] .heading-highlight {
    animation: heading-flash-dark 2s ease-out;
}

@keyframes heading-flash-dark {
    0%, 100% {
        background: transparent;
        box-shadow: none;
    }
    10%, 30% {
        background: rgba(156,141,214,0.2);
        box-shadow: 0 0 0 4px rgba(156,141,214,0.25);
        border-radius: 8px;
        padding: 0.25rem 0.5rem;
        margin-left: -0.5rem;
    }
}

/* Smooth scroll for all headings */
.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4,
.article-content h5,
.article-content h6 {
    scroll-margin-top: 100px;
    transition: all 0.3s ease;
}
