/**
 * Buy Buttons block: variation options, quantity and purchase CTAs.
 *
 * Single owner for the product form in both modes:
 * - preview (`.starterkit-product-form--preview`, Builder fixture/native data);
 * - live (`.starterkit-product-form--live`, WooCommerce `form.cart`, optionally
 *   enhanced by the WC Product Engine selector `.wpe-swatches`).
 *
 * Visual language follows the Product Gallery: 1px neutral borders, a 2px ink
 * ring for the selected state drawn inside the control (no layout shift), small
 * radii, no shadows.
 */

/* Tokens ------------------------------------------------------------------ */

.starterkit-product-form {
	--starterkit-form-ink: var(--sk-color-ink, #111827);
	--starterkit-form-muted: var(--sk-color-muted, #334155);
	--starterkit-form-surface: var(--sk-color-surface, #ffffff);
	--starterkit-form-subtle: var(--sk-color-subtle, #f8fafc);
	--starterkit-form-focus: var(--sk-color-focus, #005bd3);
	--starterkit-form-border: color-mix(in srgb, var(--starterkit-form-ink) 22%, var(--starterkit-form-surface));
	--starterkit-form-border-hover: color-mix(in srgb, var(--starterkit-form-ink) 55%, var(--starterkit-form-surface));
	--starterkit-form-border-subtle: color-mix(in srgb, var(--starterkit-form-ink) 12%, var(--starterkit-form-surface));
	--starterkit-form-disabled: color-mix(in srgb, var(--starterkit-form-ink) 45%, var(--starterkit-form-surface));
	--starterkit-form-primary-hover: color-mix(in srgb, var(--starterkit-form-ink) 86%, var(--starterkit-form-surface));
	--starterkit-form-secondary-hover: color-mix(in srgb, var(--starterkit-form-ink) 5%, var(--starterkit-form-surface));
	/* Control radius (quantity, CTAs) follows the Template button radius; option radius is the Builder "Button shape". */
	--starterkit-form-radius: var(--radius-button, 6px);
	--starterkit-form-option-radius: var(--starterkit-product-option-radius, 6px);
	/* Image cards cap the radius like Gallery thumbnails so small tiles stay crisp. */
	--starterkit-form-card-radius: min(var(--starterkit-form-option-radius), var(--sk-radius-sm, 8px));
	--starterkit-form-option-height: 44px;
	--starterkit-form-control-height: 48px;
	--starterkit-form-option-gap: 8px;
	--starterkit-form-cta-gap: 10px;
	--starterkit-form-swatch-size: 40px;
	--starterkit-form-thumb-size: 56px;
	--starterkit-form-gap: var(--starterkit-product-form-gap, 18px);
	--starterkit-form-transition: 0.15s ease;
	/* Buy now "Solid": the eCommerce CTA colour from Template settings. */
	--starterkit-form-cta: var(--color-ecommerce-cta, var(--starterkit-form-ink));
	display: grid;
	gap: var(--starterkit-form-gap);
	color: var(--starterkit-form-ink);
}

/* Live mode: WooCommerce `form.cart` is the grid (its margin/clearfix reset lives in Product Content). */
.starterkit-product-form--live form.cart {
	display: grid;
	gap: var(--starterkit-form-gap);
}

/* Builder visibility toggles ---------------------------------------------- */

.starterkit-product-form[data-show-quantity="false"] :is([data-product-quantity], .quantity) {
	display: none !important;
}

.starterkit-product-form[data-show-buy-now="false"] .starterkit-product-form__buy-button {
	display: none !important;
}

.starterkit-product-form[data-show-swatches="false"] .starterkit-product-form__swatch {
	display: none !important;
}

.starterkit-product-form[data-show-stock="false"] :is([data-product-stock], .stock) {
	display: none !important;
}

.starterkit-product-form[data-show-clear="false"] .reset_variations {
	display: none !important;
}

/* Option groups and labels ------------------------------------------------ */

.starterkit-product-form__options {
	display: grid;
	gap: 16px;
}

.starterkit-product-form__option {
	min-width: 0;
	margin: 0;
	padding: 0;
	border: 0;
}

.starterkit-product-form__option legend,
.starterkit-product-form--live form.cart table.variations th.label {
	color: var(--starterkit-form-ink);
	font-size: 14px;
	font-weight: 500;
	line-height: 1.4;
}

.starterkit-product-form__option legend {
	margin-bottom: 8px;
	padding: 0;
}

/* Preview: labels beside the values (live mode styles the WooCommerce table instead). */
.starterkit-product-form--preview[data-label-position="inline"] .starterkit-product-form__option {
	display: flex;
	align-items: center;
	gap: 12px;
}

.starterkit-product-form--preview[data-label-position="inline"] .starterkit-product-form__option legend {
	float: left;
	flex: 0 0 auto;
	min-width: 96px;
	margin: 0;
}

.starterkit-product-form--preview[data-label-position="inline"] :is(.starterkit-product-form__option-values, .starterkit-product-form__option-select) {
	flex: 1 1 auto;
	min-width: 0;
}

.starterkit-product-form__option legend strong,
.starterkit-product-form--live .starterkit-live-option-selected {
	font-weight: 600;
}

/* Live WooCommerce variations table → stacked rows. */
.woocommerce div.product .starterkit-product-form--live form.cart table.variations,
.starterkit-product-form--live form.cart table.variations {
	width: 100%;
	margin: 0;
	border: 0;
}

.starterkit-product-form--live form.cart table.variations th,
.starterkit-product-form--live form.cart table.variations td {
	padding: 0;
	border: 0;
	line-height: 1.4;
	text-align: left;
	vertical-align: middle;
}

.starterkit-product-form--live form.cart table.variations th.label label {
	color: inherit;
	font-weight: inherit;
}

.starterkit-product-form--live:not([data-label-position="inline"]) table.variations,
.starterkit-product-form--live:not([data-label-position="inline"]) table.variations tbody {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.starterkit-product-form--live:not([data-label-position="inline"]) table.variations tr {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.starterkit-product-form--live:not([data-label-position="inline"]) table.variations :is(th.label, td.value) {
	display: block;
	width: 100%;
}

.starterkit-product-form--live[data-label-position="inline"] form.cart table.variations :is(th.label, td.value) {
	padding-bottom: 12px;
}

.starterkit-product-form--live[data-label-position="inline"] form.cart table.variations th.label {
	width: 100px;
	padding-right: 12px;
}

/* Dropdown selector type. */
.woocommerce div.product .starterkit-product-form--live form.cart .variations select,
.starterkit-product-form--live form.cart table.variations select,
.starterkit-product-form__option-select {
	box-sizing: border-box;
	width: 100%;
	min-width: 0;
	min-height: var(--starterkit-form-option-height);
	margin: 0;
	padding: 8px 38px 8px 12px;
	border: 1px solid var(--starterkit-form-border);
	border-radius: var(--starterkit-form-radius);
	background-color: var(--starterkit-form-surface);
	color: var(--starterkit-form-ink);
	font-size: 14px;
}

.starterkit-product-form--live .starterkit-native-select-hidden {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	white-space: nowrap !important;
	border: 0 !important;
	opacity: 0 !important;
	pointer-events: none !important;
}

/* Theme option buttons (preview + live fallback) --------------------------- */

.starterkit-product-form__option-values {
	display: flex;
	flex-wrap: wrap;
	gap: var(--starterkit-form-option-gap);
	max-width: 100%;
}

.starterkit-product-form__option-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	box-sizing: border-box;
	min-width: var(--starterkit-form-option-height);
	min-height: var(--starterkit-form-option-height);
	margin: 0;
	padding: 0 14px;
	border: 1px solid var(--starterkit-form-border);
	border-radius: var(--starterkit-form-option-radius);
	background: var(--starterkit-form-surface);
	color: var(--starterkit-form-ink);
	font: inherit;
	font-size: 14px;
	font-weight: 500;
	line-height: 1.2;
	cursor: pointer;
	transition: border-color var(--starterkit-form-transition), box-shadow var(--starterkit-form-transition);
}

.starterkit-product-form__option-button:hover:not(:disabled):not(.is-active) {
	border-color: var(--starterkit-form-border-hover);
}

/* Selected: 2px ink ring inside the control, matching Gallery thumbnails. */
.starterkit-product-form__option-button.is-active {
	border-color: var(--starterkit-form-ink);
	box-shadow: inset 0 0 0 1px var(--starterkit-form-ink);
}

.starterkit-product-form__option-button:disabled {
	border-color: var(--starterkit-form-border-subtle);
	background: var(--starterkit-form-subtle);
	color: var(--starterkit-form-disabled);
	box-shadow: none;
	text-decoration: line-through;
	cursor: not-allowed;
}

.starterkit-product-form__swatch {
	flex-shrink: 0;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: var(--starterkit-product-swatch, #d1d5db);
	/* One hairline so white/light swatches stay visible. */
	box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

/* WC Product Engine selector ---------------------------------------------- */

/* The plugin declares its tokens on these elements, so they are remapped here. */
.starterkit-product-form :is(.variations_form, .wpe-variant-selector, .wpe-product-instance, .wpe-swatches) {
	--wpe-sel-surface: var(--starterkit-form-surface);
	--wpe-sel-surface-hover: var(--starterkit-form-surface);
	--wpe-sel-text: var(--starterkit-form-ink);
	--wpe-sel-border: var(--starterkit-form-border);
	--wpe-sel-border-hover: var(--starterkit-form-border-hover);
	--wpe-sel-accent: var(--starterkit-form-ink);
	--wpe-sel-accent-surface: var(--starterkit-form-surface);
	--wpe-sel-accent-text: var(--starterkit-form-ink);
	--wpe-sel-disabled-border: var(--starterkit-form-border-subtle);
	--wpe-sel-disabled-surface: var(--starterkit-form-subtle);
	--wpe-sel-disabled-text: var(--starterkit-form-disabled);
	--wpe-sel-unavailable-mark: var(--starterkit-form-disabled);
	--wpe-sel-light-swatch-border: var(--starterkit-form-border);
	--wpe-sel-radius: var(--starterkit-form-option-radius);
	--wpe-sel-radius-image: var(--starterkit-form-card-radius);
}

.starterkit-product-form .wpe-swatches {
	gap: var(--starterkit-form-option-gap);
}

/* Size / button values. */
.starterkit-product-form .wpe-swatches .wpe-swatch.wpe-swatch {
	min-width: var(--starterkit-form-option-height);
	min-height: var(--starterkit-form-option-height);
	padding: 0 14px;
	font-size: 14px;
	font-weight: 500;
	line-height: 1.2;
	transition: border-color var(--starterkit-form-transition), box-shadow var(--starterkit-form-transition);
}

/* Color values: one circle, no label, no stacked rings. */
.starterkit-product-form .wpe-swatches .wpe-swatch.wpe-swatch-color:not(.wpe-swatch-color-fallback) {
	flex: 0 0 var(--starterkit-form-swatch-size);
	width: var(--starterkit-form-swatch-size);
	height: var(--starterkit-form-swatch-size);
	min-width: var(--starterkit-form-swatch-size);
	min-height: var(--starterkit-form-swatch-size);
	padding: 3px;
	border-color: transparent;
	border-radius: 50%;
}

.starterkit-product-form .wpe-swatch-color-bubble {
	border: 0;
	box-shadow: none;
}

.starterkit-product-form .wpe-swatch-color-bubble.is-light-swatch {
	border: 0;
	box-shadow: inset 0 0 0 1px var(--starterkit-form-border);
}

/* Style / image values: fixed card width, square thumbnail, label below. */
.starterkit-product-form .wpe-swatches .wpe-swatch.wpe-swatch-image {
	flex-direction: column;
	justify-content: flex-start;
	gap: 6px;
	/* thumbnail + 2 × 4px padding + 2 × 1px border */
	width: calc(var(--starterkit-form-thumb-size) + 10px);
	min-width: 0;
	max-width: none;
	height: auto;
	padding: 4px 4px 6px;
	border-radius: var(--starterkit-form-card-radius);
}

.starterkit-product-form .wpe-swatch-image .wpe-swatch-image-wrap {
	width: 100%;
	height: auto;
	aspect-ratio: 1 / 1;
	border-radius: max(0px, calc(var(--starterkit-form-card-radius) - 4px));
	background-color: var(--starterkit-form-subtle);
}

.starterkit-product-form .wpe-swatches .wpe-swatch-image img {
	border-radius: 0;
}

.starterkit-product-form .wpe-swatch-image-label {
	display: -webkit-box;
	width: 100%;
	overflow: hidden;
	font-size: 12px;
	font-weight: 500;
	line-height: 1.3;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

/* Selected (all value types): the same 2px ink ring as the theme buttons. */
.starterkit-product-form .wpe-swatches .wpe-swatch.wpe-swatch:is([aria-checked="true"], .is-selected) {
	border: 1px solid var(--starterkit-form-ink);
	background-color: var(--starterkit-form-surface);
	color: var(--starterkit-form-ink);
	font-weight: 500;
	box-shadow: inset 0 0 0 1px var(--starterkit-form-ink);
}

/* Unavailable values keep the plugin's cross-out mark; the ring is dropped. */
.starterkit-product-form .wpe-swatches .wpe-swatch.wpe-swatch:is([aria-disabled="true"], .is-disabled, .is-unavailable) {
	border-color: var(--starterkit-form-border-subtle);
	background-color: var(--starterkit-form-subtle);
	color: var(--starterkit-form-disabled);
	box-shadow: none;
}

.starterkit-product-form .wpe-swatches .wpe-swatch.wpe-swatch:focus-visible {
	outline: 2px solid var(--starterkit-form-focus);
	outline-offset: 2px;
}

/* Clear selection --------------------------------------------------------- */

.woocommerce div.product .starterkit-product-form--live form.cart .reset_variations,
.starterkit-product-form--live .reset_variations,
.starterkit-product-form__clear {
	display: inline-block;
	margin-top: 8px;
	padding: 0;
	border: 0;
	background: none;
	color: var(--starterkit-form-muted);
	font-size: 13px;
	font-weight: 500;
	line-height: 1.4;
	text-decoration: underline;
	text-decoration-color: var(--starterkit-form-border);
	text-underline-offset: 3px;
	cursor: pointer;
	transition: color var(--starterkit-form-transition), text-decoration-color var(--starterkit-form-transition);
}

.starterkit-product-form__clear[hidden] {
	display: none;
}

/* The Builder preview has no form.cart; the Clear link sits under the options. */
.starterkit-product-form--preview .starterkit-product-form__clear {
	justify-self: start;
	margin-top: calc(8px - var(--starterkit-form-gap));
}

.starterkit-product-form--live .reset_variations:hover,
.starterkit-product-form__clear:hover {
	color: var(--starterkit-form-ink);
	text-decoration-color: currentColor;
}

/* Purchase row ------------------------------------------------------------ */

.starterkit-product-form__purchase-row,
.starterkit-product-form--live .starterkit-add-to-cart-row {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr);
	gap: var(--starterkit-form-cta-gap);
	align-items: stretch;
	width: 100%;
}

.starterkit-product-form[data-full-width-button="true"] :is(.starterkit-product-form__purchase-row, .starterkit-add-to-cart-row),
.starterkit-product-form[data-show-quantity="false"] :is(.starterkit-product-form__purchase-row, .starterkit-add-to-cart-row) {
	grid-template-columns: 1fr;
}

/* Quantity stepper: one bordered control, borderless parts. */
.starterkit-product-form__quantity,
.starterkit-product-form--live .starterkit-add-to-cart-row .quantity {
	display: inline-flex;
	align-items: stretch;
	box-sizing: border-box;
	width: auto;
	min-height: var(--starterkit-form-control-height);
	margin: 0;
	border: 1px solid var(--starterkit-form-border);
	border-radius: var(--starterkit-form-radius);
	background: var(--starterkit-form-surface);
	overflow: hidden;
}

.woocommerce div.product .starterkit-product-form--live form.cart div.quantity {
	float: none;
	margin: 0;
}

.starterkit-product-form__quantity button,
.starterkit-product-form--live .quantity .starterkit-qty-btn {
	display: flex;
	flex: 0 0 40px;
	align-items: center;
	justify-content: center;
	width: 40px;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	color: var(--starterkit-form-ink);
	font: inherit;
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
	user-select: none;
	transition: background-color var(--starterkit-form-transition);
}

.starterkit-product-form__quantity button:hover,
.starterkit-product-form--live .quantity .starterkit-qty-btn:hover {
	background: var(--starterkit-form-subtle);
}

/* The stepper clips overflow, so focus is drawn inside each part. */
.starterkit-product-form .starterkit-product-form__quantity :is(button, input):focus-visible,
.starterkit-product-form--live .quantity :is(.starterkit-qty-btn, .qty):focus-visible {
	outline: 2px solid var(--starterkit-form-focus);
	outline-offset: -2px;
}

.starterkit-product-form__quantity input,
.starterkit-product-form--live .quantity .qty {
	box-sizing: border-box;
	flex: 1 1 44px;
	width: 44px;
	min-width: 0;
	min-height: 0;
	margin: 0;
	padding: 0 4px;
	border: 0;
	border-radius: 0;
	background: transparent;
	color: var(--starterkit-form-ink);
	font: inherit;
	font-size: 15px;
	font-weight: 500;
	text-align: center;
	-moz-appearance: textfield;
	appearance: textfield;
}

.starterkit-product-form__quantity input::-webkit-inner-spin-button,
.starterkit-product-form__quantity input::-webkit-outer-spin-button,
.starterkit-product-form--live .quantity .qty::-webkit-inner-spin-button,
.starterkit-product-form--live .quantity .qty::-webkit-outer-spin-button {
	margin: 0;
	-webkit-appearance: none;
}

/* CTAs: primary (Add to Cart) filled, secondary (Buy It Now) outlined. ----- */

.starterkit-product-form__add-button,
.starterkit-product-form__buy-button,
.starterkit-product-form .single_add_to_cart_button.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: 100%;
	min-height: var(--starterkit-form-control-height);
	margin: 0;
	padding: 0 24px;
	border: 1px solid var(--starterkit-form-ink);
	border-radius: var(--starterkit-form-radius);
	font-family: inherit;
	/* Typography follows the Template button settings, shared by both CTAs. */
	font-size: var(--font-size-button, 15px);
	font-weight: var(--font-weight-button, 600);
	line-height: 1.2;
	letter-spacing: normal;
	text-transform: var(--text-transform-button, none);
	box-shadow: none;
	transform: none;
	cursor: pointer;
	transition: background-color var(--starterkit-form-transition), border-color var(--starterkit-form-transition), color var(--starterkit-form-transition);
}

/* Outranks the global `.woocommerce button.button.alt` (shadow + lift). */
.starterkit-product-form__add-button,
.starterkit-product-form .single_add_to_cart_button.button.alt {
	border-color: var(--starterkit-form-ink);
	background: var(--starterkit-form-ink);
	color: var(--starterkit-form-surface);
	box-shadow: none;
}

.starterkit-product-form__add-button:hover:not(:disabled),
.starterkit-product-form .single_add_to_cart_button.button.alt:hover:not(:disabled):not(.disabled) {
	border-color: var(--starterkit-form-primary-hover);
	background: var(--starterkit-form-primary-hover);
	box-shadow: none;
	transform: none;
}

.starterkit-product-form .single_add_to_cart_button.button.alt:is(:disabled, .disabled),
.starterkit-product-form .single_add_to_cart_button.button.alt:is(:disabled, .disabled):hover {
	border-color: var(--starterkit-form-ink);
	background: var(--starterkit-form-ink);
	color: var(--starterkit-form-surface);
	opacity: 0.45;
	box-shadow: none;
	transform: none;
	cursor: not-allowed;
}

.starterkit-product-form__buy-button {
	/* Sits directly under the purchase row: tighten the form gap to the CTA gap. */
	margin-top: calc(var(--starterkit-form-cta-gap) - var(--starterkit-form-gap));
	background: var(--starterkit-form-surface);
	color: var(--starterkit-form-ink);
}

.starterkit-product-form__buy-button:hover:not(:disabled) {
	background: var(--starterkit-form-secondary-hover);
}

/* Buy now style (Block setting); "outline" is the default above. */
.starterkit-product-form[data-buy-now-style="solid"] .starterkit-product-form__buy-button {
	border-color: var(--starterkit-form-cta);
	background: var(--starterkit-form-cta);
	color: var(--starterkit-form-surface);
}

.starterkit-product-form[data-buy-now-style="solid"] .starterkit-product-form__buy-button:hover:not(:disabled) {
	border-color: color-mix(in srgb, var(--starterkit-form-cta) 86%, #000000);
	background: color-mix(in srgb, var(--starterkit-form-cta) 86%, #000000);
}

.starterkit-product-form[data-buy-now-style="dark"] .starterkit-product-form__buy-button {
	border-color: var(--starterkit-form-ink);
	background: var(--starterkit-form-ink);
	color: var(--starterkit-form-surface);
}

.starterkit-product-form[data-buy-now-style="dark"] .starterkit-product-form__buy-button:hover:not(:disabled) {
	border-color: var(--starterkit-form-primary-hover);
	background: var(--starterkit-form-primary-hover);
}

/* Unavailable CTAs (incomplete or out-of-stock selection) share one disabled look. */
.starterkit-product-form__add-button:disabled,
.starterkit-product-form__buy-button:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

/* While Buy It Now navigates to checkout, neither CTA accepts another click. */
.starterkit-product-form--live form.cart.is-buy-now-pending :is(.single_add_to_cart_button, .starterkit-product-form__buy-button) {
	pointer-events: none;
}

.starterkit-product-form__buy-button[aria-busy="true"] {
	cursor: progress;
}

.starterkit-product-form__stock {
	margin: 0;
	font-size: 14px;
}

/* Responsive -------------------------------------------------------------- */

/* Matches the canonical Product Content breakpoint (768px). */
@media (max-width: 767px) {
	.starterkit-product-form {
		--starterkit-form-gap: var(--starterkit-product-form-gap-mobile, var(--starterkit-product-form-gap, 18px));
		--starterkit-form-thumb-size: 52px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.starterkit-product-form *,
	.starterkit-product-form .wpe-swatches .wpe-swatch.wpe-swatch {
		transition: none;
	}
}
