/* Homiture Antes y Después — carrusel con comparador.
 * Hereda color, radio y sombra del tema (variables --wp--preset--* / --wp--custom--*)
 * con valores neutros de respaldo. Se puede ajustar sobreescribiendo las variables --hba-*.
 *
 * Estructura: .hba > (.hba__tabs) > .hba__panel > .hba__stage > .hba__slides > .hba__slide > .hba-cmp
 *                                              > .hba__bar (flechas + miniaturas)
 * Por defecto hay UN panel con todos los pares; con pestañas hay un panel por proyecto.
 */
.hba {
	--hba-ink: var(--wp--preset--color--contrast, #1f2a28);
	--hba-muted: var(--wp--preset--color--muted, #6a706d);
	--hba-primary: var(--wp--preset--color--primary, #1f2a28);
	--hba-on-primary: #fff;
	--hba-accent: var(--wp--preset--color--accent, #eba607);
	--hba-panel: #f3eee7;
	--hba-radius: var(--wp--custom--radius--lg, 16px);
	--hba-shadow: var(--shadow-warm, 0 18px 48px rgba(74, 56, 41, 0.18));
	--hba-line: rgba(31, 42, 40, 0.18);
	--hba-aspect: 16 / 10;
	--hba-ratio: 1.6; /* mismo valor que --hba-aspect en número: sirve para limitar el ancho de un marco vertical */
	--hba-maxh: clamp(420px, 76vh, 780px); /* un marco nunca es más alto que la pantalla */
	--hba-pad: clamp(10px, 3.2vw, 32px);

	position: relative;
	width: 100%;
	max-width: var(--hba-max, 1120px);
	margin-inline: auto;
	color: var(--hba-ink);
}

.hba .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.hba [hidden] { display: none !important; }

/* Sin JS solo se ve la primera foto: los controles y el contador no tienen efecto, así que se ocultan. */
.hba:not(.hba--js) .hba__tabs,
.hba:not(.hba--js) .hba__bar,
.hba:not(.hba--js) .hba-cmp__count { display: none; }

/* ---------- Pestañas por proyecto (opcional: hba--tabs) ---------- */
.hba__tabs {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	margin: 0 0 22px;
}

.hba__tab {
	appearance: none;
	display: inline-flex;
	align-items: center;
	gap: 0.55rem;
	margin: 0;
	padding: 0.55rem 1rem;
	font: inherit;
	font-size: 0.9rem;
	font-weight: 500;
	line-height: 1.2;
	color: var(--hba-ink);
	background: transparent;
	border: 1px solid var(--hba-line);
	border-radius: 999px;
	cursor: pointer;
	transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.hba__tab:hover { border-color: var(--hba-primary); }

.hba__tab[aria-selected="true"] {
	color: var(--hba-on-primary);
	background: var(--hba-primary);
	border-color: var(--hba-primary);
}

.hba__tab-count {
	min-width: 1.6em;
	padding: 0.1em 0.5em;
	font-size: 0.72rem;
	font-weight: 600;
	text-align: center;
	background: rgba(31, 42, 40, 0.08);
	border-radius: 999px;
}

.hba__tab[aria-selected="true"] .hba__tab-count { background: rgba(255, 255, 255, 0.24); }

.hba__tab:focus-visible,
.hba__nav:focus-visible,
.hba__thumb:focus-visible {
	outline: 3px solid var(--hba-accent);
	outline-offset: 2px;
}

/* ---------- Datos del proyecto (solo con un proyecto o con pestañas) ---------- */
.hba__meta { margin: 0 0 16px; text-align: center; }
.hba__title { margin: 0 0 0.25rem; font-size: clamp(1.15rem, 2.2vw, 1.4rem); }
.hba__desc { max-width: 62ch; margin: 0.25rem auto 0; color: var(--hba-muted); }
.hba__loc {
	display: inline-block;
	margin-right: 0.6rem;
	font-size: 0.75rem;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--hba-primary);
}
.hba__link {
	display: inline-block;
	margin-top: 0.4rem;
	font-weight: 500;
	color: var(--hba-primary);
	text-decoration: none;
	border-bottom: 1px solid currentColor;
}

/* ---------- Escenario: panel cálido con la propia foto difuminada de fondo ---------- */
.hba__stage {
	position: relative;
	isolation: isolate;
	padding: var(--hba-pad);
	overflow: hidden;
	background: var(--hba-panel);
	border-radius: calc(var(--hba-radius) + 8px);
}

/* Fondo: la foto "después" actual, muy difuminada. Rellena los lados de un marco vertical en pantallas anchas. */
.hba__stage::before {
	content: "";
	position: absolute;
	inset: -40px;
	z-index: -1;
	background: var(--hba-bg, none) center / cover no-repeat;
	filter: blur(28px) saturate(1.2);
	opacity: 0.5;
	transition: opacity 0.3s ease;
	pointer-events: none;
}

/* Velo claro sobre el fondo: evita manchas grises cuando la foto tiene muebles oscuros. */
.hba__stage::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	background: rgba(243, 238, 231, 0.3);
	pointer-events: none;
}

.hba__slides { position: relative; }
.hba__slide { margin: 0; }
.hba__slide.is-entering { animation: hba-in 0.4s ease both; }

.hba__caption {
	display: table;
	margin: 12px auto 0;
	padding: 5px 14px;
	font-size: 0.78rem;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--hba-ink);
	background: rgba(255, 255, 255, 0.78);
	border-radius: 999px;
}

@keyframes hba-in {
	from { opacity: 0; transform: translateX(var(--hba-shift, 0)); }
	to { opacity: 1; transform: none; }
}

/* ---------- Comparador ---------- */
.hba-cmp {
	--pos: 50%;
	position: relative;
	width: min(100%, calc(var(--hba-maxh, 80vh) * var(--hba-ratio, 1.6)));
	margin-inline: auto;
	aspect-ratio: var(--hba-aspect, 16 / 10);
	overflow: hidden;
	border-radius: var(--hba-radius);
	background: #1f2a28;
	box-shadow: var(--hba-shadow);
	cursor: ew-resize;
	user-select: none;
	-webkit-user-select: none;
	touch-action: pan-y; /* el scroll vertical de la página sigue funcionando en móvil */
}

.hba-cmp__img {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	pointer-events: none;
	-webkit-user-drag: none;
}

.hba-cmp__before { clip-path: inset(0 calc(100% - var(--pos)) 0 0); }

.hba-cmp__divider {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--pos);
	width: 2px;
	margin-left: -1px;
	background: #fff;
	box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 0 14px rgba(0, 0, 0, 0.25);
	pointer-events: none;
}

.hba-cmp__handle {
	position: absolute;
	top: 50%;
	left: var(--pos);
	display: flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	margin: -24px 0 0 -24px;
	color: #1f2a28;
	background: #fff;
	border-radius: 50%;
	box-shadow: 0 2px 14px rgba(0, 0, 0, 0.38);
	pointer-events: none;
	transition: transform 0.15s ease;
}

.hba-cmp.is-dragging .hba-cmp__handle { transform: scale(1.1); }
.hba-cmp__handle svg { display: block; width: 22px; height: 22px; }
.hba-cmp__handle:focus-visible { outline: 3px solid var(--hba-accent); outline-offset: 3px; }

/* Pista de que se puede arrastrar: un anillo que late hasta que alguien toca la comparación. */
.hba--js:not(.is-touched) .hba-cmp[data-mode="slider"] .hba-cmp__handle::after {
	content: "";
	position: absolute;
	inset: -5px;
	border: 2px solid rgba(255, 255, 255, 0.9);
	border-radius: 50%;
	animation: hba-pulse 1.9s ease-out infinite;
}

@keyframes hba-pulse {
	0% { opacity: 0.95; transform: scale(0.9); }
	100% { opacity: 0; transform: scale(1.55); }
}

.hba-cmp__tag,
.hba-cmp__count {
	position: absolute;
	padding: 5px 11px;
	font-size: 0.72rem;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: #fff;
	background: rgba(31, 42, 40, 0.55);
	border-radius: 999px;
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
	pointer-events: none;
}

.hba-cmp__tag { bottom: 14px; transition: opacity 0.2s ease; }
.hba-cmp__tag--before { left: 14px; }
.hba-cmp__tag--after { right: 14px; }

/* Contador dentro de la imagen (arriba a la derecha). */
.hba-cmp__count {
	top: 14px;
	right: 14px;
	letter-spacing: 0.06em;
	font-variant-numeric: tabular-nums;
}

/* Con el divisor pegado a un borde, la etiqueta de ese lado sobra. */
.hba-cmp[data-edge="left"] .hba-cmp__tag--before,
.hba-cmp[data-edge="right"] .hba-cmp__tag--after { opacity: 0; }

/* Modo botón */
.hba-cmp[data-mode="toggle"] { cursor: default; }
.hba-cmp[data-mode="toggle"] .hba-cmp__before { clip-path: none; transition: opacity 0.45s ease; }
.hba-cmp[data-mode="toggle"].is-after .hba-cmp__before { opacity: 0; }
.hba-cmp[data-mode="toggle"]:not(.is-after) .hba-cmp__tag--after,
.hba-cmp[data-mode="toggle"].is-after .hba-cmp__tag--before { display: none; }

.hba-cmp__toggle {
	position: absolute;
	bottom: 14px;
	left: 50%;
	transform: translateX(-50%);
	padding: 8px 18px;
	font: inherit;
	font-size: 0.85rem;
	font-weight: 500;
	color: #1f2a28;
	background: #fff;
	border: 0;
	border-radius: 999px;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
	cursor: pointer;
}
.hba-cmp__toggle:focus-visible { outline: 3px solid var(--hba-accent); outline-offset: 2px; }

/* ---------- Barra: flecha · miniaturas · flecha ---------- */
.hba__bar {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
	margin-top: 18px;
}

.hba__mid {
	display: flex;
	flex: 0 1 auto;
	justify-content: center;
	min-width: 0; /* deja que la tira de miniaturas se encoja y haga scroll en vez de empujar las flechas */
}

.hba__nav {
	appearance: none;
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	margin: 0;
	padding: 0;
	color: var(--hba-ink);
	background: #fff;
	border: 1px solid var(--hba-line);
	border-radius: 50%;
	box-shadow: 0 2px 8px rgba(31, 42, 40, 0.08);
	cursor: pointer;
	transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.hba__nav:hover { color: var(--hba-on-primary); background: var(--hba-primary); border-color: var(--hba-primary); }
.hba__nav:active { transform: scale(0.94); }
.hba__nav svg { display: block; width: 20px; height: 20px; }

/* Contador de texto: solo cuando no hay miniaturas (con miniaturas queda para lectores de pantalla). */
.hba__counter {
	min-width: 4.5em;
	margin: 0;
	font-size: 0.9rem;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-align: center;
	font-variant-numeric: tabular-nums;
	color: var(--hba-muted);
}

.hba__thumbs {
	--fl: 0px; /* difuminado del borde izquierdo/derecho cuando hay más miniaturas fuera de vista */
	--fr: 0px;
	position: relative; /* offsetLeft de las miniaturas se mide contra la tira */
	display: flex;
	gap: 8px;
	width: max-content;
	max-width: 100%;
	padding: 6px 4px;
	overflow-x: auto;
	scroll-snap-type: x proximity;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
	-webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
	mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
}
.hba__thumbs::-webkit-scrollbar { display: none; }

.hba__thumb {
	appearance: none;
	flex: 0 0 auto;
	width: 64px;
	aspect-ratio: 1;
	margin: 0;
	padding: 0;
	overflow: hidden;
	background: #d9d6d0;
	border: 2px solid transparent;
	border-radius: 12px;
	opacity: 0.55;
	cursor: pointer;
	scroll-snap-align: center;
	transition: opacity 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.hba__thumb:hover,
.hba__thumb.is-active { opacity: 1; }
.hba__thumb.is-active { border-color: var(--hba-primary); transform: translateY(-2px); }
.hba__thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }

.hba-empty-note {
	padding: 12px 16px;
	font-size: 0.9rem;
	color: #6b5200;
	background: #fff8e1;
	border: 1px dashed #dba617;
	border-radius: 8px;
}

/* ---------- Móvil ---------- */
@media (max-width: 600px) {
	.hba { --hba-pad: 8px; }
	.hba__stage { border-radius: calc(var(--hba-radius) + 2px); }
	.hba-cmp { border-radius: calc(var(--hba-radius) - 4px); }
	.hba__tab { padding: 0.5rem 0.85rem; font-size: 0.85rem; }
	.hba__bar { gap: 8px; margin-top: 14px; }
	.hba__nav { width: 40px; height: 40px; }
	.hba__thumbs { gap: 6px; }
	.hba__thumb { width: 54px; border-radius: 10px; }
	.hba-cmp__handle { width: 42px; height: 42px; margin: -21px 0 0 -21px; }
	.hba-cmp__tag,
	.hba-cmp__count { padding: 4px 9px; font-size: 0.66rem; }
	.hba-cmp__tag { bottom: 10px; }
	.hba-cmp__tag--before { left: 10px; }
	.hba-cmp__tag--after { right: 10px; }
	.hba-cmp__count { top: 10px; right: 10px; }
	.hba__caption { font-size: 0.72rem; }
}

@media (prefers-reduced-motion: reduce) {
	.hba__slide.is-entering { animation: none; }
	.hba--js:not(.is-touched) .hba-cmp[data-mode="slider"] .hba-cmp__handle::after { animation: none; display: none; }
	.hba-cmp[data-mode="toggle"] .hba-cmp__before,
	.hba-cmp__handle,
	.hba__stage::before,
	.hba__tab,
	.hba__nav,
	.hba__thumb { transition: none; }
}
