/**
 * Simple WooCommerce Swatches - swatch styles
 * Follows the theme's palette via CSS variables (--global-palette*), with fallbacks.
 */

.sws-swatches {
	--sws-accent: var(--global-palette1, #2b6cb0);
	--sws-ink: var(--global-palette3, #1a202c);
	--sws-muted: var(--global-palette6, #718096);
	--sws-border: var(--global-palette7, #edf2f7);
	--sws-surface: var(--global-palette9, #ffffff);

	display: flex;
	flex-wrap: wrap;
	gap: 0.625rem;
	margin: 0.5rem 0 0.75rem;
	padding: 0;
}

.sws-swatch {
	position: relative;
	width: 44px;
	height: 44px;
	padding: 0;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	background: var(--sws-surface);
	box-shadow: 0 0 0 1px var(--sws-border);
	transition: box-shadow 0.15s ease, transform 0.15s ease;
	flex: 0 0 auto;
}

.sws-swatch:hover {
	box-shadow: 0 0 0 1px var(--sws-border), 0 4px 10px -4px rgba(26, 32, 44, 0.35);
	transform: translateY(-1px);
}

.sws-swatch:focus-visible {
	outline: 2px solid var(--sws-accent);
	outline-offset: 2px;
}

.sws-swatch__color {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 8px;
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
}

.sws-swatch__color--empty {
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--sws-border);
	color: var(--sws-muted);
	font-size: 0.85rem;
	font-weight: 700;
	text-transform: uppercase;
}

.sws-swatch__check {
	position: absolute;
	inset: 0;
	border-radius: 8px;
	border: 2px solid transparent;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
	pointer-events: none;
}

.sws-swatch__check::after {
	content: "";
	position: absolute;
	top: -7px;
	right: -7px;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: var(--sws-accent);
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3.5 8.5 6.5 11.5 12.5 4.5'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: center;
	background-size: 10px 10px;
	opacity: 0;
	transform: scale(0.6);
	transition: opacity 0.15s ease, transform 0.15s ease;
	box-shadow: 0 0 0 2px var(--sws-surface);
}

.sws-swatch.is-selected .sws-swatch__check {
	border-color: var(--sws-accent);
	box-shadow: 0 0 0 1px var(--sws-accent);
}

.sws-swatch.is-selected .sws-swatch__check::after {
	opacity: 1;
	transform: scale(1);
}

.sws-swatch.is-disabled {
	cursor: not-allowed;
}

.sws-swatch.is-disabled .sws-swatch__color {
	opacity: 0.35;
}

.sws-swatch.is-disabled::before {
	content: "";
	position: absolute;
	left: 4px;
	right: 4px;
	top: 50%;
	height: 1px;
	background: var(--sws-muted);
	transform: rotate(-25deg);
}

/* Tooltip on hover/focus */
.sws-swatch::after {
	content: attr(title);
	position: absolute;
	bottom: calc(100% + 8px);
	left: 50%;
	transform: translateX(-50%) translateY(4px);
	background: var(--sws-ink);
	color: var(--sws-surface);
	font-size: 0.75rem;
	line-height: 1.2;
	font-weight: 500;
	white-space: nowrap;
	padding: 0.3rem 0.55rem;
	border-radius: 6px;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.15s ease, transform 0.15s ease;
	z-index: 5;
}

.sws-swatch::before {
	content: "";
	position: absolute;
	bottom: calc(100% + 3px);
	left: 50%;
	transform: translateX(-50%);
	border: 5px solid transparent;
	border-top-color: var(--sws-ink);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.15s ease;
	z-index: 5;
}

.sws-swatch:hover::after,
.sws-swatch:hover::before,
.sws-swatch:focus-visible::after,
.sws-swatch:focus-visible::before {
	opacity: 1;
	transform: translateX(-50%) translateY(0);
}

/* Label below swatches, e.g. "Color: Muted Oak" */
.sws-swatch-label {
	margin: 0 0 1rem;
	font-size: 0.9rem;
	color: var(--global-palette5, #4a5568);
}

.sws-swatch-label__value {
	color: var(--global-palette3, #1a202c);
}

/* Hide the original <select>, but keep it for screen readers/fallback */
.sws-swatch-select-wrap {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.js .sws-swatch-select-wrap {
	/* JS is active - the select is only needed for WooCommerce's variation logic */
}

@media (max-width: 480px) {
	.sws-swatch {
		width: 38px;
		height: 38px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.sws-swatch,
	.sws-swatch__check,
	.sws-swatch__check::after,
	.sws-swatch::after,
	.sws-swatch::before {
		transition: none;
	}
}
