/* =========================================================================
   SPLASH SCREEN / APP LOADER UNIFIÉ
   ========================================================================= */

/* LA COULEUR DU RIDEAU, un seul endroit : un gris incliné, du moyen au
   sombre (le bleu de la V1 ne collait plus à l'interface). Reprise par le
   voile de l'analyse IA, le chargement du dossier et la déconnexion. */
:root { --hs-rideau: linear-gradient(160deg, #5a5f66 0%, #2b2f34 100%); --hs-rideau-encre: #2b2f34; }

#app-loader,
#app-overlay,
#dossier-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--hs-rideau);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    transition: opacity 0.5s ease-out;
}

/* Le voile des rechargements (utils/overlay.js) : même logo, même pulsation. */
#app-overlay {
    display: none;
    opacity: 1;
}

#app-overlay.is-out {
    opacity: 0;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Logo avec Ombre et Pulsation */
.loader-logo {
    max-width: 150px;
    height: auto;
    filter: drop-shadow(0px 8px 12px rgba(0, 0, 0, 0.6));
    animation: pulseLogo 2s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes pulseLogo {
    0% {
        transform: scale(0.95);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.05);
        opacity: 1;
    }

    100% {
        transform: scale(0.95);
        opacity: 0.8;
    }
}

/* Spinner discret (Chenille) */
.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Texte de chargement */
.loader-text {
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 1.1rem;
    font-weight: 500;
    opacity: 0.9;
    letter-spacing: 0.5px;
    margin-top: 15px;
}
/* =========================================================================
   LE VOILE DE TRAITEMENT (charte 03-ERGONOMIE §3ter)
   L'analyse d'une boîte mail n'a pas d'écran à elle : c'est CE voile, logo
   pulsant, avec la progression sous l'image.
   ========================================================================= */

#app-overlay .loader-off {
    display: none !important;
}

.loader-progress {
    width: min(420px, 70vw);
    margin-top: 22px;
}

.loader-bar {
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    overflow: hidden;
}

.loader-bar>span {
    display: block;
    height: 100%;
    background: #ffffff;
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* Total inconnu : la barre glisse au lieu de mentir sur l'avancement. */
.loader-bar.indetermine>span {
    animation: loaderGlisse 1.4s ease-in-out infinite;
    transition: none;
}

@keyframes loaderGlisse {
    0% {
        margin-left: -40%;
    }

    100% {
        margin-left: 100%;
    }
}

.loader-chiffres {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    opacity: 0.85;
}

.loader-action {
    margin-top: 26px;
    padding: 6px 20px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    color: #ffffff;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 0.9rem;
    transition: background 0.15s ease;
}

.loader-action:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ══ L'ATTENTE DISCRÈTE ═══════════════════════════════════
   Le voile plein écran est réservé au démarrage et au traitement d'une boîte
   mail. Quand on reste sur le même écran — une écriture qui se relit, une
   propagation de règle — c'est cette petite carte qui occupe l'attente.       */

#app-attente {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(16, 20, 28, 0.28);
}

#app-attente.on {
    display: flex;
}

#app-attente .attente-carte {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 280px;
    max-width: 90vw;
    padding: 14px 18px;
    border-radius: 10px;
    background: #ffffff;
    color: #262a30;
    box-shadow: 0 6px 26px rgba(20, 24, 32, 0.28);
}

#app-attente .attente-logo {
    width: 34px;
    height: auto;
    animation: pulseLogo 2s ease-in-out infinite;
}

#app-attente .attente-corps {
    flex: 1;
}

#app-attente .attente-texte {
    font-size: 13px;
    margin-bottom: 8px;
}

/* La barre reprend le dessin du voile, sur fond clair. */
#app-attente .loader-bar {
    background: rgba(38, 42, 48, 0.14);
}

#app-attente .loader-bar>span {
    background: #35506b;
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) #app-attente .attente-carte {
        background: #2e3440;
        color: #e5e9f0;
        box-shadow: 0 6px 26px rgba(0, 0, 0, 0.5);
    }

    html:not([data-theme="light"]) #app-attente .loader-bar {
        background: rgba(229, 233, 240, 0.18);
    }

    html:not([data-theme="light"]) #app-attente .loader-bar>span {
        background: #8bb6ff;
    }
}

html[data-theme="dark"] #app-attente .attente-carte {
    background: #2e3440;
    color: #e5e9f0;
    box-shadow: 0 6px 26px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] #app-attente .loader-bar {
    background: rgba(229, 233, 240, 0.18);
}

html[data-theme="dark"] #app-attente .loader-bar>span {
    background: #8bb6ff;
}

/* =========================================================================
   LES ÉTAPES DU VOILE — l'analyse du dossier par l'IA

   ========================================================================= */

.loader-etapes {
    list-style: none;
    margin: 16px 0 0;
    padding: 0;
    width: min(380px, 80vw);
    font-family: 'Segoe UI', system-ui, sans-serif;
}

.loader-etapes li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    font-size: 0.9rem;
    opacity: 0.55;
}

.loader-etapes li .p {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.7);
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    font-size: 11px;
}

.loader-etapes li.fait {
    opacity: 0.9;
}

.loader-etapes li.fait .p {
    background: #ffffff;
    color: var(--hs-rideau-encre);
    border-color: #ffffff;
    font-weight: 800;
}

.loader-etapes li.ici {
    opacity: 1;
    font-weight: 600;
}

.loader-etapes li.ici .p {
    border-color: #ffffff;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

.loader-etapes:not(.loader-off) ~ .loader-progress {
    width: min(380px, 80vw);
    margin-top: 16px;
}

.loader-sous {
    margin-top: 10px;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 0.85rem;
    opacity: 0.8;
}
