/*
 * Entangle Forms — the form block.
 *
 * Written to stand on any block theme. Nothing here names a class of a theme: colours, spacing and shape come from
 * custom properties with fallbacks — the theme's own where it has them (--color-*, --radius-sm, --space-*,
 * --wp--preset--spacing--*), else values derived from the colour of the text around, so a dark theme gets a dark form.
 * Override the --ef-* properties (below) to restyle the whole thing at once.
 *
 *   --ef-gap      the air between fields
 *   --ef-tight    the air inside a field: a label, its control, its help (they belong together, so far less than --ef-gap)
 *   --ef-rule     the line around controls
 *   --ef-muted    help texts
 *   --ef-error    the colour of an error (its text, its line)
 *   --ef-accent   the button, the chosen state, the focus of a control
 *   --ef-radius   the roundness of controls
 *
 * The shape of shadcn/ui's Field (the owner, 2. 11.): a small label, the control, a smaller help under it. A control
 * keeps the theme's font at 1rem (under that, iOS zooms into the field), and the 44 px of a target where shadcn has 36:
 * this is a site for everybody in a city. Its line is the one thing darker than shadcn's: it has to read at 3:1 on any
 * surface (WCAG 1.4.11), so it comes from the text around, not from the theme's hairline for dividing things.
 * Focus is the theme's ring drawn tight to the control, in the accent.
 */

.entangle-form {
	--ef-gap: 1.5rem;
	--ef-tight: 0.375rem;
	--ef-rule: color-mix(in srgb, currentColor 50%, transparent);
	--ef-muted: var(--color-ink-soft, color-mix(in srgb, currentColor 70%, transparent));
	--ef-error: var(--color-error, #b3261e);
	--ef-error-bg: color-mix(in srgb, var(--ef-error) 8%, transparent);
	--ef-accent: var(--color-brand, currentColor);
	--ef-on-accent: var(--color-on-brand, #fff);
	--ef-surface: var(--color-card, transparent);
	/* A field and a button of a form: the theme's small radius, never more than a control's 10 px (31. 10.). */
	--ef-radius: min(var(--radius-sm, 4px), var(--radius-control, 10px));
	box-sizing: border-box;
	max-width: var(--entangle-form-width, 40rem);
	/* A link to the form (`#entangle-form-<slug>`: the action of the form itself, a button of a module) lands below a sticky header, not under it. */
	scroll-margin-top: calc(var(--header-h, 0px) + var(--wp-admin--admin-bar--height, 0px) + 24px);
}
.entangle-form *,
.entangle-form *::before,
.entangle-form *::after {
	box-sizing: border-box;
}

.entangle-form__title {
	margin-block: 0 var(--space-4, 1rem);
}
.entangle-form__intro {
	margin-block: 0 var(--ef-gap);
	font-size: 1rem;
	color: var(--ef-muted);
}

/* ===== The form ===== */
.entangle-form__form {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--ef-gap);
	margin: 0;
}
.entangle-form__field {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--ef-tight);
	min-width: 0;
	margin: 0;
	padding: 0;
	border: 0;
}
fieldset.entangle-form__field {
	/* A fieldset has a min-width of its content in some browsers: a long label must not push the page wide. */
	min-inline-size: 0;
}
.entangle-form__label {
	padding: 0;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.4;
}
/* A legend stands outside the grid of its fieldset: the gap does not reach it. */
legend.entangle-form__label {
	margin-block-end: var(--ef-tight);
}
.entangle-form__required {
	font-size: 0.875rem;
	font-weight: 400;
	color: var(--ef-muted);
}
.entangle-form__help {
	margin: 0;
	font-size: 0.875rem;
	line-height: 1.45;
	color: var(--ef-muted);
}

.entangle-form__input,
.entangle-form__file {
	width: 100%;
	max-width: 100%;
	min-height: var(--btn-target, 44px);
	padding: 0.5rem 0.75rem;
	border: 1px solid var(--ef-rule);
	border-radius: var(--ef-radius);
	background: var(--ef-surface);
	box-shadow: 0 1px 2px color-mix(in srgb, currentColor 6%, transparent);
	color: inherit;
	font: inherit;
	font-size: 1rem;
	line-height: 1.5;
}
.entangle-form__input::placeholder {
	color: var(--ef-muted);
	opacity: 1;
}
/* No weight of its own: the line of an error stays red under the pointer. */
.entangle-form__input:where(:hover:not(:disabled)),
.entangle-form__file:where(:hover:not(:disabled)) {
	border-color: color-mix(in srgb, currentColor 75%, transparent);
}
/* Through the root: the base theme's ring for everything (`:is(…, [tabindex]):focus-visible`) weighs as much as one
   class and comes later. */
