/* RFL – Anagrafiche & Schede Relazionali · frontend */

.rfl-wrap {
	--rfl-primario: #3b82f6;
	--rfl-scuro: #0f172a;
	--rfl-raggio: 16px;
	--rfl-max: 950px;
	--rfl-bordo: #e2e8f0;
	--rfl-testo: #334155;
	--rfl-muto: #64748b;
	--rfl-sfondo-input: #f8fafc;
	--rfl-errore: #dc2626;
	max-width: var(--rfl-max);
	margin: 0 auto;
	color: var(--rfl-testo);
	font-size: 15px;
	line-height: 1.5;
}

.rfl-wrap *,
.rfl-wrap *::before,
.rfl-wrap *::after { box-sizing: border-box; }

.rfl-form {
	background: #fff;
	border: 1px solid var(--rfl-bordo);
	border-radius: calc(var(--rfl-raggio) + 8px);
	padding: clamp(20px, 4vw, 38px);
	box-shadow: 0 18px 40px rgba(15, 23, 42, .08);
}

.rfl-head { margin-bottom: 26px; }

.rfl-title {
	font-size: clamp(20px, 3vw, 26px);
	line-height: 1.25;
	margin: 0 0 8px;
	color: var(--rfl-scuro);
	display: flex;
	align-items: center;
	gap: 10px;
}

.rfl-sub {
	margin: 0;
	color: var(--rfl-muto);
	font-size: 14px;
	border-left: 4px solid var(--rfl-primario);
	padding-left: 14px;
}

/* Sezioni */
.rfl-section {
	border: 0;
	border-top: 2px dashed var(--rfl-bordo);
	margin: 0 0 22px;
	padding: 20px 0 0;
	min-width: 0;
}

.rfl-section:first-of-type { border-top: 0; padding-top: 0; }

.rfl-section > legend {
	font-weight: 700;
	font-size: 15px;
	color: var(--rfl-scuro);
	padding: 0;
	margin-bottom: 12px;
	display: flex;
	align-items: center;
	gap: 8px;
}

.rfl-section-desc {
	margin: -4px 0 14px;
	font-size: 13px;
	color: var(--rfl-muto);
}

.rfl-grid,
.rfl-card-body,
.rfl-dinamici {
	display: grid;
	grid-template-columns: repeat(6, 1fr);
	gap: 16px;
	align-items: start;
}

.rfl-cols-1 .rfl-grid { grid-template-columns: 1fr; }
.rfl-cols-3 .rfl-grid { grid-template-columns: repeat(6, 1fr); }

.rfl-w-meta { grid-column: span 3; }
.rfl-w-terzo { grid-column: span 2; }
.rfl-w-intero { grid-column: 1 / -1; }
.rfl-cols-1 .rfl-w-meta,
.rfl-cols-1 .rfl-w-terzo { grid-column: 1 / -1; }

/* Campi */
.rfl-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; position: relative; }

.rfl-label {
	font-weight: 600;
	font-size: 13px;
	color: var(--rfl-testo);
	letter-spacing: .2px;
}

.rfl-req { color: var(--rfl-errore); }

.rfl-field input[type="text"],
.rfl-field input[type="email"],
.rfl-field input[type="tel"],
.rfl-field input[type="url"],
.rfl-field input[type="number"],
.rfl-field input[type="date"],
.rfl-field input[type="search"],
.rfl-field input[type="password"],
.rfl-field select,
.rfl-field textarea {
	width: 100%;
	padding: 11px 13px;
	border: 2px solid var(--rfl-bordo);
	border-radius: calc(var(--rfl-raggio) - 4px);
	font: inherit;
	font-size: 14px;
	color: var(--rfl-scuro);
	background: var(--rfl-sfondo-input);
	transition: border-color .15s, box-shadow .15s, background .15s;
}

.rfl-field textarea { resize: vertical; min-height: 78px; }

.rfl-field input:focus,
.rfl-field select:focus,
.rfl-field textarea:focus {
	border-color: var(--rfl-primario);
	background: #fff;
	box-shadow: 0 0 0 4px color-mix(in srgb, var(--rfl-primario) 18%, transparent);
	outline: 2px solid transparent;
	outline-offset: 2px;
}

.rfl-field input.rfl-invalid,
.rfl-field select.rfl-invalid,
.rfl-field textarea.rfl-invalid {
	border-color: var(--rfl-errore);
	background: #fef2f2;
}

