/* ══ La ventana de campaña ════════════════════════════════════════════════════
   inc/modules/coupon-ventana*.php · js/modules/ventana-campana.js

   Hoja aparte y no en style.css: se carga solo en la página donde la
   ventana sale. Una tienda que no la enciende no descarga ni un byte.

   La foto de la campaña llena la caja y encima va una losa con el
   descuento, el código y el botón. Todo recto y sin sombra. Lo único
   redondo es el aspa.

   LA PIEL ES DE CADA TIENDA. Lo de aquí es neutro: losa opaca con el
   fondo de la web, velo con poco desenfoque, filetes con el borde de la
   web. Una tienda la viste dándole valores a las variables `--sgf-emg-*`
   sobre `.sgf-emg`, en su hoja (Le Toy Factory: cristal; css/
   ventana-campana.css del hijo). No hace falta pisar ningún selector.

   Capas: por encima de la cabecera y los cajones la ventana centrada; la
   tarjeta, entre las cookies (900) y los avisos (950). */

.sgf-emg {
	--sgf-emg-margen: var(--sgf-gutter, 24px);
	--sgf-emg-velo: color-mix(in srgb, var(--sgf-color-text) 30%, transparent);
	--sgf-emg-velo-filtro: blur(8px);
	--sgf-emg-cristal: var(--sgf-color-bg);
	--sgf-emg-cristal-filtro: none;
	--sgf-emg-cristal-borde: none;
	--sgf-emg-aspa-fondo: var(--sgf-color-bg);
	--sgf-emg-aspa-filtro: none;
	--sgf-emg-aspa-borde: none;
	--sgf-emg-tarjeta-fondo: var(--sgf-color-bg);
	--sgf-emg-tarjeta-filtro: none;
	--sgf-emg-tarjeta-borde: inset 0 0 0 1px var(--sgf-color-border);
	--sgf-emg-filete: var(--sgf-color-border);
	--sgf-emg-rotulo: var(--sgf-label-transform, none);
	--sgf-emg-rotulo-aire: var(--sgf-label-tracking, normal);
	--sgf-emg-sin-foto-fondo: var(--sgf-emg-cristal);
}

.sgf-emg[hidden] { display: none; }

/* ── Formato «ventana» ──────────────────────────────────────────────────── */
.sgf-emg--ventana {
	position: fixed;
	inset: 0;
	z-index: calc(var(--sgf-z-nav, 1000) + 20);
	display: grid;
	place-items: center;
	padding: var(--sgf-emg-margen);
}
.sgf-emg__velo {
	position: absolute;
	inset: 0;
	background: var(--sgf-emg-velo);
	-webkit-backdrop-filter: var(--sgf-emg-velo-filtro);
	backdrop-filter: var(--sgf-emg-velo-filtro);
	opacity: 0;
	transition: opacity .6s var(--sgf-ease-out);
}
.sgf-emg.is-open .sgf-emg__velo { opacity: 1; }

.sgf-emg--ventana .sgf-emg__caja {
	position: relative;
	width: min(440px, 100%);
	aspect-ratio: 3 / 4.3;
	max-height: calc(100dvh - 2 * var(--sgf-emg-margen));
	overflow: hidden;
	background: var(--sgf-color-bg-alt); /* el gris de los marcos de foto, por si la foto tarda */
	opacity: 0;
	transform: translateY(24px);
	transition: opacity .5s var(--sgf-ease-out), transform .8s var(--sgf-ease-out);
}
.sgf-emg--ventana.is-open .sgf-emg__caja { opacity: 1; transform: none; }
.sgf-emg__caja:focus { outline: none; }

/* La foto: llena la caja y se asienta despacio mientras la ventana entra. */
.sgf-emg--ventana .sgf-emg__foto { position: absolute; inset: 0; }
.sgf-emg__foto img { display: block; width: 100%; height: 100%; object-fit: cover; }
.sgf-emg--ventana .sgf-emg__foto img {
	object-position: 50% 20%;
	transform: scale(1.08);
	transition: transform 2.4s var(--sgf-ease-out);
}
.sgf-emg--ventana.is-open .sgf-emg__foto img { transform: scale(1); }

/* El aspa. */
.sgf-emg__cerrar {
	all: unset;
	box-sizing: border-box;
	position: absolute;
	top: 12px;
	right: 12px;
	z-index: 2;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	display: grid;
	place-items: center;
	cursor: pointer;
	font-size: 16px;
	line-height: 1;
	color: var(--sgf-color-text);
	background: var(--sgf-emg-aspa-fondo);
	-webkit-backdrop-filter: var(--sgf-emg-aspa-filtro);
	backdrop-filter: var(--sgf-emg-aspa-filtro);
	box-shadow: var(--sgf-emg-aspa-borde);
	transition: transform .6s var(--sgf-ease-out);
}
.sgf-emg__cerrar:hover { transform: rotate(90deg); }
.sgf-emg__cerrar:focus-visible { outline: 2px solid var(--sgf-color-text); outline-offset: 2px; }

