/* ==========================================================================
   FORM CONTATTI — Input eleganti, floating label, validazione inline, card di successo
   ========================================================================== */

:root {
	--fc-border:   #d5d5d5;
	--fc-focus:    #dc7518;
	--fc-error:    #d93025;
	--fc-success:  #1e8e3e;
	--fc-text:     #1a1a1a;
	--fc-muted:    #6b6b6b;
	--fc-bg:       #ffffff;
}

/* ==========================================================================
   LAYOUT FORM
   ========================================================================== */
.section5__form {
	max-width: 520px;
	margin: auto;
	width: 100%;
	padding: 32px 28px;
	display: block;
}

.section5__fields {
	display: flex;
	flex-direction: column;
	gap: 22px;
}

/* ==========================================================================
   FIELD — struttura con floating label
   ========================================================================== */
.field {
	position: relative;
}

.field--line .field__control {
	width: 100%;
	border: 0;
	border-bottom: 2px solid var(--fc-border);
	background: transparent;
	padding: 22px 32px 10px 0;
	font-size: 16px;
	line-height: 1.4;
	color: var(--fc-text);
	font-family: inherit;
	outline: none;
	border-radius: 0;
	transition: border-color 220ms cubic-bezier(0.22, 1, 0.36, 1);
	appearance: none;
	-webkit-appearance: none;
}

.field--line textarea.field__control {
	resize: vertical;
	min-height: 96px;
	padding-top: 24px;
}

.field--line select.field__control {
	cursor: pointer;
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='8' viewBox='0 0 14 8' fill='none'><path d='M1 1l6 6 6-6' stroke='%236b6b6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
	background-repeat: no-repeat;
	background-position: right 4px center;
	padding-right: 28px;
}

/* Floating label */
.field__label {
	position: absolute;
	left: 0;
	top: 22px;
	font-size: 16px;
	color: var(--fc-muted);
	pointer-events: none;
	transform-origin: left center;
	transition:
		transform 220ms cubic-bezier(0.22, 1, 0.36, 1),
		color 220ms cubic-bezier(0.22, 1, 0.36, 1);
	background: transparent;
}

/* Obbligatorio: asterisco rosso */
.field__label[data-required]::after {
	content: " *";
	color: var(--fc-error);
}

/* Stato "floating" quando il campo ha focus o valore */
.field--line .field__control:focus ~ .field__label,
.field--line .field__control:not(:placeholder-shown) ~ .field__label,
.field--line.has-value .field__label {
	transform: translateY(-18px) scale(0.78);
	color: var(--fc-focus);
}

/* Per select: non supporta :placeholder-shown in modo standard — usa classe has-value */
.field--line select.field__control:focus ~ .field__label,
.field--line select.field__control.has-value ~ .field__label {
	transform: translateY(-18px) scale(0.78);
	color: var(--fc-focus);
}

/* Barra focus che cresce dal centro */
.field--line::after {
	content: "";
	position: absolute;
	left: 50%;
	right: 50%;
	bottom: 0;
	height: 2px;
	background: var(--fc-focus);
	transition: left 280ms cubic-bezier(0.22, 1, 0.36, 1), right 280ms cubic-bezier(0.22, 1, 0.36, 1);
	pointer-events: none;
}

.field--line:focus-within::after {
	left: 0;
	right: 0;
}

/* ==========================================================================
   VALIDAZIONE — stati error / valid
   ========================================================================== */

.field__error {
	display: flex;
	align-items: center;
	gap: 6px;
	margin-top: 6px;
	font-size: 13px;
	color: var(--fc-error);
	line-height: 1.3;
	min-height: 0;
	max-height: 0;
	opacity: 0;
	overflow: hidden;
	transition:
		max-height 280ms ease,
		opacity 220ms ease,
		margin-top 220ms ease;
}

.field__error::before {
	content: "";
	display: inline-block;
	width: 14px;
	height: 14px;
	flex-shrink: 0;
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d93025' stroke-width='2.4' stroke-linecap='round'><circle cx='12' cy='12' r='10'/><path d='M12 8v4'/><circle cx='12' cy='16' r='.6' fill='%23d93025'/></svg>");
	background-repeat: no-repeat;
	background-size: contain;
}

.field.has-error .field__error {
	max-height: 60px;
	opacity: 1;
	margin-top: 6px;
}

.field.has-error .field__control {
	border-bottom-color: var(--fc-error);
}

.field.has-error .field__label {
	color: var(--fc-error);
}