.rfl-hint { font-size: 11.5px; color: #94a3b8; }

.rfl-error:not(:empty) {
	font-size: 12px;
	color: var(--rfl-errore);
	font-weight: 600;
}

.rfl-toggle-visibility {
	position: absolute;
	right: 8px;
	top: 30px;
	background: none;
	border: 0;
	cursor: pointer;
	font-size: 15px;
	line-height: 1;
	padding: 6px;
	opacity: .6;
}
.rfl-toggle-visibility:hover { opacity: 1; }

.rfl-choices { display: flex; flex-wrap: wrap; gap: 10px 18px; padding: 4px 0; }
.rfl-choice { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; cursor: pointer; }
.rfl-choice input { margin-top: 3px; flex: 0 0 auto; }

/* Blocchi ripetibili */
.rfl-blocco { border-top: 2px dashed var(--rfl-bordo); padding-top: 22px; margin-bottom: 22px; }

.rfl-blocco-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 12px;
	flex-wrap: wrap;
	margin-bottom: 14px;
}

.rfl-blocco-head h3 {
	margin: 0;
	font-size: 16px;
	color: var(--rfl-scuro);
	display: flex;
	align-items: center;
	gap: 8px;
}

.rfl-card {
	background: #f1f5f9;
	border-radius: var(--rfl-raggio);
	border-left: 5px solid var(--rfl-primario);
	padding: 16px 18px;
	margin-bottom: 14px;
	animation: rfl-fade .25s ease;
}

@media (prefers-reduced-motion: reduce) {
	.rfl-card { animation: none; }
}

@keyframes rfl-fade {
	from { opacity: 0; transform: translateY(-6px); }
	to { opacity: 1; transform: none; }
}

.rfl-card-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 10px;
	margin-bottom: 12px;
}

.rfl-card-title { font-weight: 700; color: var(--rfl-scuro); font-size: 14px; }

.rfl-dinamici {
	grid-column: 1 / -1;
	padding-top: 12px;
	margin-top: 4px;
	border-top: 1px dashed #cbd5e1;
}

.rfl-vuoto {
	grid-column: 1 / -1;
	margin: 0;
	padding: 16px;
	text-align: center;
	font-style: italic;
	color: #94a3b8;
	background: var(--rfl-sfondo-input);
	border-radius: var(--rfl-raggio);
}

/* Ricerca relazioni */
.rfl-search { position: relative; }

.rfl-risultati {
	list-style: none;
	margin: 4px 0 0;
	padding: 4px;
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	z-index: 20;
	background: #fff;
	border: 1px solid var(--rfl-bordo);
	border-radius: 10px;
	box-shadow: 0 12px 28px rgba(15, 23, 42, .14);
	max-height: 220px;
	overflow-y: auto;
}

.rfl-risultati li { margin: 0; }

.rfl-risultati button {
	display: block;
	width: 100%;
	text-align: left;
	background: none;
	border: 0;
	padding: 8px 10px;
	font: inherit;
	font-size: 13.5px;
	border-radius: 7px;
	cursor: pointer;
}

