/*
 * The one field recipe of Rooster One's front-end forms (Offers 16-F24, the designer's form specification of 18 Nov
 * 2026: "Your forms should look like the checkout form of the design"). Compiled by build/blocks-css.mjs (the nesting
 * flattened, minified) into assets/css/aieo-fields.css, registered by AIEO_Form_Fields as `aieo-fields`, a dependency
 * of each form's own sheet, so it loads only where a form is drawn.
 *
 * A FORM MARKUP JOINS BY ONE LINE: its root in the list just below. What it then needs of its markup:
 *   - each field's wrapper carries `data-aieo-wrap`, with the label (or a set's legend) as its first child and the
 *     control after it; a single check puts its box first and its label after it (`<input><label for>`). Only a
 *     control inside such a wrapper takes the field's look, so a markup's other controls (a quantity in an item's
 *     row, a choice's box) keep their own;
 *   - the pieces AIEO_Form_Fields prints and the script (assets/js/aieo-form-errors.js) places: the optional mark
 *     (`.aieo-optional`), a field's error line (`.aieo-field-error`), the error box (`.aieo-errsum`), the privacy line
 *     (`.aieo-privacy`);
 *   - its submit is a `button[type="submit"]` with the theme's `wp-element-button` class (the theme's primary button).
 * Everything else (the grid, the card, a check's row) stays the markup's own sheet's.
 *
 * Every value is a token of the theme (Rooster Zero's presets and custom tokens, rooster-theme 469ce568): the field's
 * height (`field--height`, 48 px on aurenne-sans, 43 px elsewhere; 3rem without the theme), its text (16 px under
 * 783 px, against the phone's zoom; `field--text` from 783 px), the button's height through the theme's own
 * `wp-element-button` (its padding derives from the field's height). Where a theme has no such colour the declaration
 * falls away to the browser's: currentColor, the inherited font; never a colour of ours. Colours are set by their
 * longhands so that a missing token drops one colour, not the whole border.
 */

