/*
 * Fluent Forms, mapped onto the theme's tokens.
 *
 * Loaded only where a form is on the page (see inc/enqueue.php), and kept in
 * its own file rather than in theme.css because it styles someone else's
 * markup: every selector below belongs to Fluent Forms and can change when the
 * plugin updates, which is a different maintenance risk from the theme's own
 * rules.
 *
 * HOW THE MAPPING WORKS. Fluent Forms' "default" style sheet declares six
 * custom properties on :root and then uses them throughout its own rules
 * (fluentform-public-default.css). Re-declaring those six is therefore the
 * whole colour and radius mapping — it reaches rules this file never names,
 * including states rendered by JavaScript after a submission. Everything after
 * the first block is what those variables cannot express: type, spacing, focus
 * rings, touch targets, and the success and error surfaces from
 * `03-design-system/04-components-and-patterns.md`.
 *
 * NO HEX, NO RAW PX for colour, type or spacing — every value is a theme.json
 * preset. The only literals are hairline borders (1px), the 2px corner radius
 * and the 2px focus ring, which the design system states in px and which
 * theme.json itself sets in px on `elements.button`; and the 44px touch floor
 * from `03-design-system/03-layout-grid-spacing.md`, written the same way as
 * the header's in theme.css.
 */

/* -------------------------------------------------------------------------
 * 1 · The variable mapping
 *
 * `--fluentform-danger` is the plugin's error colour AND the colour of the
 * required asterisk, so it must be a token that is legible on cream: the
 * design system's `error` is 6.67:1 on cream-50 where the plugin's own #f56c6c
 * is 3.05:1 and would fail AA as an error text colour.
 * ------------------------------------------------------------------------- */

.fluentform {
	--fluentform-primary: var(--wp--preset--color--maroon-700);
	--fluentform-secondary: var(--wp--preset--color--grey-700);
	--fluentform-danger: var(--wp--preset--color--error);
	--fluentform-border-color: var(--wp--preset--color--grey-500);
	--fluentform-border-radius: 2px;
	--fluentform-input-select-height: auto;
}

/* -------------------------------------------------------------------------
 * 2 · Fields
 *
 * The plugin hard-codes a system font stack and a 1 line-height on every
 * control, which is the one thing a form must not do on this site: an input
 * set in Segoe UI beside a label set in Source Sans 3 reads as a third-party
 * widget dropped into the page, which is what it is and what it must stop
 * looking like.
 * ------------------------------------------------------------------------- */

.fluentform .ff-el-form-control,
.ff-default .ff-el-form-control {
	background-color: var(--wp--preset--color--white);
	border: 1px solid var(--wp--preset--color--grey-500);
	border-radius: 2px;
	color: var(--wp--preset--color--grey-900);
	font-family: var(--wp--preset--font-family--body);

	/*
	 * The site floor is 17px, and anything under 16px also makes iOS zoom the
	 * page when the field takes focus.
	 */
	font-size: var(--wp--preset--font-size--md);
	line-height: 1.5;
	padding: var(--wp--preset--spacing--20) var(--wp--preset--spacing--30);
}

.fluentform .ff-el-form-control::placeholder {
	color: var(--wp--preset--color--grey-700);
	opacity: 1;
}

.fluentform textarea.ff-el-form-control,
.ff-default textarea.ff-el-form-control {
	line-height: 1.6;
	min-block-size: 8em;
	resize: vertical;
}

/* Match the height of a text input rather than the browser's own. */
.fluentform select.ff-el-form-control {
	padding-block: var(--wp--preset--spacing--20);
}

.fluentform .ff-el-form-control:disabled,
.fluentform .ff-el-form-control[readonly]:not(.flatpickr-input) {
	background-color: var(--wp--preset--color--grey-100);
	color: var(--wp--preset--color--grey-700);
}

/* -------------------------------------------------------------------------
 * 3 · Labels, hints and the required marker
 * ------------------------------------------------------------------------- */

.fluentform .ff-el-input--label label,
.ff-default .ff-el-input--label label {
	color: var(--wp--preset--color--grey-900);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 600;
	letter-spacing: 0.01em;
	line-height: 1.4;
}

.fluentform .ff-el-input--label {
	display: block;
	margin-bottom: var(--wp--preset--spacing--10);
}

/*
 * The hint sits under the field it explains (helpMessagePlacement:
 * under_input in every form definition). The plugin's default is a hover
 * tooltip, which a keyboard or touch user never sees — and several hints here
 * carry real constraints ("PDF, DOC or DOCX, 10 MB or smaller"), so they are
 * instructions under WCAG 2.2 · 3.3.2 and have to be on the page.
 *
 * Italic is dropped: the plugin sets it, and italic at this size in Source
 * Sans 3 is noticeably harder to read than roman.
 */
