/* Atomic WP Forms — generic frontend presentation.
 *
 * Ownership: this file defines the COMPONENT's structure, geometry, focus and
 * interaction states. A theme supplies its identity by overriding the
 * `--awp-form-*` tokens below — never by re-declaring these selectors.
 *
 * Every value falls back to a design-system token so a bare Atomic WP install
 * (no child theme) already renders a coherent form: ivory fields, dark text,
 * discreet border, brand-coloured focus, consistent field geometry.
 */
.awp-form {
	/* Field surface + text. */
	--awp-form-field-background: var(--wp--preset--color--background);
	--awp-form-field-text: var(--wp--preset--color--contrast, currentColor);
	--awp-form-field-border: var(--wp--preset--color--border, currentColor);
	--awp-form-field-border-width: var(--wp--custom--border--width, 1px);
	--awp-form-field-placeholder: currentColor;
	--awp-form-field-focus: var(--wp--preset--color--primary, currentColor);
	--awp-form-error-color: var(--wp--preset--color--contrast, #b42318);
	--awp-form-notice-color: var(--wp--preset--color--muted, #6b7280);
	/* One consistent field geometry for inputs, selects and textareas.
	   Legacy per-control tokens remain honoured as fallbacks. */
	--awp-form-field-radius: var(--wp--custom--radius--md, .5rem);
	--awp-form-checkbox-size: 1.1rem;
	--awp-form-checkbox-gap: .55rem;
	--awp-form-checkbox-radius: .3rem;
	--awp-form-checkbox-border-width: var(--awp-form-field-border-width);
	--awp-form-checkbox-border: var(--awp-form-field-border);
	--awp-form-checkbox-background: transparent;
	--awp-form-checkbox-fill: var(--awp-form-field-focus);
	/* The check mark is a token so its colour stays brand-controlled while the
	   control itself remains a native checkbox. */
	--awp-form-checkbox-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.4 8.4l3 3 6.2-6.6' fill='none' stroke='%23ffffff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	/* Rhythm. */
	--awp-form-row-gap: var(--wp--preset--spacing--40, 1rem);
	--awp-form-field-gap: var(--wp--preset--spacing--30, .75rem);
	--awp-form-label-gap: .375rem;

	display: grid;
	gap: var(--wp--preset--spacing--40, 1rem);
}

/* The form element owns the vertical rhythm between fields, notice and submit;
   without it the controls stack with no gutter of their own. */
.awp-form__form {
	display: grid;
	gap: var(--awp-form-row-gap);
}

.awp-form__form > * {
	margin-block: 0;
}

.awp-form__fields {
	display: grid;
	gap: var(--awp-form-field-gap);
}

.awp-form__field,
.awp-form__checkbox-group {
	border: 0;
	display: grid;
	gap: var(--awp-form-label-gap);
	margin: 0;
	min-inline-size: 0;
	padding: 0;
}

.awp-form__label,
.awp-form__legend {
	font: inherit;
}

.awp-form input:not([type="checkbox"]),
.awp-form select,
.awp-form textarea {
	background: var(--awp-form-field-background);
	border: var(--awp-form-field-border-width) solid var(--awp-form-field-border);
	border-radius: var(--awp-form-field-radius, var(--awp-form-field-radius-single, var(--wp--custom--radius--md, .5rem)));
	box-sizing: border-box;
	color: var(--awp-form-field-text);
	font: inherit;
	inline-size: 100%;
	max-inline-size: 100%;
	padding: var(--wp--preset--spacing--30, .75rem) var(--wp--preset--spacing--40, 1rem);
	transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}

.awp-form input::placeholder,
.awp-form textarea::placeholder {
	color: var(--awp-form-field-placeholder);
	opacity: .62;
}

/* Pointer/typing focus: discreet brand border + soft ring, no native outline. */
.awp-form input:not([type="checkbox"]):focus,
.awp-form select:focus,
.awp-form textarea:focus {
	border-color: var(--awp-form-field-focus);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--awp-form-field-focus) 22%, transparent);
	outline: none;
}

/* Keyboard focus: explicit, high-visibility ring on every control. */
.awp-form input:not([type="checkbox"]):focus-visible,
.awp-form select:focus-visible,
.awp-form textarea:focus-visible,
.awp-form input[type="checkbox"]:focus-visible,
.awp-form .awp-form__submit .wp-block-button__link:focus-visible {
	outline: 2px solid var(--awp-form-field-focus);
	outline-offset: 2px;
}

