/* MUNIVALPO Digital — Opciones de accesibilidad (tarea GestionTD 471).
 *
 * Lo aplica js/accesibilidad.js como clases y una variable en <html>; el
 * parcial Shared/Components/Accesibilidad/_AccesibilidadHead.cshtml repite esa
 * lógica antes del primer pintado para que la página no salte al navegar.
 *
 *   --a11y-escala        tamaño del texto (1 = normal)
 *   .a11y-contraste      alto contraste
 *   .a11y-enlaces        subrayar enlaces
 *   .a11y-espaciado      espaciado de texto (WCAG 1.4.12)
 *   .a11y-sin-animacion  pausar animaciones
 *
 * Este archivo va ANTES de site.css: site.css fija la letra base del layout de
 * funcionarios (14 px en celular, 16 px desde 768 px) y la multiplica por la
 * misma variable. Los layouts que no cargan site.css usan la regla de abajo.
 */

/* ── Tamaño del texto ──────────────────────────────────────────────────
   Todo lo que Tailwind mide en rem crece con la letra base. */
html {
    font-size: calc(100% * var(--a11y-escala, 1));
}

/* ── Salto al contenido principal ──────────────────────────────────────
   Primer elemento enfocable de cada layout: invisible hasta recibir el foco. */
.a11y-saltar {
    position: absolute;
    left: 0.75rem;
    top: -10rem;
    z-index: 100000;
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    background: #0b2447;
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    text-decoration: underline;
}
.a11y-saltar:focus {
    top: 0.75rem;
}
/* El destino del salto recibe el foco por programa (tabindex="-1"): sin anillo. */
main[tabindex="-1"]:focus {
    outline: none !important;
    box-shadow: none !important;
}

/* ── Foco visible al navegar con teclado (WCAG 2.4.7) ─────────────────
   Muchas vistas quitan el contorno (outline: none, focus:outline-none). Con
   teclado (:focus-visible) se dibuja siempre un anillo doble, azul oscuro y
   amarillo, que se ve sobre fondos claros y sobre el azul institucional. Los
   campos de texto tienen su propio estilo de foco; en alto contraste también
   reciben el anillo. */
:where(a[href], button, summary, [role="button"], [role="switch"], [role="tab"], [role="menuitem"],
       [tabindex]:not([tabindex="-1"]), input[type="checkbox"], input[type="radio"],
       input[type="range"], input[type="file"], input[type="submit"], input[type="button"]):focus-visible,
html.a11y-contraste :where(input, select, textarea):focus-visible {
    outline: 3px solid #ffdc04 !important;
    outline-offset: 1px !important;
    box-shadow: 0 0 0 5px #0b2447 !important;
}

/* ── Alto contraste ────────────────────────────────────────────────────
   Más oscuro el texto secundario y los bordes en claro, más claro en oscuro.
   No es una escala de grises: el color también es información. */
html.a11y-contraste:not(.theme-dark) {
    --body-bg: #ffffff;
    --card-bg: #ffffff;
    --section-bg: #eef2f7;
    --text-primary: #000000;
    --text-secondary: #0f172a;
    --text-muted: #1e293b;
    --nav-label: #0f172a;
    --border-card: #334155;
    --border-subtle: #475569;
    --table-border: #475569;
    --table-header-text: #0f172a;
    --table-row-text: #000000;
    --input-border: #1e293b;
    --input-placeholder: #334155;
    --label-text: #0f172a;
    --info-box-text: #0b2447;
    --menu-section-title: #0f172a;
}
html.a11y-contraste.theme-dark {
    --body-bg: #000000;
    --card-bg: #0b0f19;
    --section-bg: #1e293b;
    --text-primary: #ffffff;
    --text-secondary: #f8fafc;
    --text-muted: #e2e8f0;
    --nav-label: #ffffff;
    --border-card: #cbd5e1;
    --border-subtle: #94a3b8;
    --table-border: #94a3b8;
    --table-header-text: #ffffff;
    --table-row-text: #ffffff;
    --input-bg: #000000;
    --input-border: #e2e8f0;
    --input-placeholder: #cbd5e1;
    --label-text: #ffffff;
    --info-box-text: #ffffff;
    --menu-section-title: #e2e8f0;
}
/* Grises de Tailwind dentro del contenido, solo en claro (en oscuro muchas
   vistas siguen con fondo blanco y aclararlos los haría ilegibles). */
