/**
 * Vibe Cookie Consent — banner.css
 *
 * Estilos del banner y modal de cookies RGPD/LSSI-CE.
 *
 * Usa variables CSS del tema activo cuando están disponibles.
 * Los fallbacks garantizan un aspecto funcional si el tema no las define.
 *
 * WCAG 2.2 AA:
 *   - Contraste de texto mínimo 4.5:1
 *   - Target size mínimo 44x44 px
 *   - Focus visible con outline 2px
 *   - prefers-reduced-motion: sin animaciones
 *
 * Convención BEM: .vibe-cookie-banner, .vibe-cookie-modal
 */

/* -------------------------------------------------------------------------
   Variables de fallback
   Sobreescribir desde el tema con las variables del design system del proyecto.
   ------------------------------------------------------------------------- */

.vibe-cookie-banner,
.vibe-cookie-modal {
	--vcc-bg:            var(--color-surface, #1a1a2e);
	--vcc-border:        var(--color-primary, #4f46e5);
	--vcc-text:          var(--color-ink, #f0ede6);
	--vcc-text-muted:    var(--color-ink-soft, #a0a0b0);
	--vcc-accent:        var(--color-primary, #4f46e5);
	--vcc-accent-hover:  var(--color-accent, #4338ca);
	--vcc-white:         #ffffff;
	--vcc-focus:         var(--color-primary, #4f46e5);
	--vcc-toggle-off:    #4a4a5a;
	--vcc-toggle-on:     var(--color-primary, #4f46e5);
	--vcc-radius:        var(--radius-sm, 4px);
	--vcc-transition:    200ms ease;
}

/* -------------------------------------------------------------------------
   Respetar [hidden] — debe estar antes de los display: flex/block
   Sin esto el banner se renderiza visible antes de que cargue el JS.
   ------------------------------------------------------------------------- */

.vibe-cookie-banner[hidden],
.vibe-cookie-modal[hidden] {
	display: none;
}

/* -------------------------------------------------------------------------
   Visually hidden (screen reader only)
   ------------------------------------------------------------------------- */

.vibe-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border-width: 0;
}

/* -------------------------------------------------------------------------
   Banner principal (fixed bottom)
   ------------------------------------------------------------------------- */

.vibe-cookie-banner {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 9998;
	background-color: var(--vcc-bg);
	border-top: 2px solid var(--vcc-border);
	padding: 1rem 1.5rem;
	box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

.vibe-cookie-banner__inner {
	display: flex;
	align-items: center;
	gap: 1.5rem;
	flex-wrap: wrap;
	max-width: 1200px;
	margin: 0 auto;
}

.vibe-cookie-banner__text {
	flex: 1 1 320px;
	color: var(--vcc-text);
	font-size: 0.9rem;
	line-height: 1.6;
	margin: 0;
}

.vibe-cookie-banner__text a,
.vibe-cookie-banner__link {
	color: var(--vcc-accent);
	text-decoration: underline;
	text-underline-offset: 2px;
	background: none;
	border: none;
	padding: 0;
	cursor: pointer;
	font-size: inherit;
	font-family: inherit;
}

.vibe-cookie-banner__text a:hover,
.vibe-cookie-banner__link:hover {
	text-decoration: none;
}

.vibe-cookie-banner__text a:focus-visible,
.vibe-cookie-banner__link:focus-visible {
	outline: 2px solid var(--vcc-focus);
	outline-offset: 2px;
	border-radius: 2px;
}

.vibe-cookie-banner__actions {
	display: flex;
	gap: 0.75rem;
	flex-shrink: 0;
	flex-wrap: wrap;
	align-items: center;
}

.vibe-cookie-banner__btn {
	min-height: 44px;
	padding: 0.625rem 1.25rem;
	white-space: nowrap;
}

/* -------------------------------------------------------------------------
   Botones base (si el tema no tiene .vibe-btn)
   El tema puede sobreescribir con sus propios .vibe-btn styles.
   ------------------------------------------------------------------------- */

.vibe-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--vcc-radius);
	font-size: 0.9rem;
	font-weight: 600;
	cursor: pointer;
	transition: background-color var(--vcc-transition), color var(--vcc-transition), border-color var(--vcc-transition);
	text-decoration: none;
}

.vibe-btn--primary {
	background-color: var(--vcc-accent);
	color: var(--vcc-white);
	border: 2px solid var(--vcc-accent);
}

.vibe-btn--primary:hover {
	background-color: var(--vcc-accent-hover);
	border-color: var(--vcc-accent-hover);
}

.vibe-btn--primary:focus-visible {
	outline: 2px solid var(--vcc-focus);
	outline-offset: 2px;
}

/* Rechazar y aceptar comparten peso visual A PROPÓSITO: la AEPD exige que
   rechazar sea tan fácil como aceptar, y una diferencia fuerte de contraste
   entre ambos botones se lee como patrón oscuro.
   El borde era rgba(255,255,255,.25), válido solo si el banner es oscuro. Con
   --color-surface claro (el caso habitual de los temas del studio) el botón se
   volvía invisible y quedaba como un texto suelto frente a un botón relleno.
   No volver a usar colores literales aquí: derivar de los tokens. */
.vibe-btn--ghost {
	background-color: transparent;
	color: var(--vcc-accent);
	border: 2px solid var(--vcc-accent);
}

.vibe-btn--ghost:hover {
	background-color: color-mix(in srgb, var(--vcc-accent) 10%, transparent);
	border-color: var(--vcc-accent-hover);
	color: var(--vcc-accent-hover);
}

.vibe-btn--ghost:focus-visible {
	outline: 2px solid var(--vcc-focus);
	outline-offset: 2px;
}

/* -------------------------------------------------------------------------
   Modal de configuración
   ------------------------------------------------------------------------- */

.vibe-cookie-modal {
	position: fixed;
	inset: 0;
	z-index: 9999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1rem;
}

.vibe-cookie-modal__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.72);
	backdrop-filter: blur(2px);
}

.vibe-cookie-modal__panel {
	position: relative;
	z-index: 1;
	background-color: var(--vcc-bg);
	border: 1px solid var(--vcc-border);
	border-radius: var(--vcc-radius);
	width: 100%;
	max-width: 560px;
	max-height: 90vh;
	overflow-y: auto;
	box-shadow: 0 8px 48px rgba(0, 0, 0, 0.55);
}

.vibe-cookie-modal__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 1.5rem 1.5rem 0;
	gap: 1rem;
}

.vibe-cookie-modal__title {
	color: var(--vcc-text);
	font-size: 1.25rem;
	font-weight: 600;
	margin: 0;
}

.vibe-cookie-modal__close {
	background: none;
	border: 1px solid transparent;
	color: var(--vcc-text);
	font-size: 1.5rem;
	cursor: pointer;
	width: 44px;
	height: 44px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--vcc-radius);
	flex-shrink: 0;
	transition: border-color var(--vcc-transition), background-color var(--vcc-transition);
}

.vibe-cookie-modal__close:hover {
	border-color: var(--vcc-border);
	background-color: rgba(79, 70, 229, 0.1);
}

.vibe-cookie-modal__close:focus-visible {
	outline: 2px solid var(--vcc-focus);
	outline-offset: 2px;
}

.vibe-cookie-modal__desc {
	color: var(--vcc-text-muted);
	font-size: 0.875rem;
	line-height: 1.6;
	padding: 1rem 1.5rem 0;
	margin: 0;
}

/* -------------------------------------------------------------------------
   Grupos de cookies en el modal
   ------------------------------------------------------------------------- */

.vibe-cookie-modal__groups {
	padding: 0.5rem 1.5rem 0;
	display: flex;
	flex-direction: column;
}

.vibe-cookie-modal__group {
	padding: 1.125rem 0;
	border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.vibe-cookie-modal__group:last-child {
	border-bottom: none;
}

.vibe-cookie-modal__group-header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1.25rem;
}

.vibe-cookie-modal__group-info {
	flex: 1;
}

.vibe-cookie-modal__group-title {
	color: var(--vcc-text);
	font-size: 0.95rem;
	font-weight: 600;
	margin: 0 0 0.375rem;
}

.vibe-cookie-modal__group-desc {
	color: var(--vcc-text-muted);
	font-size: 0.8125rem;
	line-height: 1.5;
	margin: 0;
}

.vibe-cookie-modal__toggle-wrap {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	padding-top: 0.1rem;
}

/* Estado "siempre activas" */
.vibe-cookie-modal__toggle--always-on {
	color: var(--vcc-accent);
	font-size: 0.75rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	white-space: nowrap;
}

/* Toggle switch — rol ARIA switch */
.vibe-cookie-modal__toggle--switch {
	position: relative;
	width: 52px;
	height: 28px;
	background-color: var(--vcc-toggle-off);
	border: 2px solid var(--vcc-toggle-off);
	border-radius: 14px;
	cursor: pointer;
	transition: background-color var(--vcc-transition), border-color var(--vcc-transition);
	padding: 0;
	flex-shrink: 0;
}

.vibe-cookie-modal__toggle--switch[aria-checked="true"] {
	background-color: var(--vcc-toggle-on);
	border-color: var(--vcc-toggle-on);
}

.vibe-cookie-modal__toggle-thumb {
	position: absolute;
	top: 2px;
	left: 2px;
	width: 20px;
	height: 20px;
	background-color: var(--vcc-white);
	border-radius: 50%;
	transition: transform var(--vcc-transition);
	pointer-events: none;
}

.vibe-cookie-modal__toggle--switch[aria-checked="true"] .vibe-cookie-modal__toggle-thumb {
	transform: translateX(24px);
}

.vibe-cookie-modal__toggle--switch:focus-visible {
	outline: 2px solid var(--vcc-focus);
	outline-offset: 3px;
}

/* -------------------------------------------------------------------------
   Footer del modal
   ------------------------------------------------------------------------- */

.vibe-cookie-modal__footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 1rem 1.5rem 1.5rem;
	gap: 1rem;
	border-top: 1px solid rgba(255, 255, 255, 0.08);
	flex-wrap: wrap;
}

.vibe-cookie-modal__policy-link {
	color: var(--vcc-text-muted);
	font-size: 0.8125rem;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.vibe-cookie-modal__policy-link:hover {
	color: var(--vcc-accent);
	text-decoration: none;
}

.vibe-cookie-modal__policy-link:focus-visible {
	outline: 2px solid var(--vcc-focus);
	outline-offset: 2px;
	border-radius: 2px;
}

.vibe-cookie-modal__save {
	min-height: 44px;
	padding: 0.625rem 1.5rem;
}

/* -------------------------------------------------------------------------
   Botón de reabrir preferencias en el footer del tema
   Usar: <?php vibe_cookie_preferences_button(); ?>
   ------------------------------------------------------------------------- */

.vibe-cookie-prefs-btn {
	background: none;
	border: none;
	color: var(--vcc-text-muted);
	font-size: 0.8125rem;
	cursor: pointer;
	padding: 0;
	text-decoration: underline;
	text-underline-offset: 2px;
	font-family: inherit;
}

.vibe-cookie-prefs-btn:hover {
	color: var(--vcc-accent);
	text-decoration: none;
}

.vibe-cookie-prefs-btn:focus-visible {
	outline: 2px solid var(--vcc-focus);
	outline-offset: 2px;
	border-radius: 2px;
}

/* -------------------------------------------------------------------------
   prefers-reduced-motion — sin animaciones
   ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.vibe-cookie-banner,
	.vibe-cookie-modal__panel,
	.vibe-cookie-modal__toggle--switch,
	.vibe-cookie-modal__toggle-thumb,
	.vibe-btn {
		transition: none;
	}
}

/* -------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------- */

@media (max-width: 640px) {
	.vibe-cookie-banner__inner {
		flex-direction: column;
		align-items: flex-start;
	}

	/* Obligatorio al pasar a columna: el texto lleva `flex: 1 1 320px` para el
	   layout en fila, y en columna ese flex-basis pasa a aplicarse al ALTO, no
	   al ancho. Sin esto el banner reservaba ~320px de alto para un párrafo de
	   ~110px y dejaba un hueco vacío enorme sobre los botones. */
	.vibe-cookie-banner__text {
		flex: 0 1 auto;
		width: 100%;
	}

	.vibe-cookie-banner__actions {
		width: 100%;
	}

	.vibe-cookie-banner__btn {
		flex: 1;
		text-align: center;
	}

	.vibe-cookie-modal__footer {
		flex-direction: column;
		align-items: flex-start;
	}

	.vibe-cookie-modal__save {
		width: 100%;
		text-align: center;
	}
}