.field.has-error::after {
	background: var(--fc-error);
}

/* Icona di stato (check/alert) a destra del campo */
.field__status {
	position: absolute;
	right: 4px;
	top: 24px;
	width: 20px;
	height: 20px;
	display: none;
	pointer-events: none;
}

.field.is-valid .field__status--check,
.field.has-error .field__status--alert {
	display: block;
}

.field__status--check {
	color: var(--fc-success);
}
.field__status--alert {
	color: var(--fc-error);
}

.field.is-valid .field__control {
	border-bottom-color: var(--fc-success);
}

/* Per textarea la posizione dell'icona va allineata in alto */
.field--line textarea.field__control ~ .field__status {
	top: 24px;
}

/* Per select evita che la freccia nativa e la nostra icona si sovrappongano */
.field--line select.field__control ~ .field__status {
	right: 28px;
}

/* ==========================================================================
   PRIVACY CHECKBOX
   ========================================================================== */
.section5__privacy {
	margin-top: 24px;
}

.section5__privacy .checkbox {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	cursor: pointer;
	user-select: none;
}

.section5__privacy input[type="checkbox"] {
	appearance: none;
	-webkit-appearance: none;
	width: 22px;
	height: 22px;
	border: 2px solid var(--fc-border);
	border-radius: 5px;
	background: var(--fc-bg);
	cursor: pointer;
	flex-shrink: 0;
	margin-top: 2px;
	position: relative;
	transition: background 200ms ease, border-color 200ms ease;
}

.section5__privacy input[type="checkbox"]:hover {
	border-color: var(--fc-focus);
}

.section5__privacy input[type="checkbox"]:checked {
	background: var(--fc-focus);
	border-color: var(--fc-focus);
}

.section5__privacy input[type="checkbox"]:checked::after {
	content: "";
	position: absolute;
	left: 5px;
	top: 1px;
	width: 7px;
	height: 12px;
	border: solid #ffffff;
	border-width: 0 2.5px 2.5px 0;
	transform: rotate(45deg);
}

.section5__privacy input[type="checkbox"]:focus-visible {
	outline: 3px solid rgba(220, 117, 24, 0.3);
	outline-offset: 2px;
}

.section5__privacy .checkbox__text {
	font-size: 14px;
	line-height: 1.5;
	color: var(--fc-text);
	margin-top: 0 !important;
}

.section5__privacy.has-error input[type="checkbox"] {
	border-color: var(--fc-error);
}

.section5__privacy .field__error {
	margin-left: 34px;
}

/* ==========================================================================
   SUBMIT BUTTON
   ========================================================================== */
.section5__actions {
	margin-top: 32px;
}

.section5__button {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	min-height: 48px;
	padding: 14px 28px !important;
	font-size: 14px;
	font-weight: 700;
	letter-spacing: 0.5px;
	cursor: pointer;
	transition:
		background-color 240ms cubic-bezier(0.22, 1, 0.36, 1),
		color 240ms cubic-bezier(0.22, 1, 0.36, 1),
		transform 200ms ease;
}

.section5__button:hover:not(:disabled) {
	transform: translateY(-1px);
}

.section5__button[disabled],
.section5__button.is-loading {
	opacity: 0.75;
	cursor: wait;
}

.section5__button .btn-arrow {
	width: 16px;
	height: 16px;
	transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.section5__button:hover:not(:disabled) .btn-arrow {
	transform: translateX(4px);
}

/* Spinner durante l'invio */
.section5__button .btn-spinner {
	display: none;
	width: 18px;
	height: 18px;
	border: 2.5px solid rgba(220, 117, 24, 0.35);
	border-top-color: var(--fc-focus);
	border-radius: 50%;
	animation: fc-spin 0.7s linear infinite;
}

.section5__button.is-loading .btn-text,
.section5__button.is-loading .btn-arrow {
	display: none;
}

.section5__button.is-loading .btn-spinner {
	display: inline-block;
}

@keyframes fc-spin {
	to { transform: rotate(360deg); }
}

/* ==========================================================================
   DISCLAIMER reCAPTCHA
   ========================================================================== */
.section5__recaptcha-notice {
	margin-top: 18px;
	margin-bottom: 0;
	font-size: 11px;
	line-height: 1.5;
	color: var(--fc-muted);
	text-align: left;
}

.section5__recaptcha-notice a {
	color: var(--fc-muted);
	text-decoration: underline;
}

.section5__recaptcha-notice a:hover {
	color: var(--fc-focus);
}

/* ==========================================================================
   MESSAGGIO GENERALE (server-side error di rete / submit)
   ========================================================================== */
#form-message {
	font-size: 14px;
	line-height: 1.5;
}

