/**
 * IO Widget - Before / After v1.1.0
 * Mobile-friendly image comparison slider
 */

.io-ba-wrapper {
	position: relative;
	overflow: hidden;
	width: 100%;
	height: 420px;
	user-select: none;
	-webkit-user-select: none;
	touch-action: none;
	direction: ltr; /* slider math is LTR; labels can be RTL via text */
	box-sizing: border-box;
	background: #0f0f12;
}

.io-ba-wrapper *,
.io-ba-wrapper *::before,
.io-ba-wrapper *::after {
	box-sizing: border-box;
}

.io-ba-after,
.io-ba-before {
	position: absolute;
	inset: 0;
	overflow: hidden;
}

.io-ba-after {
	z-index: 1;
}

.io-ba-before {
	z-index: 2;
	/* default width/height set inline from PHP */
}

.io-ba-after img,
.io-ba-before img {
	display: block !important;
	width: 100% !important;
	height: 100% !important;
	max-width: none !important;
	object-fit: cover;
	object-position: center center;
	pointer-events: none;
	-webkit-user-drag: none;
	user-select: none;
}

/* Before layer image must stay full-size of container while clip changes */
.io-ba-orientation-horizontal .io-ba-before img {
	position: absolute;
	left: 0;
	top: 0;
	width: 100% !important;
	/* width of parent is the clip; image needs container width */
	min-width: 100%;
	height: 100% !important;
}

.io-ba-orientation-horizontal .io-ba-before {
	height: 100%;
	top: 0;
	left: 0;
	right: auto;
	bottom: 0;
}

/* Fix: before image should use wrapper width, not clipped parent width */
.io-ba-orientation-horizontal .io-ba-before img {
	width: var(--io-ba-w, 100%) !important;
	max-width: none !important;
}

.io-ba-orientation-vertical .io-ba-before {
	width: 100%;
	left: 0;
	right: 0;
	top: 0;
	bottom: auto;
}

.io-ba-orientation-vertical .io-ba-before img {
	height: var(--io-ba-h, 100%) !important;
	max-height: none !important;
	width: 100% !important;
	position: absolute;
	left: 0;
	top: 0;
}

/* ---- Slider / Divider / Handle ---- */
.io-ba-slider {
	position: absolute;
	z-index: 5;
	display: flex;
	align-items: center;
	justify-content: center;
	pointer-events: none;
}

.io-ba-orientation-horizontal .io-ba-slider {
	top: 0;
	bottom: 0;
	width: 0;
	transform: translateX(-50%);
}

.io-ba-orientation-vertical .io-ba-slider {
	left: 0;
	right: 0;
	height: 0;
	transform: translateY(-50%);
}

.io-ba-divider {
	position: absolute;
	background-color: #FFFFFF;
	box-shadow: 0 0 8px rgba(0, 0, 0, 0.35);
	pointer-events: none;
}

.io-ba-orientation-horizontal .io-ba-divider {
	top: 0;
	bottom: 0;
	left: 50%;
	transform: translateX(-50%);
	width: 3px;
}

.io-ba-orientation-vertical .io-ba-divider {
	left: 0;
	right: 0;
	top: 50%;
	transform: translateY(-50%);
	height: 3px;
}

.io-ba-handle {
	position: relative;
	z-index: 6;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background-color: #FFFFFF;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0;
	cursor: grab;
	pointer-events: auto;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
	border: 0 solid transparent;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
	outline: none;
	color: #1A1A2E;
}

.io-ba-handle:active,
.io-ba-wrapper.is-dragging .io-ba-handle {
	cursor: grabbing;
	transform: scale(1.08);
}

.io-ba-handle:focus-visible {
	box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.55), 0 2px 12px rgba(0, 0, 0, 0.28);
}

.io-ba-handle svg {
	display: block;
	flex-shrink: 0;
	fill: currentColor;
}

.io-ba-orientation-horizontal .io-ba-handle {
	flex-direction: row;
}

.io-ba-orientation-vertical .io-ba-handle {
	flex-direction: column;
}

/* ---- Labels ---- */
.io-ba-label {
	position: absolute;
	z-index: 4;
	font-size: 13px;
	font-weight: 600;
	line-height: 1.3;
	padding: 6px 12px;
	border-radius: 6px;
	background-color: rgba(0, 0, 0, 0.55);
	color: #FFFFFF;
	pointer-events: none;
	direction: rtl;
	white-space: nowrap;
}

.io-ba-orientation-horizontal .io-ba-label-before {
	top: 16px;
	left: 16px;
}

.io-ba-orientation-horizontal .io-ba-label-after {
	top: 16px;
	right: 16px;
}

.io-ba-orientation-vertical .io-ba-label-before {
	top: 16px;
	left: 16px;
}