/* Invalid fields keep a visible, on-brand signal without a parallel validator. */
.awp-form input[aria-invalid="true"],
.awp-form select[aria-invalid="true"],
.awp-form textarea[aria-invalid="true"] {
	border-color: var(--awp-form-error-color);
}

/* Same rounded geometry as the other fields. */
.awp-form textarea {
	border-radius: var(--awp-form-field-radius, var(--awp-form-field-radius-textarea, var(--wp--custom--radius--md, .5rem)));
	min-block-size: 8rem;
	resize: vertical;
}

/* Native checkbox, restyled: the control keeps its semantics, name and
   keyboard behaviour — only its paint follows the brand tokens. */
.awp-form input[type="checkbox"] {
	appearance: none;
	-webkit-appearance: none;
	background-color: var(--awp-form-checkbox-background);
	border: var(--awp-form-checkbox-border-width) solid var(--awp-form-checkbox-border);
	border-radius: var(--awp-form-checkbox-radius);
	block-size: var(--awp-form-checkbox-size);
	box-sizing: border-box;
	flex: 0 0 auto;
	font: inherit; /* keep em/lh in the label's typographic context */
	inline-size: var(--awp-form-checkbox-size);
	margin-block: 0;
	transition: border-color .2s ease, background-color .2s ease, box-shadow .2s ease;
}

.awp-form input[type="checkbox"]:checked {
	background-color: var(--awp-form-checkbox-fill);
	background-image: var(--awp-form-checkbox-image);
	background-position: center;
	background-repeat: no-repeat;
	background-size: 74% 74%;
	border-color: var(--awp-form-checkbox-fill);
}

/* The box sits on the FIRST line of its label and stays there when the text
   wraps. The offset is the line's half-leading, derived from the real
   line-height (`1lh`) — a principled value, never a hand-tuned displacement. */
.awp-form__checkbox-label {
	align-items: flex-start;
	display: flex;
	gap: var(--awp-form-checkbox-gap);
}

.awp-form__checkbox-label > input[type="checkbox"] {
	margin-block-start: 0; /* fallback when the `lh` unit is unavailable */
	margin-block-start: calc((1lh - var(--awp-form-checkbox-size)) / 2);
}

/* High-contrast/forced-colors: hand the control back to the OS paint. */
@media (forced-colors: active) {
	.awp-form input[type="checkbox"] {
		-webkit-appearance: auto;
		appearance: auto;
	}
}

.awp-form__help,
.awp-form__field-error {
	margin: 0;
}

.awp-form__help {
	color: var(--awp-form-notice-color);
	font-size: var(--wp--preset--font-size--small, .875rem);
	line-height: 1.5;
}

.awp-form__field-error {
	color: var(--awp-form-error-color);
	font-size: var(--wp--preset--font-size--small, .875rem);
}

.awp-form__notice {
	margin: 0;
	color: var(--awp-form-notice-color);
	font-size: var(--wp--preset--font-size--small, .875rem);
	line-height: 1.6;
}

.awp-form__notice a,
.awp-form__help a {
	color: var(--awp-form-field-focus);
}

.awp-form__error-summary,
.awp-form__result {
	border-inline-start: 4px solid currentColor;
	padding: var(--wp--preset--spacing--20, .75rem);
}

.awp-form__error-summary {
	color: var(--awp-form-error-color);
}

.awp-form__error-summary :first-child,
.awp-form__result :first-child {
	margin-block-start: 0;
}

.awp-form__error-summary :last-child,
.awp-form__result :last-child {
	margin-block-end: 0;
}

/* Submit closes the form: aligned with the fields and slightly separated from
   the notice that precedes it. */
.awp-form__submit {
	justify-self: start;
	margin: 0;
	margin-block-start: var(--wp--preset--spacing--20, .75rem);
}

.awp-form__submit .wp-block-button__link[disabled],
.awp-form__submit .wp-block-button__link[aria-busy="true"] {
	cursor: progress;
	opacity: .6;
}

.awp-form__website-field {
	block-size: 1px !important;
	clip-path: inset(50%) !important;
	inline-size: 1px !important;
	overflow: hidden !important;
	position: absolute !important;
	white-space: nowrap !important;
}

@media (prefers-reduced-motion: reduce) {
	.awp-form input,
	.awp-form select,
	.awp-form textarea {
		transition: none;
	}
}
