/* MadForms: stile frontend del blocco form.
 *
 * I colori usano i preset del tema `var(--wp--preset--color--*)` con
 * fallback letterali sicuri della palette chiara standard del tema.
 */

.madforms-form {
	/* Token locali: preset del tema con fallback chiari. */
	--mf-color-bg: #ffffff;
	--mf-color-bg: var(--wp--preset--color--base, #ffffff);
	--mf-color-fg: #101012;
	--mf-color-fg: var(--wp--preset--color--contrast, #101012);
	--mf-color-border: rgba(0, 0, 0, 0.35);
	--mf-color-border: var(--wp--preset--color--secondary, rgba(16, 16, 18, 0.38));
	--mf-color-accent: #3740b9;
	--mf-color-accent: var(--wp--preset--color--accent, #3740b9);
	--mf-color-on-accent: #ffffff;
	--mf-color-error: #b32d2e;
	--mf-color-success: #1a7f37;
	--mf-color-success-bg: rgba(70, 180, 80, 0.08);

	/* Il tema decide il dark mode con body.dark-mode / data-theme: nessuna
	 * attivazione automatica dalla preferenza del sistema operativo. */
	color-scheme: light;

	max-width: 640px;
}

.madforms-form-title {
	margin: 0 0 1rem;
}

.madforms-noscript {
	margin: 0 0 1rem;
	padding: 0.75rem 1rem;
	border-left: 4px solid var(--mf-color-error);
	background: rgba(179, 45, 46, 0.08);
}

.madforms-field {
	margin-bottom: 1rem;
}

.madforms-field-half {
	display: inline-block;
	width: calc(50% - 0.5rem);
	vertical-align: top;

	@media (max-width: 600px) {
		display: block;
		width: 100%;
	}
}

.madforms-field-third {
	display: inline-block;
	width: calc(33.333% - 0.667rem);
	vertical-align: top;

	@media (max-width: 600px) {
		display: block;
		width: 100%;
	}
}

.madforms-label {
	display: block;
	margin-bottom: 0.35rem;
	font-weight: 600;
}

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

/* Testo solo per screen reader (es. "(obbligatorio)" accanto all'asterisco). */
.madforms-sr-only {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	clip-path: inset(50%);
	overflow: hidden;
	word-wrap: normal !important;
}

.madforms-input {
	width: 100%;
	padding: 0.65rem 0.75rem;
	border: 1px solid var(--mf-color-border);
	border-radius: 4px;
	background: var(--mf-color-bg);
	color: var(--mf-color-fg);
	box-sizing: border-box;
	caret-color: currentColor;
	transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
	appearance: auto;
}

select.madforms-input,
textarea.madforms-input {
	background-color: var(--mf-color-bg);
}

textarea.madforms-input {
	resize: vertical;
	min-height: 6em;
}

::placeholder {
	color: currentColor;
	opacity: 0.55;
}

/* Focus visibile e coerente su ogni controllo del form. */
.madforms-form :is(input, select, textarea):focus-visible {
	outline: 2px solid var(--mf-color-accent);
	outline-offset: 2px;
	border-color: var(--mf-color-accent);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--mf-color-accent) 25%, transparent);
}

.madforms-form :is(input, select, textarea):focus:not(:focus-visible) {
	outline: none;
}

.madforms-help {
	margin: 0.35rem 0 0;
	font-size: 0.85em;
	opacity: 0.75;
}

.madforms-actions {
	margin-top: 1.25rem;
}

/* Mobile: bottone di invio a larghezza piena sotto i 480px. */
@media (max-width: 480px) {
	.madforms-submit {
		width: 100%;
		box-sizing: border-box;
	}
}

.madforms-submit {
	padding: 0.7rem 1.5rem;
	border: 2px solid transparent;
	border-radius: 4px;
	cursor: pointer;
	background: var(--mf-color-accent);
	color: var(--mf-color-on-accent);
	font-weight: 600;
	transition: filter 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

button.madforms-submit:hover:not(:disabled) {
	filter: brightness(0.92);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

button.madforms-submit:focus-visible {
	outline: 2px solid var(--mf-color-fg);
	outline-offset: 2px;
}

button.madforms-submit:active:not(:disabled) {
	transform: translateY(1px);
	filter: brightness(0.85);
}

.madforms-success {
	margin-top: 1rem;
	font-weight: 600;
}

/* Errore di campo: bordo rosso sull'input + messaggio collegato via aria-describedby. */
.madforms-field-error > .madforms-input {
	border-color: var(--mf-color-error) !important;
	box-shadow: 0 0 0 1px var(--mf-color-error);
}

.madforms-field-error .madforms-label {
	color: inherit;
}

.madforms-error {
	display: block;
	margin-top: 0.35rem;
	font-size: 0.85em;
	font-weight: 600;
	color: var(--mf-color-error);
	animation: madforms-fade-in 150ms ease-out;
}

.madforms-error-global {
	margin: 0.75rem 0 0;
	font-weight: 600;
	color: var(--mf-color-error);
	animation: madforms-fade-in 150ms ease-out;
}

.madforms-form-success {
	padding: 1rem;
	border: 1px solid var(--mf-color-success);
	border-radius: 4px;
	background: var(--mf-color-success-bg);
	color: var(--mf-color-fg);
	animation: madforms-slide-in 200ms ease-out;
}

button.madforms-submit:disabled {
	opacity: 0.6;
	cursor: progress;
}

.madforms-shake {
	animation: madforms-shake 0.35s ease-in-out;
}

@keyframes madforms-shake {
	0%,
	100% {
		transform: translateX(0);
	}
	25% {
		transform: translateX(-6px);
	}
	50% {
		transform: translateX(6px);
	}
	75% {
		transform: translateX(-3px);
	}
}

@keyframes madforms-fade-in {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

@keyframes madforms-slide-in {
	from {
		opacity: 0;
		transform: translateY(4px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Rispetta la preferenza "riduci movimento". */
@media (prefers-reduced-motion: reduce) {
	.madforms-form *,
	.madforms-shake {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}

/* ═══════════════════════════════════════════════════════════════════════
 * MadForms Frontend Dark Mode Overrides
 * ═══════════════════════════════════════════════════════════════════════ */

body.dark-mode .madforms-form,
html[data-theme="dark"] .madforms-form {
	color-scheme: dark;
	--mf-color-bg: var(--wp--preset--color--base-2, #1e232c);
	--mf-color-fg: var(--wp--preset--color--contrast, #eceff4);
	--mf-color-border: var(--wp--preset--color--tertiary, #3b4252);
	--mf-color-accent: var(--wp--preset--color--accent, #6b9cff);
	--mf-color-on-accent: #ffffff;
	--mf-color-error: #f87171;
	--mf-color-success: #4ade80;
	--mf-color-success-bg: rgba(74, 222, 128, 0.12);
}

body.dark-mode .madforms-input,
html[data-theme="dark"] .madforms-input {
	background-color: var(--wp--preset--color--base-3, #252a34) !important;
	border-color: var(--mf-color-border) !important;
	color: var(--mf-color-fg) !important;
}

body.dark-mode .madforms-label,
html[data-theme="dark"] .madforms-label {
	color: var(--mf-color-fg);
}

body.dark-mode .madforms-help,
html[data-theme="dark"] .madforms-help {
	color: var(--wp--preset--color--secondary, #a0aab6);
}