html.a11y-contraste:not(.theme-dark) main :is(.text-gray-400, .text-slate-400) { color: #334155 !important; }
html.a11y-contraste:not(.theme-dark) main :is(.text-gray-500, .text-slate-500) { color: #1e293b !important; }
html.a11y-contraste:not(.theme-dark) main :is(.text-gray-600, .text-slate-600) { color: #0f172a !important; }
html.a11y-contraste:not(.theme-dark) main ::placeholder { color: #334155 !important; opacity: 1; }
/* Pie del portal (_Footer.cshtml, fondo azul institucional): texto en blanco. */
html.a11y-contraste #contacto :is(.text-gray-300, .text-gray-400) { color: #ffffff !important; }

/* ── Subrayar enlaces ──────────────────────────────────────────────────
   Solo en el contenido y el pie: la barra lateral y los menús ya se leen
   como navegación. */
html.a11y-enlaces :is(main, footer) a[href] {
    text-decoration: underline !important;
    text-decoration-thickness: 0.08em !important;
    text-underline-offset: 0.18em !important;
}

/* ── Espaciado de texto (WCAG 1.4.12) ──────────────────────────────────
   Interlineado 1,5, letras +0,12 em y palabras +0,16 em. Los íconos de
   Font Awesome y el propio panel quedan fuera para no correrse. */
html.a11y-espaciado body :not(i, .fa, .fas, .far, .fab, .fa-solid, .fa-regular, svg, svg *, .a11y-panel, .a11y-panel *) {
    line-height: 1.5 !important;
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}
html.a11y-espaciado body p {
    margin-bottom: 2em;
}
html.a11y-espaciado body p:last-child {
    margin-bottom: 0;
}
/* La barra lateral tiene altos fijos: el encabezado (h-16) y cada enlace (3rem,
   sidebar.css). Con el espaciado, el nombre del módulo y los enlaces largos pasan
   a dos o tres líneas y se cortaban o se montaban sobre el siguiente. Aquí crecen
   con su texto. */
html.a11y-espaciado #sidebar:not(.minimized) .sidebar-header {
    height: auto;
    min-height: 4rem;
}
html.a11y-espaciado #sidebar:not(.minimized) .menu-section:not(.collapsed) .nav-link {
    height: auto;
    min-height: 3rem;
    max-height: none;
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
}

/* ── Pausar animaciones ────────────────────────────────────────────────
   Lo mismo que ya hace output.css con prefers-reduced-motion, a pedido. */
html.a11y-sin-animacion *,
html.a11y-sin-animacion *::before,
html.a11y-sin-animacion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* ── Botón y panel ─────────────────────────────────────────────────────
   Botón flotante en la esquina inferior derecha de todas las páginas. El panel
   usa colores propios: el portal y las páginas sin layout no tienen las
   variables de tema.

   z-index 45, como "volver arriba": queda bajo los modales (z-50), las barras
   inferiores del celular y los avisos, para no tapar sus botones. */
.a11y-wrap {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 45;
}
.a11y-btn {
    box-sizing: border-box;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    border-radius: 9999px;
    color: #fff;
    background: #294589;
    border: 2px solid #fff;
    box-shadow: 0 6px 20px rgba(10, 18, 38, 0.35);
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
    transition: background 0.18s ease, transform 0.18s ease;
}
.a11y-icono {
    width: 1.35em;
    height: 1.35em;
    flex-shrink: 0;
}
.a11y-panel-titulo .a11y-icono { color: var(--a11y-acento); width: 1.2em; height: 1.2em; }
.a11y-btn:hover {
    background: #1e3a72;
    transform: scale(1.06);
}
.a11y-btn[aria-expanded="true"] {
    background: #ffdc04;
    color: #0b2447;
}
/* Punto amarillo: hay alguna opción activa. */
.a11y-btn-activo {
    position: absolute;
    top: -0.1rem;
    right: -0.1rem;
    width: 0.8rem;
    height: 0.8rem;
    border-radius: 9999px;
    background: #ffdc04;
    box-shadow: 0 0 0 2px #fff;
}
.a11y-btn-activo[hidden] { display: none; }

.a11y-panel {
    --a11y-fondo: #ffffff;
    --a11y-texto: #0f172a;
    --a11y-suave: #475569;
    --a11y-borde: #cbd5e1;
    --a11y-acento: #294589;
    --a11y-acento-suave: #eef2fb;

    /* Abre hacia arriba desde el botón, alineado a su borde derecho. */
    position: absolute;
    bottom: calc(100% + 0.75rem);
    right: 0;
    width: 22rem;
    max-width: calc(100vw - 2rem);
    /* Sin llegar bajo el header o la barra superior del portal; con A+ se desplaza. */
    max-height: calc(100dvh - 12rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 10050;
    background: var(--a11y-fondo);
    color: var(--a11y-texto);
    border: 1px solid var(--a11y-borde);
    border-radius: 0.875rem;
    box-shadow: 0 24px 56px rgba(10, 18, 38, 0.32), 0 4px 16px rgba(10, 18, 38, 0.12);
    text-align: left;
    font-family: inherit;
    /* El panel no crece con el espaciado de texto: sus controles quedarían fuera. */
    letter-spacing: normal;
    word-spacing: normal;
}
html.theme-dark .a11y-panel {
    --a11y-fondo: #1e293b;
    --a11y-texto: #f8fafc;
    --a11y-suave: #cbd5e1;
    --a11y-borde: rgba(148, 163, 184, 0.35);
    --a11y-acento: #93c5fd;
    --a11y-acento-suave: rgba(147, 197, 253, 0.12);
}
.a11y-panel[hidden] { display: none; }
.a11y-panel:focus { outline: none; }

.a11y-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.875rem 1.1rem 0.75rem;
    border-bottom: 1px solid var(--a11y-borde);
}
.a11y-panel-titulo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--a11y-texto);
}
.a11y-restablecer {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.3rem 0.7rem;
    border-radius: 9999px;
    border: 1px solid var(--a11y-borde);
    background: transparent;
    color: var(--a11y-texto);
    cursor: pointer;
}
.a11y-restablecer:hover { background: var(--a11y-acento-suave); }

