/**
 * Sumário Automático Pro - Estilos do Frontend
 * 
 * Estilização moderna e profissional para o sumário automático.
 * Usa variáveis CSS para permitir personalização dinâmica via admin.
 * 
 * @version 1.0.0
 */

/* ============================================
   RESET E VARIÁVEIS CSS PADRÃO
   ============================================ */
:root {
    --sap-cor-primaria: #6366f1;
    --sap-cor-secundaria: #8b5cf6;
    --sap-cor-fundo: #f8fafc;
    --sap-cor-texto: #334155;
    --sap-cor-link: #4f46e5;
    --sap-cor-link-hover: #6366f1;
    --sap-cor-borda: #e2e8f0;
    --sap-largura: 100%;
    --sap-tamanho-fonte: 14px;
    --sap-raio-borda: 12px;
}

/* ============================================
   CONTAINER PRINCIPAL DO SUMÁRIO
   ============================================ */
.sap-container {
    position: relative;
    width: var(--sap-largura);
    max-width: 100%;
    margin: 28px auto;
    padding: 0;
    background: var(--sap-cor-fundo);
    border: 1px solid var(--sap-cor-borda);
    border-radius: var(--sap-raio-borda);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: var(--sap-tamanho-fonte);
    color: var(--sap-cor-texto);
    line-height: 1.6;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.04),
        0 4px 12px rgba(0, 0, 0, 0.03);
    overflow: hidden;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

/* Efeito sutil ao passar o mouse no container */
.sap-container:hover {
    box-shadow: 
        0 2px 6px rgba(0, 0, 0, 0.06),
        0 8px 24px rgba(0, 0, 0, 0.06);
}

/* Decoração superior com gradiente */
.sap-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--sap-cor-primaria), var(--sap-cor-secundaria));
    border-radius: var(--sap-raio-borda) var(--sap-raio-borda) 0 0;
}

/* ============================================
   CABEÇALHO DO SUMÁRIO
   ============================================ */
.sap-cabecalho {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: transparent;
    cursor: default;
    user-select: none;
}

.sap-titulo-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Ícone do sumário no cabeçalho */
.sap-icone-sumario {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--sap-cor-primaria), var(--sap-cor-secundaria));
    color: #ffffff;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.sap-icone-sumario svg {
    width: 18px;
    height: 18px;
}

/* Título do sumário */
.sap-titulo {
    font-size: 16px;
    font-weight: 700;
    color: var(--sap-cor-texto);
    letter-spacing: -0.01em;
}

/* Badge com contador de tópicos */
.sap-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--sap-cor-primaria);
    background: rgba(99, 102, 241, 0.08);
    border-radius: 20px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* ============================================
   BOTÃO DE TOGGLE (EXPANDIR/RECOLHER)
   ============================================ */
.sap-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    margin: 0;
    background: rgba(99, 102, 241, 0.06);
    border: 1px solid rgba(99, 102, 241, 0.12);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--sap-cor-primaria);
    flex-shrink: 0;
}

.sap-toggle:hover {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.2);
    transform: scale(1.05);
}

.sap-toggle:active {
    transform: scale(0.95);
}

/* Seta do toggle com rotação animada */
.sap-seta {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sap-toggle.sap-ativo .sap-seta {
    transform: rotate(0deg);
}

.sap-toggle:not(.sap-ativo) .sap-seta {
    transform: rotate(-90deg);
}

/* ============================================
   BARRA DE PROGRESSO DE LEITURA
   ============================================ */
.sap-progresso-container {
    width: 100%;
    height: 2px;
    background: rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.sap-progresso-barra {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--sap-cor-primaria), var(--sap-cor-secundaria));
    transition: width 0.3s ease-out;
    border-radius: 0 2px 2px 0;
}

/* ============================================
   CONTEÚDO/CORPO DO SUMÁRIO
   ============================================ */
.sap-conteudo {
    padding: 4px 20px 20px;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.3s ease,
                padding 0.3s ease;
}

/* ============================================
   LISTAS E ITENS DO SUMÁRIO
   ============================================ */
