/**
 * MiniWild form elements, site-wide.
 * Figma: Text field, Text area, Select, Number input, Checkbox, Radio, Label.
 *
 * Selectors are wrapped in :where() so they have no specificity: component
 * styles (header search, newsletter, WooCommerce overrides in woocommerce.css)
 * win without fighting.
 */

/* ------------------------------------------------------------------ */
/* Text field, Select, Text area                                       */
/* ------------------------------------------------------------------ */

:where(
	input[type="text"],
	input[type="email"],
	input[type="password"],
	input[type="tel"],
	input[type="number"],
	input[type="search"],
	input[type="url"],
	input[type="date"],
	select,
	textarea
) {
	box-sizing: border-box;
	min-height: var(--mw-size-control-lg);
	padding: 0 var(--wp--preset--spacing--30);
	border: var(--mw-border-thin) solid var(--mw-color-outline);
	border-radius: var(--wp--custom--radius--small);
	background-color: var(--wp--preset--color--white);
	color: var(--wp--preset--color--contrast);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--medium);
	line-height: 1.4;
	transition: border-color var(--mw-motion-fast) var(--mw-easing), box-shadow var(--mw-motion-fast) var(--mw-easing);
}

:where(textarea) {
	min-height: 140px;
	padding: var(--mw-space-sm) var(--wp--preset--spacing--30);
	line-height: 1.6;
	resize: vertical;
}

:where(input, select, textarea)::placeholder {
	color: var(--mw-color-on-surface-variant);
	opacity: 1;
}

:where(input, select, textarea):hover {
	border-color: var(--wp--preset--color--contrast);
}

/* Focused: primary border, 2px (Text field / Focused). */
:where(input, select, textarea):focus {
	border-color: var(--wp--preset--color--primary);
	box-shadow: 0 0 0 1px var(--wp--preset--color--primary);
	outline: none;
}

:where(input, select, textarea)[aria-invalid="true"] {
	border-color: var(--mw-color-error);
	box-shadow: 0 0 0 1px var(--mw-color-error);
}

:where(input, select, textarea):disabled {
	border-color: var(--mw-color-outline-variant);
	background-color: var(--mw-color-disabled-container);
	color: var(--mw-color-on-disabled);
	cursor: not-allowed;
}

/* Select: own chevron (expand_more) instead of the native arrow. */
:where(select) {
	padding-inline-end: calc(var(--wp--preset--spacing--30) + 28px);
	appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='%236e5b47' d='M12 15.4 6 9.4 7.4 8l4.6 4.6L16.6 8 18 9.4z'/%3E%3C/svg%3E");
	background-position: right var(--mw-space-sm) center;
	background-repeat: no-repeat;
	background-size: 24px;
	cursor: pointer;
}

:where(select[multiple]) {
	padding-inline-end: var(--wp--preset--spacing--30);
	background-image: none;
}

/* ------------------------------------------------------------------ */
/* Label                                                               */
/* ------------------------------------------------------------------ */

:where(label) {
	color: var(--wp--preset--color--contrast);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 600;
}

/* Required marker in error colour. */
:where(label .required, label abbr[title]) {
	color: var(--mw-color-error);
	text-decoration: none;
}

/* ------------------------------------------------------------------ */
/* Checkbox, Radio                                                     */
/* ------------------------------------------------------------------ */

:where(input[type="checkbox"], input[type="radio"]) {
	width: 18px;
	height: 18px;
	margin: 0 var(--wp--preset--spacing--20) 0 0;
	accent-color: var(--wp--preset--color--primary);
	vertical-align: -3px;
	cursor: pointer;
}

/* ------------------------------------------------------------------ */
/* Number input (quantity): pill, centred value                        */
/* ------------------------------------------------------------------ */

:where(input[type="number"]) {
	-moz-appearance: textfield;
}

:where(input.qty) {
	width: 88px;
	padding-inline: var(--wp--preset--spacing--20);
	border-radius: var(--wp--custom--radius--pill);
	font-family: var(--wp--preset--font-family--heading);
	font-weight: 700;
	text-align: center;
}

/* ------------------------------------------------------------------ */
/* Search block (outside the header): field + button in one row        */
/* ------------------------------------------------------------------ */

:where(.wp-block-search:not(.mw-header__search):not(.mw-header__search-toggle)) .wp-block-search__inside-wrapper {
	gap: var(--wp--preset--spacing--20);
}

:where(.wp-block-search:not(.mw-header__search):not(.mw-header__search-toggle)) .wp-block-search__input {
	flex: 1 1 auto;
	border-radius: var(--wp--custom--radius--pill);
	padding-inline: var(--wp--preset--spacing--40);
}

/* ------------------------------------------------------------------ */
/* Comment form (product reviews, posts)                               */
/* ------------------------------------------------------------------ */

.comment-form p:not(.form-submit):not(.comment-form-cookies-consent) {
	display: flex;
	flex-direction: column;
	gap: var(--mw-space-2xs);
	max-width: 560px;
}

.comment-form textarea {
	width: 100%;
	max-width: none;
}

.comment-form p.comment-form-comment {
	max-width: none;
}