.a11y-seccion {
    padding: 0.8rem 1.1rem;
    border-bottom: 1px solid var(--a11y-borde);
}
.a11y-seccion:last-child { border-bottom: none; }
.a11y-etiqueta {
    display: block;
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--a11y-texto);
}
.a11y-ayuda {
    margin: 0.45rem 0 0;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--a11y-suave);
}

/* Tamaño del texto: A− 100 % A+ */
.a11y-tamano {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.a11y-tamano-btn,
.a11y-voz-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0 0.8rem;
    border-radius: 0.6rem;
    border: 1px solid var(--a11y-borde);
    background: var(--a11y-acento-suave);
    color: var(--a11y-texto);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
}
.a11y-tamano-btn:hover:not(:disabled),
.a11y-voz-btn:hover:not(:disabled) { border-color: var(--a11y-acento); }
.a11y-tamano-btn:disabled,
.a11y-voz-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.a11y-tamano-valor {
    flex: 1;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Interruptores */
.a11y-opciones {
    list-style: none;
    margin: 0;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--a11y-borde);
}
.a11y-switch {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 2.9rem;
    padding: 0.4rem 1.1rem;
    border: none;
    background: transparent;
    color: var(--a11y-texto);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.a11y-switch:hover { background: var(--a11y-acento-suave); }
.a11y-switch > i {
    width: 1.1rem;
    text-align: center;
    color: var(--a11y-acento);
}
.a11y-switch-texto { flex: 1; }
.a11y-switch-pista {
    position: relative;
    flex-shrink: 0;
    width: 2.4rem;
    height: 1.35rem;
    border-radius: 9999px;
    background: #94a3b8;
    transition: background 0.15s;
}
.a11y-switch-pista::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: calc(1.35rem - 6px);
    height: calc(1.35rem - 6px);
    border-radius: 9999px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s;
}
.a11y-switch[aria-checked="true"] .a11y-switch-pista { background: #1d4ed8; }
.a11y-switch[aria-checked="true"] .a11y-switch-pista::after { transform: translateX(1.05rem); }

/* Lectura en voz alta */
.a11y-voz {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.a11y-voz-btn--principal { flex: 1; }
.a11y-voz-estado {
    margin: 0.45rem 0 0;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--a11y-acento);
}
.a11y-voz-estado:empty { display: none; }

/* Leer al pasar el mouse: interruptor dentro de la sección de voz. */
.a11y-al-pasar {
    margin-top: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--a11y-borde);
}
.a11y-al-pasar[hidden] { display: none; }
.a11y-al-pasar .a11y-switch {
    padding-left: 0;
    padding-right: 0;
    min-height: 2.6rem;
}
.a11y-al-pasar .a11y-switch:hover { background: transparent; }

