/*
 * Before & After — Treatment Reveal
 * Port of the 21st.dev "reveal2" comparison slider.
 */

.cw-ba {
	--cw-fg: #18181b;
	--cw-muted: #71717a;
	--cw-accent: #18181b;
	--cw-surface: #f4f4f5;

	--cw-col: 5;
	--cw-columns-gap: 2.5rem;
	--cw-box-gap: 0.75rem;
	--cw-box-radius: 0.625rem;

	--cw-divider: #ffffff;
	--cw-divider-width: 4px;
	--cw-handle: 40px;
	--cw-pos: 50%;

	position: relative;
	width: 100%;
	color: var(--cw-fg);
}

.cw-ba__inner {
	width: 100%;
	max-width: 1152px;
	margin-inline: auto;
}

.cw-ba__grid {
	display: flex;
	flex-direction: column;
	gap: var(--cw-columns-gap);
	align-items: stretch;
}

.cw-ba__content {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	min-width: 0;
}

.cw-ba__media {
	min-width: 0;
}

@media (min-width: 1024px) {
	.cw-ba__grid {
		flex-direction: row;
		align-items: center;
	}

	/* The 12-column split, as a share of the space left after the gap. */
	.cw-ba__content {
		flex: 0 0 calc((100% - var(--cw-columns-gap)) * var(--cw-col) / 12);
		max-width: calc((100% - var(--cw-columns-gap)) * var(--cw-col) / 12);
	}

	.cw-ba__media {
		flex: 1 1 0;
	}

	.cw-ba--media-left .cw-ba__grid {
		flex-direction: row-reverse;
	}
}

/* --------------------------------------------------------------------- Title block */

.cw-ba__header {
	display: flex;
	flex-direction: column;
	gap: 0;
	align-items: flex-start;
}

.cw-ba__heading {
	display: block;
	margin-top: 0.75rem;
}

.cw-w .cw-ba__description {
	margin-top: 0.75rem;
}

.cw-ba__badge {
	display: inline-flex;
	align-items: center;
	padding: 0.125rem 0.625rem;
	border-radius: 9999px;
	background-color: var(--cw-surface);
	font-size: 0.75rem;
	font-weight: 600;
	line-height: 1.6;
	color: var(--cw-fg);
}

.cw-ba__title {
	display: inline-block;
	font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.25rem);
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: -0.02em;
	color: var(--cw-fg);
	text-wrap: balance;
}

.cw-w .cw-ba__description {
	display: inline-block;
	max-width: 36rem;
	font-size: 1rem;
	line-height: 1.6;
	color: var(--cw-muted);
	text-wrap: pretty;
}

/* ---------------------------------------------------------------- Treatment boxes */

.cw-ba__boxes {
	display: grid;
	gap: var(--cw-box-gap);
	margin-top: 0.5rem;
}

.cw-w .cw-ba__box {
	display: flex;
	align-items: center;
	justify-content: var(--cw-box-justify, center);
	text-align: var(--cw-box-text, center);
	gap: 0.75rem;
	padding: 0.875rem 1rem;
	border-width: 1px;
	border-color: transparent;
	border-radius: var(--cw-box-radius);
	background-color: var(--cw-box-bg, var(--cw-surface));
	color: var(--cw-box-fg, var(--cw-fg));
	text-align: left;
	cursor: pointer;
	transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease,
		transform 150ms ease;
}

/* Both colours are re-declared on hover so a theme's button:hover rule cannot repaint
   the box. They read the same variables as the base rule, so a colour set in the panel
   still applies unless a hover colour is set explicitly. */
.cw-w .cw-ba__box:hover {
	border-color: var(--cw-accent);
	background-color: var(--cw-box-bg-hover, var(--cw-box-bg, var(--cw-surface)));
	color: var(--cw-box-fg-hover, var(--cw-box-fg, var(--cw-fg)));
}

