/*
 * UPB – Accesibilidad
 *
 * El widget usa px a propósito: así no crece ni se rompe cuando el usuario
 * agranda el texto del sitio (el escalado cambia el font-size de <html>,
 * que mueve todo lo que esté en rem).
 *
 * Colores del widget: ink #1d1d1b / blanco (16.9:1) y verde marca #c0d901 sobre ink (11:1).
 */

.upb-a11y {
	--upb-a11y-ink: #1d1d1b;
	--upb-a11y-brand: #c0d901;
	--upb-a11y-line: #d9d9d9;
	position: fixed;
	left: 24px;
	bottom: calc(24px + env(safe-area-inset-bottom));
	z-index: 9998;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	font-size: 16px;
	line-height: 1.4;
	color: var(--upb-a11y-ink);
}

.upb-a11y *,
.upb-a11y *::before,
.upb-a11y *::after {
	box-sizing: border-box;
}

/* El alto contraste fija -webkit-text-fill-color en <body>, que se hereda y le
 * gana a color: el widget usa siempre su propio color. */
.upb-a11y,
.upb-a11y * {
	-webkit-text-fill-color: currentColor;
}

.upb-a11y__sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.upb-a11y__toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 3px solid #fff;
	border-radius: 50%;
	background: var(--upb-a11y-ink);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 0 0 4px color-mix(in srgb, var(--upb-a11y-ink) 25%, transparent), 0 6px 16px rgb(0 0 0 / 25%);
	transition: transform 0.15s ease;
}

.upb-a11y__toggle:hover {
	transform: translateY(-2px);
}

.upb-a11y__toggle[aria-expanded="true"] {
	background: var(--upb-a11y-brand);
	color: var(--upb-a11y-ink);
}

.upb-a11y__panel {
	position: absolute;
	left: 0;
	bottom: 68px;
	width: 320px;
	max-width: calc(100vw - 32px);
	max-height: calc(100vh - 120px);
	overflow-y: auto;
	padding: 16px;
	border: 2px solid var(--upb-a11y-ink);
	border-radius: 12px;
	background: #fff;
	color: var(--upb-a11y-ink);
	box-shadow: 0 12px 32px rgb(0 0 0 / 25%);
}

.upb-a11y__panel[hidden] {
	display: none;
}

.upb-a11y__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 8px;
}

.upb-a11y__title {
	margin: 0;
	font-size: 18px;
	font-weight: 700;
	line-height: 1.2;
	color: var(--upb-a11y-ink);
}

.upb-a11y__close {
	width: 36px;
	height: 36px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--upb-a11y-ink);
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
}

.upb-a11y__close:hover {
	background: #ededed;
}

.upb-a11y__group {
	padding: 12px 0;
	border-top: 1px solid var(--upb-a11y-line);
}

.upb-a11y__label {
	margin: 0 0 8px;
	font-size: 14px;
	font-weight: 700;
	line-height: 1.3;
	color: var(--upb-a11y-ink);
}

.upb-a11y__row {
	display: flex;
	align-items: center;
	gap: 8px;
}

.upb-a11y__row--wrap {
	flex-wrap: wrap;
}

.upb-a11y__btn {
	min-height: 40px;
	padding: 8px 12px;
	border: 2px solid var(--upb-a11y-ink);
	border-radius: 8px;
	background: #fff;
	color: var(--upb-a11y-ink);
	font: inherit;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
}

.upb-a11y__btn:hover:not(:disabled, [aria-pressed="true"]) {
	background: #f3f3f3;
}

.upb-a11y__btn:disabled {
	border-color: #757575;
	color: #757575;
	cursor: not-allowed;
}

.upb-a11y__btn[aria-pressed="true"] {
	background: var(--upb-a11y-ink);
	color: #fff;
}

.upb-a11y__btn--square {
	width: 48px;
	padding: 8px 0;
	font-size: 16px;
}

.upb-a11y__btn--grow {
	flex: 1 1 auto;
}

.upb-a11y__value {
	flex: 1 1 auto;
	font-size: 16px;
	font-weight: 700;
	text-align: center;
}

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

.upb-a11y__segmented .upb-a11y__btn {
	padding: 8px 4px;
}

.upb-a11y__check {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-top: 10px;
	font-size: 14px;
	cursor: pointer;
}

.upb-a11y__check input {
	width: 18px;
	height: 18px;
	margin: 0;
	accent-color: var(--upb-a11y-ink);
}

.upb-a11y__status {
	margin: 8px 0 0;
	font-size: 13px;
	color: #4a4a4a;
}

.upb-a11y__status:empty {
	display: none;
}

.upb-a11y__reset {
	width: 100%;
	margin-top: 4px;
	padding: 10px;
	border: 0;
	border-radius: 8px;
	background: var(--upb-a11y-brand);
	color: var(--upb-a11y-ink);
	font: inherit;
	font-size: 14px;
	font-weight: 700;
	cursor: pointer;
}

.upb-a11y__reset:hover {
	background: #a9bf00;
}

.upb-a11y :focus-visible {
	outline: 3px solid #0b57d0;
	outline-offset: 2px;
}

