/**
 * a11y.css — Accessibility styles (RGAA 4.1)
 * Observatoire de l'Eau Grand Est
 *
 * Include on EVERY page, after all other stylesheets.
 *
 * Contents:
 *  1. .sr-only utility class (screen-reader-only content)
 *  2. Skip navigation link (skip-link)
 *  3. Visible keyboard focus indicator on all interactive elements
 *  4. Contrast corrections for brand colours on small text
 *  5. Reduced-motion media query (prefers-reduced-motion)
 *  6. ARIA state styles: aria-expanded, aria-current, aria-busy
 *
 * These styles must NOT be overridden by other stylesheets.
 * Most rules use !important to ensure accessibility is never broken
 * by later-loading component styles.
 */

/* ============================================================
   1. SCREEN-READER-ONLY CONTENT (.sr-only)
   Visually hidden but accessible to assistive technologies.
   Use for alternative text, table captions, and live-region content.
   RGAA criterion 1.1 — all non-decorative images must have text alternatives.
   ============================================================ */
.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;
}
/* Variant: becomes visible when focused (used by the skip-link) */
.sr-only-focusable:focus,
.sr-only-focusable:focus-within {
  position: static !important;
  width: auto !important;
  height: auto !important;
  padding: inherit !important;
  margin: inherit !important;
  overflow: visible !important;
  clip: auto !important;
  white-space: normal !important;
}

/* ============================================================
   2. SKIP NAVIGATION LINK — RGAA 12.1
   Visually hidden until focused via keyboard (Tab key).
   Allows keyboard users to skip directly to the main content.
   ============================================================ */
.skip-links {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 99999;
  display: flex;
  gap: 4px;
  padding: 4px;
}
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  background: #1a2660;
  color: #ffffff !important;
  font-size: 14px;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  padding: 12px 20px;
  border-radius: 0 0 8px 0;
  text-decoration: none;
  white-space: nowrap;
  border: 2px solid #ffffff;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.skip-link:focus {
  position: fixed;
  left: 0;
  top: 0;
  width: auto;
  height: auto;
  overflow: visible;
  outline: 3px solid #F59E0B;
  outline-offset: 2px;
  z-index: 99999;
}

/* ============================================================
   3. VISIBLE KEYBOARD FOCUS — RGAA 10.7
   Ensures a high-contrast focus ring is visible on all interactive
   elements (links, buttons, inputs, selects…) when navigated by keyboard.
   ============================================================ */

/* Default focus ring (dark blue on white/light backgrounds) */
:focus-visible {
  outline: 3px solid #2a347d !important;
  outline-offset: 2px !important;
  border-radius: 3px;
}

/* Focus on dark backgrounds (header, hero sections): amber ring for contrast */
.site-header :focus-visible,
.hp-nav :focus-visible,
.tdbv2-hero :focus-visible {
  outline: 3px solid #F59E0B !important;
  outline-offset: 3px !important;
}

/* Remove focus ring on mouse clicks (keep only keyboard focus) */
:focus:not(:focus-visible) {
  outline: none;
}

/* Inputs and selects: blue border on focus */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #2a347d !important;
  outline-offset: 0 !important;
  border-color: #2a347d !important;
  box-shadow: 0 0 0 3px rgba(42,52,125,.2) !important;
}

/* Buttons */
button:focus-visible,
[role="button"]:focus-visible {
  outline: 3px solid #2a347d !important;
  outline-offset: 2px !important;
}

/* Body text links */
a:focus-visible {
  outline: 3px solid #2a347d !important;
  outline-offset: 2px !important;
  border-radius: 2px;
}

/* ============================================================
   4. CONTRAST CORRECTIONS — RGAA 3.2
   Grand Est palette: muted text on white background
   rgba(42,52,125,.65) on #fff = contrast ratio > 4.5:1 ✅
   ============================================================ */

:root {
  --color-text-muted-a11y: rgba(42,52,125,.65);
  --color-text-muted-dark: rgba(42,52,125,.85);
}

/* Apply the accessible muted-text colour across all UI components that use
   --color-text-muted (ensures correct contrast is maintained) */
.tdb-card__sous,
.tdb-card__meta-item,
.listing-count,
.listing-section__count,
.tdbv2-count,
.tdbv2-acc-count,
.tdbv2-result-card__meta,
.tdbv2-filters__label,
.megamenu__col-title,
.site-header__nav-link,
.hp-nav__link,
.carto-popup__meta,
.carto-popup__meta-ligne,
.p1-filtres__count,
.p2-filtres__count,
.badge-count {
  color: rgba(42,52,125,.65) !important;
}

