/**
 * Legally360 — assets/css/motion.css
 *
 * Capa de movimiento global. Fuente de verdad: context/motion-plan.md.
 *   1. Tokens de movimiento
 *   2. Transición entre páginas (View Transitions entre documentos)
 *   3. Entrada del hero en CSS (no espera al JS; GSAP la refina en la portada)
 *   4. Revelados al hacer scroll ([data-reveal], solo con html.motion-ok)
 *   5. Animaciones ligadas al scroll (foto del hero, banda del pie)
 *   6. Microinteracciones (§4 del plan)
 *   7. prefers-reduced-motion
 *
 * Reglas: solo transform y opacity; sin rebotes, sin scale en tarjetas o texto,
 * sin bucles automáticos; sin JS todo queda visible.
 */

/* -------------------------------------------------------------------------
   1. Tokens
   ------------------------------------------------------------------------- */

:root {
	--m-ease-out:      var(--wp--custom--motion--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
	--m-ease-out-expo: var(--wp--custom--motion--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
	--m-ease-in-out:   var(--wp--custom--motion--ease-in-out, cubic-bezier(0.76, 0, 0.24, 1));
	--m-dur-fast:      var(--wp--custom--motion--dur-fast, 180ms);
	--m-dur-base:      var(--wp--custom--motion--dur-base, 240ms);
	--m-dur-slow:      var(--wp--custom--motion--dur-slow, 700ms);
	--m-dur-title:     var(--wp--custom--motion--dur-title, 800ms);
	--m-stagger:       var(--wp--custom--motion--stagger, 80ms);
}

/* -------------------------------------------------------------------------
   2. Transición entre páginas — fundido de 180 ms (Chrome 126+, Safari 18.2+)
   ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
	@view-transition { navigation: auto; }

	/* Salida: fundido corto. Entrada: el documento nuevo sube 14 px mientras aparece. */
	::view-transition-old(root) {
		animation: 160ms var(--m-ease-in-out) both l3-vt-out;
	}
	::view-transition-new(root) {
		animation: 420ms var(--m-ease-out-expo) 60ms both l3-vt-in;
	}
	/* La cabecera no parpadea entre páginas. */
	::view-transition-old(site-header),
	::view-transition-new(site-header) { animation: none; }
}

@keyframes l3-vt-out { to { opacity: 0; } }
@keyframes l3-vt-in  { from { opacity: 0; transform: translateY(14px); } }

/* -------------------------------------------------------------------------
   3. Entrada del hero (H3-H9). Arranca en el primer pintado.
   ------------------------------------------------------------------------- */

@keyframes l3-rise {
	from { opacity: 0; transform: translateY(var(--rise, 10px)); }
	to   { opacity: 1; transform: none; }
}
@keyframes l3-rule {
	from { transform: scaleX(0); }
	to   { transform: scaleX(1); }
}

@media (prefers-reduced-motion: no-preference) {
	.l3-hero__eyebrow::before,
	.l3-page-hero .l3-eyebrow::before {
		transform-origin: left;
		animation: l3-rule 500ms var(--m-ease-out) 100ms both;
	}
	.l3-hero__eyebrow,
	.l3-page-hero .l3-eyebrow {
		--rise: 8px;
		animation: l3-rise 500ms var(--m-ease-out) 150ms both;
	}
	.l3-hero__line,
	.l3-page-hero__title {
		--rise: .45em;
		display: inline-block;
		animation: l3-rise var(--m-dur-title) var(--m-ease-out-expo) 200ms both;
	}
	.l3-hero__line.l3-tone { display: block; animation-delay: 320ms; }
	.l3-hero__lede        { --rise: 12px; animation: l3-rise 600ms var(--m-ease-out) 520ms both; }
	.l3-hero__ctas        { animation: l3-rise 550ms var(--m-ease-out) 600ms both; }
	.l3-hero__trust       { --rise: 8px; animation: l3-rise 500ms var(--m-ease-out) 680ms both; }
	.l3-page-hero__title  { display: block; }

	/* Con GSAP activo, SplitText toma el titular: se quita la animación CSS de las mitades
	   (las líneas parten ya ocultas desde motion-gsap.js, sin salto). */
	html.l3-gsap .l3-hero__line { animation: none; display: inline; }
	html.l3-gsap .l3-hero__line.l3-tone { display: block; }
	html.l3-gsap:not(.l3-gsap-done) .l3-hero__title { visibility: hidden; }
}

/* -------------------------------------------------------------------------
   4. Revelados al hacer scroll — estados ocultos solo bajo html.motion-ok
   ------------------------------------------------------------------------- */

.motion-ok [data-reveal]:not(.is-in),
.motion-ok [data-reveal-group]:not(.is-in) > * {
	opacity: 0;
	transform: translateY(var(--rise, 16px));
}
.motion-ok [data-reveal],
.motion-ok [data-reveal-group] > * {
	transition:
		opacity var(--m-dur-slow) var(--m-ease-out),
		transform var(--m-dur-slow) var(--m-ease-out);
	transition-delay: calc(var(--i, 0) * var(--m-stagger));
}
/* Lo que ya estaba visible al arrancar no se anima (sin parpadeo). */
.motion-ok .is-instant,
.motion-ok .is-instant > * { transition: none !important; }

/* Filete «No incluye» de los planes (H17-H18) */
.motion-ok [data-reveal-group] .l3-plan__out {
	border-top-color: transparent;
	position: relative;
}
.motion-ok [data-reveal-group] .l3-plan__out::before {
	content: "";
	position: absolute;
	inset: -1px 0 auto;
	height: 1px;
	background: var(--color-line);
	transform: scaleX(0);
	transform-origin: left;
	transition: transform 500ms var(--m-ease-out) 420ms;
}
.motion-ok .l3-dark [data-reveal-group] .l3-plan:not(.l3-plan--feat) .l3-plan__out::before { background: rgba(255, 255, 255, .18); }
.motion-ok [data-reveal-group].is-in .l3-plan__out::before { transform: scaleX(1); }

/* -------------------------------------------------------------------------
   5. Ligadas al scroll (mejora progresiva; en Firefox quedan quietas)
   ------------------------------------------------------------------------- */

@keyframes l3-photo-out { to { transform: translateY(-40px); } }
/* Cinta del pie: movimiento continuo; avanza exactamente una copia (de tres) por ciclo. */
@keyframes l3-band-move { from { transform: translateX(0); } to { transform: translateX(calc(-100% / 3 - var(--band-gap) / 3)); } }
@media (prefers-reduced-motion: no-preference) {
	.l3-band__track { animation: l3-band-move 38s linear infinite; }
	.l3-band:hover .l3-band__track,
	.l3-band-wrap.is-paused .l3-band__track { animation-play-state: paused; }
}

@supports ((animation-timeline: view()) and (animation-range: entry)) {
	@media (prefers-reduced-motion: no-preference) {
		@media (min-width: 769px) {
			.l3-hero__media {
				animation: l3-photo-out linear both;
				animation-timeline: view();
				animation-range: exit 0% exit 100%;
			}
		}
	}
}

/* -------------------------------------------------------------------------
   6. Microinteracciones (el foco se trata igual que el hover)
   ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
	.l3-btn--primary {
		transition:
			background-color var(--m-dur-fast) var(--m-ease-out),
			color var(--m-dur-fast) var(--m-ease-out),
			transform var(--m-dur-fast) var(--m-ease-out),
			box-shadow var(--m-dur-fast) var(--m-ease-out);
	}
	.l3-btn--primary:hover,
	.l3-btn--primary:focus-visible {
		transform: translateY(-1px);
		box-shadow: 0 10px 24px -14px rgba(10, 91, 214, .8);
	}
	.l3-btn--primary:active { transform: translateY(0) scale(.98); transition-duration: 80ms; }

	@media (hover: hover) {
		.l3-card--hover:focus-within,
		a.l3-card:focus-visible {
			border-color: var(--color-line-strong);
			box-shadow: var(--shadow-card-hover);
			transform: translateY(-2px);
		}
	}
}

/* -------------------------------------------------------------------------
   6.b Refinado 2026-12-04
   ------------------------------------------------------------------------- */

/* Fotos de cabecera: la imagen se asienta al cargar (es la LCP: visible desde el primer
   pintado, solo cambia de escala). Parallax suave al salir en las cabeceras interiores. */
@keyframes l3-settle { from { transform: scale(1.08); } to { transform: none; } }
@media (prefers-reduced-motion: no-preference) {
	.l3-hero__media img,
	.l3-page-hero__img { animation: l3-settle 1.8s var(--m-ease-out) both; }
}
@supports ((animation-timeline: view()) and (animation-range: entry)) {
	@media (prefers-reduced-motion: no-preference) and (min-width: 769px) {
		.l3-page-hero__media {
			animation: l3-photo-out linear both;
			animation-timeline: view();
			animation-range: exit 0% exit 100%;
		}
	}
}

/* Barra de progreso de lectura (decorativa) */
.l3-progress { display: none; }
@supports (animation-timeline: scroll()) {
	@media (prefers-reduced-motion: no-preference) {
		.l3-progress {
			display: block;
			position: fixed;
			inset: 0 0 auto;
			z-index: 200;
			height: 2px;
			background: linear-gradient(90deg, #0A5BD6, #7FB0FF);
			transform-origin: left;
			transform: scaleX(0);
			pointer-events: none;
			animation: l3-progress linear both;
			animation-timeline: scroll(root block);
		}
	}
}
@keyframes l3-progress { to { transform: scaleX(1); } }
@keyframes l3-pop { from { opacity: 0; translate: 0 16px; } }

/* Antetítulo de sección: el filete se dibuja cuando entra la cabecera */
.motion-ok .l3-head[data-reveal] .l3-eyebrow::before {
	transform-origin: left;
	transition: transform 600ms var(--m-ease-out) 120ms;
}
.motion-ok .l3-head[data-reveal]:not(.is-in) .l3-eyebrow::before { transform: scaleX(0); }

/* Flecha de enlaces y del botón de WhatsApp */
@media (prefers-reduced-motion: no-preference) {
	.l3-link span[aria-hidden],
	.l3-link .l3-arrow { display: inline-block; transition: transform var(--m-dur-fast) var(--m-ease-out); }
	.l3-link:hover span[aria-hidden],
	.l3-link:focus-visible span[aria-hidden] { transform: translateX(3px); }

	/* Botón de WhatsApp: entra una vez tras la carga, sin bucle. */
	.l3-wa { animation: l3-pop 600ms var(--m-ease-out-expo) 1.2s backwards; }

	/* Tarjetas: el icono acompaña al hover/foco */
	@media (hover: hover) {
		.l3-card .l3-ico { transition: transform var(--m-dur-base) var(--m-ease-out), background-color var(--m-dur-base) var(--m-ease-out), color var(--m-dur-base) var(--m-ease-out); }
		.l3-card:hover .l3-ico,
		.l3-card:focus-within .l3-ico { transform: translateY(-2px); background: #0A5BD6; color: #fff; }
	}
}

/* -------------------------------------------------------------------------
   7. prefers-reduced-motion: todo en su estado final desde el primer pintado
   ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: .01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: .01ms !important;
		scroll-behavior: auto !important;
	}
	.l3-hero__media,
	.l3-band__track { animation: none !important; transform: none !important; }
	.motion-ok [data-reveal],
	.motion-ok [data-reveal-group] > * { opacity: 1 !important; transform: none !important; }
}
