/* ==========================================================================
   Maqueta · Ilustre Municipalidad de Pica
   accessibility.css — botón flotante "Modo accesible" y sus modos (herramientas de teleton.cl)
   Los modos se activan con atributos en <html> (data-a11y-*), que el <head>
   del layout aplica antes de pintar y accessibility.js actualiza.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tamaño del texto (el sitio usa rem: todo crece parejo)
   -------------------------------------------------------------------------- */
html[data-a11y-size="87.5"] { font-size: 87.5%; }
html[data-a11y-size="112.5"] { font-size: 112.5%; }
html[data-a11y-size="125"] { font-size: 125%; }
html[data-a11y-size="137.5"] { font-size: 137.5%; }
html[data-a11y-size="150"] { font-size: 150%; }

/* --------------------------------------------------------------------------
   2. Botón flotante y panel (abajo a la izquierda; Naranjín va a la derecha)
   -------------------------------------------------------------------------- */
.a11y {
  position: fixed;
  bottom: 1.1rem;
  left: 1.1rem;
  z-index: 1065;
  font-family: var(--pm-font);
}

/* Mientras el menú móvil está abierto, el botón se oculta (igual que Naranjín) */
body:has(.main-nav__panel.show) .a11y,
body:has(.main-nav__panel.showing) .a11y {
  visibility: hidden;
}

.a11y__toggle {
  position: relative;
  display: grid;
  place-items: center;
  width: 3.6rem;
  height: 3.6rem;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--pm-gold-500);
  color: var(--pm-navy-900);
  font-size: 1.9rem;
  box-shadow: var(--pm-shadow);
  cursor: pointer;
  transition: scale .2s ease, background-color .2s ease;
}

.a11y__toggle:hover {
  background: var(--pm-gold-400);
  scale: 1.06;
}

.a11y__toggle:focus-visible {
  outline: 3px solid var(--pm-gold-400);
  outline-offset: 3px;
}

.a11y__toggle-close { display: none; font-size: 1.3rem; }
.a11y.is-open .a11y__toggle-open { display: none; }
.a11y.is-open .a11y__toggle-close { display: block; }

/* Etiqueta junto al botón al pasar el mouse o llegar con el teclado */
.a11y__toggle-label {
  position: absolute;
  top: 50%;
  left: calc(100% + .6rem);
  padding: .35rem .75rem;
  border-radius: 999px;
  background: var(--pm-navy-900);
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--pm-shadow-sm);
  opacity: 0;
  translate: -.4rem -50%;
  pointer-events: none;
  transition: opacity .2s ease, translate .2s ease;
}

.a11y:not(.is-open) .a11y__toggle:focus-visible .a11y__toggle-label {
  opacity: 1;
  translate: 0 -50%;
}

@media (hover: hover) {
  .a11y:not(.is-open) .a11y__toggle:hover .a11y__toggle-label {
    opacity: 1;
    translate: 0 -50%;
  }
}

/* Punto turquesa en el botón: hay algún modo activo */
html:is([data-a11y-size], [data-a11y-contrast], [data-a11y-guide], [data-a11y-highlight], [data-a11y-cursor], [data-a11y-audio]) .a11y__toggle::after {
  content: "";
  position: absolute;
  top: -.2rem;
  right: -.2rem;
  width: 1rem;
  height: 1rem;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--pm-teal-500);
}

.a11y__panel {
  position: absolute;
  bottom: calc(100% + .8rem);
  left: 0;
  width: min(23rem, calc(100vw - 2.2rem));
  max-height: calc(100vh - 7rem);
  overflow-y: auto;
  border: 1px solid rgba(247, 209, 56, .4);
  border-radius: 20px;
  background: var(--pm-navy-800);
  color: #fff;
  box-shadow: 0 24px 60px rgba(3, 12, 28, .5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.96);
  transform-origin: bottom left;
  transition: opacity .22s ease, transform .22s ease, visibility .22s;
}

.a11y.is-open .a11y__panel {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.a11y__header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .8rem .8rem .7rem 1.1rem;
  border-bottom: 1px solid rgba(247, 209, 56, .22);
}

.a11y__header > .bi {
  color: var(--pm-gold-500);
  font-size: 1.35rem;
}

.a11y__title {
  flex: 1;
  margin: 0;
  color: #fff;
  font-family: var(--pm-font-header);
  font-size: 1.05rem;
  font-weight: 700;
}

.a11y__close {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  cursor: pointer;
  transition: background-color .2s ease;
}

.a11y__close:hover { background: rgba(255, 255, 255, .16); }

.a11y__close:focus-visible {
  outline: 3px solid var(--pm-gold-400);
  outline-offset: 2px;
}

.a11y__tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .35rem .25rem;
  padding: .8rem .6rem .7rem;
}

