/* ============================================================
   Widget d'accessibilité — Vigie24
   Amélioration progressive : sans JavaScript, rien n'est affiché
   et le site reste intégralement lisible.
   Réutilise les jetons du site (--surface, --text, --border…).
   ============================================================ */

/* --- Classes d'application posées sur <html> --------------- */

/* --- Hauteur de ligne --------------------------------------- */

/* --- Police adaptée à la dyslexie (SIL OFL, hébergée localement) --- */

@font-face {
    font-family: "OpenDyslexic";
    src: url("../fonts/opendyslexic-latin-400-normal.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
    font-family: "OpenDyslexic";
    src: url("../fonts/opendyslexic-latin-700-normal.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F, U+2122, U+2191, U+2193, U+2212, U+2215;
}

html.a11y-lh-1 { --a11y-lh: 1.7; }
html.a11y-lh-2 { --a11y-lh: 2.05; }
html[class*="a11y-lh-"] body,
html[class*="a11y-lh-"] main p,
html[class*="a11y-lh-"] main li,
html[class*="a11y-lh-"] main dd,
html[class*="a11y-lh-"] main blockquote,
html[class*="a11y-lh-"] main td { line-height: var(--a11y-lh) !important; }
html[class*="a11y-lh-"] main h1,
html[class*="a11y-lh-"] main h2,
html[class*="a11y-lh-"] main h3 { line-height: calc(var(--a11y-lh) - .35) !important; }

/* --- Espacement des textes ---------------------------------- */

html.a11y-space-1 main p,
html.a11y-space-1 main li,
html.a11y-space-1 main dd,
html.a11y-space-1 main .article-summary { letter-spacing: .03em; word-spacing: .12em; }
html.a11y-space-2 main p,
html.a11y-space-2 main li,
html.a11y-space-2 main dd,
html.a11y-space-2 main .article-summary { letter-spacing: .07em; word-spacing: .24em; }
html.a11y-space-1 main p,
html.a11y-space-2 main p { margin-block-end: 1.15em; }

/* --- Mode dyslexie ------------------------------------------ */

html.a11y-dys body,
html.a11y-dys main p,
html.a11y-dys main li,
html.a11y-dys main dd,
html.a11y-dys main blockquote,
html.a11y-dys main h1,
html.a11y-dys main h2,
html.a11y-dys main h3,
html.a11y-dys main a,
html.a11y-dys main button,
html.a11y-dys main input,
html.a11y-dys main select {
    font-family: "OpenDyslexic", "Comic Sans MS", "Chalkboard SE", "Trebuchet MS", Verdana, sans-serif !important;
    letter-spacing: .035em !important;
    word-spacing: .16em !important;
}
html.a11y-dys main p,
html.a11y-dys main li,
html.a11y-dys main dd { font-size: 1.08em; }
/* la hauteur de ligne reste pilotée par le réglage dédié s'il est actif */
html.a11y-dys:not([class*="a11y-lh-"]) main p,
html.a11y-dys:not([class*="a11y-lh-"]) main li,
html.a11y-dys:not([class*="a11y-lh-"]) main dd { line-height: 1.75 !important; }

/* --- Masquage des images ------------------------------------ */

html.a11y-no-img main img,
html.a11y-no-img main picture,
html.a11y-no-img main video,
html.a11y-no-img main figure,
html.a11y-no-img main .card-thumb { display: none !important; }

/* --- Liens et curseur (inchangé) ---------------------------- */

html.a11y-links a { text-decoration: underline; text-underline-offset: .18em; }
html.a11y-links .brand,
html.a11y-links .nav,
html.a11y-links .subnav-link,
html.a11y-links .pagination a,
html.a11y-links .pagination button { text-decoration: none; }
html.a11y-links .nav:hover,
html.a11y-links .subnav-link:hover { text-decoration: underline; }

html.a11y-no-motion *,
html.a11y-no-motion *::before,
html.a11y-no-motion *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
}

html.a11y-cursor,
html.a11y-cursor * { cursor: url("/img/a11y-cursor.svg") 4 4, auto; }
html.a11y-cursor a,
html.a11y-cursor button,
html.a11y-cursor [role="button"],
html.a11y-cursor summary { cursor: url("/img/a11y-cursor-link.svg") 6 2, pointer; }

/* --- Déclencheur ------------------------------------------- */

.a11y-trigger {
    position: fixed;
    left: 1rem;
    bottom: 1.25rem;
    z-index: 40;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 1px solid var(--border-strong, #9aa5b1);
    border-radius: 50%;
    background: var(--surface, #fff);
    color: var(--text, #1a1d21);
    box-shadow: 0 4px 14px rgb(0 0 0 / .22);
    cursor: pointer;
}
.a11y-trigger:hover { border-color: var(--accent, #1a5fb4); color: var(--accent, #1a5fb4); }
.a11y-icon, .a11y-trigger-icon { display: block; width: 24px; height: 24px; }
/* Libellé lisible par les lecteurs d'écran : le bouton reste une icône seule. */
.a11y-trigger-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}
@media (max-width: 720px) { .a11y-trigger { bottom: 4.25rem; } }

/* --- Panneau ----------------------------------------------- */

.a11y-panel {
    position: fixed;
    inset: 0 auto 0 0;
    margin: 0;
    width: min(27rem, 100vw);
    max-width: 100vw;
    max-height: 100dvh;
    height: 100%;
    padding: 0;
    border: 0;
    border-right: 1px solid var(--border, #d9dfe7);
    background: var(--surface, #fff);
    color: var(--text, #1a1d21);
    box-shadow: 0 0 32px rgb(0 0 0 / .28);
    overflow: hidden;
    font-size: 1rem;
    line-height: 1.5;
}
.a11y-panel::backdrop { background: rgb(15 23 42 / .55); }
.a11y-panel[open] { display: flex; flex-direction: column; }

.a11y-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--border, #d9dfe7);
    background: var(--surface-alt, #f8fafc);
}
.a11y-title { margin: 0; font-size: 1.05rem; font-weight: 700; }
.a11y-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--border-strong, #9aa5b1);
    border-radius: .5rem;
    background: var(--surface, #fff);
    color: var(--text, #1a1d21);
    font: inherit;
    cursor: pointer;
}
.a11y-close:hover { border-color: var(--accent, #1a5fb4); color: var(--accent, #1a5fb4); }

.a11y-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: .35rem 1rem .6rem;
    overscroll-behavior: contain;
}

.a11y-group {
    margin: 0;
    padding: .6rem 0;
    border: 0;
    border-bottom: 1px solid var(--border, #d9dfe7);
}
.a11y-group:last-of-type { border-bottom: 0; }
.a11y-group legend {
    padding: 0;
    margin-bottom: .45rem;
    font-size: .82rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted, #5b6472);
}

/* Segments (taille de texte, thème) */
.a11y-seg { display: grid; gap: .4rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.a11y-seg.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.a11y-seg button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    min-height: 40px;
    white-space: nowrap;
    padding: .34rem .5rem;
    font-size: .92rem;
    border: 1px solid var(--border-strong, #9aa5b1);
    border-radius: .5rem;
    background: var(--surface, #fff);
    color: var(--text, #1a1d21);
    font: inherit;
    font-size: .92rem;
    text-align: center;
    cursor: pointer;
}
.a11y-seg button:hover { border-color: var(--accent, #1a5fb4); }
.a11y-seg button[aria-pressed="true"] {
    border-color: var(--accent, #1a5fb4);
    background: var(--accent, #1a5fb4);
    color: var(--accent-ink, #fff);
    font-weight: 600;
}

/* Interrupteurs */
.a11y-switch {
    display: flex;
    align-items: center;
    gap: .7rem;
    min-height: 44px;
    padding: .35rem 0;
    cursor: pointer;
}
.a11y-switch input {
    position: absolute;
    opacity: 0;
    width: 44px;
    height: 44px;
    margin: 0;
    cursor: pointer;
}
.a11y-switch-track {
    position: relative;
    flex: none;
    width: 46px;
    height: 26px;
    border: 1px solid var(--border-strong, #9aa5b1);
    border-radius: 13px;
    background: var(--surface-alt, #f8fafc);
    transition: background .15s ease, border-color .15s ease;
}
.a11y-switch-track::after {
    content: "";
    position: absolute;
    inset: 2px auto 2px 2px;
    width: 20px;
    border-radius: 50%;
    background: var(--text-muted, #5b6472);
    transition: transform .15s ease;
}
.a11y-switch input:checked + .a11y-switch-track {
    background: var(--accent, #1a5fb4);
    border-color: var(--accent, #1a5fb4);
}
.a11y-switch input:checked + .a11y-switch-track::after { transform: translateX(20px); background: #fff; }
.a11y-switch-text { font-size: .95rem; }

/* --- Curseur de saturation ---------------------------------- */

.a11y-range {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: 44px;
}
.a11y-range input[type="range"] {
    flex: 1 1 auto;
    min-width: 0;
    accent-color: var(--accent, #1a5fb4);
    cursor: pointer;
}
.a11y-hint {
    margin: .2rem 0 0;
    font-size: .8rem;
    color: var(--text-muted, #5b6472);
}
.a11y-range-val {
    flex: none;
    min-width: 3.4em;
    font-variant-numeric: tabular-nums;
    font-size: .9rem;
    color: var(--text-muted, #5b6472);
    text-align: right;
}

.a11y-foot {
    display: flex;
    gap: .5rem;
    padding: .8rem 1rem calc(.8rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border, #d9dfe7);
    background: var(--surface-alt, #f8fafc);
}
.a11y-foot button {
    flex: 1 1 0;
    min-height: 44px;
    padding: .5rem;
    border: 1px solid var(--border-strong, #9aa5b1);
    border-radius: .5rem;
    background: var(--surface, #fff);
    color: var(--text, #1a1d21);
    font: inherit;
    font-size: .92rem;
    cursor: pointer;
}
.a11y-foot .a11y-reset { font-weight: 600; }
.a11y-foot button:hover { border-color: var(--accent, #1a5fb4); color: var(--accent, #1a5fb4); }

.a11y-help { margin: .75rem 0 0; font-size: .8rem; color: var(--text-muted, #5b6472); }
.a11y-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.a11y-panel :focus-visible { outline: 2px solid var(--focus, #0b57d0); outline-offset: 2px; }

/* --- Mobile : feuille pleine largeur ----------------------- */
@media (max-width: 640px) {
    .a11y-panel {
        inset: auto 0 0 0;
        width: 100%;
        height: auto;
        max-height: 92dvh;
        border-right: 0;
        border-top: 1px solid var(--border, #d9dfe7);
        border-radius: 1rem 1rem 0 0;
    }
}

/* --- Couleurs forcées (Windows contraste élevé) ------------ */
@media (forced-colors: active) {
    .a11y-trigger, .a11y-panel, .a11y-close, .a11y-seg button, .a11y-foot button {
        border: 1px solid CanvasText;
        forced-color-adjust: none;
        background: Canvas;
        color: CanvasText;
    }
    .a11y-seg button[aria-pressed="true"] { border-width: 3px; font-weight: 700; }
    .a11y-switch-track { border: 1px solid CanvasText; }
    .a11y-switch input:checked + .a11y-switch-track { background: Highlight; }
}

@media (prefers-reduced-motion: reduce) {
    .a11y-panel, .a11y-switch-track, .a11y-switch-track::after { transition: none; }
}

/* ---------------------------------------------------------------------------
   Face-IT : le panneau lit des jetons aux noms generiques. On les fait pointer
   sur ceux du site, pour que les themes clair, sombre et contraste eleve
   s'appliquent sans dupliquer une seule couleur.
   --------------------------------------------------------------------------- */
:root {
    --text: var(--ink);
    --border: var(--rule);
    --border-strong: var(--rule-strong);
}

/* Echelle de texte pilotee par le panneau (les tailles du site sont en rem). */
html[data-font="50"] { font-size: 50%; }
html[data-font="75"] { font-size: 75%; }
html[data-font="100"] { font-size: 100%; }
html[data-font="125"] { font-size: 125%; }
html[data-font="150"] { font-size: 150%; }

/* Le bouton et le panneau restent à gauche, comme sur Vigie24. */

/* Sur écran large, le bouton porte son libellé : une pastille seule se remarque mal. */
@media (min-width: 768px) {
    .a11y-trigger {
        width: auto;
        height: 48px;
        padding: 0 1rem 0 .85rem;
        gap: .55rem;
        border-radius: 999px;
    }

    .a11y-trigger-label {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        padding: 0;
        overflow: visible;
        clip: auto;
        clip-path: none;
        white-space: nowrap;
        font-size: .95rem;
        font-weight: 600;
        letter-spacing: .01em;
    }
}

.a11y-trigger { z-index: 60; }