/* La losa. Entra un poco después que la caja, desde abajo. */
.sgf-emg--ventana .sgf-emg__losa {
	position: absolute;
	left: 12px;
	right: 12px;
	bottom: 12px;
	z-index: 1;
	padding: 20px 20px 16px;
	color: var(--sgf-color-text);
	background: var(--sgf-emg-cristal);
	-webkit-backdrop-filter: var(--sgf-emg-cristal-filtro);
	backdrop-filter: var(--sgf-emg-cristal-filtro);
	box-shadow: var(--sgf-emg-cristal-borde);
	opacity: 0;
	transform: translateY(20px);
	transition: opacity .6s var(--sgf-ease-out) .25s, transform .9s var(--sgf-ease-out) .25s;
}
.sgf-emg--ventana.is-open .sgf-emg__losa { opacity: 1; transform: none; }

.sgf-emg__ante {
	margin: 0;
	font-size: 12px;
	line-height: 1.3;
	letter-spacing: var(--sgf-emg-rotulo-aire);
	text-transform: var(--sgf-emg-rotulo);
	color: var(--sgf-color-text);
}
/* El descuento es lo único grande de la ventana, y a propósito. */
.sgf-emg__titulo {
	margin: 10px 0 0;
	font-size: clamp(40px, 12vw, 56px);
	line-height: .95;
	font-weight: 400;
	letter-spacing: -.03em;
}
.sgf-emg__texto {
	margin: 10px 0 0;
	font-size: 14px;
	line-height: 1.45;
	color: var(--sgf-color-text);
}

/* El código, entre dos filetes, con «Copiar» a la derecha. */
.sgf-emg__codigo {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	margin: 16px 0 0;
	padding: 12px 0;
	border-block: 1px solid var(--sgf-emg-filete);
	font-size: 12px;
	line-height: 1.3;
	text-transform: uppercase;
}
.sgf-emg__clave { letter-spacing: .14em; user-select: all; }
.sgf-emg__copiar,
.sgf-emg__no {
	all: unset;
	cursor: pointer;
	font-size: 12px;
	line-height: 1.3;
	letter-spacing: var(--sgf-emg-rotulo-aire);
	text-transform: var(--sgf-emg-rotulo);
	padding-bottom: 2px;
	background: linear-gradient(currentColor, currentColor) 0 100% / 100% 1px no-repeat;
	transition: background-size .6s var(--sgf-ease-out);
}
.sgf-emg__copiar:hover,
.sgf-emg__no:hover { background-size: 0 1px; background-position: 100% 100%; }
.sgf-emg__copiar:focus-visible,
.sgf-emg__no:focus-visible { outline: 2px solid var(--sgf-color-text); outline-offset: 3px; }

.sgf-emg__acciones {
	display: flex;
	align-items: center;
	gap: 20px;
	margin-top: 16px;
}
/* El botón: en tinta; al pasar, se aclara. */
.sgf-emg__ir {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	height: 48px;
	padding: 0 20px;
	background: var(--sgf-color-text);
	color: var(--sgf-color-bg);
	font-size: 12px;
	line-height: 1;
	letter-spacing: var(--sgf-emg-rotulo-aire);
	text-transform: var(--sgf-emg-rotulo);
	text-decoration: none;
	transition: opacity .3s var(--sgf-ease-out);
}
.sgf-emg__ir:hover { opacity: .8; color: var(--sgf-color-bg); }
.sgf-emg__ir:focus-visible { outline: 2px solid var(--sgf-color-text); outline-offset: 3px; }

/* Sin foto, la losa es la ventana. Solo en una tienda que la pide así
   (filtro `sgf_emergente_sin_foto`); en las demás, sin foto no hay ventana. */
.sgf-emg--ventana.sgf-emg--sin-foto .sgf-emg__caja { aspect-ratio: auto; background: none; overflow: visible; }
.sgf-emg--ventana.sgf-emg--sin-foto .sgf-emg__losa { position: relative; inset: auto; padding-top: 48px; background: var(--sgf-emg-sin-foto-fondo); }

/* Con la ventana centrada abierta, la página no se desliza por detrás. En
   el body y no en <html>: así la cabecera sticky no se va (el porqué, en
   _filters.scss, 12 nov 2026). */
html.sgf-emg-abierta body { overflow: hidden; }

