/**
 * WooCommerce's classic form fields — the framework's field look.
 *
 * Every form WooCommerce draws from a PHP template (addresses, account
 * details, sign in, lost password, order tracking) shares one row class
 * (.form-row) and one control class (.input-text). They take no block
 * supports, so these rules are the only way in. The selectors are
 * WooCommerce's own generic ones: no form is named, so a form rebuilt from
 * wage/form-field blocks later simply stops matching.
 *
 * The look is wage/form-field's (wage-core, blocks/form-field/style.css),
 * read from the same `settings.custom.input.*` tokens, so a child that
 * retunes its fields retunes these too. The token block below repeats that
 * file's: change a default there, change it here.
 *
 * Loaded only on a page where WooCommerce renders a form template or a
 * woocommerce_form_field() (features/woocommerce/woocommerce.php). WooCommerce's
 * own sheets are not loaded at all, so this is the whole look of a classic
 * form: layout (the half-width first and last name rows) included, as each
 * screen is reached. The Checkout block has its own sheet, woo-checkout.css.
 */

/* Tokens sit on the row, not :root, so they resolve against the nearest
   palette, as on .form-field. The country dropdown is appended to <body>,
   outside any row, so its container declares them as well. */
.woocommerce form .form-row,
.select2-container {
	--contrast-muted: var(--wp--custom--contrast--muted);
	--primary: var(--wp--preset--color--secondary);
	--primary-subtle: color-mix(in oklch, var(--primary) 14%, transparent);
	--danger: var(--wp--custom--danger);
	--transition-fast: var(--wp--custom--transition--fast);

	--input-bg: var(--wp--custom--input--bg, var(--wp--preset--color--raised));
	--input-radius: var(--wp--custom--input--radius, var(--wp--preset--border-radius--s));
	--input-border-width: var(--wp--custom--input--border-width, var(--wp--custom--border--width));
	--input-border-style: solid;
	--input-border-color: var(--wp--custom--input--border-color, color-mix(in oklch, var(--wp--preset--color--contrast) 30%, transparent));
	--input-hover-border-color: var(--wp--custom--input--hover-border-color, var(--primary));
	--input-hover-glow: var(--wp--custom--input--hover-glow, var(--primary-subtle));
	--input-padding-top: var(--wp--custom--input--padding-block, var(--wp--preset--spacing--xs));
	--input-padding-bottom: var(--input-padding-top);
	--input-padding-inline: var(--wp--custom--input--padding-inline, var(--wp--preset--spacing--s));
	--placeholder-color: var(--wp--custom--input--placeholder-color, color-mix(in oklch, var(--wp--preset--color--contrast) 45%, transparent));

	/* The ring's own size, as on .form-field. */
	--ring-width: 2px;
	--ring-style: solid;
	--ring-color: var(--primary);
	--ring-offset: 2px;
}

/* ── Row and label ─────────────────────────────────── */

/* One row under another: the field block's gap. The paired rows (first and
   last name) sit side by side, as WooCommerce's layout sheet had them. */
.woocommerce form .form-row {
	margin: 0 0 var(--wp--preset--spacing--s);
}
.woocommerce form .form-row-first,
.woocommerce form .form-row-last {
	float: left;
	width: calc(50% - var(--wp--preset--spacing--s) / 2);
}
.woocommerce form .form-row-last {
	float: right;
}
.woocommerce form .form-row-wide,
.woocommerce form .form-row:not(.form-row-first):not(.form-row-last) {
	clear: both;
}
@media (max-width: 48rem) {
	.woocommerce form .form-row-first,
	.woocommerce form .form-row-last {
		float: none;
		width: 100%;
	}
}

.woocommerce form .form-row label {
	display: block;
	margin-bottom: 0.375rem; /* .form-field's label gap */
	font-size: var(--wp--preset--font-size--small);
	font-weight: var(--wp--custom--font-weight--regular);
	line-height: 1.5;
}

.woocommerce form .form-row .required {
	color: var(--danger);
	font-weight: inherit;
}

/* A note under a field: WooCommerce writes it as a bare <span><em>, with no
   class of its own. The look is .form-field__help's. */
.woocommerce form .form-row > span:not([class]) > em {
	display: block;
	margin-top: 0.375rem; /* .form-field's gap */
	color: var(--contrast-muted);
	font-size: var(--wp--preset--font-size--x-small);
	font-style: normal;
}

/* Native ticks and radios keep the browser's box, in the field accent. */
.woocommerce form .form-row input[type="checkbox"],
.woocommerce form .form-row input[type="radio"] {
	accent-color: var(--primary);
}

/* ── The control box ───────────────────────────────── */