.entangle-form .entangle-form__input:focus-visible,
.entangle-form .entangle-form__file:focus-visible {
	border-color: var(--ef-accent);
	outline: 3px solid color-mix(in srgb, var(--ef-accent) 35%, transparent);
	outline-offset: 0;
}
.entangle-form__input:disabled,
.entangle-form__file:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}
.entangle-form__textarea {
	min-height: 6em;
	resize: vertical;
}
.entangle-form__file {
	padding: 0.375rem;
}
.entangle-form__file::file-selector-button {
	min-height: 1.875rem;
	margin-inline-end: 0.75rem;
	padding: 0 0.75rem;
	border: 1px solid var(--ef-rule);
	border-radius: var(--ef-radius);
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	cursor: pointer;
}

/* Groups: checkboxes, a place, a contact block */
.entangle-form__choices {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
	gap: var(--space-2, 0.5rem) var(--space-4, 1rem);
}
.entangle-form__choice {
	display: flex;
	align-items: flex-start;
	gap: 0.6em;
	min-height: var(--btn-target, 44px);
	padding-block: 0.4em;
	font-size: 1rem;
	line-height: 1.5;
	cursor: pointer;
}
.entangle-form__choice input {
	flex: none;
	width: 1.125rem;
	height: 1.125rem;
	margin: 0.1875rem 0 0;
	accent-color: var(--ef-accent);
}
/* A consent is a sentence or two to agree to, not a question of the form: it stands back, as a help does. */
.entangle-form__consent {
	min-height: 0;
	padding-block: 0;
	font-size: 0.9375rem;
	line-height: 1.45;
}
.entangle-form__parts,
.entangle-form__coords {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
	gap: var(--space-3, 0.75rem) var(--space-4, 1rem);
}
.entangle-form__part {
	display: grid;
	gap: var(--ef-tight);
	min-width: 0;
}
.entangle-form__sublabel {
	font-size: 0.875rem;
	line-height: 1.4;
}
.entangle-form__map {
	width: 100%;
	height: var(--entangle-form-map-height, 20rem);
	border: 1px solid var(--ef-rule);
	border-radius: var(--ef-radius);
}
.entangle-form__map[hidden] {
	display: none;
}

/* The logo a map provider asks to be shown (Mapy.com); core's place-picker.js draws it on the map. */
.entangle-place-picker__logo {
	display: block;
	line-height: 0;
}
.entangle-place-picker__logo img {
	display: block;
	width: auto;
}

/* ===== The bar of the steps above the fields ===== */
.entangle-form__steps {
	margin-block-end: var(--space-2, 0.5rem);
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-3, 0.75rem);
	margin: 0;
	padding: 0;
	list-style: none;
}
.entangle-form__steps-item {
	margin: 0;
}
.entangle-form__steps-item[hidden] {
	display: none;
}
.entangle-form__steps-link {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	color: var(--ef-muted);
	text-decoration: none;
}
.entangle-form__steps-number {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: 1.75em;
	block-size: 1.75em;
	border: 1px solid currentColor;
	border-radius: var(--radius-pill, 999px);
	font-variant-numeric: tabular-nums;
}
.entangle-form__steps-item[data-done] .entangle-form__steps-link {
	color: inherit;
}
.entangle-form__steps-item[aria-current="step"] .entangle-form__steps-link {
	color: var(--ef-accent);
	font-weight: 700;
}
.entangle-form__steps-item[aria-current="step"] .entangle-form__steps-number {
	border-color: var(--ef-accent);
	background: var(--ef-accent);
	color: var(--ef-on-accent);
}
.entangle-form__steps-link[aria-disabled="true"] {
	cursor: default;
}

