﻿/* ==========================================================================
   BEFORE / AFTER GALLERY — interactive split-comparison slider
   Markup lives in: page-templates/home.php (section "8. BEFORE/AFTER")
   Drag + project switching lives in: assets/js/main.js

   How the reveal works: both images are stacked in .before-after__frame.
   The AFTER image sits in normal flow and defines the frame height; the BEFORE
   image is absolutely positioned on top and clipped to --ba-pos with clip-path.
   A transparent range input covers the frame and is the only input mechanism —
   it gives mouse drag, touch drag, click-to-jump and keyboard arrows for free.
   ========================================================================== */

/* Top clearance for the floating Why Choose Us cards that overhang into this
   section (see why-choose-us.css) — keeps this heading fully visible. */
.before-after {
	padding-top: 120px;
}

.before-after__viewer {
	--ba-pos: 50%;
	--ba-height: 520px;
	margin-top: var(--space-lg);
}

.before-after__frame {
	position: relative;
	border-radius: 16px;
	overflow: hidden;
	background: var(--color-primary, #03193C);
	user-select: none;
	transition: opacity 0.25s ease;
	height: var(--ba-height);
}

/* Held while the next project's images preload, so the swap fades instead of
   flashing a half-decoded image. */
.before-after__frame.is-swapping {
	opacity: 0.35;
}

.before-after__img {
	display: block;
	width: 100%;
	height: var(--ba-height);
	object-fit: cover;
}

.before-after__img--before {
	position: absolute;
	inset: 0;
	clip-path: inset(0 calc(100% - var(--ba-pos)) 0 0);
}

/* ---------------- Labels ---------------- */
.before-after__label {
	position: absolute;
	top: var(--space-sm);
	background: rgba(22, 50, 79, 0.85);
	color: var(--color-white);
	padding: 6px 14px;
	border-radius: 4px;
	font-size: 12px;
	font-weight: var(--fw-semibold);
	text-transform: uppercase;
	letter-spacing: 0.5px;
	z-index: 2;
	pointer-events: none;
}

.before-after__label--before { left: var(--space-sm); }
.before-after__label--after { right: var(--space-sm); }

/* ---------------- Divider handle ---------------- */
.before-after__viewer,
.before-after__wrapper,
.before-after__handle {
	touch-action: pan-y !important;
	user-select: none !important;
	-webkit-user-select: none !important;
	-webkit-touch-callout: none !important;
}

.before-after__wrapper img,
.before-after__frame img {
	pointer-events: none !important;
	-webkit-user-drag: none !important;
}

.before-after__handle {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--ba-pos);
	width: 44px;
	margin-left: -22px;
	background: transparent;
	z-index: 5;
	pointer-events: auto;
	cursor: ew-resize;
}

.before-after__handle::before {
	content: "";
	position: absolute;
	top: 0;
	bottom: 0;
	left: 50%;
	width: 3px;
	margin-left: -1.5px;
	background: var(--color-white);
	pointer-events: none;
}

.before-after__handle::after {
	content: "⟺";
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: var(--color-white);
	color: var(--color-primary, #03193C);
	font-size: 16px;
	line-height: 44px;
	text-align: center;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
	pointer-events: none;
}

/* ---------------- Drag input (transparent, covers the frame) ---------------- */
.before-after__range {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	opacity: 0;
	z-index: 4;
	cursor: ew-resize;
	-webkit-appearance: none;
	appearance: none;
	background: transparent;
	/* Vertical swipes still scroll the page; horizontal drags move the divider. */
	touch-action: pan-y;
}

.before-after__range::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 48px;
	height: 100%;
	cursor: ew-resize;
}

.before-after__range::-moz-range-thumb {
	width: 48px;
	height: var(--ba-height);
	border: none;
	cursor: ew-resize;
}

.before-after__range:focus-visible {
	opacity: 1;
	outline: 3px solid var(--color-accent, #FE5C08);
	outline-offset: 2px;
}

.before-after__lede {
	max-width: 46rem;
	margin: 12px auto 0;
	color: var(--color-text-muted, #6b7280);
}

.before-after__cta {
	display: flex;
	justify-content: center;
	margin-top: 28px;
}

/* ---------------- Project switcher tabs ---------------- */
.before-after__thumbnails {
	display: flex;
	gap: 14px;
	justify-content: center;
	align-items: center;
	flex-wrap: wrap;
	margin-top: 28px;
	list-style: none;
	padding: 0;
}

.before-after__thumb {
	width: 90px;
	height: 62px;
	min-width: 90px;
	min-height: 62px;
	max-width: 90px;
	max-height: 62px;
	border-radius: 8px;
	overflow: hidden;
	cursor: pointer;
	border: 2px solid transparent;
	opacity: 0.65;
	transition: border-color 0.25s ease, opacity 0.25s ease, transform 0.25s ease;
	padding: 0;
	background: transparent;
	flex-shrink: 0;
	box-sizing: border-box;
}

.before-after__thumb.is-active,
.before-after__thumb:hover {
	opacity: 1;
	border-color: var(--color-accent, #FE5C08);
	transform: translateY(-2px);
}

.before-after__thumb img {
	width: 100%;
	height: 100% !important;
	object-fit: cover;
	display: block;
	pointer-events: none;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
	.before-after {
		padding-top: 30px !important;
		padding-bottom: 30px !important;
	}

	.before-after__viewer { --ba-height: 320px; }

	.before-after__handle::after {
		width: 36px;
		height: 36px;
		line-height: 36px;
		font-size: 14px;
	}

	.before-after__thumb {
		width: 76px;
		height: 56px;
		min-width: 76px;
		min-height: 56px;
		max-width: 76px;
		max-height: 56px;
	}
}

@media (max-width: 768px) {
	.before-after .container {
		display: flex;
		flex-direction: column;
	}

	.before-after__thumbnails {
		display: flex !important;
		justify-content: left !important;
		align-items: center !important;
		gap: 12px !important;
		margin: 24px 0 !important;
		order: 3 !important;
	}

	.before-after__thumb {
		width: 90px !important;
		height: 62px !important;
		min-width: 90px !important;
		min-height: 62px !important;
		max-width: 90px !important;
		max-height: 62px !important;
		border-radius: 8px !important;
		overflow: hidden !important;
		border: 2px solid transparent !important;
		padding: 0 !important;
		flex-shrink: 0 !important;
		box-sizing: border-box !important;
	}

	.before-after__thumb img {
		width: 100% !important;
		height: 100% !important;
		max-width: none !important;
		object-fit: cover !important;
		border-radius: 0 !important;
	}

	.before-after__thumb.is-active {
		border-color: var(--color-accent, #FE5C08) !important;
		transform: scale(1.08) !important;
		opacity: 1;
	}

	.before-after__cta {
		order: 4 !important;
		margin-top: 10px !important;
	}
}