.io-ba-orientation-vertical .io-ba-label-after {
	bottom: 16px;
	left: 16px;
}

/* ---- Animations ---- */
.io-ba-anim-smooth .io-ba-before,
.io-ba-anim-smooth .io-ba-slider {
	transition: none; /* position set by JS; optional smooth only on release */
}

.io-ba-anim-smooth.is-releasing .io-ba-before,
.io-ba-anim-smooth.is-releasing .io-ba-slider {
	transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1),
	            height 0.35s cubic-bezier(0.22, 1, 0.36, 1),
	            left 0.35s cubic-bezier(0.22, 1, 0.36, 1),
	            top 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.io-ba-anim-pulse .io-ba-handle {
	animation: io-ba-pulse 1.8s ease-in-out infinite;
}

@keyframes io-ba-pulse {
	0%, 100% { box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28), 0 0 0 0 rgba(255, 255, 255, 0.5); }
	50%      { box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28), 0 0 0 10px rgba(255, 255, 255, 0); }
}

.io-ba-wrapper.is-dragging.io-ba-anim-pulse .io-ba-handle {
	animation: none;
}

.io-ba-anim-glow .io-ba-handle {
	box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35), 0 0 18px rgba(255, 255, 255, 0.55), 0 2px 12px rgba(0, 0, 0, 0.25);
	animation: io-ba-glow 2s ease-in-out infinite alternate;
}

@keyframes io-ba-glow {
	from { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3), 0 0 10px rgba(255, 255, 255, 0.4), 0 2px 10px rgba(0, 0, 0, 0.25); }
	to   { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.45), 0 0 22px rgba(255, 255, 255, 0.7), 0 2px 14px rgba(0, 0, 0, 0.3); }
}

.io-ba-anim-reveal:not(.is-ready) .io-ba-before {
	width: 0 !important;
	height: 0 !important;
}

.io-ba-anim-reveal:not(.is-ready).io-ba-orientation-horizontal .io-ba-before {
	height: 100% !important;
}

.io-ba-anim-reveal:not(.is-ready).io-ba-orientation-vertical .io-ba-before {
	width: 100% !important;
}

.io-ba-anim-reveal:not(.is-ready) .io-ba-slider {
	opacity: 0;
}

.io-ba-anim-reveal.is-ready .io-ba-before,
.io-ba-anim-reveal.is-ready .io-ba-slider {
	transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1),
	            height 0.9s cubic-bezier(0.22, 1, 0.36, 1),
	            left 0.9s cubic-bezier(0.22, 1, 0.36, 1),
	            top 0.9s cubic-bezier(0.22, 1, 0.36, 1),
	            opacity 0.5s ease;
}

.io-ba-anim-bounce.is-releasing .io-ba-handle {
	animation: io-ba-bounce 0.45s ease;
}

@keyframes io-ba-bounce {
	0%   { transform: scale(1); }
	30%  { transform: scale(1.18); }
	60%  { transform: scale(0.94); }
	100% { transform: scale(1); }
}

/* Hover mode cursor */
.io-ba-mode-hover {
	cursor: col-resize;
}

.io-ba-mode-hover.io-ba-orientation-vertical {
	cursor: row-resize;
}

.io-ba-mode-drag .io-ba-handle,
.io-ba-mode-both .io-ba-handle {
	cursor: grab;
}

/* ---- Responsive ---- */
@media (max-width: 767px) {
	.io-ba-wrapper {
		height: 280px;
	}

	.io-ba-handle {
		width: 40px;
		height: 40px;
	}

	.io-ba-label {
		font-size: 12px;
		padding: 4px 10px;
	}

	.io-ba-orientation-horizontal .io-ba-label-before,
	.io-ba-orientation-horizontal .io-ba-label-after {
		top: 10px;
	}

	.io-ba-orientation-horizontal .io-ba-label-before { left: 10px; }
	.io-ba-orientation-horizontal .io-ba-label-after { right: 10px; }
}

@media (max-width: 480px) {
	.io-ba-wrapper {
		height: 220px;
	}

	.io-ba-handle {
		width: 36px;
		height: 36px;
	}

	.io-ba-handle svg {
		width: 12px;
		height: 12px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.io-ba-anim-pulse .io-ba-handle,
	.io-ba-anim-glow .io-ba-handle,
	.io-ba-anim-bounce.is-releasing .io-ba-handle {
		animation: none !important;
	}
	.io-ba-anim-reveal.is-ready .io-ba-before,
	.io-ba-anim-reveal.is-ready .io-ba-slider,
	.io-ba-anim-smooth.is-releasing .io-ba-before,
	.io-ba-anim-smooth.is-releasing .io-ba-slider {
		transition: none !important;
	}
}
