/* ==========================================================================
   YASSUR — FEUILLE D'ACCESSIBILITÉ RGAA / WCAG 2.1 AA
   Référentiel Général d'Amélioration de l'Accessibilité
   ========================================================================== */

/* ── 1. LIEN D'ÉVITEMENT (RGAA 12.1 / WCAG 2.4.1) ─────────────────────── */
.skip-link {
  position: absolute;
  top: -120px;
  left: 16px;
  z-index: 100000;
  background: #1d4ed8;
  color: #fff !important;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  border-radius: 0 0 12px 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 0;
  outline: 3px solid #fff;
  outline-offset: 2px;
}
.skip-link:focus-visible {
  top: 0;
}

/* ── 2. FOCUS VISIBLE (RGAA 10.7 / WCAG 2.4.7) ────────────────────────── */
/* Suppression du outline par défaut uniquement si remplacé */
*:focus {
  outline: none;
}
*:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 3px;
  border-radius: 4px;
  box-shadow: 0 0 0 5px rgba(29, 78, 216, 0.2);
}

/* Focus spécifique boutons */
button:focus-visible,
[role="button"]:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(29, 78, 216, 0.25);
}

/* Focus inputs */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 0;
  border-color: #1d4ed8;
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.2);
}

/* Focus liens */
a:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 3px;
  border-radius: 3px;
  text-decoration: underline;
}

/* ── 3. UTILITAIRES LECTEURS D'ÉCRAN (RGAA 1.1, 6.1…) ──────────────────── */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static !important;
  width: auto !important;
  height: auto !important;
  padding: inherit !important;
  margin: 0 !important;
  overflow: visible !important;
  clip: auto !important;
  white-space: normal !important;
}

/* ── 4. RÉGION LIVE ARIA (RGAA 7.3) ────────────────────────────────────── */
#aria-live-region {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── 5. CONTRASTE ÉLEVÉ (RGAA 3.2 / WCAG 1.4.3) ────────────────────────── */
@media (forced-colors: active) {
  * {
    forced-color-adjust: auto;
  }
  a {
    color: LinkText;
  }
  button,
  [role="button"] {
    forced-color-adjust: none;
    border: 2px solid ButtonText;
  }
}

/* Mode sombre système */
@media (prefers-color-scheme: dark) {
  :root {
    --a11y-focus-color: #60a5fa;
  }
  *:focus-visible {
    outline-color: #60a5fa;
    box-shadow: 0 0 0 5px rgba(96, 165, 250, 0.3);
  }
}

/* ── 6. RÉDUCTION DE MOUVEMENT (RGAA 13.8 / WCAG 2.3.3) ─────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── 7. TAILLE DES ZONES CLIQUABLES (RGAA 10.11 / WCAG 2.5.5) ─────────── */
button,
[role="button"],
a,
input[type="checkbox"],
input[type="radio"],
select {
  min-height: 44px;
  min-width: 44px;
}

/* Exception pour les petits liens inline */
p a,
li a,
td a,
label a {
  min-height: unset;
  min-width: unset;
}

/* ── 8. INDICATEUR REQUIS (RGAA 11.10) ─────────────────────────────────── */
[aria-required="true"] + label::after,
label.required::after {
  content: " *";
  color: #dc2626;
}

/* ── 9. MESSAGES D'ERREUR FORMULAIRES (RGAA 11.11) ──────────────────────── */
[aria-invalid="true"] {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15) !important;
}

.field-error {
  color: #dc2626;
  font-size: 0.875rem;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-error::before {
  content: "⚠ ";
}

/* ── 10. TABLEAUX ACCESSIBLES (RGAA 5.x) ───────────────────────────────── */
table caption {
  font-weight: 700;
  text-align: left;
  margin-bottom: 8px;
  font-size: 1rem;
}

table th[scope] {
  background: #f1f5f9;
  font-weight: 700;
}

/* ── 11. IMAGES DÉCORATIVES (RGAA 1.2) ─────────────────────────────────── */
img[alt=""] { /* Conforme RGAA 1.2 : image décorative, alt vide intentionnel */ display: inline; }
img:not([alt]) {
  outline: 3px solid #dc2626;
}

/* ── 12. LIENS EXTERNES (RGAA 6.1) ─────────────────────────────────────── */
a[target="_blank"]::after {
  content: " (ouvre dans un nouvel onglet)";
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ── 13. WIDGET D'ACCESSIBILITÉ FLOTTANT ────────────────────────────────── */
#a11y-widget {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 99998;
  font-family: system-ui, -apple-system, sans-serif;
}

#a11y-toggle-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1d4ed8, #0f766e);
  color: #fff;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(29, 78, 216, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  min-width: 52px;
  min-height: 52px;
}

