/**
 * 前台 Swatches 樣式
 * 水平滑動列 UI
 *
 * @package JSD_Variation_Image_Swatches
 */

/* Swatches 包裝器 */
.jsd-swatches-wrapper {
	margin-bottom: 1.5em;
	width: 100%;
	overflow: visible;
	position: relative;
}

/* Swatches 容器包裝器（包含箭頭） */
.jsd-swatches-container-wrapper {
	position: relative;
	width: 100%;
}

/* Swatches 容器（水平滑動列） */
.jsd-swatches-container {
	display: flex;
	flex-wrap: nowrap;
	overflow-x: auto;
	overflow-y: hidden;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
	gap: 0.75em;
	padding: 0.5em 0;
	margin: 0 -0.25em;
	padding-left: 0.25em;
	padding-right: 0.25em;
	width: 100%;
	max-width: 100%;
	touch-action: pan-x;
	scroll-behavior: smooth;
	position: relative;
}

.jsd-swatches-container::-webkit-scrollbar {
	height: 6px;
}

.jsd-swatches-container::-webkit-scrollbar-track {
	background: transparent;
}

.jsd-swatches-container::-webkit-scrollbar-thumb {
	background-color: rgba(0, 0, 0, 0.2);
	border-radius: 3px;
}

.jsd-swatches-container::-webkit-scrollbar-thumb:hover {
	background-color: rgba(0, 0, 0, 0.3);
}

/* Swatch 項目 */
.jsd-swatch-item {
	flex: 0 0 auto;
	width: 80px;
	min-width: 80px;
	cursor: pointer;
	border: 2px solid #ddd;
	border-radius: 8px;
	padding: 8px;
	background: #fff;
	transition: all 0.2s ease;
	text-align: center;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	min-height: 100px;
	touch-action: manipulation;
}

