/* APSP Moduli — frontend (card PA / Bootstrap Italia) */

.apsp-forms-wrap {
	width: 100%;
	max-width: 52rem;
	margin: 2rem auto;
	clear: both;
}

.apsp-forms-card {
	background: #f8fafc;
	border: 1px solid #cbd5e1;
	border-radius: 8px;
	box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
	overflow: hidden;
}

.apsp-forms-card__intro {
	background: #fff;
	border-bottom: 1px solid #e2e8f0;
	padding: 1.25rem 1.5rem;
	font-size: 0.9375rem;
	line-height: 1.55;
	color: #334155;
}

.apsp-forms-form {
	margin: 0;
}

.apsp-forms-card__body {
	background: #fff;
	padding: 1.5rem;
}

.apsp-forms-required-note {
	font-size: 0.875rem;
	color: #475569;
	margin: 0 0 1.25rem;
	padding: 0.75rem 1rem;
	background: #f1f5f9;
	border-radius: 6px;
	border-left: 4px solid #0066cc;
}

.apsp-forms-required {
	color: #c0392b;
	font-weight: 700;
	margin-left: 0.15rem;
}

.apsp-forms-fields {
	display: grid;
	grid-template-columns: 1fr;
	gap: 0;
}

@media (min-width: 768px) {
	.apsp-forms-fields {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		column-gap: 1.25rem;
	}
}

/* Campi a tutta larghezza */
.apsp-forms-field--section,
.apsp-forms-field--html,
.apsp-forms-field--divider,
.apsp-forms-field--textarea,
.apsp-forms-field--radio,
.apsp-forms-field--checkboxes,
.apsp-forms-field--consent,
.apsp-forms-field--file,
.apsp-forms-field--declaration,
.apsp-forms-col-full {
	grid-column: 1 / -1;
}

.apsp-forms-col-2 {
	/* metà larghezza su desktop (griglia 2 col) */
}

.apsp-forms-field {
	margin-bottom: 1.25rem;
	min-width: 0;
	position: relative;
}

.apsp-forms-field[hidden] {
	display: none !important;
}

/* Intestazione modulo (come PDF) */
.apsp-forms-letterhead {
	text-align: right;
	font-size: 0.9375rem;
	line-height: 1.5;
	color: #0f172a;
	margin-bottom: 1rem;
}

.apsp-forms-letterhead p {
	margin: 0 0 0.35rem;
}

.apsp-forms-letterhead__oggetto {
	text-align: left;
	margin-top: 1.25rem;
	font-weight: 700;
}

.apsp-forms-chiede {
	text-align: center;
	margin: 1.5rem 0 1rem;
	padding: 1rem;
	background: #f8fafc;
	border-radius: 6px;
	border: 1px solid #e2e8f0;
}

.apsp-forms-chiede__title {
	font-size: 1.125rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	margin: 0 0 0.5rem;
	color: #0f172a;
}

.apsp-forms-chiede p {
	margin: 0;
	font-size: 0.9375rem;
	color: #334155;
}

/* Pannelli sezione */
.apsp-forms-panel {
	margin: 1.75rem 0 0.5rem;
	padding: 1.25rem 1.25rem 0.25rem;
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	grid-column: 1 / -1;
}

.apsp-forms-panel__title {
	font-size: 1.125rem;
	font-weight: 700;
	margin: 0 0 0.35rem;
	color: #0066cc;
	line-height: 1.35;
}

.apsp-forms-panel__lead {
	margin: 0 0 0.75rem;
	font-size: 0.875rem;
	color: #64748b;
	line-height: 1.5;
}

.apsp-forms-html {
	font-size: 0.9375rem;
	line-height: 1.55;
	color: #334155;
}

.apsp-forms-html p {
	margin: 0 0 0.75rem;
}

.apsp-forms-html p:last-child {
	margin-bottom: 0;
}

.apsp-forms-divider {
	border: 0;
	border-top: 1px solid #e2e8f0;
	margin: 1rem 0;
}

/* Controlli — isolati da cmp-input del tema (evita sovrapposizioni) */
.apsp-forms-control {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	margin: 0;
}

.apsp-forms-label {
	display: block;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.4;
	color: #0f172a;
	margin: 0;
	position: static !important;
	transform: none !important;
}

.apsp-forms-input,
.apsp-forms-form .apsp-forms-control .form-control,
.apsp-forms-form .apsp-forms-control select.form-control {
	display: block;
	width: 100%;
	min-height: 2.75rem;
	padding: 0.5rem 0.75rem;
	font-size: 1rem;
	line-height: 1.5;
	color: #0f172a;
	background-color: #fff;
	border: 1px solid #94a3b8;
	border-radius: 4px;
	box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
	position: static !important;
}

.apsp-forms-control textarea.form-control {
	min-height: 6rem;
	resize: vertical;
}

.apsp-forms-control .select-wrapper {
	width: 100%;
}

