/**
 * Floating sommaire - minimal, discreet table of contents
 * for composant and peripherique pages.
 */

.floating-sommaire {
    position: fixed;
    /* À gauche du contenu central (container 1170px) sur grands écrans */
    left: max(24px, calc(50% - 585px - 240px));
    top: 100px;
    z-index: 9998;
    font-size: 12px;
    line-height: 1.4;
    max-width: 220px;
    background: transparent;
    border: none;
    border-radius: 6px;
    padding: 10px 12px;
    box-shadow: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
}

.floating-sommaire.floating-sommaire-visible {
    opacity: 1;
    visibility: visible;
}

/* Fond uniquement quand le menu recouvre le contenu ET est ouvert (pas compact) */
.floating-sommaire.floating-sommaire-visible.floating-sommaire-overlaps:not(.floating-sommaire-compact) {
    background: rgba(30, 30, 30, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* Masqué pendant la mesure de chevauchement (évite le flash au chargement) */
.floating-sommaire.floating-sommaire-measuring {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none;
}

.floating-sommaire:hover {
    opacity: 1;
}

/* Mode réduit : icône seule (desktop) - bouton discret mais identifiable */
.floating-sommaire.floating-sommaire-compact {
    padding: 0;
    max-width: none;
    background: transparent;
    border: none;
    box-shadow: none;
    left: max(24px, calc(50% - 585px - 55px));
}

.floating-sommaire.floating-sommaire-compact .floating-sommaire-content {
    display: none;
}

.floating-sommaire.floating-sommaire-compact .floating-sommaire-icon-btn {
    display: flex;
}

.floating-sommaire-icon-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: #2a2a2a;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    color: var(--color-accent);
    cursor: pointer;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.floating-sommaire-icon-btn:hover {
    color: var(--color-accent-light);
    background: #333;
    border-color: var(--color-accent-30);
}

.floating-sommaire-icon-btn svg {
    width: 18px;
    height: 18px;
    display: block;
}

.floating-sommaire-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 6px 10px 4px;
    margin-bottom: 4px;
    border-radius: 15px 15px 0 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    transition: background 0.2s;
}

.floating-sommaire-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.floating-sommaire-collapse {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: #999;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    transition: color 0.2s, background 0.2s;
}

.floating-sommaire-collapse:hover {
    color: var(--color-accent);
    background: rgba(255, 255, 255, 0.05);
}

.floating-sommaire-content {
    padding-right: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.floating-sommaire-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex: 1;
    min-width: 0;
}

.floating-sommaire-title-icon {
    display: flex;
    color: var(--color-accent);
}

.floating-sommaire-title-icon svg {
    width: 14px;
    height: 14px;
}

.floating-sommaire-toggle {
    display: none;
    width: 100%;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    color: #f5f5f5;
    font-size: 11px;
    cursor: pointer;
    text-align: left;
}

.floating-sommaire-list {
    list-style: none;
    margin: 0;
    padding: 0;
    padding-right: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(100vh - 200px);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) rgba(255, 255, 255, 0.05);
}

.floating-sommaire-list::-webkit-scrollbar {
    width: 6px;
}

.floating-sommaire-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.floating-sommaire-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.floating-sommaire-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.floating-sommaire-list > li {
    margin-bottom: 4px;
}

.floating-sommaire-list > li:last-child {
    margin-bottom: 0;
}

.floating-sommaire-h2 > a,
.floating-sommaire-h3 > a {
    display: block;
    padding: 3px 0;
    color: #ccc;
    text-decoration: none;
    transition: color 0.15s ease;
}

.floating-sommaire-h2 > a {
    color: #f5f5f5;
    font-weight: 600;
    white-space: normal;
    word-wrap: break-word;
}

.floating-sommaire-h3 > a {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.floating-sommaire-h2 > a:hover,
.floating-sommaire-h3 > a:hover {
    color: var(--color-accent);
}

/* Scroll spy: item actif selon la section visible */
.floating-sommaire-h2 > a.floating-sommaire-active,
.floating-sommaire-h3 > a.floating-sommaire-active {
    color: var(--color-accent);
    font-weight: 600;
}

.floating-sommaire-h3 > a.floating-sommaire-active {
    font-weight: 500;
}

.floating-sommaire-sublist {
    list-style: none;
    margin: 2px 0 0 10px;
    padding: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.floating-sommaire-sublist li {
    margin-bottom: 2px;
}

.floating-sommaire-sublist a {
    padding-left: 8px;
}

/* En dessous de 1600px : version mobile (bouton, menu déroulant) - icône en position haute */
@media (max-width: 1600px) {
    .floating-sommaire {
        left: max(24px, calc(50% - 585px - 55px));
        max-width: none;
        padding: 0;
        background: transparent;
        border: none;
        box-shadow: none;
    }

    .floating-sommaire.floating-sommaire-open {
        background: #1e1e1e;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 8px;
        padding: 0 0 10px 0;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    }

    .floating-sommaire.floating-sommaire-compact .floating-sommaire-icon-btn {
        display: none;
    }

    .floating-sommaire.floating-sommaire-compact .floating-sommaire-content {
        display: block;
    }

    .floating-sommaire-header {
        display: none;
    }

    .floating-sommaire-title {
        display: none;
    }

    .floating-sommaire-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        padding: 0;
        min-width: 36px;
        font-size: 10px;
        background: #2a2a2a;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 50%;
        color: var(--color-accent);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    }

    .floating-sommaire-toggle:hover {
        background: #333;
        color: var(--color-accent-light);
    }

    .floating-sommaire-toggle-text {
        display: none;
    }

    .floating-sommaire-toggle-icon {
        display: flex;
    }

    .floating-sommaire-toggle-icon svg {
        width: 16px;
        height: 16px;
    }

    .floating-sommaire-collapse {
        display: none;
    }

    .floating-sommaire-content {
        padding-right: 0;
    }

    .floating-sommaire-list {
        display: none;
        margin-top: 0;
        padding: 10px 12px 0;
        max-height: 320px;
        overflow-y: auto;
        font-size: 11px;
    }

    .floating-sommaire-open .floating-sommaire-list {
        display: block;
    }

    .floating-sommaire-open .floating-sommaire-toggle {
        border-radius: 8px 8px 0 0;
        width: 100%;
        min-width: 100%;
        padding: 6px 10px;
    }

    .floating-sommaire-open .floating-sommaire-toggle {
        background: transparent;
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 8px 8px 0 0;
        box-shadow: none;
        padding: 8px 12px;
        justify-content: flex-start;
        gap: 8px;
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: rgba(255, 255, 255, 0.9);
    }

    .floating-sommaire-open .floating-sommaire-toggle-text {
        display: inline;
    }

    .floating-sommaire-open .floating-sommaire-toggle-icon {
        display: flex;
    }

    .floating-sommaire-open .floating-sommaire-toggle-icon {
        color: var(--color-accent);
    }

    .floating-sommaire-open .floating-sommaire-toggle-icon svg {
        width: 14px;
        height: 14px;
    }
}

/* En dessous de 768px : icône en bas à droite */
@media (max-width: 768px) {
    .floating-sommaire {
        left: auto;
        right: 12px;
        bottom: 12px;
        top: auto;
    }
}