.a11y__tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  padding: .45rem .2rem;
  border: 0;
  border-radius: 12px;
  background: none;
  color: #fff;
  font: inherit;
  cursor: pointer;
}

.a11y__icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: #fff;
  color: var(--pm-navy-900);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  transition: background-color .2s ease, translate .2s ease, box-shadow .2s ease;
}

.a11y__icon .bi { font-size: 1.2rem; }

.a11y__label {
  font-size: .74rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}

.a11y__tool:hover .a11y__icon {
  background: var(--pm-gold-300);
  translate: 0 -2px;
}

.a11y__tool:focus-visible {
  outline: 3px solid var(--pm-gold-400);
  outline-offset: 2px;
}

/* Activo: dorado + marca de verificación (no solo color) */
.a11y__tool[aria-pressed="true"] .a11y__icon {
  background: var(--pm-gold-500);
  box-shadow: 0 0 0 3px rgba(247, 209, 56, .35);
}

.a11y__tool[aria-pressed="true"] .a11y__icon::after {
  content: "\f633";
  position: absolute;
  top: -.3rem;
  right: -.35rem;
  display: grid;
  place-items: center;
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid var(--pm-navy-800);
  border-radius: 50%;
  background: var(--pm-teal-500);
  color: var(--pm-navy-900);
  font-family: bootstrap-icons;
  font-size: .6rem;
  font-weight: 400;
}

.a11y__tool[aria-pressed="true"] .a11y__label { color: var(--pm-gold-400); }

.a11y__tool[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
}

.a11y__tool[aria-disabled="true"]:hover .a11y__icon {
  background: #fff;
  translate: none;
}

.a11y__status {
  margin: 0;
  padding: 0 1rem .85rem;
  color: var(--pm-gold-300);
  font-size: .82rem;
  text-align: center;
}

/* Vacío no ocupa espacio, pero sigue en el DOM para que se anuncien los cambios */
.a11y__status:empty { padding: 0; }

@media (max-width: 575.98px) {
  .a11y {
    bottom: .9rem;
    left: .9rem;
  }

  .a11y__toggle {
    width: 3.3rem;
    height: 3.3rem;
    font-size: 1.7rem;
  }

  /* El chat ocupa la pantalla completa: el botón no queda encima */
  body:has(.chatbot.is-open) .a11y { visibility: hidden; }
}

/* En pantallas táctiles no hay cursor que agrandar */
@media (hover: none) and (pointer: coarse) {
  .a11y__tool[data-a11y-mode="cursor"] { display: none; }
}

/* --------------------------------------------------------------------------
   3. Guía de lectura
   -------------------------------------------------------------------------- */
.a11y-guide {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1049;
  display: none;
  height: 2.4rem;
  margin-top: -1.2rem;
  border-block: 2px solid rgba(229, 168, 26, .9);
  background: rgba(247, 209, 56, .16);
  pointer-events: none;
  transform: translateY(40vh);
}

html[data-a11y-guide] .a11y-guide { display: block; }

/* --------------------------------------------------------------------------
   4. Resaltar objetos: lo que se puede usar o recorrer (no cada párrafo)
   -------------------------------------------------------------------------- */
html[data-a11y-highlight] :is(a[href], button, [role="button"], input, select, textarea, summary, h1, h2, h3, h4, h5, h6):not(.a11y *) {
  outline: 3px dashed rgba(255, 229, 11, .9) !important;
  outline-offset: 2px;
  box-shadow: inset 0 0 0 100vmax rgba(255, 229, 11, .12) !important;
}

html[data-a11y-highlight] :is(a[href], button, [role="button"], input, select, textarea, summary):not(.a11y *):focus-visible {
  outline: 3px solid var(--pm-gold-500) !important;
  outline-offset: 3px;
}

/* --------------------------------------------------------------------------
   5. Cursor grande: flecha y mano
   -------------------------------------------------------------------------- */
html[data-a11y-cursor],
html[data-a11y-cursor] * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M5 3v36l9.5-9.2 6.3 15 6.6-2.8-6.2-14.6H34z' fill='%23000' stroke='%23fff' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E") 5 3, auto !important;
}

html[data-a11y-cursor] :is(a[href], button, [role="button"], label, summary, select),
html[data-a11y-cursor] :is(a[href], button, [role="button"], label, summary) * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='-1 -1 34 35'%3E%3Cpath d='M11 3.5c0-1.4 1.1-2.5 2.5-2.5S16 2.1 16 3.5V13l1-.1c1.3 0 2.3.8 2.6 2 .5-.4 1.1-.6 1.8-.6 1.3 0 2.3.8 2.6 2 .5-.3 1-.5 1.6-.5 1.6 0 2.9 1.3 2.9 2.9V24c0 4.4-3.6 8-8 8h-3.4c-2.6 0-5-1.3-6.5-3.5l-5.2-7.6c-.8-1.2-.5-2.8.7-3.6 1.1-.7 2.5-.5 3.4.4L11 20z' fill='%23000' stroke='%23fff' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E") 20 3, pointer !important;
}

