/*
 * Size selector and size chart popup.
 *
 * Deliberately quieter than the rest of the product card: the selected pill is
 * black rather than brand red so the red Add to Cart button stays the only
 * primary action on the page.
 */

.adc-size {
	display: block;
	/* form.cart is display:flex;flex-wrap:wrap in this theme, so without an
	   explicit 100% basis the selector sits beside the quantity box and Add to
	   Cart instead of taking its own row above them. */
	flex: 1 0 100%;
	width: 100%;
	/* Fieldsets default to min-width:min-content, which lets the 6-column
	   grid push past its container on narrow phones. */
	min-width: 0;
	margin: 0 0 18px;
	padding: 0;
	border: 0;
}

.adc-size__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 12px;
}

.adc-size__legend {
	padding: 0;
	margin: 0;
	color: var(--adc-black);
	font-size: 13px;
	font-weight: 500;
	letter-spacing: .02em;
}

.adc-size__chart-link {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 4px 0;
	border: 0;
	background: transparent;
	color: var(--adc-muted);
	font-size: 13px;
	font-weight: 400;
	text-decoration: underline;
	text-underline-offset: 3px;
	cursor: pointer;
	transition: color .2s cubic-bezier(.25,.1,.25,1);
}

.adc-size__chart-link:hover,
.adc-size__chart-link:focus-visible {
	color: var(--adc-black);
}

.adc-size__chart-link svg {
	width: 15px;
	height: 15px;
	fill: currentColor;
}

.adc-size__options {
	display: grid;
	grid-template-columns: repeat(6, minmax(0, 1fr));
	gap: 8px;
}

.adc-size__option {
	position: relative;
	display: block;
	margin: 0;
}

/* The real radio stays in the DOM for keyboard and screen-reader support. */
.adc-size__option input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.adc-size__option span {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 52px;
	padding: 0 4px;
	border: 1px solid var(--adc-border);
	border-radius: 14px;
	background: #fff;
	color: var(--adc-text);
	font-size: 14px;
	font-weight: 500;
	line-height: 1;
	text-align: center;
	cursor: pointer;
	transition: background .18s cubic-bezier(.25,.1,.25,1),
		color .18s cubic-bezier(.25,.1,.25,1),
		border-color .18s cubic-bezier(.25,.1,.25,1),
		transform .18s cubic-bezier(.25,.1,.25,1);
}

.adc-size__option:hover span {
	border-color: #c9ccd2;
}

.adc-size__option input:checked + span {
	border-color: var(--adc-black);
	background: var(--adc-black);
	color: #fff;
	transform: scale(1.03);
}

.adc-size__option input:focus-visible + span {
	outline: 2px solid var(--adc-blue);
	outline-offset: 2px;
}

.adc-size__error {
	min-height: 18px;
	margin: 8px 0 0;
	color: var(--adc-red);
	font-size: 12px;
	font-weight: 500;
}

.adc-size.is-invalid .adc-size__options {
	animation: adc-size-shake .32s cubic-bezier(.36,.07,.19,.97);
}

@keyframes adc-size-shake {
	10%, 90% { transform: translateX(-2px); }
	20%, 80% { transform: translateX(3px); }
	30%, 50%, 70% { transform: translateX(-5px); }
	40%, 60% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
	.adc-size__option span,
	.adc-size-modal__panel {
		transition: none !important;
	}

	.adc-size.is-invalid .adc-size__options {
		animation: none;
	}
}


/* Size chart popup ------------------------------------------------------- */

html.adc-size-modal-open,
html.adc-size-modal-open body {
	overflow: hidden;
}

.adc-size-modal {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: flex;
	align-items: center;
	justify-content: center;
}

.adc-size-modal[hidden] {
	display: none;
}

.adc-size-modal__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(20, 25, 35, .5);
	backdrop-filter: blur(3px);
	opacity: 0;
	transition: opacity .24s cubic-bezier(.25,.1,.25,1);
}

.adc-size-modal.is-open .adc-size-modal__backdrop {
	opacity: 1;
}

