/* The labeled control - a field's label, its input area, and its help,
   from the shared UI kit. A copy of mise-en-place's
   app/assets/styles/components/labeled-control.css (the source of truth -
   keep this in step by hand; pssst parts are made to be copied). Its
   markup is includes/components/labeled-control.php, the same markup the
   kit's LabeledControl.vue renders. First use here: the select, with the
   kit's drawn chevron (Derek, 2026-12-01: "We gotta fix these chevrons -
   as mise en place"). This site fills the slots it reads in
   settings/base.css ("Controls"). */

/*
	What every form control shares: the label, the input, help, and messages,
	stacked (LabeledControl, CountControl), and what sits under a field in
	ChoiceGroup too. From the form system
	(super-ultimate-form-system-pro, form.css), written in pssst's slots.

	The input is the input: its border, fill, padding, and focus ring are the
	app's (interaction/controls.css), on the element itself. This adds only
	geometry - the declared height every single-line control shares, and room
	for a textarea to grow.

	Slots it reads, which the app fills:
	  --control-height     the outer height of every single-line control
	  --control-pad-inline the room inside a control's side edges, which a
	                       prefix sits in
	  --control-note-ink   a label's note, the help line, a field's prefix
	                       and a select's chevron: quiet ink that stays calm
	                       in the alert tone, the way the label does (resolve
	                       it at the root, so the tone's repaint never
	                       reaches it). Only the error message takes the
	                       tone.

	Its own knob, with a default:
	  --prefix-width       how much room a prefix takes (1ch; 3ch for "kg")
*/

form-control {
	display: block;
	max-width: 32rem;

	label {
		display: block;
		margin-bottom: 0.375em;

		/* A short note beside the label ("(optional)"), inside it so it's
		   part of the field's name. Wraps under it when long. */
		.aside {
			margin-inline-start: 0.375em;
			color: var(--control-note-ink);
		}
	}

	/* Help is about the field, not about what's wrong with it: it stays
	   quiet when the field has an error. How far it sits from the field is
	   field-messages.css, which spaces everything under a field. */
	.help {
		color: var(--control-note-ink);
	}
}

input-area {
	display: block;
	position: relative;

	:is(input, textarea, select) {
		/* Height means outer height: border and padding inside it. */
		box-sizing: border-box;
		width: 100%;
	}

	:is(input, select) {
		height: var(--control-height);
		padding-block: 0;

		/* The height owns the vertical story. */
		line-height: normal;
	}

	/* A select draws its own chevron, a padding's width in from the edge,
	   so it never sits against the border. The browser's arrow is off: it
	   can't be moved or colored. Two small triangles make the V, in the
	   calm note ink, so it repaints with every theme and stays put when the
	   field has an error. (appearance: base-select would do more, but it's
	   Chromium-only so far - not until it's in every browser.) */
	select:not([multiple], [size]) {
		--chevron: 0.35em;

		appearance: none;
		padding-inline-end: calc(var(--control-pad-inline) * 2 + var(--chevron) * 2);
		background-image: linear-gradient(45deg, transparent 50%, var(--control-note-ink) 50%), linear-gradient(135deg, var(--control-note-ink) 50%, transparent 50%);
		background-position:
			calc(100% - var(--control-pad-inline) - var(--chevron)) 50%,
			calc(100% - var(--control-pad-inline)) 50%;
		background-size: var(--chevron) var(--chevron);
		background-repeat: no-repeat;

		/* Right to left, the room and the V are both at the left edge. */
		&:dir(rtl) {
			background-position:
				var(--control-pad-inline) 50%,
				calc(var(--control-pad-inline) + var(--chevron)) 50%;
		}
	}

	/* A textarea grows as it fills (the form system's textarea.md), starting
	   at its rows (--rows, set by TextareaControl). Browsers without
	   field-sizing keep the rows attribute. */
	textarea {
		field-sizing: content;
		min-height: calc(var(--rows, 4) * 1lh);
	}

	/* A decorative start overlay - the $ on an amount. Paint, not a
	   control: the input makes room for it, and clicks fall through to the
	   input. (The form system's amount.md.) */
	&:has(.prefix) input {
		padding-inline-start: calc(var(--control-pad-inline) + var(--prefix-width, 1ch) + 0.25em);
	}

	.prefix {
		position: absolute;
		inset-block: 0;
		inset-inline-start: var(--control-pad-inline);
		display: grid;
		place-items: center start;
		width: var(--prefix-width, 1ch);
		color: var(--control-note-ink);
		pointer-events: none;
	}
}

/*
	What sits under a field: its help, and its messages (FieldMessages, in
	LabeledControl and ChoiceGroup). Spaced as one set, so the lines under a
	field read as belonging to it:

	  one line     help alone, or one message alone: close to the field
	  two or more  help and a message, or several messages (a bulleted
	               list): a little further from the field, with the
	               paragraph gap between them - otherwise the first reads
	               as attached and the next as floating

	An empty messages region takes no room; it's still there, so a message
	arriving in it is announced. The messages read --prose-ink, the way a
	paragraph does, which the alert tone repaints - so a message, and a
	list's bullets, take the tone.
*/

:is(form-control, .choice-group) {
	--under-close: 0.375em;
	--under-apart: 0.75em;
	--under-gap: 1em;

	.help,
	.messages {
		margin-top: var(--under-close);
	}

	.messages {
		color: var(--prose-ink, var(--ink-secondary));

		&:not(:has(.message)) {
			margin-top: 0;
		}
	}

	.message {
		margin: 0;
	}

	/* The bullets line up with the label and the field's left edge,
	   not the prose list indent. */
	.message-list {
		margin: 0;
		padding-inline-start: 0;
		list-style-position: inside;
	}

	.message-list > li + li {
		margin-top: var(--under-gap);
	}

	/* Two or more lines under the field. */
	&:has(.help):has(.message) .help,
	&:has(.message-list) .messages {
		margin-top: var(--under-apart);
	}

	.help + .messages:has(.message) {
		margin-top: var(--under-gap);
	}
}

/* Windows High Contrast strips background images, so the drawn chevron
   would vanish. The user's colors win: back to the browser's own arrow. */
@media (forced-colors: active) {
	input-area select {
		appearance: auto;
	}
}
