/**
 * CryptPeer — TOC flottant (desktop + mobile)
 * Desktop: checkbox/label | Mobile: :target (fermeture auto au clic sur un lien)
 * Adapté pour pages longues : toutes-les-fonctionnalites, all-features, glossaire, etc.
 */

/* Conteneur : ne prend pas de place dans le flux */
.toc-floating-root {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    overflow: visible;
    pointer-events: none;
    z-index: 9998;
}
.toc-floating-root > * {
    pointer-events: auto;
}

/* =======================================================
   Checkbox hack — même technique que WP (position: absolute, left: -9999px)
   ======================================================= */
#toc-toggle {
    position: absolute !important;
    left: -9999px !important;
    width: 0 !important;
    height: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
}

/* =======================================================
   Bouton(s) flottant(s)
   ======================================================= */
.toc-toggle {
    position: fixed;
    top: 140px;
    left: 20px;
    z-index: 9998;
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    max-width: 240px;
    font-size: 0.85em;
    padding: 0.5em 1em;
    background-color: var(--color-teal, #00c2a8);
    color: #fff;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 194, 168, 0.35);
    transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.25;
    user-select: none;
    border: none;
}

.toc-toggle--target { display: none; }

.toc-toggle:hover {
    background-color: #00a894;
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 194, 168, 0.4);
}

.toc-toggle:active {
    transform: translateY(0);
    box-shadow: 0 4px 14px rgba(0, 194, 168, 0.3);
}

.toc-toggle:focus,
.toc-toggle:focus-visible {
    outline: 3px solid rgba(0, 194, 168, 0.5);
    outline-offset: 3px;
}

.toc-toggle i {
    font-size: 1em;
}

/* =======================================================
   Panneau TOC flottant
   ======================================================= */
.toc-floating-wrapper {
    display: none;
    position: fixed;
    top: 200px;
    left: 20px;
    width: 260px;
    max-width: 260px;
    min-width: 260px;
    max-height: calc(100vh - 240px);
    overflow-y: auto;
    overflow-x: hidden;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 194, 168, 0.2);
    border-radius: 10px;
    padding: 1rem 1rem 1.25rem;
    z-index: 9997;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    opacity: 0;
    visibility: hidden;
    box-sizing: border-box;
    will-change: opacity, visibility;
    font-size: 0.9rem;
}

.toc-floating-wrapper::-webkit-scrollbar { width: 6px; }
.toc-floating-wrapper::-webkit-scrollbar-track { background: transparent; border-radius: 10px; }
.toc-floating-wrapper::-webkit-scrollbar-thumb { background: rgba(0, 194, 168, 0.3); border-radius: 10px; }
.toc-floating-wrapper::-webkit-scrollbar-thumb:hover { background: rgba(0, 194, 168, 0.5); }

.toc-floating-wrapper ul,
.toc-floating-wrapper li {
    list-style: none !important;
    margin: 0;
    padding: 0;
}

.toc-floating-wrapper ul {
    width: 100%;
    box-sizing: border-box;
}

.toc-floating-wrapper li {
    margin-bottom: 0.35em;
}
.toc-floating-wrapper li:last-child { margin-bottom: 0; }

.toc-floating-title {
    font-weight: 600;
    font-size: 0.95em;
    color: var(--color-midnight, #0a0e27);
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(0, 194, 168, 0.25);
}

.toc-back-top {
    display: flex !important;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 0.75rem;
    padding: 0.4em 0.6em;
    font-size: 0.85em;
    color: var(--color-teal, #00c2a8) !important;
    text-decoration: none !important;
}
.toc-back-top:hover {
    background-color: rgba(0, 194, 168, 0.08);
}

.toc-floating-wrapper a {
    display: flex;
    align-items: center;
    gap: 0.5em;
    width: 100%;
    box-sizing: border-box;
    padding: 0.4em 0.6em;
    border-radius: 6px;
    transition: background-color 0.15s ease, padding-left 0.15s ease;
    color: var(--color-midnight, #0a0e27);
    text-decoration: none;
}

.toc-floating-wrapper a:hover {
    background-color: rgba(0, 194, 168, 0.08);
    padding-left: 0.9em;
}

.toc-floating-wrapper a:active {
    background-color: rgba(0, 194, 168, 0.12);
}

.toc-floating-wrapper a:focus,
.toc-floating-wrapper a:focus-visible {
    outline: 2px solid rgba(0, 194, 168, 0.5);
    outline-offset: 2px;
    border-radius: 6px;
}

.toc-floating-wrapper a i {
    color: var(--color-teal, #00c2a8);
    font-size: 0.9em;
    flex-shrink: 0;
}

/* Hiérarchie toc-l2 / toc-l3 — flèches courbes pour sous-titres */
.toc-floating-wrapper .toc-l2 { margin-left: 0; }
.toc-floating-wrapper .toc-l3 { margin-left: 14px; }
.toc-floating-wrapper .toc-l4 { margin-left: 28px; }

.toc-floating-wrapper .toc-l3 > a::before { content: "↳ "; color: var(--color-teal, #00c2a8); font-size: 0.85em; }
.toc-floating-wrapper .toc-l4 > a::before { content: "↳↳ "; color: var(--color-teal, #00c2a8); font-size: 0.85em; }

/* Groupes repliables (accordion par section principale) */
.toc-group {
    margin-bottom: 0.4em;
}

.toc-group-toggle {
    position: absolute !important;
    left: -9999px !important;
    width: 0 !important;
    height: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
}

.toc-group-label {
    display: block;
}

.toc-group-label .toc-l2 {
    display: block;
    margin-left: 0;
}

.toc-group-label .toc-l2 > a {
    font-weight: 600;
}

.toc-sublist {
    margin-top: 0.25em;
    padding-left: 0;
    list-style: none;
    display: block;
}

/* Ouverture desktop (checkbox) */
#toc-toggle:checked ~ .toc-floating-wrapper {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* =======================================================
   MOBILE
   ======================================================= */
@media (max-width: 768px) {
    .toc-toggle--checkbox { display: none !important; }
    .toc-toggle--target { display: inline-flex !important; }

    .toc-toggle {
        top: auto;
        left: auto;
        right: 20px;
        bottom: 24px;
        font-size: 0.9em;
        padding: 0.65em 1.1em;
        border-radius: 12px;
        max-width: none;
    }

    .toc-floating-wrapper {
        display: none !important;
        position: fixed;
        top: auto;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        bottom: 85px;
        width: min(92vw, 320px);
        max-width: min(92vw, 320px);
        min-width: auto;
        max-height: 55vh;
        z-index: 9999 !important;
        padding: 1.25rem;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
    }

    /* Neutraliser checkbox sur mobile */
    #toc-toggle:checked ~ .toc-floating-wrapper {
        display: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
    }

    /* Ouverture mobile via :target (id="toc") */
    #toc.toc-floating-wrapper:target {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        z-index: 9999 !important;
    }
}