/* ── Formato «tarjeta» ──────────────────────────────────────────────────────
   En la esquina, sin velo: la foto en pequeño a la izquierda y la losa
   como tarjeta entera. */
.sgf-emg--tarjeta {
	position: fixed;
	z-index: calc(var(--sgf-z-modal, 900) + 40);
	right: var(--sgf-emg-margen);
	bottom: calc(24px + var(--sgf-cookies-alto, 0px) + env(safe-area-inset-bottom, 0px));
	width: min(380px, calc(100vw - 2 * var(--sgf-emg-margen)));
}
.sgf-emg--tarjeta .sgf-emg__caja {
	position: relative;
	display: grid;
	grid-template-columns: 96px minmax(0, 1fr);
	color: var(--sgf-color-text);
	background: var(--sgf-emg-tarjeta-fondo);
	-webkit-backdrop-filter: var(--sgf-emg-tarjeta-filtro);
	backdrop-filter: var(--sgf-emg-tarjeta-filtro);
	box-shadow: var(--sgf-emg-tarjeta-borde);
	opacity: 0;
	transform: translateY(16px);
	transition: opacity .5s var(--sgf-ease-out), transform .8s var(--sgf-ease-out);
}
.sgf-emg--tarjeta.is-open .sgf-emg__caja { opacity: 1; transform: none; }
.sgf-emg--tarjeta.sgf-emg--sin-foto .sgf-emg__caja { grid-template-columns: minmax(0, 1fr); }
.sgf-emg--tarjeta .sgf-emg__foto { min-height: 100%; background: var(--sgf-color-bg-alt); }
.sgf-emg--tarjeta .sgf-emg__foto img { object-position: 50% 20%; }
.sgf-emg--tarjeta .sgf-emg__losa { padding: 16px 44px 14px 16px; }
.sgf-emg--tarjeta .sgf-emg__ante { color: var(--sgf-color-muted); }
.sgf-emg--tarjeta .sgf-emg__titulo { margin-top: 6px; font-size: 28px; line-height: 1; letter-spacing: -.02em; }
.sgf-emg--tarjeta .sgf-emg__texto { margin-top: 6px; font-size: 13px; color: var(--sgf-color-muted); }
.sgf-emg--tarjeta .sgf-emg__codigo { margin-top: 12px; padding: 10px 0; }
.sgf-emg--tarjeta .sgf-emg__acciones { margin-top: 12px; }
/* Aquí el botón es un enlace: una tarjeta pequeña no lleva un bloque en tinta. */
.sgf-emg--tarjeta .sgf-emg__ir {
	flex: none;
	height: auto;
	padding: 0 0 2px;
	background: linear-gradient(currentColor, currentColor) 0 100% / 100% 1px no-repeat;
	color: var(--sgf-color-text);
	transition: background-size .6s var(--sgf-ease-out);
}
.sgf-emg--tarjeta .sgf-emg__ir:hover { letter-spacing: var(--sgf-emg-rotulo-aire); color: var(--sgf-color-text); background-size: 0 1px; background-position: 100% 100%; }
/* «Ahora no» sobra: ya está el aspa. Se oculta por formato y no por falta
   de dato: el marcado es el mismo en los dos (heredado de Le Toy). */
.sgf-emg--tarjeta .sgf-emg__no { display: none; }
.sgf-emg--tarjeta .sgf-emg__cerrar {
	top: 8px;
	right: 8px;
	background: none;
	-webkit-backdrop-filter: none;
	backdrop-filter: none;
	box-shadow: none;
}

/* ── Móvil ──────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
	/* La ventana, como hoja pegada abajo: foto arriba, losa encima de ella. */
	.sgf-emg--ventana { place-items: end center; padding: 0; }
	.sgf-emg--ventana .sgf-emg__caja {
		width: 100%;
		aspect-ratio: auto;
		height: min(82dvh, 620px);
		max-height: none;
		transform: translateY(40px);
	}
	.sgf-emg--ventana .sgf-emg__losa {
		left: 8px;
		right: 8px;
		bottom: calc(8px + env(safe-area-inset-bottom, 0px));
		padding: 18px 16px 14px;
	}
	.sgf-emg--tarjeta { right: var(--sgf-emg-margen); bottom: calc(16px + var(--sgf-cookies-alto, 0px) + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
	.sgf-emg__velo,
	.sgf-emg .sgf-emg__caja,
	.sgf-emg .sgf-emg__losa,
	.sgf-emg .sgf-emg__foto img,
	.sgf-emg__cerrar,
	.sgf-emg__ir,
	.sgf-emg__copiar,
	.sgf-emg__no { transition: none; }
	.sgf-emg--ventana .sgf-emg__foto img { transform: none; }
}
