:root {
  --sfondo: #f4f6f8; --carta: #fff; --testo: #12202e; --testo-2: #5b6877; --bordo: #dfe5ea;
  --blu: #0f2a43; --accento: #1668c4; --accento-scuro: #10529c;
  --verde: #12784a; --verde-s: #e3f5ec; --giallo: #8a5a00; --giallo-s: #fdf1d3; --rosso: #b3261e; --rosso-s: #fde7e5; --grigio-s: #eceff2; --blu-s: #e3effb;
  --raggio: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--sfondo); color: var(--testo); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #7fb4ee; outline-offset: 2px; }

/* accesso */
.accesso { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.carta-accesso { width: 100%; max-width: 380px; background: var(--carta); border: 1px solid var(--bordo); border-radius: 20px; padding: 28px 22px; display: flex; flex-direction: column; }
.carta-accesso img { border-radius: 14px; margin-bottom: 14px; }
.carta-accesso h1 { font-size: 24px; letter-spacing: -.01em; }
.sotto { color: var(--testo-2); font-size: 14px; }
label, legend { display: block; font-size: 14px; font-weight: 600; margin: 16px 0 6px; padding: 0; }
input[type=email], input[type=password], input[type=text], input[type=search], input[type=datetime-local], textarea {
  width: 100%; padding: 12px 14px; border: 1px solid #c5ced6; border-radius: 12px; background: #fff; font-size: 16px;
}
textarea { resize: vertical; min-height: 84px; }
.primario, .secondario { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px; border-radius: 12px; font-weight: 650; text-decoration: none; border: 1px solid transparent; }
.primario { background: var(--accento); color: #fff; }
.primario:hover { background: var(--accento-scuro); }
.primario[disabled] { opacity: .6; cursor: default; }
.secondario { background: #fff; color: var(--verde); border-color: #b9dcc9; }
.carta-accesso .primario { margin-top: 20px; }
.largo { width: 100%; margin-top: 18px; }
.piccolo { font-size: 13px; color: var(--testo-2); margin-top: 14px; text-align: center; }
.errore { color: var(--rosso); background: var(--rosso-s); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-top: 14px; }
.facoltativo { font-weight: 400; color: var(--testo-2); }

/* testata */
.testata { background: var(--blu); color: #fff; padding: calc(14px + env(safe-area-inset-top)) 16px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.saluto { font-size: 20px; font-weight: 700; }
.conto { font-size: 14px; opacity: .8; }
.azioni-testata { display: flex; align-items: center; gap: 8px; }
.tondo { width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255,255,255,.3); background: transparent; color: inherit; font-size: 20px; line-height: 1; }
.tondo.gira { animation: gira .8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }
.leggero { min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid rgba(255,255,255,.3); background: transparent; color: #fff; }

.strumenti { position: sticky; top: 0; z-index: 2; background: var(--sfondo); padding: 12px 16px 8px; border-bottom: 1px solid var(--bordo); }
.filtri { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filtri::-webkit-scrollbar { display: none; }
.filtro { flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid #c5ced6; background: #fff; font-size: 14px; font-weight: 600; white-space: nowrap; }
.filtro[aria-selected=true] { background: var(--blu); border-color: var(--blu); color: #fff; }
.filtro span { opacity: .7; font-weight: 500; margin-left: 4px; }

.avviso { margin: 12px 16px 0; padding: 12px 14px; border-radius: 12px; background: var(--giallo-s); color: var(--giallo); font-size: 14px; }
.elenco { list-style: none; margin: 0 auto; padding: 12px 16px calc(32px + env(safe-area-inset-bottom)); max-width: 720px; display: flex; flex-direction: column; gap: 10px; }
.paziente { background: var(--carta); border: 1px solid var(--bordo); border-radius: var(--raggio); display: flex; align-items: stretch; overflow: hidden; }
.apri { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 14px 8px 14px 14px; }
.nome { font-weight: 650; font-size: 17px; overflow-wrap: anywhere; }
.riga-2 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 6px; font-size: 14px; color: var(--testo-2); }
.nota-breve { margin-top: 6px; font-size: 14px; color: var(--testo-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.chiama { flex: none; width: 76px; display: grid; place-items: center; background: var(--blu-s); color: var(--accento-scuro); font-weight: 700; font-size: 14px; text-decoration: none; border-left: 1px solid var(--bordo); }
.stato { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 13px; font-weight: 650; background: var(--grigio-s); color: #3d4a57; }
.stato.nuovo { background: var(--blu); color: #fff; }
.stato.prenotato { background: var(--blu-s); color: var(--accento-scuro); }   /* visita prenotata: azzurro */
.stato.bene { background: var(--verde-s); color: var(--verde); }              /* visita fatta: verde */
.stato.attesa { background: var(--giallo-s); color: var(--giallo); }          /* non risponde, da richiamare: giallo */
.stato.male { background: var(--rosso-s); color: var(--rosso); }              /* non idoneo, non presentato: rosso */
.vuoto { text-align: center; color: var(--testo-2); padding: 48px 24px; }

/* scheda */
.scheda { border: 0; padding: 0; width: 100%; max-width: 520px; max-height: 92dvh; border-radius: 20px 20px 0 0; margin: auto auto 0; background: var(--carta); color: var(--testo); }
.scheda::backdrop { background: rgba(10, 22, 34, .55); }
.scheda form { padding: 20px 18px calc(22px + env(safe-area-inset-bottom)); }
.scheda-testa { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.scheda-testa h2 { font-size: 21px; overflow-wrap: anywhere; }
.scheda .tondo { border-color: var(--bordo); flex: none; }
.contatta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.chiama-ora { min-height: 56px; font-size: 18px; margin-top: 16px; background: var(--verde); }
.chiama-ora:hover { background: #0d5f3a; }
.secondario.neutro { color: var(--testo); border-color: #c5ced6; }
input[type=datetime-local] { min-height: 48px; -webkit-appearance: none; appearance: none; }
.appunto { margin-top: 6px; overflow-wrap: anywhere; }
input[disabled] { background: var(--grigio-s); color: var(--testo-2); }
.quando { color: var(--verde); font-weight: 650; }
fieldset { border: 0; padding: 0; margin: 18px 0 0; }
fieldset legend { margin: 0 0 8px; }
.stati { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stati label { margin: 0; font-weight: 600; display: flex; align-items: center; min-height: 46px; padding: 0 12px; border: 1px solid #c5ced6; border-radius: 12px; background: #fff; cursor: pointer; }
.stati input { position: absolute; opacity: 0; pointer-events: none; }
.stati label:has(input:checked) { background: var(--blu); border-color: var(--blu); color: #fff; }
.stati label:has(input:focus-visible) { outline: 3px solid #7fb4ee; outline-offset: 2px; }

.messaggio { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--testo); color: #fff; padding: 12px 18px; border-radius: 24px; font-size: 15px; font-weight: 600; z-index: 10; max-width: calc(100% - 32px); text-align: center; }
.messaggio.no { background: var(--rosso); }

@media (min-width: 640px) {
  .scheda { border-radius: 20px; margin: auto; }
  .testata, .strumenti { padding-left: max(16px, calc(50% - 344px)); padding-right: max(16px, calc(50% - 344px)); }
}
@media (prefers-reduced-motion: reduce) { .tondo.gira { animation: none; } }

/* riepilogo e vista amministratore */
.riepilogo, .tessere { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.riepilogo { max-width: 720px; margin: 0 auto; padding: 14px 16px 2px; }
.tessera { background: var(--carta); border: 1px solid var(--bordo); border-radius: var(--raggio); padding: 12px 14px; min-width: 0; }
.tessera .numero { font-size: 24px; font-weight: 750; letter-spacing: -.01em; overflow-wrap: anywhere; }
.tessera .cosa { font-size: 13px; color: var(--testo-2); }
.tessera .dettaglio { font-size: 12px; color: var(--testo-2); margin-top: 2px; }
.tessera.verde .numero { color: var(--verde); }
.clienti { max-width: 720px; margin: 0 auto; padding: 14px 16px 40px; display: flex; flex-direction: column; gap: 16px; }
.cliente { background: var(--carta); border: 1px solid var(--bordo); border-radius: 18px; padding: 16px; }
.cliente h2 { font-size: 20px; margin-bottom: 12px; }
.cliente .tessera { background: var(--sfondo); }
.cliente details { margin-top: 14px; border-top: 1px solid var(--bordo); padding-top: 12px; }
.cliente summary { cursor: pointer; font-weight: 650; min-height: 32px; }
.righe { list-style: none; margin: 10px 0 0; padding: 0; font-size: 14px; }
.righe li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--grigio-s); }
.righe li span:last-child { font-weight: 650; text-align: right; }
.tabella { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.tabella th, .tabella td { text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--grigio-s); }
.tabella th:first-child, .tabella td:first-child { text-align: left; overflow-wrap: anywhere; }
.tabella th { color: var(--testo-2); font-weight: 600; }
.scorri { overflow-x: auto; }
.titoletto { font-size: 14px; font-weight: 600; margin: 18px 0 4px; }
h3.sezione { font-size: 14px; margin: 16px 0 0; }
/* visite nella scheda */
.visite { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.visita { border: 1px solid var(--bordo); border-radius: 12px; padding: 10px 12px; }
.visita .testa { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.visita .bottoni { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.piccolo-b { min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid #c5ced6; background: #fff; font-size: 14px; font-weight: 600; }
.piccolo-b.si { background: var(--verde); border-color: var(--verde); color: #fff; }
.piccolo-b.togli { border: 0; color: var(--testo-2); min-width: 40px; padding: 0 8px; }
.aggiungi { background: var(--sfondo); border-radius: 12px; padding: 4px 12px 12px; margin-top: 10px; }
.aggiungi label { margin-top: 10px; }
.coppia { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.coppia input { min-width: 0; width: 100%; }
.coppia button { padding: 0 14px; }
.prossima { color: var(--accento-scuro); font-weight: 650; }
.testata .azioni-testata { flex-wrap: wrap; justify-content: flex-end; }
.secondario.largo { margin-top: 8px; }
@media (min-width: 640px) { .riepilogo, .tessere { grid-template-columns: repeat(4, 1fr); } .cliente .tessere { grid-template-columns: repeat(3, 1fr); } }

/* ===== Versione 3: colori Terapis (navy → blu), superfici pulite, movimento fluido ===== */
:root {
  --sfondo: #F8FAFC; --carta: #fff; --testo: #0F172A; --testo-2: #64748B; --bordo: #E2E8F0;
  --blu: #16325F; --accento: #2563EB; --accento-scuro: #20509C; --blu-s: #EFF6FF;
  --verde: #15803D; --verde-s: #F0FDF4; --giallo: #B45309; --giallo-s: #FEF3C7; --rosso: #DC2626; --rosso-s: #FEE2E2; --grigio-s: #F1F5F9;
  --raggio: 18px; --sfuma: linear-gradient(135deg, #16325F 0%, #20509C 55%, #3B82F6 130%);
  --ombra: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .06);
  --molla: cubic-bezier(.2, .8, .2, 1);
}
body { font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
button, a, input, textarea, label { -webkit-tap-highlight-color: transparent; }
button, .primario, .secondario, .filtro, .chiama, .stati label, .tessera, .paziente, .piccolo-b, .tondo, .leggero, input, textarea {
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .25s ease, transform .2s var(--molla), opacity .2s ease;
}
button:active, .primario:active, .secondario:active, .chiama:active, .stati label:active { transform: scale(.97); }
:focus-visible { outline-color: #93C5FD; }
input:focus, textarea:focus { outline: none; border-color: var(--accento); box-shadow: 0 0 0 4px rgba(37, 99, 235, .14); }
input[type=email], input[type=password], input[type=text], input[type=search], input[type=datetime-local], textarea { border-color: var(--bordo); border-radius: 14px; }

.accesso { background: radial-gradient(1200px 500px at 50% -10%, #DBEAFE 0%, transparent 60%), var(--sfondo); }
.carta-accesso { border: 0; border-radius: 26px; box-shadow: var(--ombra); padding: 32px 24px; animation: sale .5s var(--molla) both; }
.primario { background: var(--accento); border-radius: 14px; box-shadow: 0 6px 16px rgba(37, 99, 235, .25); }
.primario:hover { background: #1D4ED8; }
.secondario { border-radius: 14px; border-color: var(--bordo); }
.secondario:hover, .piccolo-b:hover { background: var(--sfondo); }
.chiama-ora { background: var(--verde); box-shadow: 0 8px 20px rgba(21, 128, 61, .28); border-radius: 16px; }
.chiama-ora:hover { background: #166534; }

.testata { background: var(--sfuma); padding-bottom: 46px; }
.saluto { font-size: 22px; letter-spacing: -.02em; }
.tondo, .leggero { border-color: rgba(255, 255, 255, .22); background: rgba(255, 255, 255, .1); backdrop-filter: blur(6px); }
.tondo:hover, .leggero:hover { background: rgba(255, 255, 255, .2); }
.scheda .tondo { background: var(--grigio-s); border: 0; backdrop-filter: none; color: var(--testo-2); }
.riepilogo { margin-top: -34px; position: relative; z-index: 1; padding-top: 0; }
.tessera { border: 0; box-shadow: var(--ombra); padding: 14px 16px; animation: sale .5s var(--molla) both; }
.tessera:nth-child(2) { animation-delay: .05s; } .tessera:nth-child(3) { animation-delay: .1s; } .tessera:nth-child(4) { animation-delay: .15s; }
.tessera:nth-child(5) { animation-delay: .2s; } .tessera:nth-child(6) { animation-delay: .25s; }
.tessera .numero { font-size: 26px; letter-spacing: -.02em; color: var(--blu); }
.cliente .tessera { box-shadow: none; }
.clienti { margin-top: -30px; position: relative; z-index: 1; }
.cliente { border: 0; border-radius: 22px; box-shadow: var(--ombra); animation: sale .5s var(--molla) both; }

.strumenti { background: rgba(248, 250, 252, .86); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom-color: transparent; padding-top: 14px; }
.strumenti > * { max-width: 688px; margin-left: auto; margin-right: auto; }
#cerca { display: block; background: #fff; box-shadow: var(--ombra); border-color: transparent; }
.filtro { border-color: var(--bordo); color: var(--testo-2); }
.filtro:hover { border-color: #CBD5E1; }
.filtro[aria-selected=true] { background: var(--blu); border-color: var(--blu); box-shadow: 0 4px 12px rgba(22, 50, 95, .25); }

.paziente { border: 0; box-shadow: var(--ombra); }
.paziente:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(15, 23, 42, .05), 0 12px 28px rgba(15, 23, 42, .1); }
.fresco .paziente { animation: sale .45s var(--molla) both; }
.fresco .paziente:nth-child(2) { animation-delay: .04s; } .fresco .paziente:nth-child(3) { animation-delay: .08s; } .fresco .paziente:nth-child(4) { animation-delay: .12s; }
.fresco .paziente:nth-child(5) { animation-delay: .16s; } .fresco .paziente:nth-child(6) { animation-delay: .2s; } .fresco .paziente:nth-child(7) { animation-delay: .24s; }
.fresco .paziente:nth-child(n+8) { animation-delay: .28s; }
.apri { padding: 16px 8px 16px 16px; }
.chiama { background: var(--blu-s); color: var(--accento); border-left: 0; }
.chiama:hover { background: #DBEAFE; }
.stato { border-radius: 999px; padding: 3px 11px; font-size: 12.5px; }
.stato.nuovo { background: var(--accento); }
.stato.prenotato { background: #DBEAFE; color: #1D4ED8; }
.quando { color: var(--accento); }
.prossima { color: var(--verde); }

.scheda { border-radius: 26px 26px 0 0; box-shadow: 0 -10px 40px rgba(15, 23, 42, .18); }
.scheda[open] { animation: su .38s var(--molla) both; }
.scheda[open]::backdrop { animation: appare .3s ease both; }
.scheda::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.stati label { border-color: var(--bordo); border-radius: 14px; }
.stati label:hover { border-color: #93C5FD; background: var(--blu-s); }
.stati label:has(input:checked) { background: var(--blu); border-color: var(--blu); color: #fff; box-shadow: 0 6px 14px rgba(22, 50, 95, .25); }
.visita { border-color: var(--bordo); border-radius: 14px; animation: sale .35s var(--molla) both; }
.piccolo-b { border-color: var(--bordo); border-radius: 12px; }
.aggiungi { border-radius: 16px; }
.errore { animation: scuoti .35s ease both; }
.messaggio { background: var(--blu); box-shadow: 0 10px 30px rgba(15, 23, 42, .3); animation: tosta .4s var(--molla) both; }
.messaggio.no { background: var(--rosso); }
.vuoto { animation: appare .4s ease both; }

@keyframes sale { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes su { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@keyframes appare { from { opacity: 0; } to { opacity: 1; } }
@keyframes tosta { from { opacity: 0; transform: translate(-50%, 16px) scale(.96); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
@keyframes scuoti { 0%, 100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@media (min-width: 640px) { .scheda { border-radius: 26px; } .scheda[open] { animation-name: sale; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after, ::backdrop { animation: none !important; transition: none !important; } }
.testata .azioni-testata { flex-wrap: nowrap; flex: none; }
.testata > div:first-child { min-width: 0; }
.leggero { font-size: 14px; padding: 0 12px; white-space: nowrap; }
.tondo { width: 40px; height: 40px; flex: none; }

/* accesso in due passi, cambio password, sblocco */
.carta-accesso[hidden] { display: none; }
.carta-accesso .secondario { margin-top: 10px; }
.collegamento { background: none; border: 0; padding: 0; min-height: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
.piede { padding: 8px 16px 32px; }
.piede a, .piccolo a { color: inherit; }
.sblocca { max-width: 720px; margin: 0 auto; padding: 0 16px 8px; }
#codice { font-size: 24px; letter-spacing: .18em; text-align: center; text-transform: uppercase; }
