/* ============================================================
   IMC · MÓDULO DE ACCESIBILIDAD WCAG 2.1 AA
   Cumple UNE 301549:2019 (norma española de accesibilidad)
   ============================================================ */

/* Importar Atkinson Hyperlegible (fuente diseñada para dislexia) */
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400;1,700&display=swap');

/* ============================================================
   BARRA DE ACCESIBILIDAD — siempre arriba del todo
   ============================================================ */

.a11y-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: #06192B;
  color: #F5EFE0;
  font-family: 'Barlow', system-ui, sans-serif;
  border-bottom: 1px solid rgba(201, 169, 97, 0.3);
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.a11y-bar.hidden {
  transform: translateY(-100%);
}

.a11y-bar-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  max-width: 1400px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 169, 97, 0.4) transparent;
}

.a11y-bar-inner::-webkit-scrollbar { height: 4px; }
.a11y-bar-inner::-webkit-scrollbar-thumb {
  background: rgba(201, 169, 97, 0.4);
  border-radius: 2px;
}

.a11y-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #F5EFE0;
  margin-right: 0.75rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.a11y-label .a11y-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.a11y-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.5rem;
  border-left: 1px solid rgba(245, 239, 224, 0.15);
  flex-shrink: 0;
}

.a11y-group:first-of-type { border-left: none; }

.a11y-btn {
  background: transparent;
  border: 1px solid transparent;
  color: #F5EFE0;
  font-family: 'Barlow', system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.4rem 0.7rem;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 36px;
}

.a11y-btn:hover {
  background: rgba(201, 169, 97, 0.15);
  border-color: rgba(201, 169, 97, 0.3);
}

.a11y-btn:focus-visible {
  outline: 2px solid #C9A961;
  outline-offset: 2px;
}

.a11y-btn.active {
  background: #C9A961;
  color: #0A2540;
  border-color: #C9A961;
}

.a11y-btn .a11y-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Botones de tamaño de texto: A, A+, A++, A+++ */
.a11y-btn-size-1 { font-size: 0.75rem; }
.a11y-btn-size-2 { font-size: 0.85rem; }
.a11y-btn-size-3 { font-size: 0.95rem; }
.a11y-btn-size-4 { font-size: 1.05rem; }

/* Botón de cerrar la barra (en escritorio) */
.a11y-close {
  margin-left: auto;
  background: transparent;
  border: 1px solid rgba(245, 239, 224, 0.2);
  color: #F5EFE0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.a11y-close:hover {
  background: rgba(245, 239, 224, 0.1);
}

/* Cuando la barra está visible, empujamos el contenido hacia abajo */
body.a11y-bar-visible {
  padding-top: 56px;
}

/* Botón flotante para reabrir la barra (cuando está cerrada) */
.a11y-reopen {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 9998;
  background: #0A2540;
  color: #C9A961;
  border: 1px solid #C9A961;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.a11y-reopen.visible {
  display: flex;
}

.a11y-reopen:hover {
  background: #C9A961;
  color: #0A2540;
}

.a11y-reopen svg {
  width: 22px;
  height: 22px;
}

/* ============================================================
   RESPONSIVE — móvil: barra colapsada como panel deslizante
   ============================================================ */

@media (max-width: 960px) {
  .a11y-bar-inner {
    padding: 0.5rem;
    gap: 0.25rem;
  }
  .a11y-label {
    font-size: 0;
    margin-right: 0.25rem;
  }
  .a11y-label .a11y-icon { width: 22px; height: 22px; }
  .a11y-group {
    padding: 0 0.25rem;
    gap: 0.1rem;
  }
  .a11y-btn {
    padding: 0.4rem 0.5rem;
    font-size: 0.7rem;
    min-height: 36px;
  }
  body.a11y-bar-visible { padding-top: 56px; }
}

/* ============================================================
   FUNCIONALIDAD 1 — TAMAÑO DE TEXTO
   Se aplica al <html> con variables CSS
   ============================================================ */

html.a11y-size-1 { font-size: 100%; }   /* default */
html.a11y-size-2 { font-size: 112.5%; }  /* +12.5% */
html.a11y-size-3 { font-size: 125%; }    /* +25% */
html.a11y-size-4 { font-size: 140%; }    /* +40% */

/* ============================================================
   FUNCIONALIDAD 2 — ALTO CONTRASTE
   Filtro CSS que invierte colores manteniendo legibilidad
   ============================================================ */

body.a11y-high-contrast {
  background: #000 !important;
  color: #FFFF00 !important;
}

body.a11y-high-contrast * {
  background-color: #000 !important;
  color: #FFFF00 !important;
  border-color: #FFFF00 !important;
}

body.a11y-high-contrast a,
body.a11y-high-contrast a * {
  color: #00FFFF !important;
  text-decoration: underline !important;
}

body.a11y-high-contrast a:visited,
body.a11y-high-contrast a:visited * {
  color: #FF80FF !important;
}

body.a11y-high-contrast button,
body.a11y-high-contrast input,
body.a11y-high-contrast textarea,
body.a11y-high-contrast select {
  background: #000 !important;
  color: #FFFF00 !important;
  border: 2px solid #FFFF00 !important;
}

body.a11y-high-contrast img:not(.a11y-icon img):not([alt=""]) {
  opacity: 0.85;
  filter: contrast(1.2);
}

