.rpj-product-selector {
	width: 100%;
	margin: 1rem 0;
	padding: 1.25rem;
	border: none;
	border-radius: 14px;
	background: #fff;
	box-shadow:
		0 8px 24px hsl(var(--rpj-color-dark-900, 212 61% 5%) / 0.06),
		0 0 0 1px hsl(var(--rpj-color-line, 212 61% 12%) / 0.15);
	grid-column: 1 / -1;
	position: relative;
	transition: opacity 0.18s ease, filter 0.18s ease;
}

.rpj-product-selector__header {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	margin-bottom: 0.85rem;
}

.rpj-product-selector__heading {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
}

.rpj-product-selector__title {
	margin: 0;
	font-family: var(--rpj-font-heading, sans-serif);
	font-size: 1.1rem;
	font-weight: 700;
	color: hsl(var(--rpj-color-dark-500, 212 61% 12%));
	letter-spacing: 0.02em;
}

.rpj-product-selector__hint {
	margin: 0;
	font-family: var(--rpj-font-body, sans-serif);
	color: hsl(var(--rpj-color-muted-600, 209 13% 49%));
	font-size: 0.95rem;
}

/* Hidden checkbox for CSS-only toggle (works without JavaScript) */
.rpj-product-selector__checkbox {
	position: absolute;
	opacity: 0;
	pointer-events: none;
	width: 0;
	height: 0;
}

/* Shared styles for both label and button toggle */
.rpj-product-selector__toggle-label,
.rpj-product-selector__toggle {
	/* Reset all defaults to ensure identical appearance */
	margin: 0;
	border: 1px solid hsl(var(--rpj-color-line, 212 61% 12%) / 0.2);
	border-radius: 999px;
	background: transparent;
	color: hsl(var(--rpj-color-dark-500, 212 61% 12%));
	font-family: var(--rpj-font-heading, sans-serif);
	font-size: 0.75rem;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	padding: 0.35rem 0.9rem;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
	white-space: nowrap;
	box-sizing: border-box;
	line-height: 1.2;
	vertical-align: middle;
	/* Ensure identical text rendering */
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;
	/* Remove any browser-specific button styles */
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	/* Force identical height and width calculation */
	height: auto;
	min-height: auto;
	width: auto;
	min-width: auto;
	/* Ensure text is centered identically */
	text-align: center;
	display: inline-block;
}

/* Label toggle (visible when JS is disabled) */
.rpj-product-selector__toggle-label {
	display: none; /* Hidden by default, shown via rules below */
	text-decoration: none;
}

.rpj-product-selector__toggle-label:hover,
.rpj-product-selector__toggle:hover {
	background: hsl(var(--rpj-color-surface-300, 220 45% 97%));
	border-color: hsl(var(--rpj-color-line, 212 61% 12%) / 0.35);
}

.rpj-product-selector__toggle-label:focus-visible,
.rpj-product-selector__toggle:focus-visible {
	outline: 2px solid hsl(var(--rpj-color-brand-500, 206 100% 34%));
	outline-offset: 2px;
}

/* Show label only when JS is disabled */
.no-js .rpj-product-selector__toggle-label,
.rpj-product-selector:not([data-js-enabled="true"]) .rpj-product-selector__toggle-label {
	display: inline-block;
}

/* Hide button when JS is disabled (label is shown instead) */
.no-js .rpj-product-selector__toggle,
.rpj-product-selector:not([data-js-enabled="true"]) .rpj-product-selector__toggle {
	display: none;
}

/* Hide label when JS is enabled */
.rpj-product-selector[data-js-enabled="true"] .rpj-product-selector__toggle-label {
	display: none !important;
	visibility: hidden !important;
}

/* Show button when JS is enabled */
.rpj-product-selector[data-js-enabled="true"] .rpj-product-selector__toggle {
	display: inline-block !important;
}

/* Button toggle (visible when JS is enabled) - inherits all shared styles above */
.rpj-product-selector__toggle {
	/* Additional button-specific resets to match label exactly */
	text-decoration: none;
	/* Ensure button doesn't have any default browser styling */
	outline: none;
	/* Remove any button-specific browser defaults */
	border-style: solid;
	/* Ensure no button-specific spacing or overflow */
	overflow: visible;
	text-indent: 0;
	/* Explicitly match all font properties (don't use font: inherit as it overrides our explicit values) */
	font-family: var(--rpj-font-heading, sans-serif);
	font-size: 0.75rem;
	font-weight: 600;
	font-style: normal;
	font-variant: normal;
	/* Match label's display exactly */
	display: inline-block;
}

.rpj-product-selector__list {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.rpj-product-selector__body {
	position: relative;
	overflow: hidden;
	max-height: 0;
	opacity: 0;
	transform: translateY(-6px);
	transition: max-height 0.3s ease, opacity 0.2s ease, transform 0.2s ease;
	will-change: max-height, opacity, transform;
}

.rpj-product-selector__item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.75rem;
	padding: 0.85rem 0.75rem;
	border: 1px solid hsl(var(--rpj-color-line, 212 61% 12%) / 0.1);
	border-radius: 12px;
	background: hsl(var(--rpj-color-surface-100, 220 45% 99%));
	flex-wrap: wrap;
}