.comment-form-cookies-consent {
	display: flex;
	align-items: flex-start;
	gap: var(--wp--preset--spacing--20);
}

.comment-form-cookies-consent label {
	font-weight: 400;
}

/* Number input (Design system: Number input, Small 112×40): product page and cart.
 * The − / + buttons are added by product.js / cart.js. */
:is(.mw-product, .mw-cart) .quantity {
	display: inline-flex;
	align-items: center;
	justify-content: space-between;
	box-sizing: border-box;
	width: 112px;
	height: 40px;
	margin: 0 !important;
	padding-inline: var(--mw-space-2xs);
	border: var(--mw-border-thin) solid var(--mw-color-outline);
	border-radius: var(--wp--custom--radius--pill);
	background: var(--wp--preset--color--white);
}

:is(.mw-product, .mw-cart) .quantity:has(input[type="hidden"]) {
	display: none;
}

:is(.mw-product, .mw-cart) .quantity input.qty {
	flex: 1 1 auto;
	width: 100%;
	min-width: 0;
	min-height: 0;
	height: 100%;
	padding: 0 !important;
	border: 0;
	border-radius: 0;
	background: none;
	box-shadow: none;
	color: var(--wp--preset--color--contrast);
	font-family: var(--wp--preset--font-family--body);
	font-size: 1rem;
	font-weight: 600;
	text-align: center;
	-moz-appearance: textfield;
}

:is(.mw-product, .mw-cart) .quantity input.qty::-webkit-inner-spin-button,
:is(.mw-product, .mw-cart) .quantity input.qty::-webkit-outer-spin-button {
	margin: 0;
	-webkit-appearance: none;
}

:is(.mw-product, .mw-cart) .quantity input.qty:focus-visible {
	outline: 2px solid var(--mw-color-focus);
	outline-offset: 2px;
	border-radius: var(--mw-radius-xs);
}

.mw-qty-step {
	display: grid;
	flex: none;
	place-items: center;
	width: 32px;
	height: 32px;
	padding: 0;
	border: 0;
	border-radius: var(--wp--custom--radius--pill);
	background: none;
	color: var(--wp--preset--color--primary);
	cursor: pointer;
}

.mw-qty-step::before {
	content: "";
	width: var(--mw-size-icon-md);
	height: var(--mw-size-icon-md);
	background: currentColor;
	-webkit-mask: var(--mw-icon-remove) center / contain no-repeat;
	mask: var(--mw-icon-remove) center / contain no-repeat;
}

.mw-qty-step--up::before {
	-webkit-mask-image: var(--mw-icon-add);
	mask-image: var(--mw-icon-add);
}

.mw-qty-step:hover {
	background: color-mix(in srgb, var(--wp--preset--color--primary) 8%, transparent);
}

.mw-qty-step:focus-visible {
	outline: 2px solid var(--mw-color-focus);
	outline-offset: 0;
}

.mw-qty-step:disabled {
	color: var(--mw-color-on-disabled);
	background: none;
	cursor: default;
}

/* Password (Design system: Password): lock, field, eye button, helper text. */
.mw-password {
	display: flex;
	flex-direction: column;
	gap: var(--mw-space-2xs);
	width: 100%;
}

.mw-password label {
	color: var(--wp--preset--color--contrast);
}

.mw-password__field {
	position: relative;
	display: block;
}

.mw-password__field::before {
	content: "";
	position: absolute;
	top: 50%;
	left: var(--wp--preset--spacing--30);
	width: var(--mw-size-icon-md);
	height: var(--mw-size-icon-md);
	transform: translateY(-50%);
	background: var(--mw-color-on-surface-variant);
	-webkit-mask: var(--mw-icon-lock) center / contain no-repeat;
	mask: var(--mw-icon-lock) center / contain no-repeat;
	pointer-events: none;
}

.mw-password__field input {
	box-sizing: border-box;
	width: 100%;
	padding-inline: 2.75rem 3rem !important;
}

.mw-password__toggle {
	position: absolute;
	top: 50%;
	right: var(--mw-space-2xs);
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	padding: 0;
	transform: translateY(-50%);
	border: 0;
	border-radius: var(--wp--custom--radius--pill);
	background: none;
	cursor: pointer;
}

.mw-password__toggle::before {
	content: "";
	width: var(--mw-size-icon-md);
	height: var(--mw-size-icon-md);
	background: var(--mw-color-on-surface-variant);
	-webkit-mask: var(--mw-icon-visibility) center / contain no-repeat;
	mask: var(--mw-icon-visibility) center / contain no-repeat;
}

.mw-password__toggle[aria-pressed="true"]::before {
	-webkit-mask-image: var(--mw-icon-visibility-off);
	mask-image: var(--mw-icon-visibility-off);
}

.mw-password__help {
	font-size: var(--mw-font-size-x-small);
	line-height: 22px;
	letter-spacing: 0.1px;
}

/* Edge's own reveal button would sit next to ours. */
.mw-password__field input::-ms-reveal {
	display: none;
}

/* A field the shop does not need (e.g. the country when it sells to one country). */
.mw-hidden {
	display: none !important;
}
