/* =========================================================================
 * Size picker — custom, animated, for WooCommerce variation attributes.
 *
 * The native <select> stays in the DOM and remains the single source of truth.
 * It is only visually hidden; every click here writes the value back to it and
 * fires a real `change` event, so WooCommerce's own variation script — and the
 * store's custom "notify me when back in stock" tool — react exactly as before.
 *
 * Scope: only `.summary table.variations`, i.e. the product page variable
 * product form. Nothing on the shop, category, cart or checkout pages.
 *
 * Loaded on single-product pages only (see functions.php), so the other
 * templates pay nothing for it.
 *
 * Design notes: the picker reads as a soft panel, not a browser dropdown.
 * Colours come from the store palette (--ink / --line / --muted) so it matches
 * the buttons and the Brand Style band.
 * ========================================================================= */

/* --- The wrapper shell ---------------------------------------------------- */
.mg-size {
	position: relative;
	width: 100%;
}

/* The trigger button. Same footprint as the select it replaces, so the product
 * summary does not shift when the script swaps them in. */
.mg-size__trigger {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	width: 100%;
	padding: 12px;
	border: 1px solid var(--line, #e9e9e9);
	border-radius: 10px;
	background: #fff;
	color: var(--ink, #0a0a0a);
	font: inherit;
	font-size: 14px;
	line-height: 1.4;
	text-align: right;
	cursor: pointer;
	transition: border-color 160ms ease, box-shadow 160ms ease;
}

.mg-size__trigger:hover {
	border-color: #c9c9c9;
}

/* Keyboard focus must stay obvious — the native select is hidden, so its focus
 * ring disappears with it. This restores an equivalent affordance. */
.mg-size__trigger:focus-visible {
	outline: 2px solid var(--ink, #0a0a0a);
	outline-offset: 2px;
}

.mg-size__trigger[aria-expanded="true"] {
	border-color: var(--ink, #0a0a0a);
}

/* Placeholder state reads as a prompt, chosen state as a value. */
.mg-size__trigger.is-empty {
	color: var(--muted, #8c8c8c);
}

.mg-size__value {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Chevron: pure CSS so no icon font or SVG file is needed. Rotates on open. */
.mg-size__chev {
	flex: 0 0 auto;
	width: 9px;
	height: 9px;
	margin-inline-start: 4px;
	border-right: 1.5px solid currentColor;
	border-bottom: 1.5px solid currentColor;
	transform: rotate(45deg) translateY(-2px);
	transition: transform 220ms cubic-bezier(0.22, 0.61, 0.36, 1);
	opacity: 0.55;
}

.mg-size__trigger[aria-expanded="true"] .mg-size__chev {
	transform: rotate(-135deg) translateY(-2px);
}

/* --- The panel ------------------------------------------------------------ */
.mg-size__panel {
	position: absolute;
	inset-inline: 0;
	top: calc(100% + 6px);
	z-index: 40;
	max-height: 268px;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 6px;
	background: #fff;
	border: 1px solid var(--line, #e9e9e9);
	border-radius: 12px;
	box-shadow: 0 16px 40px rgba(10, 10, 10, 0.13);
	/* Closed state: invisible and non-interactive, but still in the DOM so the
	 * open animation has something to start from. */
	opacity: 0;
	visibility: hidden;
	transform: translateY(-6px) scale(0.985);
	transform-origin: top center;
	transition:
		opacity 160ms ease,
		transform 200ms cubic-bezier(0.22, 0.61, 0.36, 1),
		visibility 0s linear 200ms;
}

.mg-size.is-open .mg-size__panel {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition:
		opacity 160ms ease,
		transform 200ms cubic-bezier(0.22, 0.61, 0.36, 1),
		visibility 0s;
}

/* --- Options -------------------------------------------------------------- */
.mg-size__opt {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	width: 100%;
	min-height: 44px;          /* comfortable touch target */
	padding: 8px 12px;
	border: 0;
	border-radius: 8px;
	background: none;
	color: var(--ink, #0a0a0a);
	font: inherit;
	font-size: 14px;
	text-align: right;
	cursor: pointer;
	transition: background-color 120ms ease;
}

.mg-size__opt:hover {
	background: var(--soft, #f2f2f2);
}

.mg-size__opt:focus-visible {
	outline: 2px solid var(--ink, #0a0a0a);
	outline-offset: -2px;
}

/* Selected row: bold ink text, no background — the tick does the talking. */
.mg-size__opt[aria-selected="true"] {
	font-weight: 600;
}

.mg-size__opt-label {
	flex: 1 1 auto;
}

/* --- The drawn tick -------------------------------------------------------
 * Two strokes drawn with stroke-dashoffset, the same idea as the Animate UI
 * "draw" check animation referenced in the brief. Pure CSS/SVG, no library.
 * ---------------------------------------------------------------------- */
.mg-size__tick {
	flex: 0 0 auto;
	width: 16px;
	height: 16px;
	overflow: visible;
	opacity: 0;
	transition: opacity 120ms ease;
}

.mg-size__opt[aria-selected="true"] .mg-size__tick {
	opacity: 1;
}

.mg-size__tick path {
	fill: none;
	stroke: currentColor;
	stroke-width: 2.2;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-dasharray: 18;
	stroke-dashoffset: 18;
}

/* Playing the animation only on the selected row means it is not fired for
 * every option on open — cheaper, and it lands where the eye already is. */
.mg-size__opt[aria-selected="true"] .mg-size__tick path {
	animation: mg-tick-draw 260ms cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

@keyframes mg-tick-draw {
	to { stroke-dashoffset: 0; }
}

/* --- Hidden native control -----------------------------------------------
 * Kept in the accessibility tree and still focusable/operable by WooCommerce's
 * script, but with no visual footprint. `clip-path` is used instead of
 * display:none because a display:none element cannot receive the synthetic
 * change event in some browsers.
 * ---------------------------------------------------------------------- */
.mg-size__native {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	margin: -1px !important;
	padding: 0 !important;
	border: 0 !important;
	overflow: hidden !important;
	white-space: nowrap !important;
	clip-path: inset(50%) !important;
}

/* --- "clear" link ---------------------------------------------------------
 * WooCommerce prints its own reset link. It stays functional but is aligned to
 * the trigger instead of floating under a select that is no longer visible.
 * ---------------------------------------------------------------------- */
.summary table.variations .reset_variations {
	display: inline-block;
	margin-top: 6px;
	text-decoration: underline;
	text-underline-offset: 3px;
}

/* --- Phones --------------------------------------------------------------- */
@media (max-width: 767px) {
	.mg-size__trigger {
		padding: 10px;
		font-size: 13px;
		border-radius: 8px;
	}
	.mg-size__panel {
		max-height: 232px;
		border-radius: 10px;
	}
	.mg-size__opt {
		min-height: 42px;
		padding: 7px 10px;
		font-size: 13px;
	}
}

/* Very small phones (iPhone SE and similar). */
@media (max-width: 380px) {
	.mg-size__trigger {
		padding: 7px 6px;
		font-size: 12px;
	}
	.mg-size__opt {
		min-height: 40px;
		font-size: 12px;
	}
}

/* --- Reduce motion --------------------------------------------------------
 * Honours the OS setting: no slide, no scale, no tick drawing. The picker is
 * fully usable, it just changes instantly.
 * ---------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
	.mg-size__panel,
	.mg-size__chev,
	.mg-size__opt,
	.mg-size__trigger {
		transition: none;
		transform: none;
	}
	.mg-size__tick path {
		animation: none;
		stroke-dashoffset: 0;
	}
}