.fluentform .ff-el-help-message {
	color: var(--wp--preset--color--grey-700);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--xs);
	font-style: normal;
	line-height: 1.5;
	margin-top: var(--wp--preset--spacing--10);
}

.fluentform .ff-el-input--label.ff-el-is-required.asterisk-right label::after {
	color: var(--wp--preset--color--error);
}

.fluentform .ff-el-group {
	margin-bottom: var(--wp--preset--spacing--40);
}

/* -------------------------------------------------------------------------
 * 4 · Focus
 *
 * The same ring theme.json puts on links and buttons. `:focus-visible` alone
 * is wrong for text inputs: a click into a field is exactly when a sighted
 * user needs to see where the caret went, and browsers do not treat a mouse
 * click on an input as focus-visible. So text controls take the ring on
 * `:focus`; the checkbox and radio inputs, which are clicked deliberately,
 * take it on `:focus-visible`.
 * ------------------------------------------------------------------------- */

.fluentform .ff-el-form-control:focus,
.ff-default .ff-el-form-control:focus {
	background-color: var(--wp--preset--color--white);
	border-color: var(--wp--preset--color--maroon-700);
	color: var(--wp--preset--color--grey-900);
	outline: 2px solid var(--wp--preset--color--maroon-700);
	outline-offset: 2px;
}

.fluentform .ff-el-form-check-input {
	accent-color: var(--wp--preset--color--maroon-700);
	flex: none;
	inline-size: 1.125rem;
	block-size: 1.125rem;
	margin-block-start: 0.2em;
	top: 0;
}

.fluentform .ff-el-form-check-input:focus-visible,
.fluentform .ff_tc_checkbox input:focus-visible {
	outline: 2px solid var(--wp--preset--color--maroon-700);
	outline-offset: 2px;
}

/* -------------------------------------------------------------------------
 * 5 · Checkboxes and radios
 * ------------------------------------------------------------------------- */

.fluentform .ff-el-form-check {
	margin-bottom: var(--wp--preset--spacing--20);
}

.fluentform .ff-el-form-check-label,
.ff-default .ff-el-form-check label.ff-el-form-check-label {
	color: var(--wp--preset--color--grey-900);
	display: flex;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--md);
	gap: var(--wp--preset--spacing--20);
	line-height: 1.5;
	margin-bottom: 0;
}

/*
 * WCAG 2.2 · 2.5.8 asks for 24x24; the design system asks for 44 on touch.
 * The box itself stays 1.125rem — a 44px checkbox looks broken — so the label
 * row carries the target instead, which is the thing a finger actually hits.
 */
@media (pointer: coarse) {

	.fluentform .ff-el-form-check-label {
		min-block-size: 44px;
		padding-block: var(--wp--preset--spacing--10);
	}
}

/* The consent row: the field, its explanation and the policy link. */
.fluentform .ff-el-tc .ff_tc_label {
	align-items: flex-start;
}

.fluentform .ff_t_c {
	font-size: var(--wp--preset--font-size--sm);
	line-height: 1.5;
}

.fluentform .ff_t_c a {
	color: var(--wp--preset--color--maroon-700);
}

/* -------------------------------------------------------------------------
 * 6 · The NFR-11 notice
 *
 * Every form carries one: what is collected, why, how long it is kept, and a
 * link to the privacy policy. It is a quiet cream panel rather than a warning,
 * because it is not one — it is the part of the form the Institute is obliged
 * to say and the visitor is entitled to read before ticking the box.
 * `container_class: aias-form-notice` in each JSON definition is what puts
 * this class on the wrapper.
 * ------------------------------------------------------------------------- */

.fluentform .aias-form-notice {
	background-color: var(--wp--preset--color--cream-100);
	border-left: 2px solid var(--wp--preset--color--gold-500);
	color: var(--wp--preset--color--grey-900);
	padding: var(--wp--preset--spacing--30);
}

.fluentform .aias-form-notice h3 {
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 500;
	letter-spacing: 0.06em;
	margin-block: 0;
	text-transform: uppercase;
}

.fluentform .aias-form-notice > p {
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--sm);
	line-height: 1.6;
	margin-block: var(--wp--preset--spacing--20) 0;
}

.fluentform .aias-form-notice > :first-child {
	margin-block-start: 0;
}

.fluentform .aias-form-notice a {
	color: var(--wp--preset--color--maroon-700);
}

/* -------------------------------------------------------------------------
 * 7 · Submit button
 *
 * Matches theme.json's `elements.button` rather than importing it: the plugin
 * renders a bare <button class="ff-btn ff-btn-submit ff_btn_style">, which is
 * not a `.wp-element-button`, so core's button styles never reach it.
 * ------------------------------------------------------------------------- */