/* --------------------------------------------------------------------------
   6. Audio lectura: bloque que se está leyendo
   -------------------------------------------------------------------------- */
html[data-a11y-audio] main :is(p, h1, h2, h3, h4, h5, h6, li, blockquote, figcaption, dt, dd, td, th) {
  cursor: pointer;
}

html[data-a11y-audio] .a11y-reading {
  border-radius: 4px;
  outline: 3px solid var(--pm-gold-500) !important;
  outline-offset: 4px;
  box-shadow: inset 0 0 0 100vmax rgba(247, 209, 56, .18) !important;
}

/* --------------------------------------------------------------------------
   7. Alto contraste oscuro: fondo negro, texto blanco, enlaces amarillos
   Las reglas base usan :where() para que las de abajo ganen sin pelear especificidad.
   Todo fondo es negro opaco (paneles, menús y el chat no transparentan), salvo
   fotos (img y fondos puestos en style=""); degradados y adornos se quitan.
   -------------------------------------------------------------------------- */
html[data-a11y-contrast] { color-scheme: dark; }

html[data-a11y-contrast] body {
  background: #000 !important;
  color: #fff !important;
}

html[data-a11y-contrast] body :where(*:not(img, video, iframe, canvas, picture, svg, svg *)) {
  background-color: #000 !important;
  color: #fff !important;
  text-shadow: none !important;
  box-shadow: none !important;
}

html[data-a11y-contrast] body :where(*:not(input, [style*="background-image"])) {
  background-image: none !important;
}

html[data-a11y-contrast] body :where(*)::before,
html[data-a11y-contrast] body :where(*)::after {
  background-color: transparent !important;
  background-image: none !important;
  color: inherit !important;
}

/* El logo del encabezado trae letras oscuras (pensado para fondo blanco): va sobre una placa blanca */
html[data-a11y-contrast] .brand:not(.brand--inverse) .brand-logo {
  padding: .3rem .45rem;
  border-radius: 6px;
  background-color: #fff !important;
}

html[data-a11y-contrast] .form-check-input:checked {
  border-color: #ff0 !important;
  background-color: #ff0 !important;
}

html[data-a11y-contrast] body :where(a, a *) { color: #ff0 !important; }
html[data-a11y-contrast] body :where(a) { text-decoration: underline !important; }

html[data-a11y-contrast] body :where(button, .btn, [role="button"], input, select, textarea) {
  box-shadow: inset 0 0 0 2px #fff !important;
}

html[data-a11y-contrast] ::placeholder {
  color: #ccc !important;
  opacity: 1;
}

html[data-a11y-contrast] :focus-visible {
  outline: 3px solid #ff0 !important;
  outline-offset: 2px !important;
}

/* El propio modo accesible en alto contraste */
html[data-a11y-contrast] .a11y__panel { border-color: #fff; }
html[data-a11y-contrast] .a11y__header { border-bottom-color: #fff; }
html[data-a11y-contrast] .a11y .a11y__tool { box-shadow: none !important; }

html[data-a11y-contrast] .a11y .a11y__toggle {
  border-color: #fff;
  box-shadow: none !important;
}

html[data-a11y-contrast] .a11y .a11y__toggle::after {
  border-color: #000;
  background-color: #ff0 !important;
}

html[data-a11y-contrast] .a11y .a11y__icon {
  color: #fff !important;
  box-shadow: inset 0 0 0 2px #fff !important;
}

html[data-a11y-contrast] .a11y .a11y__tool[aria-pressed="true"] .a11y__icon {
  background-color: #ff0 !important;
  color: #000 !important;
}

html[data-a11y-contrast] .a11y .a11y__tool[aria-pressed="true"] .a11y__icon::after {
  border-color: #000;
  background-color: #fff !important;
  color: #000 !important;
}

html[data-a11y-contrast] .a11y .a11y__tool[aria-pressed="true"] .a11y__label { color: #ff0 !important; }
html[data-a11y-contrast] .a11y__status { color: #ff0 !important; }

html[data-a11y-contrast] .a11y-guide {
  border-color: #ff0;
  background-color: rgba(255, 255, 0, .2) !important;
}

/* --------------------------------------------------------------------------
   8. Movimiento reducido e impresión
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .a11y__toggle,
  .a11y__toggle-label,
  .a11y__panel,
  .a11y__icon {
    transition: none;
  }
}

@media print {
  .a11y,
  .a11y-guide {
    display: none !important;
  }
}
