:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #17242b;
  --muted: #5e6f78;
  --line: #dde5e8;
  --primary: #0f6e6e;
  --primary-2: #0b5757;
  --primary-soft: #e3f1f0;
  --red: #c62828;
  --red-soft: #fdecec;
  --red-line: #f3b5b5;
  --orange: #c25e00;
  --orange-soft: #fff2e2;
  --yellow: #8a6d00;
  --yellow-soft: #fff8d6;
  --green: #2e7d32;
  --green-soft: #e7f5e8;
  --blue: #1f5fbf;
  --shadow: 0 1px 2px rgba(16, 40, 48, .06), 0 4px 16px rgba(16, 40, 48, .06);
  --radius: 12px;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--primary); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.boot { padding: 4rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mt-s { margin-top: .5rem; }
.mb { margin-bottom: 1rem; }
.hidden { display: none !important; }
.grow { flex: 1; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.stack > * + * { margin-top: 1rem; }
.icon { width: 1.15em; height: 1.15em; vertical-align: -.2em; flex: none; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: #0d3c40;
  color: #d6e8e8;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 1.1rem .8rem;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: .2rem .5rem 1.2rem; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: #14a0a0; display: grid; place-items: center; }
.brand-name { font-weight: 800; font-size: 1.25rem; color: #fff; letter-spacing: .5px; }
.brand-sub { font-size: .72rem; color: #9cc3c3; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .65rem .8rem; border-radius: 9px;
  color: #d6e8e8; text-decoration: none; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .07); }
.nav a.active { background: #14a0a0; color: #fff; }
.nav .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 99px; font-size: .75rem; padding: 0 .5rem; font-weight: 700; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .12); padding-top: .8rem; }
.side-user { padding: .2rem .5rem .6rem; font-size: .9rem; }
.side-user b { color: #fff; display: block; }
.side-foot button { width: 100%; justify-content: flex-start; background: transparent; color: #d6e8e8; border-color: transparent; }
.side-foot button:hover { background: rgba(255, 255, 255, .07); }
/* Margini laterali che crescono con lo schermo: stretti su portatili/tablet, più ariosi sui monitor grandi */
main { padding: 1.6rem clamp(1.2rem, calc((100vw - 1200px) * 0.16 + 1.5rem), 12rem) 4rem; width: 100%; min-width: 0; }
.btn-back { gap: .35rem; padding: .5rem 1rem .5rem .7rem; font-size: .95rem; }
.btn-back .icon { width: 1.3em; height: 1.3em; }
body.modal-open { overflow: hidden; }
.modal-bg { overscroll-behavior: contain; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
.page-head p { margin: .25rem 0 0; }

/* ---------- Componenti ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.2rem 1.3rem; }
.card + .card { margin-top: 1rem; }
/* Riquadri affiancati: stessa altezza e allineati in alto */
.grid > .card + .card { margin-top: 0; }
.grid { align-items: stretch; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .9rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

button, .btn {
  font: inherit; font-weight: 600; font-size: .95rem;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .6rem 1rem; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none;
  transition: background .12s, border-color .12s, transform .05s;
  min-height: 42px;
}
button:hover, .btn:hover { border-color: #b9c8cd; background: var(--surface-2); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid #7fc8c8; outline-offset: 1px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #a61f1f; border-color: #a61f1f; }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { background: #256a29; border-color: #256a29; }
.btn-wa { background: #1fa855; color: #fff; border-color: #1fa855; }
.btn-wa:hover { background: #178a45; border-color: #178a45; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: .35rem .65rem; min-height: 34px; font-size: .85rem; }
.btn-lg { padding: .85rem 1.4rem; font-size: 1.05rem; min-height: 52px; }
.btn-icon { padding: .35rem; min-height: 34px; min-width: 34px; }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .3rem; color: #2c3d45; }
.field { margin-bottom: .9rem; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; font-weight: 400; }
.field .err { color: var(--red); }
input:not([type]), input[type=text], input[type=password], input[type=date], input[type=time], input[type=month], input[type=number], input[type=tel], input[type=email], input[type=search], select, textarea {
  font: inherit; width: 100%;
  padding: .6rem .75rem; border: 1px solid #c9d5da; border-radius: 9px; background: #fff; color: var(--text);
  min-height: 44px;
}
textarea { resize: vertical; min-height: 90px; }
input.invalid { border-color: var(--red); background: var(--red-soft); }
input.valid { border-color: var(--green); }
.check { display: flex; align-items: flex-start; gap: .6rem; font-weight: 500; cursor: pointer; margin: .35rem 0; }
.check input { width: 20px; height: 20px; margin: .1rem 0 0; flex: none; accent-color: var(--primary); }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .9rem 1rem .3rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .4rem; color: var(--primary); font-size: .92rem; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .8rem; border: 1px solid #c9d5da; border-radius: 99px; cursor: pointer; font-weight: 500; font-size: .92rem; background: #fff; user-select: none; margin: 0; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip:has(input:focus-visible) { outline: 3px solid #7fc8c8; }
.seg { display: inline-flex; border: 1px solid #c9d5da; border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg label { margin: 0; padding: .55rem 1rem; cursor: pointer; font-weight: 600; border-right: 1px solid #c9d5da; background: #fff; }
.seg label:last-child { border-right: none; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--primary); color: #fff; }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: #eef2f3; color: #3a4b52; }
.badge.red { background: var(--red); color: #fff; }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.teal { background: var(--primary-soft); color: var(--primary); }
.badge.blue { background: #e6eefb; color: var(--blue); }
.badge.grey { background: #eceff1; color: #5e6f78; }

.alert { border-radius: 10px; padding: .8rem 1rem; display: flex; gap: .7rem; align-items: flex-start; border: 1px solid; margin-bottom: 1rem; }
.alert.red { background: var(--red-soft); border-color: var(--red-line); color: #7d1515; }
.alert.yellow { background: var(--yellow-soft); border-color: #eedc8a; color: #5c4900; }
.alert.blue { background: #eaf1fc; border-color: #bcd0f2; color: #173f7a; }
.alert.green { background: var(--green-soft); border-color: #b9dfbb; color: #1d5a20; }
.alert .icon { margin-top: .15rem; }

/* Banner "deve pagare" */
.pay-banner {
  background: var(--red); color: #fff; border-radius: var(--radius);
  padding: 1rem 1.3rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1rem; box-shadow: 0 6px 20px rgba(198, 40, 40, .28);
  animation: pulse 2.4s ease-in-out infinite;
}
.pay-banner .amount { font-size: 1.7rem; font-weight: 800; }
.pay-banner button { background: #fff; color: var(--red); border-color: #fff; }
.pay-banner .btn-wa { background: #1fa855; color: #fff; border-color: transparent; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.pay-banner .btn-wa:hover { background: #178a45; border-color: transparent; }
.pay-banner button { box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.pay-banner.orange { background: var(--orange); animation: none; box-shadow: none; }
.pay-banner.yellow { background: #f5d64a; color: #4a3b00; animation: none; box-shadow: none; }
.pay-banner.yellow button { color: #4a3b00; }
@keyframes pulse { 0%, 100% { box-shadow: 0 6px 20px rgba(198, 40, 40, .25); } 50% { box-shadow: 0 6px 28px rgba(198, 40, 40, .55); } }
@media (prefers-reduced-motion: reduce) { .pay-banner { animation: none; } }

/* Tabelle */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: .55rem .6rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: .6rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f1f7f7; }
tr.debt td { background: var(--red-soft); }
tr.debt td:first-child { box-shadow: inset 4px 0 0 var(--red); }
tr.debt:hover td { background: #fbdcdc; }
tr.due td:first-child { box-shadow: inset 4px 0 0 var(--orange); }
tr.low td:first-child { box-shadow: inset 4px 0 0 #e2bd18; }
tr.absent td { color: var(--muted); }
.empty { padding: 1.6rem; text-align: center; color: var(--muted); }

/* KPI */
.kpi { padding: 1rem 1.2rem; }
.kpi .lbl { font-size: .82rem; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 1.7rem; font-weight: 800; margin-top: .15rem; }
.kpi.red { background: var(--red); border-color: var(--red); color: #fff; }
.kpi.red .lbl { color: #ffd7d7; }

/* Ricerca */
.search-box { position: relative; }
.search-box input { padding-left: 2.6rem; font-size: 1.05rem; min-height: 52px; }
.search-box > .icon { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 360px; overflow: auto; }
.search-results a { display: flex; justify-content: space-between; gap: 1rem; padding: .65rem 1rem; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--line); }
.search-results a:hover, .search-results a.sel { background: var(--primary-soft); }

/* Lista */
.list-item { display: flex; align-items: center; gap: .8rem; padding: .7rem; border-bottom: 1px solid var(--line); border-left: 1px solid transparent; border-right: 1px solid transparent; flex-wrap: wrap; }
.list-item:last-child { border-bottom: none; }
.list-item .who { flex: 1; min-width: 180px; }
.list-item .who a { font-weight: 700; text-decoration: none; color: var(--text); }
.list-item .who a:hover { color: var(--primary); text-decoration: underline; }
.list-item.debt { background: var(--red-soft); border-radius: 8px; margin-bottom: .35rem; border: 1px solid var(--red-line); }
.search-results a.off { opacity: .6; background: #f4f6f7; }
.search-results a.off:hover { opacity: 1; background: var(--yellow-soft); }
.search-results a.off .tiny { color: var(--muted); font-weight: 400; }
.amount-red { color: var(--red); font-weight: 800; }
.amount-green { color: var(--green); font-weight: 800; }

/* Paziente */
.p-head { display: flex; gap: 1.2rem; align-items: flex-start; flex-wrap: wrap; }
.avatar { width: 64px; height: 64px; border-radius: 16px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 800; font-size: 1.4rem; flex: none; }
.p-head h1 { font-size: 1.7rem; }
.kv { display: flex; flex-wrap: wrap; gap: .8rem 2.8rem; margin-top: 1rem; }
.kv > div { flex: 0 1 auto; min-width: 140px; max-width: 100%; }
.kv div span { display: block; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kv div b { font-weight: 600; overflow-wrap: anywhere; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.8rem 0 .8rem; flex-wrap: wrap; }
.section-title h2 { display: flex; align-items: center; gap: .5rem; }

.cycle { border-left: 5px solid var(--primary); }
.cycle.posturale { border-left-color: #7b4bb7; }
.cycle.altro { border-left-color: #8a8f2c; }
.cycle.closed { opacity: .92; border-left-color: #a9b6bb; }
.cycle.lvl-debt { border-color: var(--red-line); border-left-color: var(--red); box-shadow: 0 0 0 2px var(--red-line), var(--shadow); }
.cycle-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin: .9rem 0; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .8rem; }
.stat span { display: block; font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat b { font-size: 1.15rem; }
.stat.red { background: var(--red); border-color: var(--red); color: #fff; }
.stat.red span { color: #ffd7d7; }
.stat.orange { background: var(--orange-soft); border-color: #f2c48c; color: var(--orange); }
.stat.yellow { background: var(--yellow-soft); border-color: #eedc8a; color: var(--yellow); }
.stat.green { background: var(--green-soft); border-color: #b9dfbb; color: var(--green); }
.progress { height: 8px; background: #e5ecee; border-radius: 99px; overflow: hidden; margin-top: .35rem; }
.progress > div { height: 100%; background: var(--primary); border-radius: 99px; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
details > summary { cursor: pointer; font-weight: 600; color: var(--primary); padding: .4rem 0; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; }
details[open] > summary::before { content: "▾ "; }

/* Calendario presenze */
.cal-wrap { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .6rem; }
.cal { border: 1px solid var(--line); border-radius: 10px; padding: .6rem; background: #fff; width: 268px; }
.cal-title { font-weight: 700; text-align: center; margin-bottom: .4rem; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-grid .dow { font-size: .7rem; text-align: center; color: var(--muted); font-weight: 700; }
.cal-day { font: inherit; font-size: .85rem; min-height: 32px; padding: 0; border-radius: 7px; border: 1px solid transparent; background: transparent; font-weight: 500; }
.cal-day:hover { border-color: #b9c8cd; background: #f2f6f7; }
.cal-day.today { border-color: var(--primary); font-weight: 800; }
.cal-day.p { background: var(--green); color: #fff; font-weight: 700; }
.cal-day.p.unpaid { background: var(--red); }
.cal-day.ag { background: #cfd8dc; color: #37474f; }
.cal-day.a { background: #ffcdd2; color: #8e1c1c; text-decoration: line-through; }
.cal-day.sel { background: var(--primary); color: #fff; font-weight: 700; }
.cal-day.out { visibility: hidden; }
.cal-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.cal-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }

/* Modale */
.modal-bg { position: fixed; inset: 0; background: rgba(12, 30, 36, .45); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 620px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--line); }
.modal-body { padding: 1.2rem 1.3rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.3rem; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 14px 14px; flex-wrap: wrap; }
.modal-foot { align-items: center; }
.modal-foot .push { margin-right: auto; }
/* Finestre di scelta: un pulsante grande per ogni opzione, in colonna */
.choice-stack { display: grid; gap: .6rem; margin-top: 1.2rem; }
.choice-stack button { width: 100%; min-height: 54px; font-size: 1.05rem; }
.choice-cards { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin-top: 1rem; }
.choice-card { flex-direction: column; align-items: flex-start; justify-content: flex-start; text-align: left; gap: .35rem; padding: 1rem 1.1rem; border: 2px solid var(--line); border-radius: 12px; min-height: 0; font-size: 1rem; }
.choice-card:hover { border-color: var(--primary); background: var(--primary-soft); }
.choice-card .icon { width: 1.6em; height: 1.6em; color: var(--primary); }
.choice-card b { font-size: 1.05rem; }
.choice-card span { font-weight: 400; font-size: .85rem; color: var(--muted); line-height: 1.35; }
.choice-card.main { border-color: var(--primary); }
@media (max-width: 700px) { .choice-cards { grid-template-columns: 1fr; } }
.modal.alarm .modal-head { background: var(--red); color: #fff; border-radius: 14px 14px 0 0; }
.modal.alarm .modal-head button { color: #fff; }
.big-amount { font-size: 2.4rem; font-weight: 800; color: var(--red); text-align: center; margin: .5rem 0; }

/* Toast */
#toasts { position: fixed; bottom: 1.2rem; right: 1.2rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; }
.toast { background: #17242b; color: #fff; padding: .8rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); max-width: 420px; animation: tin .2s ease-out; font-weight: 500; }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

/* Accesso */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #0d3c40, #0f6e6e 60%, #14a0a0); }
.auth-card { width: 100%; max-width: 440px; background: #fff; border-radius: 18px; padding: 2rem; box-shadow: 0 30px 80px rgba(0, 0, 0, .3); }
.auth-card.wide { max-width: 680px; }
.auth-logo { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.4rem; }
.auth-logo .brand-mark { width: 48px; height: 48px; }
.auth-logo b { font-size: 1.6rem; color: var(--primary); }
.recovery { font-family: Consolas, "Courier New", monospace; font-size: 1.25rem; font-weight: 700; letter-spacing: .06em; background: var(--yellow-soft); border: 2px dashed #d6b300; border-radius: 10px; padding: 1rem; text-align: center; word-break: break-all; }
.steps { display: flex; gap: .4rem; margin-bottom: 1.2rem; }
.steps span { flex: 1; height: 5px; border-radius: 99px; background: #e0e7ea; }
.steps span.on { background: var(--primary); }

.tabs { display: flex; gap: .3rem; flex-wrap: wrap; border-bottom: 2px solid var(--line); margin-bottom: 1.2rem; }
.tabs a { padding: .6rem 1rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.code-big { font-size: 3rem; font-weight: 800; letter-spacing: .3em; text-align: center; color: var(--primary); font-family: Consolas, monospace; }
pre.msg { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: .7rem; font-family: inherit; margin: .4rem 0; font-size: .9rem; }

@media print {
  .side, .no-print, #toasts { display: none !important; }
  .shell { display: block; }
  main { padding: 0; }
  .card { box-shadow: none; }
}

/* Agenda */
.ag-card { padding: .8rem; }
.ag { min-width: 0; }
.ag-head, .ag-body { display: grid; grid-template-columns: 54px repeat(var(--cols), minmax(0, 1fr)); }
.ag-head { position: sticky; top: 0; z-index: 3; background: #fff; border-bottom: 1px solid var(--line); }
.ag-head > div { padding: .5rem .3rem; text-align: center; font-size: .9rem; }
.ag-head > div.today { color: var(--primary); }
.ag-head > div.today b { background: var(--primary); color: #fff; border-radius: 6px; padding: 0 .35rem; }
.ag-times { position: relative; }
.ag-times span { position: absolute; right: 6px; transform: translateY(-50%); font-size: .72rem; color: var(--muted); }
.ag-times span:first-child { transform: none; }
.ag-day { position: relative; border-left: 1px solid var(--line); cursor: copy; }
.ag-day.today { background: #f4fbfa; }
.ag-day:hover { background: #f7fafb; }
.ag-line { position: absolute; left: 0; right: 0; border-top: 1px dashed #edf1f2; pointer-events: none; }
.ag-line.hour { border-top: 1px solid #e3e9eb; }
.ag-now { position: absolute; left: 0; right: 0; border-top: 2px solid var(--red); z-index: 2; pointer-events: none; }
.ag-now::before { content: ""; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.ag-appt { position: absolute; z-index: 1; display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 0; padding: .2rem .4rem; min-height: 0; border: none; border-left: 4px solid var(--c); border-radius: 6px; background: color-mix(in srgb, var(--c) 14%, #fff); color: #13262c; font-size: .78rem; font-weight: 500; text-align: left; overflow: hidden; cursor: pointer; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.ag-appt:hover { background: color-mix(in srgb, var(--c) 24%, #fff); border-color: var(--c); }
.ag-appt > span { flex: none; line-height: 1.25; }
.ag-appt .t { font-weight: 700; font-size: .72rem; }
.ag-appt .n { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ag-appt .s { font-size: .7rem; color: var(--muted); }
.ag-appt.st-arrivato { background: var(--green-soft); border-left-color: var(--green); }
.ag-appt.st-assente { background: #fdecec; border-left-color: var(--red); text-decoration: line-through; opacity: .8; }
.ag-appt.st-annullato { background: #f0f2f3; border-left-color: #b0bcc1; color: #7a878d; text-decoration: line-through; opacity: .7; }
.dot { font-style: normal; background: var(--red); color: #fff; border-radius: 99px; padding: 0 .3rem; font-size: .68rem; font-weight: 800; }
.opdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .35rem; vertical-align: 0; }
/* Scala del dolore */
/* Storico, valutazioni, esercizi */
.timeline { list-style: none; margin: 0; padding: 0 0 0 1.1rem; border-left: 3px solid var(--line); }
.timeline li { position: relative; padding: .35rem 0 .35rem .6rem; font-size: .92rem; }
.timeline li::before { content: ""; position: absolute; left: -1.55rem; top: .7rem; width: 12px; height: 12px; border-radius: 50%; background: #b0bcc1; border: 2px solid #fff; }
.timeline li.on::before { background: var(--green); }
.timeline li.tl-gap { color: var(--orange); font-style: italic; }
.timeline li.tl-gap::before { background: #fff; border: 2px dashed var(--orange); }
.timeline li.tl-gap span { font-weight: 700; }
.chip.was { box-shadow: inset 0 0 0 2px #e2bd18; }
.photo-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.photo { width: 120px; height: 150px; padding: 0; border-radius: 10px; background: #eef2f3 center / cover no-repeat; display: flex; align-items: flex-end; overflow: hidden; }
.photo span { background: rgba(0, 0, 0, .55); color: #fff; font-size: .7rem; width: 100%; padding: .2rem .3rem; text-align: left; }
.ex-lib { display: flex; flex-wrap: wrap; gap: .4rem; max-height: 180px; overflow-y: auto; margin-top: .5rem; padding: .4rem; border: 1px solid var(--line); border-radius: 10px; }
.ex-row { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; margin-bottom: .5rem; background: var(--surface-2); }
.ex-row textarea { min-height: 54px; margin-top: .4rem; }
.choice-cards.cols-4 { grid-template-columns: repeat(4, 1fr); }
.choice-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
@media (max-width: 980px) { .choice-cards.cols-4 { grid-template-columns: 1fr 1fr; } }
/* Registro presenze: stesse colonne in tutti i giorni */
.reg-table { table-layout: fixed; width: 100%; }
.reg-table .c-time { width: 70px; }
.reg-table .c-name { width: 28%; }
.reg-table .c-area { width: 13%; }
.reg-table .c-tr { width: 27%; }
.reg-table .c-op { width: 15%; }
.reg-table .c-st { width: 110px; }
.reg-table td, .reg-table th { overflow: hidden; text-overflow: ellipsis; }
/* Indirizzo con suggerimenti */
.addr-grid { display: grid; grid-template-columns: minmax(0, 1fr) 140px; gap: 0 1rem; }
@media (max-width: 600px) { .addr-grid { grid-template-columns: 1fr; } }
.addr-box { position: relative; }
.addr-box .search-results a { align-items: baseline; }
/* Allegati */
.upload-zone { border: 2px dashed #c9d5da; border-radius: 14px; padding: 1rem; margin-bottom: 1rem; background: #fbfdfd; transition: background .15s, border-color .15s; }
.upload-zone.drag { background: var(--primary-soft); border-color: var(--primary); }
.upload-btns { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 520px) { .upload-btns { grid-template-columns: 1fr; } }
.upload-btn { display: flex; flex-direction: column; align-items: center; gap: .25rem; padding: 1rem .8rem; border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; text-align: center; margin: 0; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.upload-btn:hover { border-color: var(--primary); background: var(--primary-soft); }
.upload-btn .icon { width: 30px; height: 30px; color: var(--primary); }
.upload-btn b { font-size: 1.05rem; }
.upload-btn span { font-size: .8rem; color: var(--muted); font-weight: 400; }
.upload-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.up-list { display: grid; gap: .4rem; margin-top: .6rem; }
.up-item { display: flex; align-items: center; gap: .7rem; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.up-item img { width: 46px; height: 46px; object-fit: cover; border-radius: 6px; }
.up-ico { width: 46px; height: 46px; display: grid; place-items: center; background: var(--primary-soft); border-radius: 6px; color: var(--primary); }
.up-item b { word-break: break-all; font-size: .9rem; }
/* Programma in palestra */
.program-box { border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem; margin: .8rem 0; background: #fbfdfd; }
.program-list { margin: .5rem 0 0; padding-left: 1.4rem; display: grid; gap: .25rem; }
.program-list li span:first-child { margin-right: .5rem; }
.program-list li { display: list-item; }
.program-list li .badge { float: right; }
.prog-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) 80px 30px 36px; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.prog-n { font-weight: 700; color: var(--muted); text-align: right; }
/* Orari */
.hours-table input[type=time] { min-width: 110px; }
.hours-table tr.closed td:not(:first-child):not(:nth-child(2)) { opacity: .35; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #c9d5da; border-radius: 99px; cursor: pointer; transition: background .15s; }
.switch span::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(20px); }
.ex-row { display: flex; flex-wrap: wrap; gap: 0 .8rem; align-items: flex-end; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; background: #fbfdfd; }
.ex-row .field { margin-bottom: .3rem; }
.ex-row .grow { flex: 1; min-width: 160px; }
.ag-off { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(135deg, #eef2f3, #eef2f3 6px, #e6ebed 6px, #e6ebed 12px); pointer-events: none; z-index: 0; }
.ag-off.closed { display: flex; align-items: flex-start; justify-content: center; }
.ag-off span { margin-top: .5rem; font-size: .78rem; font-weight: 600; color: var(--muted); background: #fff; padding: .1rem .5rem; border-radius: 99px; }
.ag-off.pause span { margin-top: .2rem; }
.ag-gev { background: #fff; border: 2px dashed #1f5fbf; border-left: 4px solid #1f5fbf; color: #1f3f7a; }
.ag-gev .icon { width: 1em; height: 1em; }
/* Filtro vista (amministratore) */
.view-filter { padding: 0 .9rem .7rem; }
.view-filter > span { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; opacity: .7; margin-bottom: .3rem; }
.view-filter .seg { display: flex; width: 100%; gap: 3px; padding: 3px; border: none; border-radius: 11px; background: rgba(255, 255, 255, .09); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25); }
.view-filter .seg label { flex: 1; text-align: center; padding: .4rem .2rem; font-size: .8rem; font-weight: 600; border: none; border-radius: 8px; background: transparent; color: rgba(255, 255, 255, .78); transition: background .15s, color .15s; }
.view-filter .seg label:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.view-filter .seg label:has(input:checked) { background: #fff; color: var(--primary-dark, #0b4f4f); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.view-filter .seg label:has(input:focus-visible) { outline: 2px solid #7fc8c8; outline-offset: 1px; }
.kpi.dim { opacity: .45; }
.save-state .icon { width: 1em; height: 1em; vertical-align: -2px; }
/* Listino */
.price-table { table-layout: fixed; width: 100%; min-width: 900px; }
.price-table input:not([type=checkbox]), .price-table select { padding-left: .55rem; padding-right: .55rem; }
.price-table input[type=number] { padding-right: .3rem; }
.price-table .c-name { width: 24%; } .price-table .c-cat { width: 16%; } .price-table .c-pr { width: 13%; } .price-table .c-pk { width: 15%; }
.price-table .c-pp { width: 14%; } .price-table .c-on { width: 8%; } .price-table .c-st { width: 10%; }
.price-table td { vertical-align: middle; padding-top: .45rem; padding-bottom: .45rem; }
.price-table input:not([type=checkbox]), .price-table select { width: 100%; min-width: 0; }
.money-in { display: flex; align-items: center; gap: .35rem; }
.money-in span { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.money-in input { text-align: right; }
.price-table tr.off td:not(.center):not(.state-cell) { opacity: .45; }
.price-table tr.new-row td { background: #fbfdfd; border-top: 2px dashed var(--line); }
.price-table .state-cell { white-space: nowrap; }
.price-table td.center .switch { vertical-align: middle; }
/* Gestione gruppi */
.member-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.mchip { display: inline-flex; align-items: center; gap: .1rem; padding: .15rem .2rem .15rem .7rem; border: 1px solid var(--line); border-radius: 99px; background: #fff; font-size: .9rem; }
.mchip a { color: var(--text); text-decoration: none; font-weight: 600; }
.mchip button { min-height: 0; width: 26px; height: 26px; padding: 0; border-radius: 50%; }
.mchip button .icon { width: 14px; height: 14px; }
.group-card.inactive { opacity: .6; }
/* Gruppi e turni */
.roster { display: grid; gap: .45rem; }
.roster-row { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; padding: .55rem .75rem; border: 1px solid var(--line); border-left: 5px solid var(--primary); border-radius: 10px; background: #fff; }
.roster-row .who { flex: 1; min-width: 200px; }
.roster-row .who a { text-decoration: none; color: var(--text); }
.roster-row.st-presente { border-left-color: var(--green); background: var(--green-soft); }
.roster-row.st-assente { border-left-color: #b0bcc1; background: #f4f6f7; }
.roster-row.st-programmato { border-left-color: #e2bd18; background: var(--yellow-soft); }
.ag-group { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 12%, #fff), color-mix(in srgb, var(--c) 12%, #fff) 8px, color-mix(in srgb, var(--c) 20%, #fff) 8px, color-mix(in srgb, var(--c) 20%, #fff) 16px); border-left-style: double; border-left-width: 5px; }
.ag-group .icon { width: 1em; height: 1em; }
/* Statistiche */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--primary); }
.chart .bar2 { fill: #f3a3a3; }
.chart .bar:hover { fill: var(--primary-2); }
.chart text { font-size: 11px; fill: var(--muted); font-family: inherit; }
.chart .val { fill: var(--text); font-weight: 700; font-size: 10.5px; }
.chart .axis { stroke: var(--line); }
.hbar { display: grid; grid-template-columns: minmax(90px, 140px) minmax(0, 1fr) auto; gap: .6rem; align-items: center; margin: .45rem 0; font-size: .9rem; }
.hbar > b { white-space: nowrap; min-width: 2.5rem; text-align: right; }
.hbar .track { background: #eef2f3; border-radius: 99px; height: 12px; overflow: hidden; }
.hbar .fill { background: var(--primary); height: 100%; border-radius: 99px; }

/* Visualizzatore documenti e prezzi per terapia */
.modal.doc { max-width: 1100px; }
.doc-frame { width: 100%; height: 72vh; border: 0; border-radius: 8px; background: #525659; display: block; }
.doc-img-wrap { text-align: center; background: #f0f3f4; border-radius: 8px; padding: .5rem; }
.doc-img { max-width: 100%; max-height: 72vh; }
.price-rows { display: grid; gap: .4rem; }
.price-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
.price-in { display: flex; align-items: center; gap: .35rem; white-space: nowrap; }
.price-in input { width: 110px; }
.menu-btn { display: none; }

/* ---------- Tablet ---------- */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 210px 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- Menu a scomparsa (tablet in verticale e telefono) ---------- */
@media (max-width: 900px) {
  .shell { display: block; }
  .side { position: sticky; top: 0; z-index: 50; height: auto; padding: .5rem .8rem; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { padding: 0; flex: 1; }
  .brand-mark { width: 34px; height: 34px; }
  .menu-btn { display: inline-flex; background: transparent; color: #fff; border-color: rgba(255, 255, 255, .35); }
  .menu-btn:hover { background: rgba(255, 255, 255, .1); }
  .side .nav, .side .side-foot { display: none; width: 100%; }
  .side.open .nav, .side.open .side-foot { display: flex; }
  .side.open .nav { margin-top: .6rem; }
  .nav a { padding: .8rem; font-size: 1.05rem; }
  .side-foot { margin-top: .4rem; flex-direction: column; }
  main { padding: 1rem 1rem 4rem; }
}

/* ---------- Telefono ---------- */
@media (max-width: 700px) {
  :root { font-size: 15px; }
  h1 { font-size: 1.35rem; }
  .brand-sub { display: none; }
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .val { font-size: 1.3rem; }
  .card { padding: 1rem; }
  .page-head > .btn-primary, .page-head > button { width: 100%; }
  .actions > button, .actions > .btn { flex: 1 1 auto; }
  .card-head .actions { width: 100%; }
  .pay-banner { flex-direction: column; align-items: stretch; text-align: center; }
  .pay-banner > .icon { display: none; }
  .pay-banner button { width: 100%; }
  .p-head { gap: .8rem; }
  .p-head .actions { width: 100%; }
  .avatar { width: 48px; height: 48px; font-size: 1.1rem; }
  .cal { width: 100%; }
  .cal-day { min-height: 38px; }
  .seg { display: flex; }
  .seg label { flex: 1 1 auto; text-align: center; }
  .list-item .actions { width: 100%; }
  #toasts { left: 1rem; right: 1rem; bottom: 1rem; }
  .toast { max-width: none; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; }
  .tabs a { white-space: nowrap; }
  input[type=date], input[type=time] { min-width: 0; }

  /* Tabelle → schede */
  table:has(thead) thead { display: none; }
  table:has(thead), table:has(thead) tbody, table:has(thead) tr, table:has(thead) td { display: block; width: 100%; }
  table:has(thead) tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: .6rem; padding: .45rem .75rem; background: #fff; }
  table:has(thead) td { border: none; padding: .3rem 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; text-align: right; }
  table:has(thead) td[data-label]::before { content: attr(data-label); font-weight: 700; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: none; }
  table:has(thead) td:empty { display: none; }
  table:not(:has(thead)), table:not(:has(thead)) tbody { display: block; width: 100%; }
  table:not(:has(thead)) tr { display: flex; flex-wrap: wrap; gap: 0 .6rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
  table:not(:has(thead)) td { border: none; padding: .1rem 0; width: auto !important; }
  table:not(:has(thead)) td:empty { display: none; }
  table:has(thead) td input, table:has(thead) td select { max-width: 60%; }
  tr.debt { border-color: var(--red-line) !important; border-left: 5px solid var(--red) !important; background: var(--red-soft) !important; }
  tr.debt td, tr.debt:hover td { background: transparent; box-shadow: none !important; }
  tr.due { border-left: 5px solid var(--orange) !important; }
  tr.low { border-left: 5px solid #e2bd18 !important; }
  tr.due td:first-child, tr.low td:first-child { box-shadow: none; }

  /* Finestre a tutto schermo */
  .modal-bg { padding: 0; }
  .modal, .modal.wide, .modal.doc { max-width: none; min-height: 100%; border-radius: 0; display: flex; flex-direction: column; }
  .modal-body { flex: 1; }
  .modal-head { position: sticky; top: 0; background: #fff; z-index: 2; border-radius: 0; }
  .modal.alarm .modal-head { border-radius: 0; }
  .modal-foot { position: sticky; bottom: 0; border-radius: 0; }
  .modal-foot > * { flex: 1 1 auto; }
  .price-in input { width: 90px; }
  .ag-head > div { font-size: .78rem; padding: .4rem .1rem; }
  .ag-head .tiny { display: none; }
  .ag-appt .s { display: none; }
  .hbar { grid-template-columns: 90px minmax(0, 1fr) auto; }
}

.choice-card { display: flex; cursor: pointer; margin: 0; font-weight: 400; color: var(--text); }

/* Verifica in due passaggi */
.qr-box { width: 220px; max-width: 70%; margin: .5rem auto; padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.qr-box svg { display: block; width: 100%; height: auto; }
.enroll-steps { padding-left: 1.2rem; }
.backup-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem; }
.backup-codes code { display: block; text-align: center; padding: .45rem; font-size: 1.05rem; letter-spacing: .08em; background: #f4f6f7; border-radius: 8px; }

.install-notice { margin: 0 0 1.25rem; padding: 1rem; border: 1px solid #b6d9d4; border-radius: 12px; background: #eaf6f3; color: #164942; }
.install-notice p { margin: .35rem 0 .8rem; font-size: .9rem; }
.install-notice .row { flex-wrap: wrap; }

/* Monthly backup controls follow the shared field styling. */
.backup-download-controls { align-items: flex-end; }
.backup-download-controls .field { flex: 0 1 240px; min-width: 0; margin: 0; }
.backup-download-controls input[type=month] { height: 44px; min-width: 0; cursor: pointer; color-scheme: light; }
.backup-download-controls input[type=month]:hover { border-color: var(--primary); }
.backup-download-controls input[type=month]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .65; padding: .2rem; }
.backup-download-controls button { min-height: 44px; }
@media (max-width: 600px) {
  .backup-download-controls .field, .backup-download-controls button { flex: 1 1 100%; width: 100%; }
}