.jsd-swatch-item:hover {
	border-color: #999;
	transform: translateY(-2px);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Swatch 選中狀態 */
.jsd-swatch-item.jsd-swatch-active {
	border-color: #800000;
	border-width: 3px;
	box-shadow: 0 0 0 2px rgba(128, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.15);
	background: #f9f9f9;
}


/* Swatch 圖片 */
.jsd-swatch-image {
	width: 64px;
	height: 64px;
	border-radius: 4px;
	overflow: hidden;
	margin-bottom: 6px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #f5f5f5;
}

.jsd-swatch-image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* Swatch 名稱 */
.jsd-swatch-name {
	font-size: 12px;
	line-height: 1.3;
	color: #333;
	word-break: break-word;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	max-height: 2.6em;
	width: 100%;
}

/* 無圖片時的名稱樣式 */
.jsd-swatch-item.no-image .jsd-swatch-name {
	font-size: 13px;
	padding: 8px 4px;
	-webkit-line-clamp: 3;
	max-height: 3.9em;
}

/* 響應式設計 */
@media (max-width: 768px) {
	.jsd-swatches-wrapper {
		margin-bottom: 1.2em;
	}

	.jsd-swatches-container {
		padding: 0.5em 0;
		gap: 0.6em;
	}

	.jsd-swatch-item {
		width: 72px;
		min-width: 72px;
		min-height: 92px;
	}

	.jsd-swatch-image {
		width: 56px;
		height: 56px;
	}

	.jsd-swatch-name {
		font-size: 11px;
	}
}

/* 更小的手機螢幕 */
@media (max-width: 480px) {
	.jsd-swatch-item {
		width: 65px;
		min-width: 65px;
		min-height: 85px;
		padding: 6px;
	}

	.jsd-swatch-image {
		width: 50px;
		height: 50px;
	}

	.jsd-swatch-name {
		font-size: 10px;
	}

	.jsd-swatches-container {
		gap: 0.5em;
	}
}

/* 左右箭頭按鈕 */
.jsd-swatches-nav {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	background: rgba(255, 255, 255, 0.95);
	border: 1px solid #ddd;
	border-radius: 50%;
	box-sizing: border-box;
	width: 36px;
	height: 36px;
	min-width: 36px;
	min-height: 36px;
	max-width: 36px;
	max-height: 36px;
	aspect-ratio: 1 / 1;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	z-index: 10;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
	transition: all 0.2s ease;
	padding: 0;
	margin: 0;
	opacity: 0;
	pointer-events: none;
	flex-shrink: 0;
}

.jsd-swatches-wrapper:hover .jsd-swatches-nav,
.jsd-swatches-nav.visible {
	opacity: 1;
	pointer-events: auto;
}

.jsd-swatches-nav:hover {
	background: #fff;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
	transform: translateY(-50%) scale(1.1);
}

.jsd-swatches-nav:active {
	transform: translateY(-50%) scale(0.95);
}

.jsd-swatches-nav-prev {
	left: -18px;
}

.jsd-swatches-nav-next {
	right: -18px;
}

.jsd-swatches-nav-icon {
	font-size: 24px;
	line-height: 1;
	color: #333;
	font-weight: bold;
	display: block;
	width: auto;
	height: auto;
	margin: 0;
	padding: 0;
	flex-shrink: 0;
}

.jsd-swatches-nav:disabled,
.jsd-swatches-nav.hidden {
	opacity: 0;
	pointer-events: none;
	cursor: not-allowed;
}

/* 響應式：手機上顯示箭頭 */
@media (max-width: 768px) {
	.jsd-swatches-wrapper {
		overflow: visible;
		padding: 0 35px;
	}

	.jsd-swatches-container-wrapper {
		position: relative;
		overflow: visible;
	}

	.jsd-swatches-nav {
		width: 30px;
		height: 30px;
		min-width: 30px;
		min-height: 30px;
		max-width: 30px;
		max-height: 30px;
		aspect-ratio: 1 / 1;
		background: #fff;
		border: 2px solid #333;
		border-radius: 50%;
		box-sizing: border-box;
		box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
		pointer-events: auto;
		z-index: 20;
		flex-shrink: 0;
	}

	.jsd-swatches-nav-icon {
		font-size: 18px;
		color: #333;
		font-weight: bold;
		line-height: 1;
		display: block;
		width: auto;
		height: auto;
		margin: 0;
		padding: 0;
		flex-shrink: 0;
	}

	.jsd-swatches-nav-prev {
		left: -5px;
	}

	.jsd-swatches-nav-next {
		right: -5px;
	}

	/* 手機版：只要不是 hidden，就顯示箭頭 */
	.jsd-swatches-nav:not(.hidden) {
		opacity: 1 !important;
		display: flex !important;
	}

	.jsd-swatches-wrapper:hover .jsd-swatches-nav,
	.jsd-swatches-nav.visible {
		opacity: 1 !important;
		display: flex !important;
	}
}

@media (max-width: 480px) {
	.jsd-swatches-wrapper {
		padding: 0 35px;
	}

	.jsd-swatches-nav {
		width: 30px;
		height: 30px;
		min-width: 30px;
		min-height: 30px;
		max-width: 30px;
		max-height: 30px;
		aspect-ratio: 1 / 1;
		background: #fff;
		border: 2px solid #333;
		border-radius: 50%;
		box-sizing: border-box;
		box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
		pointer-events: auto;
		z-index: 20;
		flex-shrink: 0;
	}

	.jsd-swatches-nav-icon {
		font-size: 18px;
		color: #333;
		font-weight: bold;
		line-height: 1;
		display: block;
		width: auto;
		height: auto;
		margin: 0;
		padding: 0;
		flex-shrink: 0;
	}

	.jsd-swatches-nav-prev {
		left: -5px;
	}

	.jsd-swatches-nav-next {
		right: -5px;
	}

	/* 小手機：只要不是 hidden，就顯示箭頭 */
	.jsd-swatches-nav:not(.hidden) {
		opacity: 1 !important;
		display: flex !important;
	}
}

/* 確保在 WooCommerce 變化表單中的樣式 */
.woocommerce-variation-add-to-cart-wrapper ~ .jsd-swatches-wrapper,
.variations .jsd-swatches-wrapper {
	margin-bottom: 1em;
}

/* 確保父容器不會阻止滾動 */
.variations tr .jsd-swatches-wrapper,
.variations .jsd-swatches-wrapper {
	overflow: visible !important;
}

.variations tr td .jsd-swatches-wrapper,
.variations .jsd-swatches-container {
	overflow-x: auto !important;
	overflow-y: hidden !important;
}

/* 防止父容器影響滾動 */
table.variations .jsd-swatches-wrapper,
table.variations td .jsd-swatches-wrapper {
	max-width: 100%;
	overflow: visible;
}

/* 手機版：確保箭頭不會被截斷 */
@media (max-width: 768px) {
	.variations tr td,
	.variations td {
		overflow: visible !important;
	}

	.variations .jsd-swatches-wrapper {
		overflow: visible !important;
	}
}