@media (max-width: 640px) {
	.upb-a11y {
		left: 16px;
		bottom: calc(16px + env(safe-area-inset-bottom));
	}

	.upb-a11y__toggle {
		width: 48px;
		height: 48px;
	}

	.upb-a11y__panel {
		bottom: 60px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.upb-a11y__toggle {
		transition: none;
	}
}


/* Bloque que se está leyendo en voz alta. */
.upb-a11y-leyendo {
	outline: 3px solid #c0d901 !important;
	outline-offset: 4px !important;
	background-color: rgb(192 217 1 / 18%) !important;
}


/* =====================================================================
 * Ajustes que se aplican sobre el sitio (texto agrandado y alto contraste)
 *
 * Van dentro de la capa "upb-a11y", que se declara en el <head> antes que
 * las del tema (ver upb-accesibilidad.php). El tema usa utilidades de
 * Tailwind con "!" (p. ej. text-white!), que viven en una capa: en CSS un
 * !important dentro de una capa le gana a uno sin capa, y entre capas gana
 * la declarada primero. Por eso estas reglas tienen que estar en la primera.
 * ===================================================================== */
@layer upb-a11y {
	/* Texto agrandado: los textos largos sin espacios (emails, URLs) se cortan en
	 * vez de desbordar la página horizontalmente (WCAG 1.4.10 Reflow). */
	html[data-upb-texto="grande"] body :is(a, span, p, li, td, th, dd, h1, h2, h3, h4, h5, h6):not(.upb-a11y *) {
		overflow-wrap: anywhere !important;
	}

	/* -----------------------------------------------------------------
	 * Modos de alto contraste
	 *
	 * Combinaciones que superan WCAG 2.2 AAA (1.4.6, 7:1):
	 *   - claro:  #000 sobre #fff = 21:1, enlaces #0000cc sobre #fff = 12.6:1
	 *   - oscuro: #fff sobre #000 = 21:1, enlaces #ffff00 sobre #000 = 19.6:1
	 *
	 * Los contenedores quedan transparentes y el fondo sólido se pone sólo
	 * detrás del texto (elementos marcados con data-upb-txt por el JS). Así el
	 * texto que está sobre una foto se lee bien sin tapar la foto con un
	 * bloque blanco/negro. Se quitan sombras, degradés e imágenes de fondo CSS;
	 * las <img> y videos se mantienen.
	 * ----------------------------------------------------------------- */
	html[data-upb-contraste] body *:not(.upb-a11y, .upb-a11y *) {
		background-color: transparent !important;
		background-image: none !important;
		text-shadow: none !important;
		box-shadow: none !important;
	}

	html[data-upb-contraste="claro"] body,
	html[data-upb-contraste="claro"] body *:not(.upb-a11y, .upb-a11y *) {
		color: #000 !important;
		-webkit-text-fill-color: #000 !important;
		border-color: #000 !important;
	}

	html[data-upb-contraste="oscuro"] body,
	html[data-upb-contraste="oscuro"] body *:not(.upb-a11y, .upb-a11y *) {
		color: #fff !important;
		-webkit-text-fill-color: #fff !important;
		border-color: #fff !important;
	}

	html[data-upb-contraste="claro"] body {
		background-color: #fff !important;
		background-image: none !important;
	}

	html[data-upb-contraste="oscuro"] body {
		background-color: #000 !important;
		background-image: none !important;
	}

	/* Fondo sólido detrás del texto, de los campos y de lo que flota (fixed/sticky). */
	html[data-upb-contraste="claro"] body :is([data-upb-txt], [data-upb-solid], input, select, textarea):not(.upb-a11y *) {
		background-color: #fff !important;
	}

	html[data-upb-contraste="oscuro"] body :is([data-upb-txt], [data-upb-solid], input, select, textarea):not(.upb-a11y *) {
		background-color: #000 !important;
	}

	/* Logos oscuros sobre fondo transparente: se invierten para que se vean sobre negro. */
	html[data-upb-contraste="oscuro"] body :is(.by40q-logo, .custom-logo, .by40q-floating-button img) {
		filter: invert(1) !important;
	}

	/* Logo blanco del footer: en modo claro se le pone fondo oscuro detrás (conserva sus colores). */
	html[data-upb-contraste="claro"] body img.by40q-footer-logo {
		background-color: #1d1d1b !important;
		padding: 8px;
	}

	/* Enlaces: color de alto contraste y siempre subrayados (WCAG 1.4.1). */
	html[data-upb-contraste="claro"] body a:not(.upb-a11y *),
	html[data-upb-contraste="claro"] body a *:not(.upb-a11y *) {
		color: #0000cc !important;
		-webkit-text-fill-color: #0000cc !important;
	}

	html[data-upb-contraste="oscuro"] body a:not(.upb-a11y *),
	html[data-upb-contraste="oscuro"] body a *:not(.upb-a11y *) {
		color: #ff0 !important;
		-webkit-text-fill-color: #ff0 !important;
	}

	html[data-upb-contraste] body a:not(.upb-a11y *) {
		text-decoration: underline !important;
		text-underline-offset: 0.15em;
	}

	/* Botones y campos: borde visible aunque hayan perdido su color de fondo (WCAG 1.4.11). */
	html[data-upb-contraste] body :is(button, [role="button"], .wp-block-button__link, .by40q-btn, .by40q-floating-button, input, select, textarea):not(.upb-a11y *) {
		outline: 2px solid currentColor !important;
		outline-offset: -2px;
	}

	/* Foco muy visible (WCAG 2.4.7 / 2.4.13). */
	html[data-upb-contraste="claro"] body :focus-visible:not(.upb-a11y *) {
		outline: 3px solid #0000cc !important;
		outline-offset: 3px !important;
	}

	html[data-upb-contraste="oscuro"] body :focus-visible:not(.upb-a11y *) {
		outline: 3px solid #ff0 !important;
		outline-offset: 3px !important;
	}

	html[data-upb-contraste] body .upb-a11y-leyendo {
		outline: 3px solid currentColor !important;
	}
}
