/* Before/after (docs/widgets/before-after.md), in the Soft design (spec §3.7): a photo with round corners and a
   soft shadow, a round white handle with the arrows in the accent, and white pill labels. The
   before image is the base; the after layer is clipped at the divider, --hafe-ba-pos (the share of
   the before image, from the start or the top).

   Every colour is a token set here; Outline and Solid (before-after-outline.css, -solid.css) change
   tokens only. The Style tab's controls write their own properties, which win over the tokens. The
   divider stays light in both schemes, since it sits on photos. */
.hafe-ba {
	--hafe-ba-o: var(--hafe-ba-label-offset, 0.75em);
	--hafe-ba-lw: var(--hafe-ba-line-width, 2px);
	--hafe-ba-line: #fff;
	--hafe-ba-line-shade: 0 0 3px rgb(0 0 0 / 35%);
	--hafe-ba-knob: var(--hafe-surface);
	--hafe-ba-arrows: var(--hafe-accent);
	--hafe-ba-knob-line: transparent;
	--hafe-ba-knob-shade: 0 1px 2px rgb(16 24 40 / 15%), 0 6px 16px -4px rgb(16 24 40 / 35%);
	--hafe-ba-tag: var(--hafe-surface);
	--hafe-ba-tag-ink: var(--hafe-ink);
	--hafe-ba-tag-line: transparent;
	--hafe-ba-edge: 0 solid transparent;
	position: relative;
	overflow: hidden;
	aspect-ratio: var(--hafe-ba-ratio, 3 / 2);
	border: var(--hafe-ba-edge);
	border-radius: var(--hafe-ba-radius, var(--hafe-radius));
	box-shadow: var(--hafe-shadow);
	user-select: none;
	-webkit-user-select: none;
	touch-action: pan-y;
}

.hafe-scheme-dark .hafe-ba {
	--hafe-ba-line: var(--hafe-ink);
	--hafe-ba-arrows: var(--hafe-accent-ink);
}

.hafe-ba--vertical {
	touch-action: pan-x;
}

/* Everything inside is positioned, so the root takes its width from its container (also as a
   flex item); zero specificity, so a class of the user's can still size it. */
:where(.hafe-ba) {
	width: 100%;
}

/* A container that wraps its items (Elementor's do on phones) measures each item's own width
   before stretching it, and an all-positioned root measures 0 wide, hence 0 high. This spacer
   gives it the available width instead (found by E2E). */
.hafe-ba::before {
	content: "";
	display: block;
	width: 100vw;
	max-width: 100%;
}

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

.hafe-ba--horizontal .hafe-ba__layer--after {
	clip-path: inset(0 0 0 var(--hafe-ba-pos, 50%));
}

.hafe-ba--horizontal:dir(rtl) .hafe-ba__layer--after {
	clip-path: inset(0 var(--hafe-ba-pos, 50%) 0 0);
}

.hafe-ba--vertical .hafe-ba__layer--after {
	clip-path: inset(var(--hafe-ba-pos, 50%) 0 0 0);
}

/* Specific enough to beat Elementor's own `.elementor img` rule. */
.hafe-ba .hafe-ba__img {
	display: block;
	width: 100%;
	max-width: none;
	height: 100%;
	margin: 0;
	border-radius: 0;
	object-fit: cover;
	pointer-events: none;
	-webkit-user-drag: none;
}

.hafe-ba__label {
	position: absolute;
	max-width: calc(50% - 2 * var(--hafe-ba-o));
	padding: var(--hafe-ba-label-padding, 0.35em 0.85em);
	border: 1px solid var(--hafe-ba-tag-line);
	border-radius: var(--hafe-ba-label-radius, var(--hafe-pill));
	background: var(--hafe-ba-label-bg, var(--hafe-ba-tag));
	color: var(--hafe-ba-label-color, var(--hafe-ba-tag-ink));
	font-size: 0.875em;
	font-weight: 500;
	line-height: 1.3;
	overflow-wrap: break-word;
	pointer-events: none;
	transition: opacity 0.2s;
}

/* Horizontal: before at the start edge, after at the end edge; the position is the height. */
.hafe-ba--horizontal .hafe-ba__layer--before .hafe-ba__label {
	inset-inline-start: var(--hafe-ba-o);
}

.hafe-ba--horizontal .hafe-ba__layer--after .hafe-ba__label {
	inset-inline-end: var(--hafe-ba-o);
}

.hafe-ba--horizontal.hafe-ba--label-start .hafe-ba__label {
	top: var(--hafe-ba-o);
}

.hafe-ba--horizontal.hafe-ba--label-center .hafe-ba__label {
	top: 50%;
	transform: translateY(-50%);
}

.hafe-ba--horizontal.hafe-ba--label-end .hafe-ba__label {
	bottom: var(--hafe-ba-o);
}