.apsp-forms-hint {
	display: block;
	font-size: 0.8125rem;
	line-height: 1.4;
	color: #64748b;
	margin: 0;
	position: static !important;
}

.apsp-forms-field--invalid .apsp-forms-input,
.apsp-forms-field--invalid .form-control,
.apsp-forms-control--invalid .apsp-forms-input,
.apsp-forms-control--invalid .form-control {
	border-color: #c0392b !important;
	background-color: #fff5f5 !important;
	box-shadow: 0 0 0 1px rgba(192, 57, 43, 0.25);
}

.apsp-forms-label--invalid,
.apsp-forms-field--invalid .apsp-forms-label {
	color: #c0392b !important;
}

.apsp-forms-field--invalid .apsp-forms-control {
	border-left: 4px solid #c0392b;
	padding-left: 0.75rem;
	margin-left: -0.75rem;
}

.apsp-forms-group--invalid,
.apsp-forms-consent--invalid {
	border-color: #c0392b !important;
	background-color: #fff5f5 !important;
	box-shadow: 0 0 0 1px rgba(192, 57, 43, 0.2);
}

.apsp-forms-group--invalid .apsp-forms-group__title {
	color: #c0392b;
}

.apsp-forms-check--invalid {
	border-color: #fca5a5 !important;
	background-color: #fff5f5 !important;
}

.apsp-forms-field-error {
	color: #c0392b;
	font-size: 0.875rem;
	font-weight: 600;
	margin: 0.5rem 0 0;
	padding: 0.35rem 0.5rem;
	background: #fef2f2;
	border-radius: 4px;
}

.apsp-forms-alert__list a {
	color: #991b1b;
	font-weight: 600;
}

/* Gruppi radio / checkbox (senza fieldset/legend del tema) */
.apsp-forms-group {
	margin: 0;
	padding: 1rem 1.15rem;
	background: #fff;
	border: 1px solid #e2e8f0;
	border-radius: 6px;
}

.apsp-forms-group__title {
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.45;
	color: #0f172a;
	margin: 0 0 0.85rem;
	padding: 0;
	position: static !important;
	float: none !important;
	width: auto !important;
	background: transparent !important;
}

.apsp-forms-choice-list {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	margin: 0;
	padding: 0;
}

/* Opzione singola: flex allineato, niente float Bootstrap Italia */
.apsp-forms-check {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin: 0;
	padding: 0.75rem 1rem;
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 4px;
	cursor: pointer;
	min-height: 3rem;
	box-sizing: border-box;
}

.apsp-forms-check__input {
	/* Bootstrap Italia nasconde input[type=checkbox] (opacity:0; width:0) — ripristino esplicito */
	opacity: 1 !important;
	visibility: visible !important;
	width: 1.25rem !important;
	height: 1.25rem !important;
	min-width: 1.25rem !important;
	min-height: 1.25rem !important;
	margin: 0 !important;
	padding: 0 !important;
	flex-shrink: 0;
	float: none !important;
	position: relative !important;
	left: auto !important;
	top: auto !important;
	display: block !important;
	vertical-align: middle;
	accent-color: #0066cc;
	cursor: pointer;
	appearance: auto !important;
	-webkit-appearance: checkbox !important;
	background-color: #fff !important;
	background-image: none !important;
	border: 2px solid #64748b !important;
	border-radius: 3px;
	box-sizing: border-box;
	clip: auto !important;
	overflow: visible !important;
}

.apsp-forms-check__input[type='radio'] {
	-webkit-appearance: radio !important;
	border-radius: 50%;
}

.apsp-forms-check__input--invalid {
	outline: 2px solid #c0392b;
	outline-offset: 1px;
}

.apsp-forms-check__text {
	flex: 1;
	font-size: 0.9375rem;
	line-height: 1.45;
	color: #0f172a;
	font-weight: 400;
	padding: 0 !important;
	margin: 0 !important;
	position: static !important;
	float: none !important;
	cursor: pointer;
}

.apsp-forms-check__text p {
	margin: 0 0 0.5rem;
}

.apsp-forms-check__text p:last-child {
	margin-bottom: 0;
}

.apsp-forms-check--declaration,
.apsp-forms-field--declaration .apsp-forms-check {
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 6px;
}

.apsp-forms-check--declaration .apsp-forms-check__text,
.apsp-forms-field--declaration .apsp-forms-check__text {
	font-weight: 500;
}

.apsp-forms-consent {
	padding: 1rem 1.15rem;
	background: #f1f5f9;
	border: 1px solid #cbd5e1;
	border-radius: 6px;
}

.apsp-forms-check--consent {
	background: transparent;
	border: none;
	padding: 0;
	min-height: 0;
	align-items: flex-start;
}

.apsp-forms-check--consent .apsp-forms-check__input {
	margin-top: 0.15rem !important;
}