#a11y-toggle-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(29, 78, 216, 0.5);
}

#a11y-toggle-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

#a11y-panel {
  position: absolute;
  bottom: 62px;
  left: 0;
  width: 280px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(15, 23, 42, 0.2);
  border: 1px solid #e2e8f0;
  overflow: hidden;
  animation: a11y-slide-up 0.2s ease;
}

@keyframes a11y-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.a11y-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #1d4ed8, #0f766e);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
}

.a11y-panel-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
  transition: background 0.2s;
}
.a11y-panel-close:hover { background: rgba(255,255,255,0.3); }

.a11y-options {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 380px;
  overflow-y: auto;
}

.a11y-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  border: 2px solid transparent;
}
.a11y-option:hover { background: #f1f5f9; }
.a11y-option.active { background: #eff6ff; border-color: #bfdbfe; }

.a11y-opt-icon {
  font-size: 1.1rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.a11y-opt-label {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 600;
  color: #1e293b;
}

.a11y-toggle-track {
  width: 40px;
  height: 22px;
  background: #cbd5e1;
  border-radius: 999px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
  cursor: pointer;
}
.a11y-toggle-track[aria-checked="true"] { background: #1d4ed8; }
.a11y-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.a11y-toggle-track[aria-checked="true"] .a11y-toggle-thumb { transform: translateX(18px); }

.a11y-panel-footer {
  padding: 10px 16px;
  border-top: 1px solid #f1f5f9;
}
.a11y-reset-btn {
  width: 100%;
  padding: 8px;
  background: #f1f5f9;
  border: none;
  border-radius: 8px;
  color: #475569;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  min-height: 36px;
}
.a11y-reset-btn:hover { background: #e2e8f0; }

/* ── 14. MODES ACTIVABLES PAR LE WIDGET ─────────────────────────────────── */

/* Contraste élevé */
.a11y-high-contrast body,
.a11y-high-contrast {
  filter: contrast(1.5) !important;
}

/* Grande police */
.a11y-large-text body,
.a11y-large-text p,
.a11y-large-text li,
.a11y-large-text span,
.a11y-large-text div {
  font-size: 120% !important;
  line-height: 1.8 !important;
}

/* Police dyslexie */
.a11y-dyslexia,
.a11y-dyslexia body,
.a11y-dyslexia p,
.a11y-dyslexia li,
.a11y-dyslexia h1,
.a11y-dyslexia h2,
.a11y-dyslexia h3 {
  font-family: 'OpenDyslexic', 'Comic Sans MS', cursive !important;
  letter-spacing: 0.05em !important;
  word-spacing: 0.15em !important;
}

/* Réduire animations */
.a11y-reduce-motion *,
.a11y-reduce-motion *::before,
.a11y-reduce-motion *::after {
  animation-duration: 0.01ms !important;
  transition-duration: 0.01ms !important;
}

/* Souligner les liens */
.a11y-underline-links a {
  text-decoration: underline !important;
  text-decoration-thickness: 2px !important;
  text-underline-offset: 3px !important;
}

/* Curseur large */
.a11y-big-cursor,
.a11y-big-cursor * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M8 2 L8 26 L14 20 L18 30 L21 29 L17 19 L25 19 Z' fill='black' stroke='white' stroke-width='1.5'/%3E%3C/svg%3E") 0 0, auto !important;
}

/* Espacement texte */
.a11y-text-spacing p,
.a11y-text-spacing li,
.a11y-text-spacing h1,
.a11y-text-spacing h2,
.a11y-text-spacing h3 {
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
  line-height: 1.9 !important;
}

/* Masque de lecture */
.a11y-mask-el {
  position: fixed;
  left: 0;
  right: 0;
  height: 56px;
  background: rgba(29, 78, 216, 0.08);
  border-top: 2px solid rgba(29, 78, 216, 0.3);
  border-bottom: 2px solid rgba(29, 78, 216, 0.3);
  pointer-events: none;
  z-index: 99997;
  transition: top 0.05s;
}

/* ── 15. PRINT (RGAA 13.x) ──────────────────────────────────────────────── */
@media print {
  .skip-link,
  nav,
  .no-print {
    display: none !important;
  }
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8rem;
    color: #475569;
  }
  a[href^="#"]::after,
  a[href^="javascript"]::after {
    content: "";
  }
}
