/**
 * Accessible Forms — front-end styles.
 *
 * Defaults are accessibility-first: a thick visible focus indicator, large
 * touch targets, errors that never rely on colour alone, and a layout that
 * reflows cleanly to 320px.
 *
 * EVERY colour and size below comes from a custom property on .aaf-form, and
 * the plugin writes those properties from Settings → Appearance as an inline
 * style that lands after this file. So a site owner brands the form from the
 * admin screen, and a theme developer only has to redeclare the tokens:
 *
 *     .aaf-form { --aaf-accent: #0b1f3a; --aaf-on-accent: #fff; }
 *
 * No rule here needs to be fought with !important.
 *
 * @package Ananyoo_Accessible_Forms
 */

.aaf-form {
	--aaf-target: 44px;
	--aaf-focus-width: 3px;
	--aaf-border: #4b5563;
	--aaf-error: #b00020;
	--aaf-text: #1f2937;

	/* Brand tokens. The defaults are all measured against WCAG 2.2 AA:
	 * white on the accent is 6.7:1 (1.4.3 asks 4.5:1), the focus ring is
	 * 6.7:1 on a white page (1.4.11 asks 3:1), and the example text is
	 * 6.0:1 on a white field. Change them from Settings > Form appearance,
	 * which measures each pair for you as you pick it. */
	--aaf-accent: #1d4ed8;
	--aaf-accent-hover: #1e40af;
	--aaf-on-accent: #ffffff;
	--aaf-focus: #1d4ed8;
	--aaf-placeholder: #5b6472;

	max-width: 40rem;
}

.aaf-form * {
	box-sizing: border-box;
}

.aaf-form-title {
	margin: 0 0 1rem;
	font-size: 1.25rem;
	line-height: 1.3;
}

.aaf-field {
	margin: 0 0 1.25rem;
}

.aaf-label,
.aaf-group legend {
	display: block;
	margin: 0 0 0.35rem;
	font-weight: 600;
	color: var(--aaf-text);
}

.aaf-required {
	color: var(--aaf-error);
}

.aaf-required-note {
	margin: 0 0 1rem;
	font-size: 0.9rem;
	color: #4b5563;
}

.aaf-help {
	display: block;
	margin: 0 0 0.4rem;
	font-size: 0.9rem;
	color: #4b5563;
}

