/**
 * Form fields for every form on the site: comments, search, WooCommerce, Fluent Forms and FluentCRM.
 *
 * Fields are 52px high with a clear 1.5px border and an accent focus ring; checkboxes and radios are
 * drawn in the theme colours; a checkbox with the class "is-switch" becomes a switch. All selectors
 * use :where(), so a plugin or block that styles its own fields still wins without a fight.
 *
 * @package DeWittePrins\Theme
 * @since   0.1.0
 */

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

:where(
	input[type="text"],
	input[type="email"],
	input[type="url"],
	input[type="tel"],
	input[type="password"],
	input[type="search"],
	input[type="number"],
	input[type="date"],
	select,
	textarea
) {
	box-sizing: border-box;
	width: 100%;
	min-height: 3.25rem;
	padding: 0.75rem 0.875rem;
	border: 1.5px solid var(--wp--custom--color--line-strong);
	border-radius: var(--wp--preset--border-radius--medium);
	background-color: var(--wp--preset--color--base);
	color: var(--wp--preset--color--contrast);
	font: inherit;
	font-feature-settings: var(--wp--custom--font--features);
	line-height: 1.4;
}

:where(textarea) {
	min-height: 8rem;
	resize: vertical;
}

:where(input, select, textarea)::placeholder {
	color: var(--wp--preset--color--muted);
	opacity: 1;
}

:where(
	input[type="text"],
	input[type="email"],
	input[type="url"],
	input[type="tel"],
	input[type="password"],
	input[type="search"],
	input[type="number"],
	input[type="date"],
	select,
	textarea
):focus {
	border-color: var(--wp--preset--color--accent);
	outline: 3px solid transparent; /* Shows as the focus ring in forced colours, where box-shadow is dropped. */
	box-shadow: 0 0 0 3px var(--wp--custom--color--ring);
}

/*
 * Checkbox and radio: 22px boxes in the theme colours, with the label as a 44px tap row.
 * appearance: none removes the browser's own size, so the box keeps its shape through aspect-ratio:
 * when a plugin sets the width to auto (as in some checkout fields), the height still makes it square.
 */
:where(input[type="checkbox"], input[type="radio"]) {
	display: inline-grid;
	place-content: center;
	flex: none;
	inline-size: 1.375rem;
	block-size: 1.375rem;
	aspect-ratio: 1;
	margin: 0 0.5rem 0 0;
	border: 1.5px solid var(--wp--custom--color--line-strong);
	background-color: var(--wp--preset--color--base);
	vertical-align: -0.3em;
	cursor: pointer;
	appearance: none;
}

:where(input[type="checkbox"]) {
	border-radius: 0.25rem;
}

:where(input[type="radio"]) {
	border-radius: 50%;
}

:where(input[type="checkbox"]:checked) {
	border-color: var(--wp--preset--color--accent);
	background-color: var(--wp--preset--color--accent);
}

:where(input[type="checkbox"]:checked)::after {
	content: "";
	width: 0.3125rem;
	height: 0.625rem;
	border: solid var(--wp--custom--color--on-accent);
	border-width: 0 2.5px 2.5px 0;
	transform: translateY(-1px) rotate(45deg);
}

:where(input[type="radio"]:checked) {
	border-width: 2px;
	border-color: var(--wp--preset--color--accent);
}

:where(input[type="radio"]:checked)::after {
	content: "";
	width: 0.625rem;
	height: 0.625rem;
	border-radius: 50%;
	background-color: var(--wp--preset--color--accent);
}

:where(input[type="checkbox"], input[type="radio"]):focus-visible {
	outline: 3px solid transparent; /* Shows as the focus ring in forced colours, where box-shadow is dropped. */
	box-shadow: 0 0 0 3px var(--wp--custom--color--ring);
}

:where(input[type="checkbox"], input[type="radio"]):disabled {
	cursor: not-allowed;
	opacity: 0.5;
}

/* Switch: a checkbox with the class "is-switch", for settings that are on or off. */
:where(input[type="checkbox"].is-switch) {
	position: relative;
	display: inline-block;
	aspect-ratio: auto;
	width: 2.875rem;
	height: 1.75rem;
	border: 0;
	border-radius: 0.875rem;
	background-color: var(--wp--custom--color--line-strong);
	transition: background-color var(--wp--custom--motion--duration) var(--wp--custom--motion--easing);
}

:where(input[type="checkbox"].is-switch)::after {
	content: "";
	position: absolute;
	top: 0.1875rem;
	left: 0.1875rem;
	width: 1.375rem;
	height: 1.375rem;
	border: 0;
	border-radius: 50%;
	background-color: #fff;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
	transform: none;
	transition: transform var(--wp--custom--motion--duration) var(--wp--custom--motion--easing);
}

:where(input[type="checkbox"].is-switch:checked) {
	background-color: var(--wp--preset--color--accent);
}

:where(input[type="checkbox"].is-switch:checked)::after {
	transform: translateX(1.125rem);
}
