/**
 * Webspectations Colour Swatches
 *
 * Deliberately low-specificity and theme-neutral. Sizes and colours are exposed
 * as custom properties so a theme can retune them without overriding rules.
 */

.wspec-cs {
	--wspec-cs-size: 46px;
	--wspec-cs-gap: 8px;
	--wspec-cs-radius: 4px;
	--wspec-cs-border: rgba( 0, 0, 0, 0.18 );
	--wspec-cs-border-hover: rgba( 0, 0, 0, 0.45 );
	--wspec-cs-border-selected: currentColor;

	margin: 0 0 0.5em;
}

.wspec-cs__list {
	display: flex;
	flex-wrap: wrap;
	gap: var( --wspec-cs-gap );
	margin: 0;
	padding: 0;
	list-style: none;
}

.wspec-cs__item {
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Reset, because themes style bare <button> heavily. */
.wspec-cs__swatch {
	display: block;
	position: relative;
	box-sizing: border-box;
	width: var( --wspec-cs-size );
	height: var( --wspec-cs-size );
	margin: 0;
	padding: 0;
	overflow: hidden;
	border: 2px solid var( --wspec-cs-border );
	border-radius: var( --wspec-cs-radius );
	background: #fff;
	color: inherit;
	font: inherit;
	line-height: 1;
	text-align: center;
	cursor: pointer;
	transition: border-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.wspec-cs__swatch:hover,
.wspec-cs__swatch:focus-visible {
	border-color: var( --wspec-cs-border-hover );
	transform: translateY( -1px );
}

.wspec-cs__swatch:focus-visible {
	outline: 2px solid var( --wspec-cs-border-selected );
	outline-offset: 2px;
}

.wspec-cs__swatch.is-selected {
	border-color: var( --wspec-cs-border-selected );
	border-width: 2px;
	box-shadow: inset 0 0 0 2px #fff;
}

.wspec-cs__img {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	object-fit: cover;
	/* Some themes force max-width on loop images. */
	max-width: none;
}

/* Colours with no variation image fall back to a readable text chip. */
.wspec-cs__swatch--text {
	width: auto;
	min-width: var( --wspec-cs-size );
	height: auto;
	padding: 0.4em 0.7em;
	font-size: 0.8125em;
	white-space: nowrap;
}

.wspec-cs__label {
	display: block;
}

.wspec-cs__more {
	display: inline-flex;
	align-items: center;
	height: var( --wspec-cs-size );
	padding: 0 0.4em;
	font-size: 0.8125em;
	opacity: 0.7;
}

/* Screen-reader-only text, self-contained so it does not rely on the theme. */
.wspec-cs__sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect( 0 0 0 0 );
	clip-path: inset( 50% );
	white-space: nowrap;
	border: 0;
}

/*
 * Unavailable for the current Pack Size / Envelopes combination. WooCommerce has
 * removed or disabled the matching <option>, so we mirror that state.
 */
.wspec-cs__swatch[disabled],
.wspec-cs__swatch.is-unavailable {
	cursor: not-allowed;
	opacity: 0.3;
	transform: none;
}

.wspec-cs__swatch.is-unavailable:hover {
	border-color: var( --wspec-cs-border );
}

/*
 * Single product page. WooCommerce's own <select> stays in the DOM and keeps
 * driving everything - it is only hidden from sight. Never display:none, which
 * would take it out of the accessibility tree and out of some browsers' form
 * serialisation.
 */
.wspec-cs--single .wspec-cs__select {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect( 0 0 0 0 );
	clip-path: inset( 50% );
	white-space: nowrap;
	border: 0;
}

/*
 * Button-style option lists for non-colour attributes (Pack Size, Envelopes and
 * anything else short enough). These are the same controls as a text-fallback
 * swatch, just sized to read as proper option buttons.
 */
.wspec-cs--choices {
	--wspec-cs-gap: 6px;
}

.wspec-cs--choices .wspec-cs__swatch {
	width: auto;
	height: auto;
	min-width: 2.75em;
	padding: 0.55em 0.9em;
	border-width: 1px;
	border-radius: var( --wspec-cs-radius );
	font-size: 0.9375em;
	line-height: 1.3;
	white-space: nowrap;
}

.wspec-cs--choices .wspec-cs__swatch.is-selected {
	border-width: 2px;
	padding: calc( 0.55em - 1px ) calc( 0.9em - 1px );
	box-shadow: none;
	font-weight: 600;
}

/* Loop indicator: smaller, and never pushes the card around. */
.wspec-cs--loop {
	--wspec-cs-size: 28px;
	--wspec-cs-gap: 5px;

	margin: 0.5em 0;
}

.wspec-cs--loop .wspec-cs__swatch {
	border-width: 1px;
}

.wspec-cs--loop .wspec-cs__swatch.is-selected {
	box-shadow: inset 0 0 0 1px #fff;
}

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

	.wspec-cs__swatch:hover,
	.wspec-cs__swatch:focus-visible {
		transform: none;
	}
}
