:root {
    --toc-bg: #FEFCF9;
    --toc-border: #f8e5d2;
    --toc-line: #FEFCF9;
    --toc-text-size: 15px;
    --toc-sticky-top: 32px;
}

.toc-sidebar-widget {
    font-size: var(--toc-text-size);
    line-height: 1.5;
    background: var(--toc-bg);
    border: 1.5px solid var(--toc-border);
    border-radius: 10px;
    padding: 18px 20px;
    box-sizing: border-box;
}

/* Botón título / acordeón */
.toc-sidebar-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    font: inherit;
    color: inherit;
    text-align: left;
}

.toc-sidebar-title {
    font-family: 'EB Garamond', serif;
    font-weight: 600;
    font-size: 1.25em;
    letter-spacing: 0.01em;
}

.toc-sidebar-chevron {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    border-right: 2px solid #b98a5e;
    border-bottom: 2px solid #b98a5e;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    margin-top: -4px;
}

/* Lista de enlaces */
.toc-sidebar-list {
    list-style: none;
    margin: 14px 0 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

.toc-sidebar-list li {
    margin: 0;
    padding: 8px 0;
    border-top: 1px solid var(--toc-line);
}

.toc-sidebar-list li:first-child {
    border-top: none;
    padding-top: 0;
}

.toc-sidebar-list a {
    font-family: 'Inter', sans-serif;
    font-size: var(--toc-text-size);
    text-decoration: none;
    color: #3a2f28;
    display: block;
}

.toc-sidebar-list a:hover {
    text-decoration: underline;
}

/* Sangría para subniveles (h3 dentro de h2) */
.toc-sidebar-list li.toc-level-3 {
    padding-left: 14px;
    font-size: 0.95em;
    opacity: 0.9;
}

/* Elemento activo mientras se hace scroll (controlado por script.js) */
.toc-sidebar-list li.toc-active > a {
    font-weight: 600;
    color: #b45f2e;
}

/* --- Desktop: sticky con altura máxima y scroll interno --- */
@media (min-width: 783px) {
    .toc-sidebar-widget {
        position: sticky;
        top: var(--toc-sticky-top);
        max-height: calc(100vh - var(--toc-sticky-top) - 40px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .toc-sidebar-list {
        overflow-y: auto;
    }

    .toc-sidebar-list::-webkit-scrollbar {
        width: 6px;
    }
    .toc-sidebar-list::-webkit-scrollbar-thumb {
        background: var(--toc-border);
        border-radius: 6px;
    }
}

/*
 * --- Móvil: colapsado por defecto, 100% vía CSS ---
 * Esto NO depende de que el JS cargue a tiempo: si por cualquier
 * motivo el script.js no se ejecuta, el índice igual aparece
 * colapsado en pantallas angostas.
 */
@media (max-width: 782px) {
    .toc-sidebar-list {
        max-height: 0;
        margin-top: 0;
        overflow: hidden;
    }
    .toc-sidebar-chevron {
        transform: rotate(-135deg);
        margin-top: 4px;
    }
}

/*
 * --- Overrides explícitos aplicados por el clic del usuario ---
 * data-toc-state lo controla script.js y manda sobre el estado
 * por defecto de cualquier ancho de pantalla.
 */
.toc-sidebar-widget[data-toc-state="open"] .toc-sidebar-list {
    max-height: 2000px !important;
    margin-top: 14px !important;
    overflow-y: auto;
}
.toc-sidebar-widget[data-toc-state="open"] .toc-sidebar-chevron {
    transform: rotate(45deg) !important;
    margin-top: -4px !important;
}
.toc-sidebar-widget[data-toc-state="closed"] .toc-sidebar-list {
    max-height: 0 !important;
    margin-top: 0 !important;
    overflow: hidden;
}
.toc-sidebar-widget[data-toc-state="closed"] .toc-sidebar-chevron {
    transform: rotate(-135deg) !important;
    margin-top: 4px !important;
}