/* Vertical: before at the top, after at the bottom; the position is across. */
.hafe-ba--vertical .hafe-ba__label {
	max-width: calc(100% - 2 * var(--hafe-ba-o));
}

.hafe-ba--vertical .hafe-ba__layer--before .hafe-ba__label {
	top: var(--hafe-ba-o);
}

.hafe-ba--vertical .hafe-ba__layer--after .hafe-ba__label {
	bottom: var(--hafe-ba-o);
}

.hafe-ba--vertical.hafe-ba--label-start .hafe-ba__label {
	inset-inline-start: var(--hafe-ba-o);
}

.hafe-ba--vertical.hafe-ba--label-center .hafe-ba__label {
	left: 50%;
	transform: translateX(-50%);
}

.hafe-ba--vertical.hafe-ba--label-end .hafe-ba__label {
	inset-inline-end: var(--hafe-ba-o);
}

/* Labels on hover show on keyboard focus too, and always on touch screens. */
.hafe-ba--labels-hover .hafe-ba__label {
	opacity: 0;
}

.hafe-ba--labels-hover:hover .hafe-ba__label,
.hafe-ba--labels-hover:focus-within .hafe-ba__label {
	opacity: 1;
}

@media (hover: none) {
	.hafe-ba--labels-hover .hafe-ba__label {
		opacity: 1;
	}
}

/* The range input carries the position for keyboards and screen readers; it stays out of
   sight, and its focus shows on the handle. */
.hafe-ba .hafe-ba__range:not(#hafe-never) {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	border: 0;
	white-space: nowrap;
}

.hafe-ba__handle {
	display: none;
	position: absolute;
	background: var(--hafe-ba-line-color, var(--hafe-ba-line));
	box-shadow: var(--hafe-ba-line-shade);
	pointer-events: none;
}

.hafe-ba.is-ready .hafe-ba__handle {
	display: block;
}

.hafe-ba--horizontal .hafe-ba__handle {
	top: 0;
	bottom: 0;
	inset-inline-start: var(--hafe-ba-pos, 50%);
	width: var(--hafe-ba-lw);
	margin-inline-start: calc(var(--hafe-ba-lw) / -2);
}

.hafe-ba--vertical .hafe-ba__handle {
	top: var(--hafe-ba-pos, 50%);
	right: 0;
	left: 0;
	height: var(--hafe-ba-lw);
	margin-top: calc(var(--hafe-ba-lw) / -2);
}

.hafe-ba__knob {
	box-sizing: border-box;
	display: flex;
	position: absolute;
	top: 50%;
	left: 50%;
	align-items: center;
	justify-content: center;
	width: var(--hafe-ba-knob-size, 44px);
	height: var(--hafe-ba-knob-size, 44px);
	border: 2px solid var(--hafe-ba-knob-line);
	border-radius: 50%;
	background: var(--hafe-ba-knob-bg, var(--hafe-ba-knob));
	box-shadow: var(--hafe-ba-knob-shade);
	color: var(--hafe-ba-knob-color, var(--hafe-ba-arrows));
	transform: translate(-50%, -50%);
}

.hafe-ba__knob svg {
	width: 55%;
	height: 55%;
}

.hafe-ba--vertical .hafe-ba__knob svg {
	transform: rotate(90deg);
}

/* Two rings, light then the accent, so the focus shows on any photo. */
.hafe-ba__range:focus-visible + .hafe-ba__handle .hafe-ba__knob {
	outline: 3px solid #fff;
	outline-offset: 2px;
	box-shadow: 0 0 0 7px var(--hafe-accent);
}

.hafe-ba.is-ready,
.hafe-ba.is-dragging {
	cursor: ew-resize;
}

.hafe-ba--vertical.is-ready,
.hafe-ba--vertical.is-dragging {
	cursor: ns-resize;
}

.hafe-ba[data-move="click"].is-ready {
	cursor: pointer;
}

/* Dragging: the resize cursor shows on the handle, with a few pixels either side of the line to
   aim at, and during a drag. A press elsewhere still moves the divider there. */
.hafe-ba[data-move="drag"].is-ready:not(.is-dragging) {
	cursor: default;
}

.hafe-ba[data-move="drag"] .hafe-ba__handle {
	pointer-events: auto;
	cursor: ew-resize;
}

.hafe-ba--vertical[data-move="drag"] .hafe-ba__handle {
	cursor: ns-resize;
}

.hafe-ba[data-move="drag"] .hafe-ba__handle::before {
	content: "";
	position: absolute;
	inset: 0 -6px;
}

.hafe-ba--vertical[data-move="drag"] .hafe-ba__handle::before {
	inset: -6px 0;
}

.hafe-empty {
	margin: 0;
	padding: 1em;
	border: 1px dashed currentColor;
	opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
	.hafe-ba__label {
		transition: none;
	}
}

@media print {
	.hafe-ba__handle {
		display: none !important;
	}
}
