/**
 * Pro Variation Swatches - storefront styles.
 * Every selector is prefixed with .pvs- so it cannot collide with a theme or another plugin.
 */

.pvs-control {
	--pvs-w: 32px;
	--pvs-h: 32px;
	--pvs-border: #ccc;
	--pvs-border-hover: #000;
	--pvs-selected: #2e8b57;
	margin: 0;
}

/* The native select stays in the DOM so WooCommerce keeps working; it is only hidden. */
.pvs-select select,
.pvs-select .select2-container,
.pvs-select .nice-select,
.pvs-select .selectric-wrapper,
.pvs-select .ts-wrapper,
.pvs-select .select-styled,
.pvs-select .select-wrapper > .select-dropdown {
	display: none !important;
}

/*
 * Remove the dropdown arrow. Many themes draw it with ::before / ::after on the
 * select's wrapper or on the table cell, so it stays visible after the select
 * itself is hidden.
 */
.pvs-select::before,
.pvs-select::after,
.pvs-control::before,
.pvs-control::after {
	content: none !important;
	display: none !important;
}

.pvs-select {
	background-image: none !important;
}

.variations td.value:has(.pvs-control)::before,
.variations td.value:has(.pvs-control)::after,
.variations .value:has(.pvs-control)::before,
.variations .value:has(.pvs-control)::after {
	content: none !important;
	display: none !important;
}

.variations td.value:has(.pvs-control),
.variations .value:has(.pvs-control) {
	background-image: none !important;
}

/* ---------- Swatch tiles ---------- */
.pvs-items {
	display: flex;
	flex-wrap: wrap;
	gap: 5px;
	margin: 0;
	padding: 0;
}

.pvs-control .pvs-tile {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	margin: 0;
	padding: 2px;
	border: 1px solid var(--pvs-border);
	border-radius: 0;
	background: #fff;
	color: inherit;
	font: inherit;
	line-height: 1;
	text-transform: none;
	text-decoration: none;
	box-shadow: none;
	cursor: pointer;
	transition: border-color .15s ease, opacity .15s ease;
}

.pvs-control .pvs-tile:hover {
	border-color: var(--pvs-border-hover);
	background: #fff;
	color: inherit;
}

.pvs-control .pvs-tile:focus-visible {
	outline: 2px solid var(--pvs-border-hover);
	outline-offset: 2px;
}

.pvs-control .pvs-tile.is-selected {
	padding: 1px;
	border: 2px solid var(--pvs-selected);
}

.pvs-tile__face {
	display: block;
	width: var(--pvs-w);
	height: var(--pvs-h);
	box-sizing: border-box;
}

.pvs-tile__color {
	box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1);
}

.pvs-tile__img {
	max-width: none;
	object-fit: cover;
}

/* Options without a color or image fall back to a text button. */
.pvs-control .pvs-tile--text {
	min-width: var(--pvs-w);
	min-height: var(--pvs-h);
	padding: 2px 10px;
}

.pvs-control .pvs-tile--text.is-selected {
	padding: 1px 9px;
}

.pvs-tile__text {
	font-size: 14px;
	white-space: nowrap;
}

/* ---------- Label above / below ---------- */
.pvs-label {
	min-height: 1.4em;
	margin: 0 0 8px;
}

.pvs-select + .pvs-label {
	margin: 8px 0 0;
}

/* ---------- Radio buttons (wide box style) ---------- */
.pvs-radio-list {
	display: grid;
	grid-template-columns: repeat(var(--pvs-cols, 2), minmax(0, 1fr));
	gap: 14px;
	width: 100%;
	margin: 0 !important;
	padding: 0 !important;
	list-style: none !important;
}

.pvs-radio-item {
	position: relative;
	min-width: 0;
	margin: 0;
	padding: 0;
	list-style: none !important;
}

/* Visually hidden but still focusable and announced by screen readers. */
.pvs-radio-input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: 0;
	opacity: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
}

.pvs-radio-label {
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: 100%;
	height: 100%;
	min-height: 64px;
	margin: 0;
	padding: 10px 12px;
	border: 1px solid #ccc;
	border-radius: 6px;
	background: #fff;
	color: #333;
	font-size: 16px;
	font-weight: 700;
	line-height: 1.2;
	text-align: center;
	cursor: pointer;
	transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}

.pvs-radio-label:hover {
	border-color: #000;
}

.pvs-radio-input:checked + .pvs-radio-label {
	border-color: #000;
	background-color: #000;
	color: #fff;
}

.pvs-radio-input:focus-visible + .pvs-radio-label {
	outline: 2px solid #000;
	outline-offset: 2px;
}

/* ---------- Unavailable combinations ---------- */
.pvs-control .pvs-tile.is-disabled,
.pvs-radio-item.is-disabled .pvs-radio-label {
	opacity: .5;
	cursor: not-allowed;
}

.pvs-control .pvs-tile.is-disabled:hover {
	border-color: var(--pvs-border);
}

.pvs-radio-item.is-disabled .pvs-radio-label:hover {
	border-color: #ccc;
}

/* Four wide buttons do not fit on a small phone, so they drop to two per row. */
@media (max-width: 480px) {
	.pvs-control.pvs-cols-4 .pvs-radio-list {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.pvs-radio-label {
		min-height: 52px;
		font-size: 15px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.pvs-control .pvs-tile,
	.pvs-radio-label {
		transition: none;
	}
}