.rpj-product-selector__info {
	flex: 1;
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.rpj-product-selector__name {
	font-family: var(--rpj-font-heading, sans-serif);
	font-weight: 600;
	color: hsl(var(--rpj-color-dark-500, 212 61% 12%));
	font-size: 1rem;
}

.rpj-product-selector__thumb {
	width: 56px;
	height: 56px;
	border-radius: 12px;
	overflow: hidden;
	flex-shrink: 0;
	background: hsl(var(--rpj-color-surface-300, 220 45% 97%));
}

.rpj-product-selector__thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.rpj-product-selector__qty {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
}

.rpj-product-selector__btn {
	width: 36px;
	height: 36px;
	border-radius: 10px;
	border: 1px solid hsl(var(--rpj-color-line, 212 61% 12%) / 0.12);
	background: #fff;
	color: hsl(var(--rpj-color-dark-500, 212 61% 12%));
	font-weight: 700;
	cursor: pointer;
	transition: all 0.15s ease;
}

.rpj-product-selector__btn:hover {
	background: hsl(var(--rpj-color-surface-300, 220 45% 97%));
	box-shadow: 0 4px 12px hsl(var(--rpj-color-dark-900, 212 61% 5%) / 0.08);
}

.rpj-product-selector__input {
	width: 64px;
	text-align: center;
	padding: 0.45rem 0.4rem;
	border-radius: 10px;
	border: 1px solid hsl(var(--rpj-color-line, 212 61% 12%) / 0.12);
	font-family: var(--rpj-font-body, sans-serif);
	color: hsl(var(--rpj-color-dark-500, 212 61% 12%));
	background: #fff;
	-moz-appearance: textfield;
	appearance: textfield;
}

.rpj-product-selector__input::-webkit-outer-spin-button,
.rpj-product-selector__input::-webkit-inner-spin-button {
	margin: 0;
	-webkit-appearance: none;
}

.rpj-product-selector__loading,
.rpj-product-selector__error,
.rpj-product-selector__empty {
	font-family: var(--rpj-font-body, sans-serif);
	color: hsl(var(--rpj-color-muted-600, 209 13% 49%));
	font-size: 0.95rem;
}

.rpj-product-selector__empty--zip {
	color: hsl(var(--rpj-color-dark-500, 212 61% 12%));
	font-weight: 600;
}

.rpj-product-selector--disabled {
	opacity: 0.6;
	filter: grayscale(0.1);
	pointer-events: none;
}

.rpj-product-selector--collapsed .rpj-product-selector__header {
	margin-bottom: 0;
}

.rpj-product-selector--collapsed .rpj-product-selector__body {
	pointer-events: none;
}

.rpj-product-selector:not(.rpj-product-selector--collapsed) .rpj-product-selector__body {
	opacity: 1;
	transform: translateY(0);
}

/* CSS-only toggle: checkbox controls visibility (works without JavaScript) */
/* Only apply these rules when JS is not enabled */
.rpj-product-selector:not([data-js-enabled="true"]) .rpj-product-selector__checkbox:not(:checked) ~ .rpj-product-selector__header ~ .rpj-product-selector__body {
	max-height: 0 !important;
	opacity: 0 !important;
	transform: translateY(-6px) !important;
	pointer-events: none !important;
}

.rpj-product-selector:not([data-js-enabled="true"]) .rpj-product-selector__checkbox:checked ~ .rpj-product-selector__header ~ .rpj-product-selector__body {
	max-height: 5000px !important; /* Large enough for content */
	opacity: 1 !important;
	transform: translateY(0) !important;
	pointer-events: auto !important;
}

/* Note: Label text won't update dynamically without JS, but the toggle will work.
   When JS is enabled, the button handles dynamic text updates. */

.rpj-product-selector__overlay {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 14px;
	background: rgba(255, 255, 255, 0.75);
	color: hsl(var(--rpj-color-dark-500, 212 61% 12%));
	font-family: var(--rpj-font-body, sans-serif);
	font-weight: 600;
	font-size: 0.95rem;
	padding: 1rem;
	text-align: center;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.18s ease;
}

.rpj-product-selector--disabled .rpj-product-selector__overlay {
	opacity: 1;
}

@media (max-width: 640px) {
	.rpj-product-selector__item {
		flex-direction: row;
		align-items: center;
		flex-wrap: nowrap;
		padding: 0.65rem 0.5rem;
		gap: 0.5rem;
	}

	.rpj-product-selector__info {
		flex: 0 0 auto;
		width: 120px;
		min-width: 0;
		gap: 0.5rem;
	}

	.rpj-product-selector__thumb {
		width: 44px;
		height: 44px;
		border-radius: 8px;
	}

	.rpj-product-selector__name {
		font-size: 0.8rem;
		line-height: 1.3;
	}

	.rpj-product-selector__qty {
		flex-shrink: 0;
		margin-left: auto;
		gap: 0.25rem;
	}

	.rpj-product-selector__btn {
		width: 28px;
		height: 28px;
		border-radius: 6px;
		font-size: 0.875rem;
	}

	.rpj-product-selector__input {
		width: 44px;
		padding: 0.3rem 0.25rem;
		border-radius: 6px;
		font-size: 0.875rem;
	}
}