/* Visually-hidden helper (self-contained, not theme-dependent). */
.aaf-sr-only {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* Character-limit counter (FEAT-06). */
.aaf-count {
	display: block;
	margin-top: 0.25rem;
	font-size: 0.85rem;
	color: #4b5563;
	text-align: end;
}

.aaf-count.is-limit {
	color: var(--aaf-error);
	font-weight: 600;
}

.aaf-form input[type="text"],
.aaf-form input[type="email"],
.aaf-form input[type="tel"],
.aaf-form input[type="url"],
.aaf-form input[type="number"],
.aaf-form textarea,
.aaf-form select {
	width: 100%;
	min-height: var(--aaf-target);
	padding: 0.5rem 0.65rem;
	font-family: inherit;
	font-size: inherit;
	line-height: 1.4;
	color: var(--aaf-text);
	background-color: #fff;
	border: 2px solid var(--aaf-border);
	border-radius: 6px;
}

.aaf-form textarea {
	min-height: calc(var(--aaf-target) * 2.5);
	resize: vertical;
}

/* Example text (placeholder).
 *
 * A placeholder is never a label here — every field keeps its own visible
 * <label>, and the example text is only ever a sample of the format. Browsers
 * default to a pale grey that fails WCAG 1.4.3, so the colour is set
 * explicitly: #5b6472 is 6.0:1 on white. `opacity: 1` is needed because
 * Firefox dims placeholders by default, which would undo that ratio. */
.aaf-form input::placeholder,
.aaf-form textarea::placeholder {
	color: var(--aaf-placeholder);
	opacity: 1;
}

/* Visible, high-contrast focus indicator (never removed). */
.aaf-form :focus-visible {
	outline: var(--aaf-focus-width) solid var(--aaf-focus);
	outline-offset: 2px;
}

.aaf-form :focus {
	outline: var(--aaf-focus-width) solid var(--aaf-focus);
	outline-offset: 2px;
}

/* Robust label-to-field spacing: a fixed gap that resists theme margins. */
.aaf-form .aaf-field {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
}

.aaf-form .aaf-field > label,
.aaf-form .aaf-field > .aaf-label,
.aaf-form .aaf-field > .aaf-help,
.aaf-form .aaf-field > input,
.aaf-form .aaf-field > select,
.aaf-form .aaf-field > textarea,
.aaf-form .aaf-field > .aaf-group,
.aaf-form .aaf-field > .aaf-choice,
.aaf-form .aaf-field > .aaf-error {
	margin: 0 !important;
}

.aaf-form .aaf-group legend {
	margin: 0 0 0.35rem !important;
}

.aaf-form .aaf-group .aaf-choice {
	margin-top: 0 !important;
}

/* Choice controls sit on a row with a large hit area. */
.aaf-choice {
	display: flex;
	align-items: flex-start;
	gap: 0.5rem;
	margin: 0 0 0.4rem;
}

.aaf-choice input[type="radio"],
.aaf-choice input[type="checkbox"] {
	width: 1.25rem;
	height: 1.25rem;
	min-width: 1.25rem;
	margin-top: 0.15rem;
}

.aaf-choice label {
	font-weight: 400;
	margin: 0;
}

.aaf-group {
	margin: 0;
	padding: 0;
	border: 0;
}

/* Errors: icon + bold text + colour, so never colour-only. */
.aaf-error {
	display: block;
	margin: 0.35rem 0 0;
	font-weight: 600;
	color: var(--aaf-error);
}

.aaf-error::before {
	content: "\26A0";
	margin-inline-end: 0.35rem;
}

.aaf-has-error input,
.aaf-has-error textarea,
.aaf-has-error select {
	border-color: var(--aaf-error);
	border-width: 3px;
}

/* Error summary box. */
.aaf-errors {
	margin: 0 0 1.5rem;
	padding: 1rem 1.25rem;
	border: 3px solid var(--aaf-error);
	border-radius: 6px;
	background: #fff5f5;
}

.aaf-errors-title {
	margin: 0 0 0.5rem;
	font-size: 1.05rem;
	color: var(--aaf-error);
}

.aaf-errors ul {
	margin: 0;
	padding-inline-start: 1.25rem;
}

.aaf-errors a {
	color: var(--aaf-error);
	font-weight: 600;
}

/* Success status. */
.aaf-success {
	padding: 1rem 1.25rem;
	border: 3px solid #146c2e;
	border-radius: 6px;
	background: #f0fdf4;
	color: #14532d;
	font-weight: 600;
}

.aaf-success::before {
	content: "\2713";
	margin-inline-end: 0.5rem;
}

/* Submit button — large target, clear focus. */
.aaf-submit {
	min-height: var(--aaf-target);
	min-width: var(--aaf-target);
	padding: 0.6rem 1.4rem;
	font-family: inherit;
	font-size: inherit;
	font-weight: 600;
	color: var(--aaf-on-accent);
	background: var(--aaf-accent);
	border: 2px solid var(--aaf-accent);
	border-radius: 6px;
	cursor: pointer;
}

.aaf-submit:hover {
	background: var(--aaf-accent-hover);
	border-color: var(--aaf-accent-hover);
}

/* Honeypot — hidden from sight AND from assistive tech. */
.aaf-hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

/* Reflow / small screens. */
@media ( max-width: 30rem ) {
	.aaf-form {
		max-width: 100%;
	}
}

/* Honour reduced-motion. */
@media ( prefers-reduced-motion: reduce ) {
	.aaf-form * {
		transition: none !important;
		animation: none !important;
	}
}

/* Forced-colors / Windows High Contrast: keep focus visible. */
@media ( forced-colors: active ) {
	.aaf-form :focus,
	.aaf-form :focus-visible {
		outline: 3px solid CanvasText;
	}
}

/* Optional Cloudflare Turnstile widget (rendered by the companion plugin) */
.aaf-turnstile {
	margin: 1rem 0;
}
.aaf-turnstile:focus {
	outline: none;
}

/*
 * The companion Turnstile plugin appends <br class="cf-turnstile-br …"> after
 * the widget for spacing in generic themes. We control spacing here with
 * margins, so hide those line breaks to close the gap below the widget.
 */
.aaf-turnstile .cf-turnstile-br {
	display: none;
}

/* -------------------------------------------------------------------------
 * File upload field
 * ---------------------------------------------------------------------- */
.aaf-field-file input[type="file"] {
	max-width: 100%;
	padding: 0.35rem 0;
}
.aaf-field-file input[type="file"]:disabled {
	cursor: not-allowed;
}
.aaf-file-off {
	font-weight: 600;
	color: var(--aaf-error);
}

/* -------------------------------------------------------------------------
 * Multi-step forms (progressive enhancement)
 *
 * With JavaScript off, every .aaf-step is visible in order (no rules hide
 * them). The script adds .aaf-has-steps to the form and toggles [hidden] on
 * inactive steps, so only these enhanced styles ever apply.
 * ---------------------------------------------------------------------- */
.aaf-step {
	margin: 0 0 1.5rem;
	padding: 0;
	border: 0;
}
.aaf-step-title {
	margin: 0 0 1rem;
	font-size: 1.1rem;
	line-height: 1.3;
}
.aaf-has-steps .aaf-step {
	border: 2px solid var(--aaf-border);
	border-radius: 8px;
	padding: 1rem 1.25rem 1.25rem;
}
.aaf-has-steps .aaf-step:focus {
	outline: var(--aaf-focus-width) solid var(--aaf-focus);
	outline-offset: 2px;
}

/* Numbered progress indicator. Never colour alone: the current step is bold
 * and marked "►", completed steps are marked "✓". */
.aaf-step-progress {
	list-style: none;
	margin: 0 0 0.75rem;
	padding: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem 1rem;
	font-size: 0.95rem;
}
.aaf-step-dot {
	color: #4b5563;
}
.aaf-step-dot.is-done::before {
	content: "\2713\00a0"; /* ✓ */
}
.aaf-step-dot.is-current {
	font-weight: 700;
	color: var(--aaf-text);
}
.aaf-step-dot.is-current::before {
	content: "\25BA\00a0"; /* ► */
}
.aaf-step-status {
	margin: 0 0 1rem;
	font-weight: 600;
	color: var(--aaf-text);
}

/* Previous / Next buttons. */
.aaf-step-nav {
	display: flex;
	gap: 0.75rem;
	margin: 0 0 1rem;
}
.aaf-step-nav button {
	min-height: var(--aaf-target);
	min-width: var(--aaf-target);
	padding: 0.6rem 1.4rem;
	font-family: inherit;
	font-size: inherit;
	font-weight: 600;
	/* Secondary button: its WORDS use the body text colour, not the accent, so
	 * a pale brand colour can never drag the label below 4.5:1. The accent is
	 * used only for the boundary, which needs 3:1 (WCAG 1.4.11). */
	color: var(--aaf-text);
	background: #fff;
	border: 2px solid var(--aaf-accent);
	border-radius: 6px;
	cursor: pointer;
}
.aaf-step-nav .aaf-step-next {
	color: var(--aaf-on-accent);
	background: var(--aaf-accent);
}
.aaf-step-nav button:hover {
	background: var(--aaf-accent-hover);
	border-color: var(--aaf-accent-hover);
	color: var(--aaf-on-accent);
}
.aaf-step-nav button[hidden] {
	display: none;
}
@media ( forced-colors: active ) {
	.aaf-step-dot.is-current {
		text-decoration: underline;
	}
}