#form-message.form-error {
	color: var(--fc-error);
}

#form-message.form-success {
	color: var(--fc-success);
}

/* ==========================================================================
   CARD SUCCESSO (sostituisce il form dopo invio ok)
   ========================================================================== */
.form-success-card {
	display: none;
	max-width: 520px;
	margin: 40px auto;
	padding: 40px 32px;
	background: #ffffff;
	border-radius: 14px;
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
	text-align: center;
	position: relative;
	overflow: hidden;
	border: 1px solid #f0f0f0;
}

.form-success-card.is-visible {
	display: block;
	animation: fc-card-in 560ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes fc-card-in {
	0%   { opacity: 0; transform: translateY(20px) scale(0.96); }
	60%  { opacity: 1; }
	100% { opacity: 1; transform: translateY(0) scale(1); }
}

.form-success-card__icon {
	width: 72px;
	height: 72px;
	margin: 0 auto 20px;
	border-radius: 50%;
	background: rgba(30, 142, 62, 0.1);
	color: var(--fc-success);
	display: flex;
	align-items: center;
	justify-content: center;
	animation: fc-icon-pop 700ms cubic-bezier(0.22, 1, 0.36, 1) 180ms both;
}

.form-success-card__icon svg {
	width: 36px;
	height: 36px;
	stroke: currentColor;
	fill: none;
	stroke-width: 3;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-dasharray: 48;
	stroke-dashoffset: 48;
	animation: fc-check-draw 520ms cubic-bezier(0.22, 1, 0.36, 1) 380ms forwards;
}

@keyframes fc-icon-pop {
	0%   { transform: scale(0); }
	70%  { transform: scale(1.1); }
	100% { transform: scale(1); }
}

@keyframes fc-check-draw {
	to { stroke-dashoffset: 0; }
}

.form-success-card__title {
	font-size: 24px;
	font-weight: 700;
	color: var(--fc-text);
	margin: 0 0 10px;
	line-height: 1.25;
}

.form-success-card__text {
	font-size: 15px;
	line-height: 1.6;
	color: var(--fc-muted);
	margin: 0 0 28px;
}

.form-success-card__email {
	color: var(--fc-focus);
	font-weight: 600;
	word-break: break-word;
}

.form-success-card__again {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 10px 20px;
	background: transparent;
	color: var(--fc-focus);
	border: 2px solid var(--fc-focus);
	border-radius: 6px;
	font-size: 13px;
	font-weight: 700;
	letter-spacing: 0.3px;
	cursor: pointer;
	transition: background 220ms ease, color 220ms ease;
	text-decoration: none;
}

.form-success-card__again:hover,
.form-success-card__again:focus-visible {
	background: var(--fc-focus);
	color: #ffffff;
	outline: none;
}

/* Nascondi il form quando la success card è mostrata */
.section5__form.is-hidden {
	display: none;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 991px) {
	/* Padding laterale sul wrapper della colonna che contiene il form
	   (pagina contatti: evita che il form tocchi i bordi viewport) */
	.qualita-hero-section:has(#section5__form) .qualita-hero-section__col--image {
		padding: var(--spaceS);
	}
}

@media (max-width: 575px) {
	.qualita-hero-section:has(#section5__form) .qualita-hero-section__col--image {
		padding: var(--spaceXs);
	}
	.section5__form {
		padding: 20px 16px;
	}
	.form-success-card {
		margin: 20px 12px;
		padding: 32px 22px;
	}
	.form-success-card__title {
		font-size: 20px;
	}
}

/* ==========================================================================
   OVERRIDE PLACEHOLDER — nascosto (usiamo floating label)
   ========================================================================== */
.field--line .field__control::placeholder {
	color: transparent;
}

.field--line .field__control:focus::placeholder {
	color: #bbb;
}

/* Accessibilità: rispetto prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
	.field--line .field__control,
	.field--line .field__label,
	.field--line::after,
	.field__error,
	.form-success-card,
	.form-success-card__icon,
	.form-success-card__icon svg,
	.section5__button,
	.section5__button .btn-arrow {
		transition: none !important;
		animation: none !important;
	}
	.form-success-card__icon svg {
		stroke-dashoffset: 0 !important;
	}
}