/* ===== Headings above fields, steps, skipped fields ===== */
.entangle-form__heading {
	margin-block: var(--space-2, 0.5rem) calc(var(--space-2, 0.5rem) - var(--ef-gap));
}
.entangle-form__step {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--ef-gap);
	min-inline-size: 0;
	margin: 0;
	padding: 0;
	border: 0;
}
.entangle-form__step-nav {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-3, 0.75rem);
	align-items: center;
}
.entangle-form__progress {
	flex-basis: 100%;
	margin: 0;
	color: var(--ef-muted);
}
.entangle-form__back,
.entangle-form__next {
	min-height: var(--btn-target, 44px);
	cursor: pointer;
}
.entangle-form__back:where(:not([class*="wp-element-button"])),
.entangle-form__next:where(:not([class*="wp-element-button"])) {
	padding: 0.75em 1.5em;
	border: 1px solid var(--ef-accent);
	border-radius: var(--ef-radius);
	background: transparent;
	color: inherit;
	font: inherit;
}
/* The way back is the quiet one: the theme paints every .wp-element-button as the primary button (the accent of
   the site), and two filled buttons side by side would both ask to be pressed. Outline, in the accent. */
.entangle-form__back,
.entangle-form__back.wp-element-button {
	background: transparent;
	color: var(--ef-accent, currentColor);
	border: 1px solid currentColor;
}
.entangle-form__back.wp-element-button:hover,
.entangle-form__back.wp-element-button:focus-visible {
	background: var(--ef-accent, currentColor);
	color: var(--ef-on-accent, #fff);
	border-color: transparent;
}
.entangle-form [hidden] {
	display: none !important;
}

/* ===== Errors ===== */
.entangle-form__summary {
	margin-block: 0 var(--ef-gap);
	padding: var(--space-4, 1rem) var(--space-5, 1.25rem);
	border: 2px solid var(--ef-error);
	border-radius: var(--ef-radius);
	background: var(--ef-error-bg);
}
.entangle-form__summary:focus {
	outline: 3px solid var(--ef-error);
	outline-offset: 2px;
}
.entangle-form__summary-title {
	margin: 0 0 var(--space-2, 0.5rem);
	font-size: 1.125em;
}
.entangle-form__summary-list {
	margin: 0;
	padding-inline-start: 1.25em;
}
.entangle-form__summary-list a {
	color: var(--ef-error);
	font-weight: 600;
	text-decoration: underline;
}
.entangle-form__error {
	margin: 0;
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.45;
	color: var(--ef-error);
}
/* A group has no line of its own to turn red: it gets one down its side. A single control's own line says it, thicker
   without moving anything (a shadow, not a border), so a field in error does not jump. */
fieldset.entangle-form__field--error {
	padding-inline-start: var(--space-4, 1rem);
	border-inline-start: 4px solid var(--ef-error);
}
.entangle-form__field--error .entangle-form__input,
.entangle-form__field--error .entangle-form__file {
	border-color: var(--ef-error);
	box-shadow: inset 0 0 0 1px var(--ef-error);
}
.entangle-form__field--error .entangle-form__input:focus-visible,
.entangle-form__field--error .entangle-form__file:focus-visible {
	border-color: var(--ef-error);
	outline-color: color-mix(in srgb, var(--ef-error) 35%, transparent);
}

/* ===== The button, the result ===== */
.entangle-form__actions {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-3, 0.75rem);
	align-items: center;
}
.entangle-form__submit {
	min-height: var(--btn-target, 44px);
	cursor: pointer;
}
.entangle-form__submit:where(:not([class*="wp-element-button"])) {
	padding: 0.75em 1.5em;
	border: 0;
	border-radius: var(--ef-radius);
	background: var(--ef-accent);
	color: var(--ef-on-accent);
	font: inherit;
}
.entangle-form[aria-busy="true"] .entangle-form__submit {
	opacity: 0.6;
	cursor: progress;
}
.entangle-form__live:empty {
	display: none;
}
.entangle-form__live {
	margin-block: 0 var(--space-4, 1rem);
	color: var(--ef-muted);
}
.entangle-form__result {
	padding: var(--space-4, 1rem) var(--space-5, 1.25rem);
	border-inline-start: 4px solid var(--ef-accent);
	background: color-mix(in srgb, var(--ef-accent) 8%, transparent);
	border-radius: var(--ef-radius);
}
.entangle-form__result:focus {
	outline: 3px solid var(--ef-accent);
	outline-offset: 2px;
}
.entangle-form__result > p {
	margin: 0;
}
.entangle-form__closed,
.entangle-form__missing {
	color: var(--ef-muted);
}

/* ===== Hidden: the honeypot, the words for screen readers ===== */
.entangle-form__hp {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	inset-inline-start: -10000px;
}
.entangle-form .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}