/* La barra de accesibilidad mantiene SU propio contraste */
body.a11y-high-contrast .a11y-bar,
body.a11y-high-contrast .a11y-bar *,
body.a11y-high-contrast .a11y-reopen {
  background-color: #000 !important;
  color: #FFFF00 !important;
}
body.a11y-high-contrast .a11y-btn.active {
  background: #FFFF00 !important;
  color: #000 !important;
}

/* ============================================================
   FUNCIONALIDAD 3 — TIPOGRAFÍA PARA DISLEXIA
   Atkinson Hyperlegible es libre y diseñada para dislexia
   ============================================================ */

body.a11y-dyslexia,
body.a11y-dyslexia * {
  font-family: 'Atkinson Hyperlegible', system-ui, sans-serif !important;
  letter-spacing: 0.03em !important;
  word-spacing: 0.08em !important;
  line-height: 1.8 !important;
}

body.a11y-dyslexia p,
body.a11y-dyslexia li {
  text-align: left !important;
  hyphens: none !important;
}

/* Excepto la barra de accesibilidad */
body.a11y-dyslexia .a11y-bar,
body.a11y-dyslexia .a11y-bar * {
  font-family: 'Atkinson Hyperlegible', system-ui, sans-serif !important;
  letter-spacing: 0.02em !important;
  line-height: 1.4 !important;
}

/* ============================================================
   FUNCIONALIDAD 4 — SIN ANIMACIÓN
   ============================================================ */

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

/* ============================================================
   FUNCIONALIDAD 5 — LEER PÁGINA
   Indicador visual de que se está leyendo
   ============================================================ */

body.a11y-reading {
  cursor: progress;
}

.a11y-reading-highlight {
  background: rgba(201, 169, 97, 0.3) !important;
  outline: 2px solid #C9A961 !important;
  outline-offset: 2px !important;
}

/* ============================================================
   FUNCIONALIDAD 6 — LECTURA FÁCIL
   Oculta elementos decorativos, simplifica presentación
   ============================================================ */

body.a11y-easy-read {
  background: #FFFEF5 !important;
}

body.a11y-easy-read main,
body.a11y-easy-read article {
  max-width: 65ch !important;
  margin: 2rem auto !important;
  padding: 0 1.5rem !important;
  font-size: 1.15rem !important;
  line-height: 1.9 !important;
  color: #000 !important;
}

body.a11y-easy-read p {
  margin-bottom: 1.5rem !important;
  text-align: left !important;
}

body.a11y-easy-read h1,
body.a11y-easy-read h2,
body.a11y-easy-read h3,
body.a11y-easy-read h4 {
  color: #000 !important;
  margin-top: 2rem !important;
  margin-bottom: 1rem !important;
  line-height: 1.3 !important;
}

/* Oculta elementos decorativos en lectura fácil */
body.a11y-easy-read .hero-bg,
body.a11y-easy-read .decorative,
body.a11y-easy-read [aria-hidden="true"],
body.a11y-easy-read .imc-chat-launcher,
body.a11y-easy-read video,
body.a11y-easy-read iframe[src*="youtube"],
body.a11y-easy-read iframe[src*="vimeo"] {
  display: none !important;
}

/* Aumenta contraste de enlaces */
body.a11y-easy-read a {
  color: #0A2540 !important;
  text-decoration: underline !important;
  text-underline-offset: 3px !important;
  font-weight: 600 !important;
}

/* ============================================================
   SKIP LINK — saltar al contenido principal (obligatorio WCAG)
   ============================================================ */

.a11y-skip {
  position: absolute;
  top: -40px;
  left: 0;
  z-index: 10000;
  background: #0A2540;
  color: #F5EFE0;
  padding: 0.75rem 1.25rem;
  text-decoration: none;
  font-family: 'Barlow', sans-serif;
  font-weight: 600;
  font-size: 0.875rem;
}

.a11y-skip:focus {
  top: 0;
  outline: 3px solid #C9A961;
}

/* ============================================================
   FOCUS VISIBLE GLOBAL — mejora navegación con teclado
   ============================================================ */

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #C9A961 !important;
  outline-offset: 2px !important;
}


/* ============================================================
   v1.2 — FIX DEFINITIVO: empujar el nav fijo dinámicamente
   ============================================================

   El problema: tu nav usa position: fixed; top: 0. Mi barra
   también está fijada arriba. Si uso un valor fijo (56px), no
   sirve cuando la barra cambia de altura (varía según viewport
   y según tamaño de texto seleccionado).

   La solución: una CSS variable --a11y-bar-h que el JavaScript
   mide dinámicamente (ResizeObserver) y actualiza en cada cambio.
   El nav y todo lo demás usa esa variable. Siempre exacto.
   ============================================================ */

:root {
  --a11y-bar-h: 0px;
}

/* Cuando la barra está visible, el body deja hueco arriba (sobrescribe
   la regla anterior `padding-top: 56px` con el valor exacto medido) */
body.a11y-bar-visible {
  padding-top: var(--a11y-bar-h, 56px) !important;
}

/* Empujar el nav fijo de IMC */
body.a11y-bar-visible .nav {
  top: var(--a11y-bar-h, 56px) !important;
  transition: top 0.25s ease !important;
}

/* El menú móvil de IMC (panel deslizante) también respeta el offset */
body.a11y-bar-visible .nav-menu {
  top: var(--a11y-bar-h, 56px) !important;
}

/* Botón de reabrir la barra: esquina inferior izquierda
   (libre de conflictos con logo arriba y chat launcher abajo-derecha) */
.a11y-reopen {
  position: fixed !important;
  top: auto !important;
  bottom: 20px !important;
  left: 20px !important;
  right: auto !important;
}