.apsp-forms-check--consent .apsp-forms-check__text {
	font-size: 0.875rem;
	line-height: 1.55;
	color: #334155;
}

/* Neutralizza regole tema su checkbox/radio dentro il modulo */
.apsp-forms-wrap input[type='checkbox'],
.apsp-forms-wrap input[type='radio'],
.apsp-forms-form input.apsp-forms-check__input {
	opacity: 1 !important;
	visibility: visible !important;
	width: 1.25rem !important;
	height: 1.25rem !important;
	min-width: 1.25rem !important;
	min-height: 1.25rem !important;
	position: relative !important;
	left: auto !important;
	top: auto !important;
	clip: auto !important;
}

.apsp-forms-wrap .apsp-forms-check__text::before,
.apsp-forms-wrap .apsp-forms-check__text::after {
	content: none !important;
	display: none !important;
}

.apsp-forms-wrap .form-check,
.apsp-forms-wrap .form-check-input,
.apsp-forms-wrap .form-check-label {
	float: none !important;
	position: static !important;
	padding-left: 0 !important;
	margin-left: 0 !important;
}

.apsp-forms-card__footer {
	background: #f8fafc;
	border-top: 1px solid #e2e8f0;
	padding: 1.25rem 1.5rem;
}

.apsp-forms-actions {
	margin: 0;
}

.apsp-forms-actions .btn-primary {
	min-height: 48px;
	padding: 0.65rem 2rem;
	font-weight: 600;
}

.apsp-forms-hp {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.apsp-forms-alert {
	padding: 1rem 1.25rem;
	border-radius: 6px;
	margin-bottom: 1.25rem;
	border: 1px solid transparent;
	grid-column: 1 / -1;
}

.apsp-forms-alert--success {
	background: #ecfdf5;
	border-color: #6ee7b7;
	color: #065f46;
}

.apsp-forms-alert--error {
	background: #fef2f2;
	border-color: #fca5a5;
	color: #991b1b;
}

.apsp-forms-alert__title {
	font-weight: 700;
	margin: 0 0 0.35rem;
}

.apsp-forms-alert__list {
	margin: 0.5rem 0 0 1.25rem;
}

/* Captcha integrato */
.apsp-forms-captcha {
	margin: 0 0 1.25rem;
	padding: 1rem 1.15rem;
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	grid-column: 1 / -1;
}

.apsp-forms-captcha__challenge {
	margin-bottom: 0.85rem;
}

.apsp-forms-captcha__label {
	margin: 0 0 0.5rem;
	font-size: 0.9375rem;
	font-weight: 600;
	color: #0f172a;
}

.apsp-forms-captcha__math,
.apsp-forms-captcha__code {
	margin: 0;
	padding: 0.65rem 1rem;
	font-size: 1.375rem;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-align: center;
	background: #fff;
	border: 2px dashed #94a3b8;
	border-radius: 6px;
	color: #0f172a;
	font-family: ui-monospace, monospace;
}

.apsp-forms-captcha__image {
	display: block;
	max-width: 100%;
	height: auto;
	border: 1px solid #cbd5e1;
	border-radius: 4px;
	background: #fff;
}

.apsp-forms-captcha__answer {
	margin-bottom: 0.75rem;
}

.apsp-forms-captcha__refresh {
	margin: 0;
}

.apsp-forms-captcha--invalid {
	border-color: #c0392b !important;
	background-color: #fff5f5 !important;
}

.apsp-forms-captcha--invalid .apsp-forms-captcha__answer .form-control {
	border-color: #c0392b !important;
}

/* Focus arancione AGID: regole globali in apsp-agid-focus.css (bridge) */
.apsp-forms-form .form-control:focus:not(:focus-visible),
.apsp-forms-check__input:focus:not(:focus-visible) {
	outline: none;
	box-shadow: none;
}

/* Tema Comuni: blocca label/input flottanti del tema dentro il modulo */
.apsp-forms-wrap .cmp-input,
.apsp-forms-wrap .cmp-input__label,
.apsp-forms-wrap .cmp-input__text,
.apsp-forms-form .cmp-input__text,
.apsp-comuni-page .apsp-forms-form .cmp-input__label {
	position: static !important;
	transform: none !important;
	float: none !important;
	top: auto !important;
	left: auto !important;
	margin: 0 !important;
}

.apsp-forms-wrap label,
.apsp-forms-wrap input:not([type='checkbox']):not([type='radio']),
.apsp-forms-wrap textarea,
.apsp-forms-wrap select {
	position: static !important;
	transform: none !important;
}

.apsp-comuni-page .apsp-forms-wrap {
	max-width: 52rem;
}

@media (max-width: 767.98px) {
	.apsp-forms-wrap {
		margin: 1rem 0;
	}

	.apsp-forms-card__body,
	.apsp-forms-card__footer,
	.apsp-forms-card__intro {
		padding: 1rem;
	}
}
