/* ============================================================================
 *  OPMR — Module accessibilité enrichie
 *  Complète le RGAA AA en exposant des préférences utilisateur explicites :
 *    - 3 contrastes : normal / élevé / inversé
 *    - 4 tailles de texte : 90 % / 100 % / 115 % / 130 %
 *    - Synthèse vocale (Web Speech API) sur tout texte cliqué
 *  Préférences persistées en localStorage, restituées à chaque visite.
 * ============================================================================ */

/* ─── Bouton flottant d'ouverture (bottom-right, visible partout) ──────── */
.a11y-fab {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 9000;
  width: 48px;
  height: 48px;
  border: 0 !important;
  border-radius: 50% !important;
  background-color: #1e5f8a !important;
  background-image: none !important;
  color: #ffffff !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
  text-decoration: none !important;
}
.a11y-fab:hover,
.a11y-fab:focus,
.a11y-fab:focus-visible,
.a11y-fab:active {
  background-color: #164974 !important;
  background-image: none !important;
  color: #ffffff !important;
  transform: scale(1.06);
  text-decoration: none !important;
}
.a11y-fab:focus-visible { outline: 3px solid #0a6b3b !important; outline-offset: 3px; }
.a11y-fab i, .a11y-fab svg {
  color: #ffffff !important;
  fill: #ffffff !important;
}

/* Sur mobile, on remonte le FAB au-dessus du juicy-fab (qui occupe bottom-right) */
@media (max-width: 1023px) {
  .a11y-fab {
    right: 1rem;
    bottom: calc(var(--juicy-bottom-nav-h, 64px) + var(--juicy-bottom-safe, 0px) + 80px);
  }
}

/* ─── Panneau de réglages ──────────────────────────────────────────────── */
.a11y-panel {
  position: fixed;
  right: 1rem;
  bottom: 70px;
  z-index: 9001;
  width: 320px;
  max-width: calc(100vw - 2rem);
  background: white;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  padding: 1.25rem 1.25rem 1rem;
  display: none;
  animation: a11y-pop 220ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.a11y-panel.is-open { display: block; }

@keyframes a11y-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.a11y-panel__title {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--opmr-basalte, #1a1a1a);
  display: flex;
  align-items: center;
  gap: 8px;
}

.a11y-group { margin-bottom: 1.25rem; }
.a11y-group__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--opmr-pierre-ponce, #6b7280);
  margin-bottom: 6px;
}

.a11y-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.a11y-options--4 { grid-template-columns: repeat(4, 1fr); }

.a11y-opt {
  padding: 8px 4px;
  background: white;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 120ms ease;
}
.a11y-opt:hover { border-color: var(--opmr-bleu-cabesterre, #1e5f8a); background: #f8fafc; }
.a11y-opt[aria-pressed="true"] {
  background: var(--opmr-vert-morne, #0a6b3b);
  border-color: transparent;
  color: white;
  font-weight: 600;
}

.a11y-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.875rem;
}
.a11y-toggle input {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 22px;
  background: #d1d5db;
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 160ms;
  flex: 0 0 auto;
}
.a11y-toggle input:checked { background: var(--opmr-vert-morne, #0a6b3b); }
.a11y-toggle input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
  transition: transform 160ms cubic-bezier(0.16, 1, 0.3, 1);
}
.a11y-toggle input:checked::after { transform: translateX(18px); }

.a11y-panel__reset {
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: var(--opmr-pierre-ponce, #6b7280);
  font-size: 0.8125rem;
  cursor: pointer;
  margin-top: 0.5rem;
}
.a11y-panel__reset:hover { background: #f8fafc; color: var(--opmr-basalte, #1a1a1a); }

/* ─── Application des préférences (data-attributes sur <html>) ─────────── */

/* Taille texte */
html[data-a11y-size="sm"]  { font-size: 90%; }
html[data-a11y-size="md"]  { font-size: 100%; }
html[data-a11y-size="lg"]  { font-size: 115%; }
html[data-a11y-size="xl"]  { font-size: 130%; }

/* Contraste élevé : darken les textes, lighten les fonds */
html[data-a11y-contrast="high"] {
  --opmr-pierre-ponce: #1a1a1a;
  --opmr-basalte: #000;
  background: white;
}
html[data-a11y-contrast="high"] * {
  text-shadow: none !important;
}
html[data-a11y-contrast="high"] body { color: #000; }
html[data-a11y-contrast="high"] a { text-decoration: underline; }

/* Contraste inversé : fond noir, texte blanc */
html[data-a11y-contrast="invert"] body,
html[data-a11y-contrast="invert"] .juicy-card,
html[data-a11y-contrast="invert"] section,
html[data-a11y-contrast="invert"] .juicy-hero {
  background: #1a1a1a !important;
  color: #fff !important;
}
html[data-a11y-contrast="invert"] .juicy-product__name,
html[data-a11y-contrast="invert"] .juicy-product__price,
html[data-a11y-contrast="invert"] .juicy-hero__title,
html[data-a11y-contrast="invert"] h1, html[data-a11y-contrast="invert"] h2, html[data-a11y-contrast="invert"] h3 { color: #fff !important; }
html[data-a11y-contrast="invert"] a:not(.juicy-search__button):not(.juicy-fab) {
  color: #4ec3ff !important;
}
html[data-a11y-contrast="invert"] .juicy-card {
  border-color: #444 !important;
}

/* Élément actuellement « parlé » par TTS */
.a11y-tts-active {
  outline: 3px solid var(--opmr-bleu-cabesterre, #1e5f8a);
  outline-offset: 2px;
  background: rgba(30, 95, 138, 0.08);
  border-radius: 4px;
}

/* Mode TTS-on : curseur spécial sur les éléments parlables */
html[data-a11y-tts="on"] p,
html[data-a11y-tts="on"] h1,
html[data-a11y-tts="on"] h2,
html[data-a11y-tts="on"] h3,
html[data-a11y-tts="on"] li {
  cursor: help;
}

/* ─── prefers-reduced-motion : désactive nos animations panel ──────────── */
@media (prefers-reduced-motion: reduce) {
  .a11y-panel,
  .a11y-fab,
  .a11y-toggle input::after { animation: none !important; transition: none !important; }
}
