/* SPDX-License-Identifier: GPL-3.0-or-later */
/* SPDX-FileCopyrightText: 2026 ITSM Factory */
/*
 * Plugin Accessibilité GLPI — Corrections de contraste GLPI baseline
 * RGAA 3.2 (issue #304) : Contraste éléments de formulaire ≥ 3:1
 * RGAA 3.2 (issue #309) : Contraste texte ≥ 4.5:1
 *
 * Ces corrections NE s'appliquent QUE lorsque l'utilisateur a activé
 * l'interrupteur maître « Activer l'accessibilité » dans le widget
 * (html[data-a11y-baseline="1"]). Sans cet attribut, le rendu GLPI
 * natif est préservé à l'identique.
 */

/* ─────────────────────────────────────────────────────────────────────────
   #304 — Contraste bordures éléments de formulaire (RGAA 3.2 / WCAG 1.4.11)
   Thème GLPI par défaut : bordures trop claires (#FEC85B / blanc = 1.5:1)
   Correction : bordure #767676 sur fond blanc = 4.5:1 ✓
   ───────────────────────────────────────────────────────────────────────── */
html[data-a11y-baseline="1"] input:not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
html[data-a11y-baseline="1"] select,
html[data-a11y-baseline="1"] textarea {
    border-color: #767676 !important;
}

/* .input-group-flat (Tabler/GLPI 11) : la bordure visible est sur le wrapper,
   pas sur l'input interne. On fixe le wrapper à #767676 et on efface la bordure
   de l'input interne pour éviter une double bordure. */
html[data-a11y-baseline="1"] .input-group-flat {
    border: 1px solid #767676 !important;
    border-radius: 6px !important;
}

html[data-a11y-baseline="1"] .input-group-flat input:not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
html[data-a11y-baseline="1"] .input-group-flat select,
html[data-a11y-baseline="1"] .input-group-flat textarea {
    border-color: transparent !important;
}

/* Le focus sur .input-group-flat doit rester visible */
html[data-a11y-baseline="1"] .input-group-flat:focus-within {
    border-color: #005FCC !important;
    outline: none;
}

/* Checkboxes et radios — bordure visible ≥ 3:1 */
html[data-a11y-baseline="1"] input[type="checkbox"],
html[data-a11y-baseline="1"] input[type="radio"] {
    outline: 1px solid #767676;
    outline-offset: 0;
}

/* Éviter un double outline sur les checkboxes Bootstrap custom */
html[data-a11y-baseline="1"] .form-check-input {
    border-color: #767676 !important;
}

/* ─────────────────────────────────────────────────────────────────────────
   #309 — Contraste texte (RGAA 3.2 / WCAG 1.4.3)
   Choix produit : le maître ne recolore PAS le texte courant de GLPI
   (liens, libellés, en-têtes, texte secondaire) — ces couleurs relèvent du
   thème choisi par l'admin et le « contraste renforcé » du widget couvre ce
   besoin à la demande. Seuls restent les états réellement sous le seuil
   dans Bootstrap/Tabler : placeholders, champs désactivés, badges, etc.

   NOTE fond sombre : ces couleurs sont pensées pour fond clair. Elles sont
   exclues quand le fond est sombre — mode sombre du plugin ([data-a11y-dark])
   ou palette GLPI nativement sombre ([data-a11y-glpi-dark], détectée par
   a11y-init.js) — et remplacées par le bloc « fond sombre » plus bas.
   ───────────────────────────────────────────────────────────────────────── */

/* ─────────────────────────────────────────────────────────────────────────
   Corrections de contraste supplémentaires — scopées hors mode high-contrast
   pour ne pas interférer avec a11y-contrast.css
   ───────────────────────────────────────────────────────────────────────── */