.cw-w .cw-ba__box.is-active,
.cw-w .cw-ba__box.is-active:hover {
	border-color: var(--cw-accent);
	background-color: var(--cw-box-bg-active, var(--cw-accent));
	color: var(--cw-box-fg-active, #ffffff);
}

.cw-w .cw-ba__box:focus-visible {
	outline: 2px solid var(--cw-accent);
	outline-offset: 2px;
}

.cw-ba__box-icon {
	display: inline-flex;
	flex: 0 0 auto;
	color: currentColor;
	opacity: 0.85;
}

.cw-ba__box-icon .cw-icon {
	width: 20px;
	height: 20px;
}

.cw-ba__box-body {
	display: flex;
	flex-direction: column;
	gap: 0.125rem;
	min-width: 0;
	align-items: var(--cw-box-items, center);
}

.cw-ba__box-title {
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.35;
}

.cw-ba__box-text {
	font-size: 0.8125rem;
	line-height: 1.5;
	opacity: 0.8;
}

/* Layout A — two per row, with an odd last box spanning the full width so five items
   fill the column without a gap. */
.cw-ba--boxes-grid .cw-ba__boxes {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Layout B — square-ish tiles, icon stacked above the title. */
.cw-ba--boxes-tiles .cw-ba__boxes {
	grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.cw-w .cw-ba--boxes-tiles .cw-ba__box {
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	aspect-ratio: 1 / 1;
	text-align: center;
}

.cw-ba--boxes-tiles .cw-ba__box-body {
	align-items: center;
}

/* Layout C — one per row. */
.cw-ba--boxes-rows .cw-ba__boxes {
	grid-template-columns: minmax(0, 1fr);
}

/* ---------------------------------------------------------------- Comparison stage */

.cw-ba__stage {
	position: relative;
	width: 100%;
	overflow: hidden;
	aspect-ratio: 16 / 10;
	border-radius: 0.5rem;
	background-color: var(--cw-surface);
	user-select: none;
	touch-action: none;
	cursor: ew-resize;
}

.cw-ba--vertical .cw-ba__stage {
	cursor: ns-resize;
}

.cw-ba__stage:focus-visible {
	outline: 2px solid var(--cw-accent);
	outline-offset: 3px;
}

.cw-ba__layer {
	position: absolute;
	inset: 0;
}

/* The before layer is clipped to the divider position; the after layer shows through. */
.cw-ba--horizontal .cw-ba__layer--before {
	clip-path: inset(0 calc(100% - var(--cw-pos)) 0 0);
}

.cw-ba--vertical .cw-ba__layer--before {
	clip-path: inset(0 0 calc(100% - var(--cw-pos)) 0);
}

/* Sizing is also inline in PHP: Elementor's `.elementor img { height: auto }` outranks
   a single class here. */
.cw-ba .cw-ba__img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	pointer-events: none;
}

.cw-ba__placeholder {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: var(--cw-surface);
	font-size: 0.875rem;
	color: var(--cw-muted);
}

.cw-ba__layer--before .cw-ba__placeholder {
	background-color: #e4e4e7;
}

/* --------------------------------------------------------------- Divider + handle */

.cw-ba__divider {
	position: absolute;
	z-index: 10;
	background-color: var(--cw-divider);
	box-shadow: 0 0 12px rgb(0 0 0 / 0.25);
	pointer-events: none;
}

.cw-ba--horizontal .cw-ba__divider {
	top: 0;
	bottom: 0;
	left: var(--cw-pos);
	width: var(--cw-divider-width);
	transform: translateX(-50%);
}

.cw-ba--vertical .cw-ba__divider {
	left: 0;
	right: 0;
	top: var(--cw-pos);
	height: var(--cw-divider-width);
	transform: translateY(-50%);
}

.cw-ba__handle {
	position: absolute;
	top: 50%;
	left: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--cw-handle);
	height: var(--cw-handle);
	transform: translate(-50%, -50%);
	border-width: 2px;
	border-color: var(--cw-accent);
	border-radius: 9999px;
	background-color: #ffffff;
	color: var(--cw-accent);
	box-shadow: 0 4px 12px rgb(0 0 0 / 0.2);
	transition: transform 150ms ease;
}

.cw-ba__stage.is-dragging .cw-ba__handle {
	transform: translate(-50%, -50%) scale(1.1);
}

.cw-ba__handle .cw-icon {
	width: 50%;
	height: 50%;
}

/* ------------------------------------------------------------------------- Labels */

.cw-ba__label {
	position: absolute;
	z-index: 20;
	padding: 0.375rem 0.75rem;
	border-radius: 9999px;
	background-color: rgba(0, 0, 0, 0.7);
	color: #ffffff;
	font-size: 0.875rem;
	font-weight: 500;
	line-height: 1.4;
	pointer-events: none;
}

.cw-ba__label--before {
	top: 1rem;
	left: 1rem;
}

.cw-ba--horizontal .cw-ba__label--after {
	top: 1rem;
	right: 1rem;
}

.cw-ba--vertical .cw-ba__label--after {
	bottom: 1rem;
	left: 1rem;
}

/* --------------------------------------------------------------- Mobile capsules */

@media (max-width: 767px) {
	/* Boxes become a swipeable row of pills sitting above the image. */
	.cw-ba--capsules .cw-ba__boxes {
		display: flex;
		grid-template-columns: none;
		flex-wrap: nowrap;
		overflow-x: auto;
		overscroll-behavior-x: contain;
		scroll-snap-type: x proximity;
		scrollbar-width: none;
		-ms-overflow-style: none;
		padding-bottom: 0.25rem;
	}

	.cw-ba--capsules .cw-ba__boxes::-webkit-scrollbar {
		display: none;
	}

	.cw-w .cw-ba--capsules .cw-ba__box {
		flex: 0 0 auto;
		align-items: center;
		flex-direction: row;
		gap: 0.5rem;
		aspect-ratio: auto;
		padding: 0.5rem 0.875rem;
		border-radius: 9999px;
		scroll-snap-align: start;
		white-space: nowrap;
	}

	/* The description would break the pill shape. */
	.cw-ba--capsules .cw-ba__box-text {
		display: none;
	}

	.cw-ba--capsules .cw-ba__box-title {
		font-size: 0.8125rem;
	}

	.cw-ba__label {
		font-size: 0.75rem;
		padding: 0.25rem 0.625rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cw-w .cw-ba__box,
	.cw-ba__handle {
		transition: none;
	}
}