/* Lo que se está leyendo al pasar el mouse. Contorno discontinuo para no
   confundirlo con el foco del teclado. */
.a11y-leyendo-al-pasar {
    outline: 3px dashed #f59e0b !important;
    outline-offset: 2px !important;
    border-radius: 0.25rem;
}

/* Aviso "haz un clic": burbuja sobre el botón. */
.a11y-aviso {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.75rem);
    width: max-content;
    max-width: min(16rem, calc(100vw - 2rem));
    margin: 0;
    padding: 0.6rem 0.85rem;
    border-radius: 0.6rem;
    background: #0b2447;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.35;
    box-shadow: 0 8px 24px rgba(10, 18, 38, 0.35);
}
.a11y-aviso[hidden] { display: none; }
.a11y-aviso::after {
    content: "";
    position: absolute;
    right: 1.15rem;
    top: 100%;
    border: 0.4rem solid transparent;
    border-top-color: #0b2447;
}

/* ── Convivencia con otros elementos de la esquina ─────────────────────
   Celular: los layouts de funcionarios y del portal tienen una barra de
   navegación inferior fija de 4rem (bottom-nav.css, bottom-nav-publico.css);
   el botón sube sobre ella. Las páginas sin layout no la tienen. */
@media (max-width: 767px) {
    .a11y-wrap {
        right: 1rem;
        bottom: 1rem;
    }
    body:has(.bottom-nav, .bottom-nav-publico) .a11y-wrap {
        bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
    }

    /* El panel ocupa el ancho de la pantalla (menos un margen), fijo sobre el
       botón: anclado a él se salía por la izquierda en 360 px. */
    .a11y-panel {
        position: fixed;
        left: 0.75rem;
        right: 0.75rem;
        bottom: calc(1rem + 3rem + 0.75rem);
        width: auto;
        max-width: none;
        max-height: calc(100dvh - 10rem);
    }
    body:has(.bottom-nav, .bottom-nav-publico) .a11y-panel {
        bottom: calc(5rem + 3rem + 0.75rem + env(safe-area-inset-bottom, 0px));
        max-height: calc(100dvh - 15rem);
    }
}

/* El chat Porteño (OP y OIRS, _PortenoWidget.cshtml) usa la misma esquina:
   ahí el botón de accesibilidad se corre a su izquierda. Su panel abre sobre
   la burbuja, así que no se tapan. */
body:has(#chat-ia-wrapper:not([hidden])) .a11y-wrap {
    right: calc(1.5rem + 3.25rem + 0.75rem);
}
