/**
 * Checkout en 3 pasos: timeline, visibilidad por paso, resumen y navegación.
 *
 * Colores y radios salen de la paleta y los tokens del tema activo
 * (var(--wp--preset--color--*), --wp--custom--radius--*), con un respaldo para
 * temas que no los definan.
 *
 * @package FlatWooCommerce
 */

.flat-wc-checkout-steps,
.wp-block-woocommerce-checkout[data-flat-wc-step] {
	--fwc-accent: var(--wp--preset--color--bg-accent, #e30613);
	--fwc-ink: var(--wp--preset--color--bg-inverse, #111);
	--fwc-muted: var(--wp--preset--color--text-support, #666);
	--fwc-line: var(--wp--preset--color--border-muted, #ddd);
	--fwc-radius: var(--wp--custom--radius--m, 8px);
}

/* -------------------------------------------------------------------------
 * Visibilidad por paso
 *
 * Solo se ocultan hijos del formulario que son bloques (`wp-block-*`): los
 * contenedores sin clase que mete WooCommerce (avisos...) se ven siempre.
 * Un bloque de extensión desconocido cae en el paso 3, junto al botón que
 * valida el formulario entero.
 * ---------------------------------------------------------------------- */

.wp-block-woocommerce-checkout[data-flat-wc-step="1"]
	.wc-block-checkout__form
	> [class*="wp-block-"]:not(.wp-block-woocommerce-checkout-contact-information-block) {
	display: none !important;
}

.wp-block-woocommerce-checkout[data-flat-wc-step="2"]
	.wc-block-checkout__form
	> [class*="wp-block-"]:not(
		.wp-block-woocommerce-checkout-shipping-method-block,
		.wp-block-woocommerce-checkout-pickup-options-block,
		.wp-block-woocommerce-checkout-shipping-address-block,
		.wp-block-woocommerce-checkout-billing-address-block,
		.wp-block-woocommerce-checkout-shipping-methods-block
	) {
	display: none !important;
}

.wp-block-woocommerce-checkout[data-flat-wc-step="3"]
	.wc-block-checkout__form
	> :is(
		.wp-block-woocommerce-checkout-contact-information-block,
		.wp-block-woocommerce-checkout-shipping-method-block,
		.wp-block-woocommerce-checkout-pickup-options-block,
		.wp-block-woocommerce-checkout-shipping-address-block,
		.wp-block-woocommerce-checkout-billing-address-block,
		.wp-block-woocommerce-checkout-shipping-methods-block
	) {
	display: none !important;
}

/* -------------------------------------------------------------------------
 * Pago exprés (Apple Pay / Google Pay)
 *
 * Solo en el paso 3, bajo la casilla de términos: el contenedor es el primer
 * hijo del formulario, así que se reordena con flex.
 * ---------------------------------------------------------------------- */

.wp-block-woocommerce-checkout[data-flat-wc-step="3"] .wc-block-checkout__form {
	display: flex;
	flex-direction: column;
}

.wp-block-woocommerce-checkout[data-flat-wc-step="3"] .wc-block-checkout__form > * {
	order: 2;
}

.wp-block-woocommerce-checkout[data-flat-wc-step="3"]
	.wc-block-checkout__form
	> .wp-block-woocommerce-checkout-payment-block {
	order: 0;
}

.wp-block-woocommerce-checkout[data-flat-wc-step="3"]
	.wc-block-checkout__form
	> .flat-wc-wallets {
	order: 1;
}

/* Los iframes de Stripe, bajo la casilla de términos y antes de "Realizar el pedido". */
.wp-block-woocommerce-checkout[data-flat-wc-step="3"]
	.wc-block-checkout__form
	> :has(.wc-block-components-express-payment--checkout) {
	order: 3;
}

/* El contenedor exprés es un `div` sin clase `wp-block-*`: no lo alcanzan las reglas por paso. */
.wp-block-woocommerce-checkout:is([data-flat-wc-step="1"], [data-flat-wc-step="2"])
	.wc-block-checkout__form
	> :has(.wc-block-components-express-payment--checkout) {
	display: none !important;
}

.wp-block-woocommerce-checkout[data-flat-wc-step="3"]
	.wc-block-checkout__form
	> .wp-block-woocommerce-checkout-actions-block {
	order: 4;
}

/* Los radios no llevan `wp-block-*`, así que las reglas de visibilidad por paso no los alcanzan. */
.wp-block-woocommerce-checkout:is([data-flat-wc-step="1"], [data-flat-wc-step="2"]) .flat-wc-wallets {
	display: none;
}

/* -------------------------------------------------------------------------
 * Timeline
 * ---------------------------------------------------------------------- */

.flat-wc-checkout-steps {
	margin: 0 0 2rem;
	scroll-margin-top: 1.5rem;
}

.flat-wc-checkout-steps__list {
	display: flex;
	margin: 0;
	padding: 0;
	list-style: none;
	counter-reset: none;
}

.flat-wc-checkout-steps__item {
	position: relative;
	flex: 1 1 0;
	margin: 0;
	text-align: center;
}

/* Pasos de extensión sin contenido (el JS los enseña cuando su bloque está). */
.flat-wc-checkout-steps__item[hidden] {
	display: none;
}

/* Tramo de línea hacia el paso anterior, detrás del marcador. */
.flat-wc-checkout-steps__item + .flat-wc-checkout-steps__item::before {
	content: "";
	position: absolute;
	top: 1rem;
	right: 50%;
	left: -50%;
	height: 2px;
	background: var(--fwc-line);
	transform: translateY(-50%);
}

.flat-wc-checkout-steps__item.is-active::before,
.flat-wc-checkout-steps__item.is-complete::before {
	background: var(--fwc-accent);
}

.flat-wc-checkout-steps__button {
	position: relative;
	z-index: 1;
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	gap: 0.5rem;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: var(--fwc-muted);
	font: inherit;
	cursor: pointer;

	&:focus-visible {
		outline: 2px solid var(--fwc-accent);
		outline-offset: 4px;
		border-radius: var(--fwc-radius);
	}
}

.flat-wc-checkout-steps__marker {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2rem;
	height: 2rem;
	border: 2px solid var(--fwc-line);
	border-radius: 50%;
	background: #fff;
	color: var(--fwc-muted);
	font-size: 0.875rem;
	font-weight: 700;
	line-height: 1;
}

.flat-wc-checkout-steps__label {
	font-size: 0.875rem;
	line-height: 1.3;
}

.flat-wc-checkout-steps__item.is-active .flat-wc-checkout-steps__button {
	color: var(--fwc-ink);
	cursor: default;
}

.flat-wc-checkout-steps__item.is-active .flat-wc-checkout-steps__marker {
	border-color: var(--fwc-accent);
	background: var(--fwc-accent);
	color: #fff;
}

.flat-wc-checkout-steps__item.is-active .flat-wc-checkout-steps__label {
	font-weight: 700;
}

.flat-wc-checkout-steps__item.is-complete .flat-wc-checkout-steps__button {
	color: var(--fwc-ink);
}

.flat-wc-checkout-steps__item.is-complete .flat-wc-checkout-steps__marker {
	border-color: var(--fwc-accent);
	color: transparent;
	/* Check (✓) en el color de acento. */
	background: #fff
		url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e30613' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E")
		center / 1rem no-repeat;
}

.flat-wc-checkout-steps__item.is-complete
	.flat-wc-checkout-steps__button:hover
	.flat-wc-checkout-steps__label {
	text-decoration: underline;
}

/* -------------------------------------------------------------------------
 * Resumen de pasos anteriores
 * ---------------------------------------------------------------------- */

.flat-wc-checkout-recap {
	margin: 0 0 1.5rem;
	border: 1px solid var(--fwc-line);
	border-radius: var(--fwc-radius);
	background: #fff;
}

.flat-wc-checkout-recap__row {
	display: grid;
	grid-template-columns: 7rem minmax(0, 1fr) auto;
	gap: 1rem;
	align-items: baseline;
	padding: 0.875rem 1rem;
	font-size: 0.875rem;
}

/* En la columna lateral (bajo "Resumen del pedido"): mismo aspecto que las
 * tarjetas de producto del resumen — blanca, sin borde, radio l, 1rem de
 * separación — y columna de etiquetas más estrecha. */
.wc-block-checkout__sidebar .flat-wc-checkout-recap {
	margin: 0 0 1rem;
	border: 0;
	border-radius: var(--wp--custom--radius--l, 12px);
}

.wc-block-checkout__sidebar .flat-wc-checkout-recap__row {
	grid-template-columns: 5.5rem minmax(0, 1fr) auto;
	gap: 0.75rem;
	padding: var(--wp--preset--spacing--40, 1rem);
}

.flat-wc-checkout-recap__row + .flat-wc-checkout-recap__row {
	border-top: 1px solid var(--fwc-line);
}

.flat-wc-checkout-recap__label {
	color: var(--fwc-muted);
}

.flat-wc-checkout-recap__value {
	overflow-wrap: anywhere;
	color: var(--fwc-ink);
}

.flat-wc-checkout-recap__change,
.flat-wc-checkout-nav__back {
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: var(--fwc-ink);
	font: inherit;
	font-size: 0.875rem;
	text-decoration: underline;
	cursor: pointer;

	&:hover {
		color: var(--fwc-accent);
	}

	&:focus-visible {
		outline: 2px solid var(--fwc-accent);
		outline-offset: 2px;
	}
}

/* -------------------------------------------------------------------------
 * Navegación
 * ---------------------------------------------------------------------- */

.flat-wc-checkout-nav {
	margin-top: 1.5rem;
}

/* `.wc-block-components-button` declara su propio `display` y anula el
 * `[hidden]` del navegador. */
.flat-wc-checkout-recap[hidden],
.flat-wc-checkout-nav [hidden] {
	display: none !important;
}

.flat-wc-checkout-nav__message {
	margin: 0 0 1rem;
	color: var(--wp--preset--color--error, #cc1818);
	font-size: 0.875rem;
}

.flat-wc-checkout-nav__actions {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 1rem 1.5rem;
	align-items: center;
	justify-content: space-between;
}

/* Mismo aspecto que "Realizar el pedido": hereda las reglas del tema y de
 * WooCommerce para `.wc-block-components-button.contained`. */
.flat-wc-checkout-nav__next {
	flex: 1 1 16rem;
	min-height: 3rem;
	margin-left: auto;

	&[aria-busy="true"] {
		opacity: 0.6;
		cursor: progress;
	}
}

/* Con el botón de continuar oculto (paso 3), "Volver" queda solo a la izquierda. */
.flat-wc-checkout-nav__back[hidden] + .flat-wc-checkout-nav__next {
	margin-left: 0;
}

@media (max-width: 600px) {
	.flat-wc-checkout-steps__label {
		font-size: 0.75rem;
	}

	.flat-wc-checkout-recap__row,
	.wc-block-checkout__sidebar .flat-wc-checkout-recap__row {
		grid-template-columns: minmax(0, 1fr) auto;
	}

	.flat-wc-checkout-recap__value {
		grid-column: 1 / -1;
		grid-row: 2;
	}

	.flat-wc-checkout-nav__actions {
		flex-direction: column-reverse;
		align-items: stretch;
		text-align: center;
	}

	.flat-wc-checkout-nav__next {
		flex-basis: auto;
		width: 100%;
		margin-left: 0;
	}
}

/* -------------------------------------------------------------------------
 * Apple Pay / Google Pay como radios (checkout-wallet-options.js)
 *
 * El título y el separador nativos sobran; de los iframes de Stripe solo se ve
 * el del wallet elegido, y sin ninguno elegido no se ve ninguno.
 * ---------------------------------------------------------------------- */

.wc-block-components-express-payment--checkout .wc-block-components-express-payment__title-container,
.wc-block-components-express-payment--checkout .wc-block-components-express-payment-continue-rule {
	display: none;
}

.wc-block-components-express-payment--checkout .wc-block-components-express-payment__event-buttons > li {
	display: none;
}

.wc-block-components-express-payment--checkout[data-wallet="applePay"]
	#express-payment-method-express_checkout_element_applePay,
.wc-block-components-express-payment--checkout[data-wallet="googlePay"]
	#express-payment-method-express_checkout_element_googlePay {
	display: block;
}

.wc-block-components-express-payment--checkout.is-terms-pending
	.wc-block-components-express-payment__content {
	opacity: 0.5;
	pointer-events: none;
}

.flat-wc-wallets {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	margin-bottom: 0.75rem;
}

/* Con un wallet elegido paga su botón, no "Realizar el pedido". */
.flat-wc-wallet-selected .wc-block-components-checkout-place-order-button {
	display: none;
}

/* Con un wallet elegido, los métodos de pago normales se pintan sin marcar y sin su panel. */
.flat-wc-wallet-selected .wc-block-checkout__payment-method .wc-block-components-radio-control-accordion-content {
	display: none;
}

.flat-wc-wallet-selected .wc-block-checkout__payment-method .wc-block-components-radio-control__input:checked::before {
	display: none;
}

.flat-wc-wallet-selected .wc-block-checkout__payment-method .wc-block-components-radio-control__input:checked {
	border-color: var(--fwc-line, #ddd);
}

/* Texto solo para lectores de pantalla (región de estado de los wallets). */
.flat-wc-wallets__status {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}
