/* === Greg TOC v1.2.0 — Cruip dark theme native === */
/*
 * Couleurs auto-adaptatives via var(--accent) défini par chaque thème :
 *   untelephone → indigo #6366F1  |  dgedl → teal #4ECDC4
 * Animation grid-template-rows (1fr → 0fr) — native, pas de valeur
 * arbitraire, s'adapte au contenu. Chrome 107+, Firefox 96+, Safari 17+.
 * Stagger fade-out des <li> via transition-delay (collapse uniquement).
 */

.greg-toc-wrapper {
    max-width: 860px;
    margin: 0 auto 2rem auto;
}

/* Container — glass morphism (matching Cruip header style) */
.greg-toc {
    background: linear-gradient(135deg, #0F172A, #1E293B);
    border: 1px solid rgba(55, 65, 81, 0.6);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Clickable header — toggle collapse */
.greg-toc-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    padding: 0.125rem 0;
    outline: none;
}
.greg-toc-header:focus-visible {
    border-radius: 6px;
    box-shadow: 0 0 0 2px var(--accent, #818CF8);
}

/* Chevron icon — accent color, rotates on collapse */
.greg-toc-icon {
    font-size: 1.1rem;
    color: var(--accent, #818CF8);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1;
    flex-shrink: 0;
}
/* Hover scale only when expanded (fix: no conflict with collapsed rotate) */
.greg-toc:not(.collapsed) .greg-toc-header:hover .greg-toc-icon {
    transform: scale(1.15);
}
.greg-toc.collapsed .greg-toc-icon {
    transform: rotate(-90deg) scale(0.85);
}

/* Title — Space Grotesk uppercase */
.greg-toc-title {
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-weight: 700;
    font-size: 0.9375rem;
    color: #E5E7EB;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Collapsed state — grid collapses to zero height */
.greg-toc.collapsed .greg-toc-list {
    grid-template-rows: 0fr;
    opacity: 0;
    margin-top: 0;
    padding-top: 0;
    border-top-color: transparent;
}

/* Grid container — expand/collapse animation */
.greg-toc-list {
    display: grid;
    grid-template-rows: 1fr;
    opacity: 1;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(55, 65, 81, 0.5);
    transition: grid-template-rows 0.45s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                margin-top 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                padding-top 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                border-top-color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.greg-toc-list-inner {
    overflow: hidden;
    min-height: 0;
}

/* Numbered list — auto-counter */
.greg-toc-list ol {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: toc-counter;
}
.greg-toc-list li {
    counter-increment: toc-counter;
    margin-bottom: 0.4rem;
    line-height: 1.45;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
/* Staggered collapse: items fade/slide out with increasing delay */
.greg-toc.collapsed .greg-toc-list li {
    opacity: 0;
    transform: translateY(-4px);
}
.greg-toc.collapsed .greg-toc-list li:nth-child(1) { transition-delay: 0.00s; }
.greg-toc.collapsed .greg-toc-list li:nth-child(2) { transition-delay: 0.03s; }
.greg-toc.collapsed .greg-toc-list li:nth-child(3) { transition-delay: 0.06s; }
.greg-toc.collapsed .greg-toc-list li:nth-child(4) { transition-delay: 0.09s; }
.greg-toc.collapsed .greg-toc-list li:nth-child(5) { transition-delay: 0.12s; }
.greg-toc.collapsed .greg-toc-list li:nth-child(6) { transition-delay: 0.15s; }
.greg-toc.collapsed .greg-toc-list li:nth-child(7) { transition-delay: 0.18s; }
.greg-toc.collapsed .greg-toc-list li:nth-child(8) { transition-delay: 0.21s; }

/* Numbered prefix (gray, tabular-nums for alignment) */
.greg-toc-list li::before {
    content: counter(toc-counter) ".";
    color: #6B7280;
    font-size: 0.85rem;
    margin-right: 0.5rem;
    font-variant-numeric: tabular-nums;
}

/* Links — accent color + animated underline on hover/focus */
.greg-toc-list a {
    position: relative;
    color: var(--accent, #818CF8);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    transition: color 0.2s ease;
}
.greg-toc-list a::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 0;
    height: 1.5px;
    background: var(--accent, #818CF8);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.greg-toc-list a:hover::after,
.greg-toc-list a:focus::after {
    width: 100%;
}
.greg-toc-list a:focus {
    outline: none;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .greg-toc-wrapper {
        max-width: 100%;
        margin: 0 1rem 1.5rem 1rem;
    }
    .greg-toc {
        border-radius: 10px;
        padding: 1rem 1.125rem;
    }
    .greg-toc-title {
        font-size: 0.875rem;
    }
    .greg-toc-list a {
        font-size: 0.875rem;
    }
}

/* ===== Reduced motion — accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    .greg-toc-icon,
    .greg-toc-list,
    .greg-toc-list li,
    .greg-toc-list a,
    .greg-toc-list a::after {
        transition: none;
    }
    .greg-toc.collapsed .greg-toc-list li {
        opacity: 0;
        transform: none;
    }
}