.sap-lista {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Numeração automática quando habilitada */
.sap-numerado .sap-lista {
    counter-reset: sap-contador;
}

.sap-numerado .sap-item {
    counter-increment: sap-contador;
}

.sap-numerado .sap-link::before {
    content: counters(sap-contador, ".") ". ";
    font-weight: 600;
    color: var(--sap-cor-primaria);
    margin-right: 6px;
    font-size: 0.9em;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    min-width: max-content;
    flex-shrink: 0;
}

.sap-numerado .sap-link:hover::before {
    opacity: 1;
}

/* Sub-listas aninhadas */
.sap-sublista {
    margin: 0;
    padding: 0 0 0 16px;
    list-style: none;
    border-left: 2px solid rgba(99, 102, 241, 0.1);
    margin-left: 10px;
    counter-reset: sap-contador;
}

/* Itens individuais do sumário */
.sap-item {
    position: relative;
    margin: 1px 0;
}

/* ============================================
   LINKS DOS ITENS
   ============================================ */
.sap-link {
    display: flex;
    align-items: baseline;
    padding: 7px 12px;
    color: var(--sap-cor-link);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    font-weight: 500;
    line-height: 1.5;
}

.sap-link:hover {
    color: var(--sap-cor-link-hover);
    background: rgba(99, 102, 241, 0.06);
    text-decoration: none;
    transform: translateX(3px);
}

.sap-link:active {
    transform: translateX(1px);
}

/* Indicador lateral ao passar o mouse */
.sap-link::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%) scaleY(0);
    width: 3px;
    height: 60%;
    background: linear-gradient(180deg, var(--sap-cor-primaria), var(--sap-cor-secundaria));
    border-radius: 3px;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sap-link:hover::after {
    transform: translateY(-50%) scaleY(1);
}

/* Item ativo (seção visível na tela) */
.sap-link.sap-link-ativo {
    color: var(--sap-cor-primaria);
    background: rgba(99, 102, 241, 0.08);
    font-weight: 600;
}

.sap-link.sap-link-ativo::after {
    transform: translateY(-50%) scaleY(1);
    background: var(--sap-cor-primaria);
}

/* Texto do link */
.sap-link-texto {
    flex: 1;
}

/* ============================================
   ESTILOS POR NÍVEL DE TÍTULO
   ============================================ */
.sap-nivel-1 > .sap-link { font-weight: 700; font-size: 1em; }
.sap-nivel-2 > .sap-link { font-weight: 600; font-size: 1em; }
.sap-nivel-3 > .sap-link { font-weight: 500; font-size: 0.95em; opacity: 0.9; }
.sap-nivel-4 > .sap-link { font-weight: 400; font-size: 0.9em; opacity: 0.85; }
.sap-nivel-5 > .sap-link { font-weight: 400; font-size: 0.85em; opacity: 0.8; }
.sap-nivel-6 > .sap-link { font-weight: 400; font-size: 0.8em; opacity: 0.75; }

/* Item ativo sempre com opacidade total, independente do nível */
.sap-nivel-3 > .sap-link.sap-link-ativo,
.sap-nivel-4 > .sap-link.sap-link-ativo,
.sap-nivel-5 > .sap-link.sap-link-ativo,
.sap-nivel-6 > .sap-link.sap-link-ativo {
    opacity: 1;
}

/* ============================================
   BOTÃO "VOLTAR AO SUMÁRIO" NOS TÍTULOS
   ============================================ */
.sap-titulo-ancora {
    position: relative;
    scroll-margin-top: 80px;
}

.sap-voltar-topo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    width: 24px;
    height: 24px;
    color: var(--sap-cor-primaria);
    opacity: 0;
    text-decoration: none;
    border-radius: 4px;
    background: rgba(99, 102, 241, 0.06);
    transition: all 0.25s ease;
    vertical-align: middle;
}

.sap-titulo-ancora:hover .sap-voltar-topo {
    opacity: 0.6;
}

.sap-voltar-topo:hover {
    opacity: 1 !important;
    background: rgba(99, 102, 241, 0.12);
    transform: translateY(-1px);
}

/* ============================================
   TEMA ESCURO
   ============================================ */
.sap-tema-escuro {
    --sap-cor-fundo: #1e293b;
    --sap-cor-texto: #e2e8f0;
    --sap-cor-link: #a5b4fc;
    --sap-cor-link-hover: #c7d2fe;
    --sap-cor-borda: #334155;
    background: #1e293b;
    color: #e2e8f0;
}

.sap-tema-escuro .sap-titulo {
    color: #f1f5f9;
}

.sap-tema-escuro .sap-badge {
    background: rgba(165, 180, 252, 0.12);
    color: #a5b4fc;
}

.sap-tema-escuro .sap-toggle {
    background: rgba(165, 180, 252, 0.08);
    border-color: rgba(165, 180, 252, 0.15);
    color: #a5b4fc;
}

.sap-tema-escuro .sap-toggle:hover {
    background: rgba(165, 180, 252, 0.15);
}

.sap-tema-escuro .sap-link:hover {
    background: rgba(165, 180, 252, 0.08);
}

.sap-tema-escuro .sap-link.sap-link-ativo {
    background: rgba(165, 180, 252, 0.1);
    color: #c7d2fe;
}

.sap-tema-escuro .sap-sublista {
    border-left-color: rgba(165, 180, 252, 0.15);
}

.sap-tema-escuro .sap-progresso-container {
    background: rgba(255, 255, 255, 0.06);
}

.sap-tema-escuro .sap-voltar-topo {
    color: #a5b4fc;
    background: rgba(165, 180, 252, 0.08);
}