.woocommerce form .form-row .input-text,
.woocommerce form .form-row select {
	box-sizing: border-box;
	width: 100%;
	padding: var(--input-padding-top) var(--input-padding-inline) var(--input-padding-bottom);
	border: var(--input-border-width) var(--input-border-style) var(--input-border-color);
	border-radius: var(--input-radius);
	background-color: var(--input-bg);
	color: inherit;
	font: inherit;
	line-height: 1.5;
	transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.woocommerce form .form-row .input-text::placeholder {
	color: var(--placeholder-color);
	opacity: 1;
}

/* The chevron. WooCommerce's sheet used to draw it; this is the same glyph
   as the field block's mask, as a background image because a bare select has
   no wrapper to hang a pseudo-element on. The stroke colour is baked in: a
   background image cannot read a token. */
.woocommerce form .form-row select {
	appearance: none;
	cursor: pointer;
	padding-right: calc(var(--input-padding-inline) + 1.5rem);
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-size: 1rem;
	background-position: calc(100% - var(--input-padding-inline)) 50%;
}

.woocommerce form .form-row textarea {
	height: auto;
	min-height: 120px; /* .form-field__textarea */
	resize: vertical;
}

/* Hover: the soft glow. The doubled row class outweighs the invalid border
   rule below, so a hovered field always answers. */
.woocommerce form .form-row.form-row .input-text:hover,
.woocommerce form .form-row.form-row select:hover {
	border-color: var(--input-hover-border-color);
	box-shadow: 0 0 0 4px var(--input-hover-glow); /* .wage-control's glow */
}

/* Focus: the sharp ring, distinct from the glow. Doubled for the same reason. */
.woocommerce form .form-row.form-row .input-text:focus-visible,
.woocommerce form .form-row.form-row select:focus-visible {
	border-color: var(--input-hover-border-color);
	box-shadow: none;
	outline: var(--ring-width) var(--ring-style) var(--ring-color);
	outline-offset: var(--ring-offset);
}

/* ── Invalid ───────────────────────────────────────── */

/* The row is retokenised, so border, hover and ring all turn. */
.woocommerce form .form-row.woocommerce-invalid {
	--input-border-color: var(--danger);
	--input-hover-border-color: var(--danger);
	--input-hover-glow: color-mix(in oklch, var(--danger), transparent 85%);
	--ring-color: var(--danger);
}

.woocommerce form .form-row.woocommerce-invalid label {
	color: var(--danger);
}

.woocommerce form .form-row.woocommerce-invalid input.input-text,
.woocommerce form .form-row.woocommerce-invalid select {
	border-color: var(--danger);
}

/* ── Show password ─────────────────────────────────── */

/* WooCommerce's script wraps a password field in .password-input and adds an
   empty button after it (.show-password-input; .display-password while the
   password shows). The button's place and its glyph came from WooCommerce's
   layout sheet, which is not loaded, so the whole control is here: the look
   of .form-field__reveal, with the same two icons (eye, eye-off) as masks,
   since the button has no markup to hold an <svg>. */
.woocommerce form .form-row .password-input {
	position: relative;
	display: block;
}

/* Room for the eye button, which sits over the field's right edge. */
.woocommerce form .form-row .password-input .input-text {
	padding-right: calc(var(--input-padding-inline) + 2em);
}

.woocommerce form .show-password-input {
	position: absolute;
	right: var(--input-padding-inline);
	top: 50%;
	transform: translateY(-50%);
	display: flex;
	padding: 0;
	border: 0;
	background: none;
	color: var(--contrast-muted);
	cursor: pointer;
	transition: color var(--transition-fast);
}
.woocommerce form .show-password-input:hover {
	color: var(--wp--preset--color--contrast);
}
.woocommerce form .show-password-input:focus-visible {
	outline: var(--ring-width) var(--ring-style) var(--ring-color);
	outline-offset: var(--ring-offset);
	border-radius: var(--wp--preset--border-radius--s);
}
.woocommerce form .show-password-input::after {
	content: "";
	width: 1.5em;
	height: 1.5em;
	background-color: currentColor;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 5C7 5 2.7 8.1 1 12c1.7 3.9 6 7 11 7s9.3-3.1 11-7c-1.7-3.9-6-7-11-7zm0 12.5c-3.8 0-7.1-2.1-8.9-5.5C4.9 8.6 8.2 6.5 12 6.5s7.1 2.1 8.9 5.5c-1.8 3.4-5.1 5.5-8.9 5.5zM12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8zm0 6.5a2.5 2.5 0 1 1 0-5 2.5 2.5 0 0 1 0 5z'/%3E%3C/svg%3E") no-repeat center / contain;
}
.woocommerce form .show-password-input.display-password::after {
	mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3.5 2.4 2.4 3.5l3.3 3.3C4 8.1 2.1 9.9 1 12c1.7 3.9 6 7 11 7 1.9 0 3.7-.4 5.3-1.2l3.2 3.2 1.1-1.1L3.5 2.4zM12 17.5c-3.8 0-7.1-2.1-8.9-5.5.9-1.7 2.3-3.1 3.8-4.1l2.2 2.2A4 4 0 0 0 12 16c.5 0 1-.1 1.5-.3l1.6 1.6c-1 .1-2 .2-3.1.2zm-1.4-6.4 2.3 2.3a2.5 2.5 0 0 1-2.3-2.3zM12 6.5c3.8 0 7.1 2.1 8.9 5.5-.6 1.1-1.3 2-2.2 2.8l1.1 1.1c1.3-1.1 2.3-2.4 3.2-3.9-1.7-3.9-6-7-11-7-1.3 0-2.5.2-3.7.5l1.3 1.3c.8-.2 1.6-.3 2.4-.3zm1.8 5.3 2.4 2.4c.2-.6.3-1.2.3-1.7a4 4 0 0 0-4-4c-.6 0-1.2.1-1.7.3l1.2 1.2a2.5 2.5 0 0 1 1.8 1.8z'/%3E%3C/svg%3E");
}

/* ── Country and county picker (selectWoo) ─────────── */

/* The closed control: the same box as an input. */
.woocommerce form .form-row .select2-container {
	font-size: inherit;
}

.woocommerce form .form-row .select2-container .select2-selection {
	height: auto;
	border: var(--input-border-width) var(--input-border-style) var(--input-border-color);
	border-radius: var(--input-radius);
	background-color: var(--input-bg);
	transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.woocommerce form .form-row .select2-container .select2-selection--single .select2-selection__rendered {
	padding: var(--input-padding-top) calc(var(--input-padding-inline) + 1.5rem) var(--input-padding-bottom) var(--input-padding-inline); /* 1.5rem: the arrow's room */
	color: inherit;
	font-weight: inherit;
	line-height: 1.5;
}

.woocommerce form .form-row .select2-container .select2-selection--single .select2-selection__placeholder {
	color: var(--placeholder-color);
}

.woocommerce form .form-row .select2-container .select2-selection--single .select2-selection__arrow {
	top: 0;
	right: var(--input-padding-inline);
}

.woocommerce form .form-row .select2-container:hover .select2-selection {
	border-color: var(--input-hover-border-color);
	box-shadow: 0 0 0 4px var(--input-hover-glow); /* .wage-control's glow */
}

.woocommerce form .form-row .select2-container--focus .select2-selection,
.woocommerce form .form-row .select2-container--open .select2-selection {
	border-color: var(--input-hover-border-color);
	box-shadow: none;
	outline: var(--ring-width) var(--ring-style) var(--ring-color);
	outline-offset: var(--ring-offset);
}

.woocommerce form .form-row.woocommerce-validated .select2-container:not(.select2-container--open) .select2-selection {
	border-color: var(--input-border-color);
}

.woocommerce form .form-row.woocommerce-invalid .select2-container:not(.select2-container--open) .select2-selection {
	border-color: var(--danger);
}

/* The open list, appended to <body>. It sits a ring's width clear of the
   control, as its own box. */
.select2-container .select2-dropdown.select2-dropdown {
	margin-block: var(--wp--preset--spacing--xxs);
	border: var(--input-border-width) var(--input-border-style) var(--input-border-color);
	border-radius: var(--input-radius);
	background-color: var(--input-bg);
	box-shadow: var(--wp--preset--shadow--l);
	overflow: hidden;
}

.select2-container .select2-search--dropdown {
	padding: var(--wp--preset--spacing--xxs);
}

.select2-container--default .select2-search--dropdown .select2-search__field {
	padding: var(--wp--preset--spacing--xxs) var(--wp--preset--spacing--xs);
	border: var(--input-border-width) var(--input-border-style) var(--input-border-color);
	border-radius: var(--wp--preset--border-radius--s);
	background-color: var(--input-bg);
	color: inherit;
	font: inherit;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus-visible {
	border-color: var(--input-hover-border-color);
	outline: var(--ring-width) var(--ring-style) var(--ring-color);
	outline-offset: calc(var(--ring-offset) * -1);
}

.select2-container .select2-results__option {
	padding: var(--wp--preset--spacing--xxs) var(--input-padding-inline);
}

/* selectWoo marks rows with data-selected, select2 with aria-selected. */
.select2-container--default .select2-results__option[aria-selected="true"],
.select2-container--default .select2-results__option[data-selected="true"] {
	background-color: var(--primary-subtle);
	color: inherit;
}

.select2-container--default .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted[data-selected] {
	background-color: color-mix(in oklch, currentColor 8%, transparent);
	color: inherit;
}
