/* =================================================================
   Wapu Variation Swatches – Frontend CSS
   Three swatch types: color · image · label (text button)
   Three shapes:       round · rounded · square
   Five states:        default · hover · selected · disabled · hidden
   ================================================================= */

/* ── Hide native WooCommerce <select> ───────────────────────────── */
/* PHP injects data-wapu-hidden="1" so the select is hidden before JS runs */
select[data-wapu-hidden],
.wapu-vs-hidden-select {
	display: none !important;
}

/* ── Swatch Wrapper ─────────────────────────────────────────────── */
.wapu-swatches-wrapper {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 6px 0 14px;
	--wapu-swatch-size: 40px; /* overridden inline from PHP settings */
}

/* ── Base Swatch (all types inherit this) ───────────────────────── */
.wapu-swatch {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 2px solid transparent;
	cursor: pointer;
	background: transparent;
	font-family: inherit;
	font-size: 13px;
	line-height: 1;
	outline: none;
	transition:
		border-color 0.18s ease,
		box-shadow 0.18s ease,
		opacity 0.18s ease,
		transform 0.12s ease;
}

.wapu-swatch:focus-visible {
	outline: 2px solid #2563EB;
	outline-offset: 3px;
}

/* ── Shape modifiers ────────────────────────────────────────────── */
.wapu-swatch--round   { border-radius: 50%; }
.wapu-swatch--rounded { border-radius: 6px; }
.wapu-swatch--square  { border-radius: 2px; }

/* ================================================================
   COLOR SWATCH
   ================================================================ */
.wapu-swatch--color {
	width:  var(--wapu-swatch-size);
	height: var(--wapu-swatch-size);
	border-color: #e5e7eb;
	background: transparent;
}

/* Inner colour disc – slightly smaller than the button so the border shows */
.wapu-swatch__color {
	display: block;
	width:  calc(var(--wapu-swatch-size) - 8px);
	height: calc(var(--wapu-swatch-size) - 8px);
	border-radius: inherit;
	/* For very light / white colours, add a subtle inner shadow */
	box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}

/* Shape adjustments for the inner disc */
.wapu-swatch--rounded .wapu-swatch__color { border-radius: 4px; }
.wapu-swatch--square  .wapu-swatch__color { border-radius: 1px; }

/* ================================================================
   IMAGE SWATCH
   ================================================================ */
.wapu-swatch--image {
	width:  var(--wapu-swatch-size);
	height: var(--wapu-swatch-size);
	overflow: hidden;
	border-color: #e5e7eb;
	padding: 0;
}

.wapu-swatch__img {
	display: block;
	width:  100%;
	height: 100%;
	object-fit: cover;
	border-radius: inherit;
	pointer-events: none;
}

/* ================================================================
   LABEL (TEXT BUTTON) SWATCH
   ================================================================ */
.wapu-swatch--label {
	height:     var(--wapu-swatch-size);
	min-width:  var(--wapu-swatch-size);
	padding:    0 12px;
	border-color: #d1d5db;
	background: #ffffff;
	color:      #374151;
	font-weight: 500;
	/* Shape overrides */
	border-radius: 4px;
}

.wapu-swatch--label.wapu-swatch--round   { border-radius: calc( var(--wapu-swatch-size) / 2 ); }
.wapu-swatch--label.wapu-swatch--rounded { border-radius: 6px; }
.wapu-swatch--label.wapu-swatch--square  { border-radius: 2px; }

.wapu-swatch__label {
	white-space:    nowrap;
	pointer-events: none;
}

/* ================================================================
   STATES
   ================================================================ */

/* ── Hover (available swatches only) ── */
.wapu-swatch:not( .wapu-swatch--disabled ):hover {
	border-color: #6b7280;
	transform: scale(1.08);
}

.wapu-swatch--label:not( .wapu-swatch--disabled ):hover {
	border-color: #4b5563;
	background:   #f9fafb;
	color:        #111827;
}