/* Muted text on coloured backgrounds (dark header) → near-white */
.site-header .site-header__nav-link,
.hp-nav .hp-nav__link {
  color: rgba(255,255,255,.92) !important;
}
.site-header .site-header__nav-link:hover,
.site-header .site-header__nav-link.is-active,
.hp-nav .hp-nav__link:hover,
.hp-nav .hp-nav__link.is-active {
  color: #ffffff !important;
}

/* Badge / secondary text contrast correction */
.autocomplete-item,
.tdbv2-ac-item {
  color: #1d1d1b !important;
}
.autocomplete-item__badge,
.tdbv2-ac-badge {
  /* Coloured badges: ensure text remains legible */
  font-weight: 700 !important;
}

/* ============================================================
   5. REDUCED MOTION — RGAA 13.8
   Respects the user's OS 'Reduce Motion' preference.
   Disables all CSS animations and transitions.
   ============================================================ */
@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;
  }
  /* Disable page transition overlay */
  .page-transition,
  .page-transition-overlay {
    display: none !important;
  }
}

/* ============================================================
   6. ARIA STATE STYLES
   CSS hooks for ARIA attributes used by interactive components.
   ============================================================ */

/* aria-expanded on accordions and mega-menus: rotates the chevron icon */
[aria-expanded="false"] .chevron-icon { transform: rotate(0deg); }
[aria-expanded="true"]  .chevron-icon { transform: rotate(180deg); }

/* aria-current="page": visually marks the active link in navigation */
[aria-current="page"] {
  font-weight: 700 !important;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* aria-disabled */
[aria-disabled="true"],
[disabled] {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}

/* aria-busy : indicateur de chargement */
[aria-busy="true"] {
  cursor: wait;
}

/* aria-invalid : champ en erreur */
[aria-invalid="true"] {
  border-color: #ec947b !important;
  box-shadow: 0 0 0 3px rgba(198,40,40,.2) !important;
}

/* ============================================================
   7. TABLEAUX DE DONNÉES ACCESSIBLES (Chart.js alternatives)
   ============================================================ */
.chart-table-a11y {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  color: #1d1d1b;
}
.chart-table-a11y caption {
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  padding-bottom: 8px;
  color: #1d1d1b;
}
.chart-table-a11y th,
.chart-table-a11y td {
  border: 1px solid rgba(42,52,125,.18);
  padding: 6px 10px;
  text-align: left;
}
.chart-table-a11y th {
  background: #bab0ed;
  font-weight: 600;
}
.chart-table-a11y tr:nth-child(even) {
  background: rgba(42,52,125,.03);
}

/* ============================================================
   8. COMPOSANTS INTERACTIFS ACCESSIBLES
   ============================================================ */

/* Boutons-chips : état sélectionné clairement signalé */
.filter-chip[aria-pressed="true"],
.tdbv2-chip[aria-pressed="true"] {
  /* Déjà stylé via .is-active – on ajoute l'indicateur non-couleur */
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Méga-menu : visible aussi au focus clavier */
.has-megamenu:focus-within .megamenu {
  display: flex !important;
  gap: 28px;
  flex-wrap: wrap;
}

/* Rôle listbox pour autocomplétion */
[role="listbox"] {
  list-style: none;
  padding: 0;
  margin: 0;
}
[role="option"] {
  cursor: pointer;
}
[role="option"][aria-selected="true"] {
  background: #bab0ed;
  color: #2a347d;
}

/* ============================================================
   9. FORMULAIRES – RGAA 11.x
   ============================================================ */
/* Astérisque pour champs obligatoires */
.field-required::after {
  content: ' *';
  color: #ec947b;
  font-weight: 700;
  aria-hidden: true; /* décoratif, le required est dans le label */
}

/* Message d'erreur */
.field-error {
  color: #ec947b;
  font-size: 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============================================================
   10. FIL D'ARIANE ACCESSIBLE (RGAA 12.2)
   Le <nav> fil d'ariane utilise un <ol> — on neutralise le style
   de liste pour conserver l'apparence visuelle existante.
   ============================================================ */
.page-hero__eyebrow ol {
  list-style: none !important;
  padding: 0 !important;
  margin: 0 !important;
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: inherit !important;
}
.page-hero__eyebrow ol li {
  display: flex !important;
  align-items: center !important;
  gap: inherit !important;
}

/* ============================================================
   10. LIVE REGIONS (annonces dynamiques)
   ============================================================ */
[aria-live] {
  /* Rien de spécial visuellement – juste s'assurer que la région existe */
}
.a11y-announcer {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