/* ============================================
   TEMA CLARO MINIMALISTA
   ============================================ */
.sap-tema-claro {
    --sap-cor-fundo: #ffffff;
    --sap-cor-borda: #f1f5f9;
    border: 1px solid #f1f5f9;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
}

.sap-tema-claro::before {
    height: 2px;
    background: #e2e8f0;
}

.sap-tema-claro .sap-icone-sumario {
    background: #f1f5f9;
    color: var(--sap-cor-primaria);
    box-shadow: none;
}

/* ============================================
   TEMA MODERNO (GLASSMORPHISM SUTIL)
   ============================================ */
.sap-tema-moderno {
    background: rgba(248, 250, 252, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(226, 232, 240, 0.6);
}

/* ============================================
   ANIMAÇÃO DE ENTRADA
   ============================================ */
.sap-animado {
    animation: sapEntrada 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes sapEntrada {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Animação suave dos itens da lista */
.sap-animado .sap-item {
    animation: sapItemEntrada 0.3s ease forwards;
    opacity: 0;
}

.sap-animado .sap-item:nth-child(1)  { animation-delay: 0.05s; }
.sap-animado .sap-item:nth-child(2)  { animation-delay: 0.08s; }
.sap-animado .sap-item:nth-child(3)  { animation-delay: 0.11s; }
.sap-animado .sap-item:nth-child(4)  { animation-delay: 0.14s; }
.sap-animado .sap-item:nth-child(5)  { animation-delay: 0.17s; }
.sap-animado .sap-item:nth-child(6)  { animation-delay: 0.20s; }
.sap-animado .sap-item:nth-child(7)  { animation-delay: 0.23s; }
.sap-animado .sap-item:nth-child(8)  { animation-delay: 0.26s; }
.sap-animado .sap-item:nth-child(9)  { animation-delay: 0.29s; }
.sap-animado .sap-item:nth-child(10) { animation-delay: 0.32s; }
.sap-animado .sap-item:nth-child(n+11) { animation-delay: 0.35s; }

@keyframes sapItemEntrada {
    from {
        opacity: 0;
        transform: translateX(-8px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================
   RESPONSIVIDADE
   ============================================ */
@media (max-width: 768px) {
    .sap-container {
        margin: 20px 0;
        border-radius: 10px;
    }

    .sap-cabecalho {
        padding: 14px 16px;
    }

    .sap-conteudo {
        padding: 2px 16px 16px;
    }

    .sap-titulo {
        font-size: 14px;
    }

    .sap-badge {
        font-size: 10px;
        padding: 2px 8px;
    }

    .sap-icone-sumario {
        width: 32px;
        height: 32px;
    }

    .sap-icone-sumario svg {
        width: 16px;
        height: 16px;
    }

    .sap-link {
        padding: 6px 10px;
        font-size: 13px;
    }

    .sap-sublista {
        padding-left: 12px;
        margin-left: 6px;
    }
}

@media (max-width: 480px) {
    .sap-badge {
        display: none;
    }

    .sap-titulo-wrapper {
        gap: 8px;
    }

    .sap-link {
        padding: 5px 8px;
    }
}

/* ============================================
   ACESSIBILIDADE - FOCO VISÍVEL PARA TECLADO
   ============================================ */
.sap-link:focus-visible {
    outline: 2px solid var(--sap-cor-primaria);
    outline-offset: 2px;
    border-radius: 6px;
}

.sap-toggle:focus-visible {
    outline: 2px solid var(--sap-cor-primaria);
    outline-offset: 2px;
}

/* ============================================
   EFEITO DE DESTAQUE TEMPORÁRIO NOS TÍTULOS
   ============================================ */
.sap-titulo-destaque {
    animation: sapDestaque 2s ease forwards;
}

@keyframes sapDestaque {
    0%   { background-color: rgba(99, 102, 241, 0.15); border-radius: 6px; }
    70%  { background-color: rgba(99, 102, 241, 0.08); }
    100% { background-color: transparent; }
}

/* ============================================
   ACESSIBILIDADE - RESPEITAR PREFERÊNCIA DE MOVIMENTO REDUZIDO
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .sap-animado {
        animation: none;
    }

    .sap-animado .sap-item {
        animation: none;
        opacity: 1;
    }

    .sap-container,
    .sap-toggle,
    .sap-link,
    .sap-seta,
    .sap-progresso-barra {
        transition: none;
    }
}

/* ============================================
   IMPRESSÃO - OCULTAR ELEMENTOS INTERATIVOS
   ============================================ */
@media print {
    .sap-toggle,
    .sap-voltar-topo,
    .sap-progresso-container {
        display: none !important;
    }

    .sap-container {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .sap-conteudo {
        display: block !important;
    }

    .sap-link {
        color: #333 !important;
    }
}