.fluentform .ff-btn-submit,
.ff-default .ff-btn-submit.ff_btn_style {
	background-color: var(--wp--preset--color--maroon-700);
	border: 1px solid var(--wp--preset--color--maroon-700);
	border-radius: 2px;
	color: var(--wp--preset--color--white);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--md);
	font-weight: 600;
	line-height: 1.4;
	min-block-size: 44px;
	padding: var(--wp--preset--spacing--20) var(--wp--preset--spacing--40);
	text-decoration: none;
	transition: background-color 0.15s ease-out;
}

.fluentform .ff-btn-submit:hover,
.ff-default .ff-btn-submit.ff_btn_style:hover {
	background-color: var(--wp--preset--color--maroon-500);
	border-color: var(--wp--preset--color--maroon-500);
	color: var(--wp--preset--color--white);

	/* The plugin fades the button to 80% on hover, which drops the label to
	   3.9:1 on maroon. Contrast is not a hover effect. */
	opacity: 1;
}

.fluentform .ff-btn-submit:focus-visible,
.ff-default .ff-btn-submit.ff_btn_style:focus-visible {
	opacity: 1;
	outline: 2px solid var(--wp--preset--color--maroon-700);
	outline-offset: 2px;
}

/* The plugin adds .ff_working while the request is in flight. */
.fluentform .ff-btn-submit.ff_working,
.fluentform .ff-btn-submit:disabled {
	cursor: progress;
	opacity: 0.7;
}

/* -------------------------------------------------------------------------
 * 8 · Error state
 *
 * The plugin marks the group `.ff-el-is-error`, sets `aria-invalid` on the
 * control and inserts `div.error.text-danger[role=alert]` inside the field's
 * content wrapper. Colour is never the only signal: the message is text, and
 * the field takes a 2px border so the change survives a greyscale screenshot.
 * ------------------------------------------------------------------------- */

.fluentform .ff-el-is-error .ff-el-form-control,
.ff-default .ff-el-is-error .ff-el-form-control {
	border-color: var(--wp--preset--color--error);
	border-width: 2px;
}

.fluentform .error.text-danger,
.fluentform .ff-el-is-error .text-danger {
	color: var(--wp--preset--color--error);
	font-family: var(--wp--preset--font-family--body);

	/* The plugin sets 12px, which is below the site's floor for any text a
	   visitor has to act on. */
	font-size: var(--wp--preset--font-size--xs);
	font-weight: 600;
	line-height: 1.5;
	margin-top: var(--wp--preset--spacing--10);
}

/*
 * `#<form>_errors` is the stacked summary the plugin fills when the server
 * rejects a submission. It is empty on every other render, so it must not
 * occupy space or draw a box until it has something in it.
 */
.fluentform .ff-errors-in-stack:not(:empty) {
	background-color: var(--wp--preset--color--maroon-100);
	border-left: 2px solid var(--wp--preset--color--error);
	color: var(--wp--preset--color--maroon-900);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--sm);
	margin-top: var(--wp--preset--spacing--30);
	padding: var(--wp--preset--spacing--30);
}

/* -------------------------------------------------------------------------
 * 9 · Success state
 *
 * Inserted after the <form> (so still inside .fluentform) as
 * `div.ff-message-success[role=status]`, and given
 * focus by the plugin, so it is announced and reachable. `error` and `success`
 * are only ever used on light surfaces (03.1: `error` is 1.62:1 on maroon-700,
 * so a dark variant of this panel would be unreadable).
 * ------------------------------------------------------------------------- */

.fluentform .ff-message-success {
	background-color: var(--wp--preset--color--cream-50);
	border: 1px solid var(--wp--preset--color--success);
	border-left-width: 2px;
	border-radius: 2px;
	box-shadow: none;
	color: var(--wp--preset--color--grey-900);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--md);
	line-height: 1.6;
	margin-top: var(--wp--preset--spacing--30);
	padding: var(--wp--preset--spacing--40);
}

.fluentform .ff-message-success:focus-visible {
	outline: 2px solid var(--wp--preset--color--maroon-700);
	outline-offset: 2px;
}

.fluentform .ff-message-success > p {
	margin-block: var(--wp--preset--spacing--20) 0;
}

.fluentform .ff-message-success > :first-child {
	margin-block-start: 0;
}

/* -------------------------------------------------------------------------
 * 10 · Reduced motion
 * ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {

	.fluentform .ff-el-form-control,
	.fluentform .ff-btn-submit {
		transition: none;
	}
}