/* ── Selected ── */
.wapu-swatch--selected {
	border-color: #1d4ed8;
	box-shadow:   0 0 0 1px #1d4ed8;
	transform: scale(1.06);
}

.wapu-swatch--label.wapu-swatch--selected {
	background:   #1d4ed8;
	border-color: #1d4ed8;
	color:        #ffffff;
}

.wapu-swatch--label.wapu-swatch--selected:hover {
	background: #1e40af;
	color:      #ffffff;
}

/* ── Disabled / Out-of-Stock ── */
.wapu-swatch--disabled {
	opacity:        0.5;
	cursor:         not-allowed;
	pointer-events: auto; /* keep pointer so oosClickable can still fire */
	transform:      none !important;
}

/* Cross line for color & image swatches (oos_behavior = 'cross') */
.wapu-swatch--disabled.wapu-swatch--color::after,
.wapu-swatch--disabled.wapu-swatch--image::after {
	content: '';
	position: absolute;
	inset: 0;
	border-radius: inherit;
	/* Diagonal line using a linear-gradient */
	background: linear-gradient(
		to top right,
		transparent       calc( 50% - 1px ),
		rgba(0,0,0,0.45)  50%,
		transparent       calc( 50% + 1px )
	);
	pointer-events: none;
}

/* Strikethrough for label swatches */
.wapu-swatch--disabled.wapu-swatch--label .wapu-swatch__label {
	text-decoration: line-through;
	color: #9ca3af;
}

/* Blur (oos_behavior = 'blur') */
.wapu-swatch--blur {
	filter: grayscale(0.6) opacity(0.45);
}

/* Hidden (oos_behavior = 'hide') */
.wapu-swatch--hidden {
	display: none !important;
}

/* ================================================================
   TOOLTIP
   ================================================================ */
.wapu-swatch__tooltip {
	position:        absolute;
	bottom:          calc( 100% + 9px );
	left:            50%;
	transform:       translateX(-50%);
	z-index:         999;
	background:      #111827;
	color:           #ffffff;
	font-size:       11px;
	line-height:     1.3;
	white-space:     nowrap;
	padding:         5px 9px;
	border-radius:   5px;
	pointer-events:  none;
	opacity:         0;
	transition:      opacity 0.15s ease;
}

/* Arrow */
.wapu-swatch__tooltip::after {
	content:      '';
	position:     absolute;
	top:          100%;
	left:         50%;
	transform:    translateX(-50%);
	border:       5px solid transparent;
	border-top-color: #111827;
}

.wapu-swatch:hover .wapu-swatch__tooltip {
	opacity: 1;
}

/* ================================================================
   ARCHIVE / SHOP LOOP – small swatch indicator dots
   ================================================================ */
.wapu-archive-swatches {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px;
	margin: 6px 0 4px;
}

.wapu-archive-swatch {
	display: inline-block;
	width: 16px;
	height: 16px;
	border: 1.5px solid rgba(0,0,0,.12);
	vertical-align: middle;
	flex-shrink: 0;
}

.wapu-archive-swatch--round   { border-radius: 50%; }
.wapu-archive-swatch--rounded { border-radius: 3px; }
.wapu-archive-swatch--square  { border-radius: 1px; }

.wapu-archive-swatch--img {
	object-fit: cover;
	vertical-align: middle;
}

.wapu-archive-swatch--label {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: auto;
	height: 18px;
	padding: 0 5px;
	font-size: 9px;
	font-weight: 600;
	color: #374151;
	background: #f3f4f6;
	border: 1px solid #e5e7eb;
	border-radius: 3px;
	line-height: 1;
	letter-spacing: 0.2px;
}

/* ================================================================
   RESPONSIVE ADJUSTMENTS
   ================================================================ */
@media ( max-width: 480px ) {
	.wapu-swatches-wrapper {
		gap: 6px;
	}

	.wapu-swatch--label {
		padding: 0 9px;
		font-size: 12px;
	}
}
