/* The choice group - radios and checkboxes, from the shared UI kit.
   A copy of mise-en-place's app/assets/styles/components/choice-group.css
   (the source of truth - keep this in step by hand; pssst parts are made
   to be copied). Its markup is includes/components/choice-group.php, the
   same markup the kit's ChoiceGroup.vue renders. This site fills the
   slots it reads in settings/base.css ("Controls"). */

/*
	The choice primitive: radio and checkbox share everything (ChoiceGroup).
	From the form system (super-ultimate-form-system-pro, form.css, choice.md),
	written in pssst's slots. The label is the whole row, at least a control
	tall, so the gaps between choices are clickable too. The native input
	stays the input, repainted - no decorator twin.

	Slots it reads, which the app fills:
	  --control-height        the row's hit-target floor
	  --choice-size           the box and the circle
	  --control-border        their edge, repainted by the alert tone
	  --control-fill          their inside, unchecked
	  --control-radius        the box's corners
	  --control-focus-ring    the outline a focused choice wears, around
	                          the whole row: the box or circle and its label
	  --control-focus-offset  how far out it sits

	Its own knob, off unless set:
	  --choice-hover-fill     a row's fill under the pointer (none by default)
	  --control-note-ink      the legend's note, calm in the alert tone
	  --accent                checked
	  --accent-ink            the mark drawn on the accent: the dot, the tick
*/

.choice-group {
	border: none;
	margin: 0;
	padding: 0;
	max-width: 32rem;

	legend {
		padding: 0;
		margin-bottom: 0.375em;

		/* A short note beside the question ("(optional)"), as on a label. */
		.aside {
			margin-inline-start: 0.375em;
			color: var(--control-note-ink);
		}
	}

	/* One choice per line, each row as wide as its own label. */
	.choices {
		display: grid;
		justify-items: start;
	}

	/* Several errors: the bullets line up with the legend, as on a
	   labeled field (labeled-control.css). */
	.message-list {
		margin: 0;
		padding-inline-start: 0;
		list-style-position: inside;
	}
}

.choice {
	display: flex;
	align-items: center;
	gap: 0.625em;
	box-sizing: border-box;
	min-height: var(--control-height);

	/* The invisible hit area: the rhythm between rows stays clickable. The
	   side padding gives the ring and the hover room around the label; the
	   matching negative margin keeps the box in line with the legend. */
	padding: 0.25em 0.5em;
	margin-inline: -0.5em;
	border-radius: var(--control-radius);
	cursor: pointer;

	/* Focus wraps the whole choice, as wide as its own label - not a ring
	   on the little box alone, and not one width for every row. */
	&:has(input:focus-visible) {
		outline: var(--control-focus-ring);
		outline-offset: var(--control-focus-offset);
	}

	&:hover:not(:has(input:disabled)) {
		background: var(--choice-hover-fill, transparent);
	}

	input {
		appearance: none;
		flex: none;
		width: var(--choice-size);
		height: var(--choice-size);
		margin: 0;
		background: var(--control-fill);
		border: var(--control-border);
		cursor: inherit;

		/* The row wears the ring (above), so the box itself shows none. */
		&:focus-visible {
			outline: none;
		}

		&:checked {
			background-color: var(--accent);
			border-color: var(--accent);
		}

		&:disabled {
			opacity: 0.55;
			cursor: not-allowed;
		}
	}

	input[type='radio'] {
		/* A circle is what makes it a radio, not a look a theme picks. */
		/* stylelint-disable-next-line scale-unlimited/declaration-strict-value */
		border-radius: 50%;

		/* The dot: accent-ink in the middle, the accent ring around it. */
		&:checked {
			background: radial-gradient(var(--accent-ink) 30%, var(--accent) 35%);
		}
	}

	input[type='checkbox'] {
		border-radius: var(--control-radius);

		/* The tick is an SVG, which can't read a custom property, so it's a
		   mask: the shape comes from the SVG, the color from the slot. (The
		   form system draws it in a literal; this closes its $open.) */
		&:checked::before {
			content: '';
			display: block;
			width: 100%;
			height: 100%;
			background-color: var(--accent-ink);
			mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 8'%3E%3Cpath d='M1 4l2.5 2.5L9 1' fill='none' stroke='black' stroke-width='2'/%3E%3C/svg%3E") center / 0.6em no-repeat;
		}
	}

	&:has(input:disabled) {
		cursor: not-allowed;
	}
}

/* An option's full label, for screen readers only: the short label shows
   ("Mon"), the full one is read ("Monday"). The standard clip recipe. */
.choice .full-label {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* Side by side (data-direction="inline"), wrapping: for two or three short
   choices only. Longer lists stay stacked, the default. */
.choice-group[data-direction='inline'] .choices {
	display: flex;
	flex-wrap: wrap;
	gap: 0 1.25em;
}

/*
	The compact look (data-look="compact"): each choice a small toggle chip,
	the set on one row - a weekday picker. A little shorter than a full
	control. Off, it's outlined, its label in the accent; on, it's filled
	with the accent, its label in the accent's ink. The real checkbox or
	radio is still there, invisible over the whole chip, so clicking,
	keyboard and screen readers work unchanged; the chip wears its focus.

	Slots it reads, beyond the ones above:
	  --action-radius-primary  the chip's corners, a button's (falls back
	                           to --corners)

	Its own knob, with a default:
	  --chip-height            how tall a chip is (0.8 of a control)
*/
.choice-group[data-look='compact'] {
	.choices {
		display: flex;
		flex-wrap: wrap;
		gap: 0.375em;
	}

	.choice {
		position: relative;
		justify-content: center;
		min-width: var(--chip-height, calc(var(--control-height) * 0.8));
		min-height: var(--chip-height, calc(var(--control-height) * 0.8));
		padding: 0 0.75em;
		margin-inline: 0;
		color: var(--accent);
		border: 1px solid var(--accent);
		border-radius: var(--action-radius-primary, var(--corners));

		input {
			position: absolute;
			inset: 0;
			width: 100%;
			height: 100%;
			opacity: 0;
		}

		&:has(input:checked) {
			color: var(--accent-ink);
			background: var(--accent);
		}

		&:has(input:disabled) {
			opacity: 0.55;
		}
	}
}

/* Windows High Contrast strips backgrounds and shadows, so a repainted
   checked state would vanish. The user's colors win: back to native, and
   a compact chip shows its real box again. */
@media (forced-colors: active) {
	.choice input {
		appearance: auto;
	}

	.choice-group[data-look='compact'] .choice input {
		position: static;
		width: auto;
		height: auto;
		opacity: 1;
	}
}