.adc-size-modal__panel {
	position: relative;
	width: min(680px, calc(100% - 40px));
	/* A definite height, not max-height: the chart image is absolutely
	   positioned so it contributes no intrinsic height for flex to divide. */
	height: min(86vh, 760px);
	display: flex;
	flex-direction: column;
	padding: 22px 24px 26px;
	border-radius: var(--adc-radius);
	background: #fff;
	box-shadow: 0 24px 60px rgba(20, 25, 35, .22);
	opacity: 0;
	transform: translateY(12px) scale(.98);
	transition: opacity .24s cubic-bezier(.25,.1,.25,1),
		transform .24s cubic-bezier(.25,.1,.25,1);
}

.adc-size-modal.is-open .adc-size-modal__panel {
	opacity: 1;
	transform: none;
}

.adc-size-modal__grabber {
	display: none;
}

.adc-size-modal__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 14px;
	margin-bottom: 14px;
}

.adc-size-modal__title {
	margin: 0;
	color: var(--adc-black);
	font-size: 17px;
	font-weight: 500;
	letter-spacing: -.01em;
}

.adc-size-modal__close {
	display: grid;
	place-items: center;
	flex: 0 0 auto;
	width: 34px;
	height: 34px;
	border: 0;
	border-radius: 50%;
	background: var(--adc-soft);
	color: var(--adc-muted);
	cursor: pointer;
	transition: background .2s cubic-bezier(.25,.1,.25,1), color .2s cubic-bezier(.25,.1,.25,1);
}

.adc-size-modal__close:hover {
	background: #e9eaed;
	color: var(--adc-black);
}

.adc-size-modal__close svg {
	width: 15px;
	height: 15px;
	fill: currentColor;
}

.adc-size-modal__viewport {
	position: relative;
	flex: 1 1 auto;
	/* Flex items default to min-height:auto and refuse to shrink below their
	   content, which is what let the chart overflow and get clipped. */
	min-height: 0;
	overflow: hidden;
	border: 1px solid var(--adc-border);
	border-radius: 16px;
	background: var(--adc-soft);
	touch-action: none;
	cursor: zoom-in;
}

.adc-size-modal__viewport.is-zoomed {
	cursor: grab;
}

/*
 * Two classes on purpose. WooCommerce ships `.woocommerce img { height: auto }`
 * at specificity (0,1,1), which outranks a single class and stretches the chart
 * past the viewport. (0,2,0) wins that cleanly without !important.
 *
 * Filling the box exactly also keeps the zoom maths honest: the image box and
 * the viewport box share an origin, so transform-origin 0 0 and the pan clamps
 * in size-selector.js line up.
 */
.adc-size-modal__viewport .adc-size-modal__image {
	display: block;
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: none;
	max-height: none;
	object-fit: contain;
	transform-origin: 0 0;
	transition: transform .22s cubic-bezier(.25,.1,.25,1);
	will-change: transform;
	user-select: none;
	-webkit-user-drag: none;
}

.adc-size-modal__viewport.is-panning .adc-size-modal__image {
	transition: none;
}

.adc-size-modal__hint,
.adc-size-modal__caption {
	margin: 10px 0 0;
	color: var(--adc-muted);
	font-size: 12px;
	line-height: 1.5;
}

.adc-size-modal__caption {
	margin-top: 6px;
}


/* Mobile: full-bleed bottom sheet ---------------------------------------- */

@media (max-width: 760px) {
	.adc-size__options {
		gap: 7px;
	}

	.adc-size__option span {
		height: 48px;
		border-radius: 13px;
		font-size: 13px;
	}

	.adc-size-modal {
		align-items: flex-end;
	}

	.adc-size-modal__panel {
		width: 100%;
		max-width: none;
		height: 88vh;
		padding: 12px 18px 24px;
		border-radius: var(--adc-radius) var(--adc-radius) 0 0;
		transform: translateY(100%);
	}

	.adc-size-modal.is-open .adc-size-modal__panel {
		transform: none;
	}

	.adc-size-modal__grabber {
		display: block;
		width: 38px;
		height: 4px;
		margin: 0 auto 14px;
		border-radius: 999px;
		background: var(--adc-border);
	}
}