:is(
	.aieo-cf,
	.aieo-form--panel,
	.aieo-pr,
	.aieo-wd,
	.aieo-selfreg,
	.aieo-nl,
	.aieo-nl-band
) {
	/* The field: the theme's field height, its text 16 px on a phone (FE-F4), a 1 px border in the muted colour, the
	   control's corners. Its states are nested so that each outranks the one before it, whatever a theme's own field
	   rules say. */
	& [data-aieo-wrap] :is(input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="submit"], [type="button"], [type="file"], [type="range"], [type="color"]), select, textarea) {
		box-sizing: border-box;
		width: 100%;
		min-width: 0;
		height: var(--wp--custom--rooster--field--height, 3rem);
		min-height: 0;
		margin: 0;
		padding: 0 var(--wp--preset--spacing--4);
		border-width: 1px;
		border-style: solid;
		border-color: var(--wp--preset--color--muted);
		border-radius: var(--wp--custom--rooster--shape--control);
		background-color: var(--wp--preset--color--bg);
		box-shadow: none;
		color: var(--wp--preset--color--fg);
		font: inherit;
		font-size: 1rem;
		line-height: normal;
		/* Focused by the keyboard, never left under the phone's bottom bar (the theme's offset for it, contract C11). */
		scroll-margin-bottom: var(--rooster-fab-offset, 0px);

		@media (min-width: 783px) {
			font-size: var(--wp--custom--rooster--field--text, 1rem);
		}

		&::placeholder {
			color: var(--wp--preset--color--muted);
			opacity: 1;
		}

		/* Hover and focus: the border takes the text colour; the focus adds the theme's ring, whatever the form's tone. */
		&:hover {
			border-color: var(--wp--preset--color--fg);
		}

		&:focus-visible {
			border-color: var(--wp--preset--color--fg);
			outline: none;
			box-shadow: var(--wp--custom--rooster--focus-ring, 0 0 0 2px currentColor);
		}

		/* A refused field: the danger colour, two pixels of it (the border and an inset), hovered or not; marked by the
		   form, or refused by the browser once the visitor has left it (a rule of its own: a browser that does not know
		   :user-invalid drops only that one). Never while it has the focus (11.3.16, F42; the designer: "the focused field
		   gets the same red edge as an error"): the field being typed in is the theme's focus, the text colour and the
		   ring, and its error line under it still says what is wrong. */
		&[aria-invalid="true"]:not(:focus) {
			border-color: var(--wp--preset--color--danger);
			box-shadow: inset 0 0 0 1px var(--wp--preset--color--danger);
		}

		&:user-invalid:not(:focus) {
			border-color: var(--wp--preset--color--danger);
			box-shadow: inset 0 0 0 1px var(--wp--preset--color--danger);
		}

		&:is(textarea) {
			height: auto;
			min-height: 104px;
			padding-block: var(--wp--preset--spacing--3);
			line-height: 1.5;
			resize: vertical;
		}

		/* The select: the field's box with its own chevron, drawn in the text's colour. */
		&:is(select) {
			-webkit-appearance: none;
			appearance: none;
			padding-right: 40px;
			background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
			background-position: calc(100% - 21px) 50%, calc(100% - 16px) 50%;
			background-size: 5px 5px;
			background-repeat: no-repeat;
			cursor: pointer;
		}
	}

	& [data-aieo-wrap] select option {
		background-color: var(--wp--preset--color--bg);
		color: var(--wp--preset--color--fg);
	}

	/* The label above its field (a set's legend likewise): 14 px, semi-bold. */
	& [data-aieo-wrap] > :is(label, legend):first-child {
		display: block;
		float: none;
		width: auto;
		margin: 0 0 6px;
		padding: 0;
		font-size: var(--wp--preset--font-size--sm);
		font-weight: 600;
		line-height: 1.4;
	}

	/* "(optional)" after an optional field's label; no asterisks anywhere. */
	& .aieo-optional {
		color: var(--wp--preset--color--muted);
		font-size: inherit;
		font-weight: 400;
	}

	/* A field's message under it: what to do, after Lucide's triangle-alert, as the theme's own message (sm, 600, the
	   danger colour). */
	& .aieo-field-error {
		display: flex;
		gap: 6px;
		align-items: flex-start;
		max-width: none;
		margin: 6px 0 0;
		color: var(--wp--preset--color--danger);
		font-size: var(--wp--preset--font-size--sm);
		font-weight: 600;
		line-height: 1.4;

		&::before {
			content: "";
			flex: none;
			width: 16px;
			height: 16px;
			margin-top: 2px;
			background-color: currentColor;
			-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E") center / contain no-repeat;
			mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E") center / contain no-repeat;
		}
	}

	/* The box above the fields after a refused send: one line, then a link to each field to correct. */
	& .aieo-errsum {
		box-sizing: border-box;
		display: grid;
		gap: 4px;
		margin: 0 0 var(--wp--preset--spacing--5);
		padding: 12px var(--wp--preset--spacing--4);
		border-width: 1px 1px 1px 4px;
		border-style: solid;
		border-color: var(--wp--preset--color--danger);
		background-color: var(--wp--preset--color--neutral-50);
		font-size: var(--wp--preset--font-size--sm);
		font-weight: 600;
		line-height: 1.4;

		&:focus-visible {
			outline: none;
			box-shadow: var(--wp--custom--rooster--focus-ring, 0 0 0 2px currentColor);
		}
	}

	& .aieo-errsum__title {
		display: flex;
		gap: 8px;
		align-items: flex-start;
		max-width: none;
		margin: 0;

		&::before {
			content: "";
			flex: none;
			width: 20px;
			height: 20px;
			background-color: var(--wp--preset--color--danger);
			-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4'/%3E%3Cpath d='M12 16h.01'/%3E%3C/svg%3E") center / contain no-repeat;
			mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4'/%3E%3Cpath d='M12 16h.01'/%3E%3C/svg%3E") center / contain no-repeat;
		}
	}

	& .aieo-errsum__list {
		display: grid;
		gap: 2px;
		margin: 0;
		padding: 0 0 0 28px;
		list-style: none;
	}

	& .aieo-errsum__list a {
		display: inline-flex;
		align-items: center;
		min-height: 24px;
		color: var(--wp--preset--color--danger);
		font-weight: 600;
	}

	/* One plain sentence about the details, with its link, above the button. */
	& .aieo-privacy {
		max-width: none;
		margin: var(--wp--preset--spacing--4) 0 0;
		color: var(--wp--preset--color--muted);
		font-size: var(--wp--preset--font-size--sm);
		line-height: 1.5;
	}

	& .aieo-privacy a {
		color: inherit;
		text-decoration: underline;
	}

	/* The send button: the theme's primary button (`wp-element-button`: its padding makes it as tall as a field), the
	   whole width on a phone (the designer's own phone width, 767 px and under). Busy while it sends: it says so and
	   ignores a second press. */
	& button[type="submit"] {
		box-sizing: border-box;
		margin: 0;
		cursor: pointer;
		scroll-margin-bottom: var(--rooster-fab-offset, 0px);
	}

	& button[type="submit"][aria-disabled="true"] {
		cursor: progress;
		opacity: 0.7;
	}

	@media (max-width: 767px) {
		& button[type="submit"] {
			width: 100%;
		}
	}

	/* What a script hides stays hidden, whatever the markup's own display (the form under its confirmation). */
	& [hidden] {
		display: none !important;
	}
}