.rfl-risultati button:hover,
.rfl-risultati button:focus { background: #eff6ff; }

.rfl-risultato-vuoto { padding: 8px 10px; font-size: 13px; color: var(--rfl-muto); }

/* GDPR + honeypot */
.rfl-gdpr {
	border-top: 2px dashed var(--rfl-bordo);
	padding-top: 18px;
	margin-bottom: 8px;
	font-size: 13.5px;
}

.rfl-gdpr a { color: var(--rfl-primario); }

.rfl-hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

/* Pulsanti */
.rfl-btn {
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	border: 0;
	border-radius: 999px;
	transition: background .15s, transform .15s, opacity .15s;
}

.rfl-btn:focus-visible { outline: 3px solid var(--rfl-primario); outline-offset: 2px; }

.rfl-btn-add { background: var(--rfl-primario); color: #fff; padding: 9px 20px; font-size: 14px; }
.rfl-btn-add:hover { filter: brightness(.93); }

.rfl-btn-remove { background: #fee2e2; color: #b91c1c; padding: 6px 14px; font-size: 12px; }
.rfl-btn-remove:hover { background: #fecaca; }

.rfl-btn-submit {
	width: 100%;
	background: var(--rfl-scuro);
	color: #fff;
	padding: 15px;
	font-size: 17px;
	border-radius: var(--rfl-raggio);
	margin-top: 24px;
}

.rfl-btn-submit:hover { filter: brightness(1.25); }
.rfl-btn-submit:disabled { opacity: .6; cursor: progress; }

/* Alert */
.rfl-alert {
	padding: 14px 16px;
	border-radius: var(--rfl-raggio);
	margin-bottom: 18px;
	font-size: 14px;
	font-weight: 500;
}

.rfl-alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.rfl-alert-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.rfl-alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }

.rfl-notice-error {
	padding: 12px 16px;
	background: #fef2f2;
	border: 1px solid #fecaca;
	color: #991b1b;
	border-radius: 8px;
}

/* Responsive */
@media (max-width: 720px) {
	.rfl-w-meta,
	.rfl-w-terzo { grid-column: 1 / -1; }
	.rfl-blocco-head { align-items: stretch; }
	.rfl-btn-add { width: 100%; }
}

/* Modalità scura del tema ospite */
@media (prefers-color-scheme: dark) {
	.rfl-wrap.rfl-auto-dark .rfl-form { background: #0b1220; border-color: #1e293b; }
	.rfl-wrap.rfl-auto-dark { --rfl-testo: #cbd5e1; --rfl-bordo: #1e293b; --rfl-sfondo-input: #0f172a; }
	.rfl-wrap.rfl-auto-dark .rfl-title { color: #e2e8f0; }
	.rfl-wrap.rfl-auto-dark .rfl-card { background: #111c2f; }
}

/* Uploader universale (avatar e allegati) */
.rfl-uploader { display: flex; flex-direction: column; gap: 8px; }

.rfl-dropzone {
	position: relative;
	border: 2px dashed var(--rfl-bordo, #cbd5e1);
	border-radius: 12px;
	padding: 16px;
	text-align: center;
	background: var(--rfl-sfondo-input, #f8fafc);
	cursor: pointer;
	transition: border-color .15s, background .15s;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
}
.rfl-dropzone:hover,
.rfl-dropzone:focus-visible { border-color: var(--rfl-primario, #3b82f6); background: #fff; outline: none; }
.rfl-dropzone.sopra { border-color: var(--rfl-primario, #3b82f6); background: #eff6ff; }
.rfl-dropzone-icona { font-size: 22px; line-height: 1; }
.rfl-dropzone-testo { font-size: 12.5px; color: #64748b; }
.rfl-file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.rfl-anteprime { display: flex; flex-wrap: wrap; gap: 10px; }

.rfl-anteprima {
	position: relative;
	margin: 0;
	width: 96px;
	border: 1px solid var(--rfl-bordo, #e2e8f0);
	border-radius: 10px;
	overflow: hidden;
	background: #fff;
	text-align: center;
}
.rfl-anteprima img { display: block; width: 100%; height: 74px; object-fit: cover; }
.rfl-anteprima a { display: block; text-decoration: none; }
.rfl-file-ext {
	display: flex; align-items: center; justify-content: center;
	height: 74px; font-weight: 800; font-size: 15px; color: #475569; background: #f1f5f9; letter-spacing: .5px;
}
.rfl-anteprima figcaption { font-size: 10.5px; padding: 4px 5px; color: #475569; word-break: break-word; }
.rfl-anteprima-mime { display: none; }
.rfl-anteprima-del {
	position: absolute; top: 3px; right: 3px;
	width: 20px; height: 20px; border: 0; border-radius: 50%;
	background: rgba(15, 23, 42, .72); color: #fff; cursor: pointer;
	font-size: 11px; line-height: 20px; padding: 0;
}
.rfl-anteprima-del:hover { background: #b91c1c; }

.rfl-caricamento { display: flex; align-items: center; justify-content: center; flex-direction: column; height: 100px; }
.rfl-spinner {
	width: 20px; height: 20px; border: 2px solid #cbd5e1; border-top-color: var(--rfl-primario, #3b82f6);
	border-radius: 50%; animation: rfl-gira .7s linear infinite;
}
@keyframes rfl-gira { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .rfl-spinner { animation: none; } }

.rfl-upload-errore { color: var(--rfl-errore, #dc2626); font-size: 12.5px; font-weight: 600; margin: 0; }
