/**
 * Before/After 对比滑块
 */

.baijia-cmp {
	--bjcmp-pos: 50%;
	--bjcmp-line: 2px;
	--bjcmp-line-color: #ffffff;

	position: relative;
	width: 100%;
	aspect-ratio: 16 / 9; /* 默认宽高比（PHP 内联可覆盖） */
	min-height: 200px;    /* 兜底：防止父容器宽度 0 时塌陷 */
	overflow: hidden;
	user-select: none;
	-webkit-user-select: none;
	touch-action: pan-y;
	cursor: ew-resize;
	background: #111;
	margin: 0 auto;
	isolation: isolate;
	display: block;
}

.baijia-cmp[data-direction="vertical"] {
	cursor: ns-resize;
	touch-action: pan-x;
}

.baijia-cmp * {
	box-sizing: border-box;
}

/* 媒体层 */
.bjcmp-media {
	position: absolute;
	inset: 0;
	overflow: hidden;
}

.bjcmp-media img,
.bjcmp-media video {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	pointer-events: none; /* 让容器接收鼠标事件 */
}

/* 右侧（底层，完整） */
.bjcmp-right {
	z-index: 1;
}

/* 左侧（上层，clip-path 裁剪） */
.bjcmp-left {
	z-index: 2;
	clip-path: inset(0 calc(100% - var(--bjcmp-pos)) 0 0);
}

.baijia-cmp[data-direction="vertical"] .bjcmp-left {
	clip-path: inset(0 0 calc(100% - var(--bjcmp-pos)) 0);
}

/* 角标 */
.bjcmp-label {
	position: absolute;
	bottom: 14px;
	padding: 6px 14px;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 1px;
	background-color: rgba(0, 0, 0, 0.6);
	color: #fff;
	border-radius: 3px;
	pointer-events: none;
	z-index: 3;
}
.bjcmp-label-left  { left: 14px; }
.bjcmp-label-right { right: 14px; }

/* 分隔线 */
.bjcmp-divider {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--bjcmp-pos);
	width: var(--bjcmp-line);
	background-color: var(--bjcmp-line-color);
	transform: translateX(-50%);
	z-index: 4;
	pointer-events: none;
}

.baijia-cmp[data-direction="vertical"] .bjcmp-divider {
	left: 0;
	right: 0;
	top: var(--bjcmp-pos);
	bottom: auto;
	width: auto;
	height: var(--bjcmp-line);
	transform: translateY(-50%);
}

/* 手柄 */
.bjcmp-handle {
	position: absolute;
	top: 50%;
	left: var(--bjcmp-pos);
	transform: translate(-50%, -50%);
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background-color: #fff;
	color: #1e1e1e;
	border: none;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: inherit;
	z-index: 5;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25), 0 0 0 2px rgba(255, 255, 255, 0.3);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.baijia-cmp[data-direction="vertical"] .bjcmp-handle {
	top: var(--bjcmp-pos);
	left: 50%;
	transform: translate(-50%, -50%) rotate(90deg);
}

.bjcmp-handle:hover,
.bjcmp-handle:focus-visible {
	transform: translate(-50%, -50%) scale(1.08);
	outline: none;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35), 0 0 0 3px rgba(255, 255, 255, 0.45);
}
.baijia-cmp[data-direction="vertical"] .bjcmp-handle:hover,
.baijia-cmp[data-direction="vertical"] .bjcmp-handle:focus-visible {
	transform: translate(-50%, -50%) rotate(90deg) scale(1.08);
}

.bjcmp-handle.is-dragging {
	transition: none;
}

.bjcmp-handle svg {
	width: 60%;
	height: 60%;
	display: block;
}

/* 手机端微调 */
@media (max-width: 640px) {
	.bjcmp-handle {
		width: 38px;
		height: 38px;
	}
	.bjcmp-label {
		font-size: 11px;
		padding: 4px 10px;
		bottom: 10px;
	}
	.bjcmp-label-left  { left: 10px; }
	.bjcmp-label-right { right: 10px; }
}