html[data-a11y-baseline="1"]:not([data-a11y-contrast]):not([data-a11y-dark="1"]):not([data-a11y-glpi-dark="1"]) {

    /* Placeholders trop pâles (ratio ~2.5:1 dans Bootstrap 5) → 4.5:1 */
    input::placeholder,
    textarea::placeholder {
        color: #595959 !important;
        opacity: 1;
    }

    /* Champs désactivés : texte #6c757d sur #e9ecef = ~3.3:1 → forcer ≥ 4.5:1 */
    .form-control:disabled,
    .form-control[readonly],
    .form-select:disabled {
        color: #444444 !important;
    }

    /* Badges secondaires : fond #6c757d + texte blanc = 4.4:1 — insuffisant.
       Forcer un fond légèrement plus sombre pour atteindre 4.5:1. */
    .badge.bg-secondary {
        background-color: #5a6571 !important;
    }

    /* Liens de navigation désactivés */
    .nav-link.disabled,
    .nav-link[aria-disabled="true"] {
        color: #595959 !important;
    }

    /* Boutons outline secondaires : texte #6c757d = ratio ~3.5:1 */
    .btn-outline-secondary {
        color: #444444 !important;
        border-color: #444444 !important;
    }

    .btn-outline-secondary:hover,
    .btn-outline-secondary:focus {
        color: #fff !important;
        background-color: #444444 !important;
    }
}

/* ─────────────────────────────────────────────────────────────────────────
   Variantes FOND SOMBRE des corrections ci-dessus.
   S'appliquent quand GLPI utilise une palette nativement sombre
   ([data-a11y-glpi-dark], détectée par a11y-init.js). Le mode sombre du
   plugin ([data-a11y-dark]) a ses propres règles dans a11y-dark.css.
   Ratios vérifiés sur fond ≈ #1a2130 (palette midnight).
   ───────────────────────────────────────────────────────────────────────── */
html[data-a11y-baseline="1"]:not([data-a11y-contrast])[data-a11y-glpi-dark="1"]:not([data-a11y-dark="1"]) {

    /* Placeholders : gris-bleu clair ≈ 7:1 */
    & input::placeholder,
    & textarea::placeholder {
        color: #a7b0bd !important;
        opacity: 1;
    }

    /* Champs désactivés / lecture seule : chez GLPI ils portent de
       l'information (page préférences entière) → viser ≥ 4.5:1.
       opacity:1 neutralise le gris fantôme de Tabler/Bootstrap ;
       -webkit-text-fill-color est requis car WebKit ignore `color`
       sur les contrôles désactivés. */
    & .form-control:disabled,
    & .form-control[readonly],
    & .form-select:disabled,
    & select:disabled,
    & input:disabled,
    & textarea:disabled {
        color: #b8c2cd !important;
        -webkit-text-fill-color: #b8c2cd;
        opacity: 1 !important;
    }

    /* Onglets / liens de navigation désactivés */
    & .nav-link.disabled,
    & .nav-link[aria-disabled="true"] {
        color: #9aa6b2 !important;
        opacity: 1 !important;
    }

    /* Boutons outline secondaires : gris clair au lieu du #444 illisible */
    & .btn-outline-secondary {
        color: #c3cbd4 !important;
        border-color: #8a94a0 !important;
    }
    & .btn-outline-secondary:hover,
    & .btn-outline-secondary:focus {
        color: #10151c !important;
        background-color: #c3cbd4 !important;
    }
}

/* ─────────────────────────────────────────────────────────────────────────
   Indicateur visuel « nouvelle fenêtre » (RGAA 13.2 / WCAG 3.2)
   Affiche une flèche ↗ après les liens qui ouvrent un nouvel onglet.
   Le module JS marque ces liens via data-a11y-new-window ; l'affichage est
   piloté par html[data-a11y-new-window="1"] et gaté sous l'interrupteur maître.
   ───────────────────────────────────────────────────────────────────────── */
html[data-a11y-baseline="1"][data-a11y-new-window="1"] a[data-a11y-new-window]::after {
    content: "\00a0\2197";
    display: inline;
    font-size: 0.85em;
    line-height: 1;
    color: currentColor;
    text-decoration: none;
}
