/* ============================================================
   Cartella Clinica — fogli di stile
   Adattato 1:1 dall'app originale (stesso design, stesso layout):
   l'unica differenza voluta è che i font non arrivano più da Google
   Fonts (nessuna richiesta esterna che riveli l'IP del dispositivo a
   terzi ad ogni apertura) — restano gli stack di sistema già previsti
   come fallback nell'app originale. In fondo al file sono aggiunte le
   sole regole nuove richieste dal passaggio al backend: login,
   schermata di blocco, banner di stato (caricamento/errore/offline).
   ============================================================ */


:root{
  --bg:#F5F2EA; --bg-elevated:#FFFFFF; --surface:#FBF9F4; --surface-2:#EFEAE0;
  --border:#DBD5C4; --border-strong:#C7BFA9;
  --text:#201C15; --text-muted:#6B6355; --text-faint:#948C7A;
  --accent:#1F6F6B; --accent-strong:#154E4B; --accent-soft:#E2EEEC; --accent-contrast:#FFFFFF;
  --warn:#B5651D; --warn-soft:#F6E7D8; --warn-strong:#8C4B14;
  --danger:#AE3B3B; --danger-soft:#F5E1DF;
  --good:#3C7A4F; --good-soft:#E3EFE4;
  --shadow:0 10px 30px -14px rgba(32,28,21,0.28);
  --radius-s:6px; --radius-m:10px; --radius-l:18px;
  --font-display:Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --font-body:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#101614; --bg-elevated:#161F1C; --surface:#131B18; --surface-2:#1C2622;
    --border:#2A3733; --border-strong:#3A4A44;
    --text:#EAEDE9; --text-muted:#A2ACA3; --text-faint:#75817A;
    --accent:#4FA89D; --accent-strong:#6FC2B6; --accent-soft:#1B302C; --accent-contrast:#06120F;
    --warn:#D98A4E; --warn-soft:#2E2116; --warn-strong:#F0B37E;
    --danger:#E17B76; --danger-soft:#2E1918;
    --good:#6FBF82; --good-soft:#17281B;
    --shadow:0 10px 30px -14px rgba(0,0,0,0.55);
  }
}
:root[data-theme="dark"]{
  --bg:#101614; --bg-elevated:#161F1C; --surface:#131B18; --surface-2:#1C2622;
  --border:#2A3733; --border-strong:#3A4A44;
  --text:#EAEDE9; --text-muted:#A2ACA3; --text-faint:#75817A;
  --accent:#4FA89D; --accent-strong:#6FC2B6; --accent-soft:#1B302C; --accent-contrast:#06120F;
  --warn:#D98A4E; --warn-soft:#2E2116;
  --danger:#E17B76; --danger-soft:#2E1918;
  --good:#6FBF82; --good-soft:#17281B;
  --shadow:0 10px 30px -14px rgba(0,0,0,0.55);
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:var(--font-body); font-size:15px; line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
#toast-region{position:fixed; top:16px; right:16px; z-index:900; display:flex; flex-direction:column; gap:8px; pointer-events:none;}
.toast{
  background:var(--text); color:var(--bg-elevated); padding:9px 14px; border-radius:var(--radius-s);
  font-size:13px; box-shadow:var(--shadow); opacity:0.96; max-width:280px;
}
.toast.warn{background:var(--warn-strong,var(--warn));}
.toast.danger{background:var(--danger);}

#app{ display:flex; height:100vh; width:100%; overflow:hidden; }

/* ---------- Sidebar ---------- */
#sidebar{
  width:308px; flex:0 0 308px; background:var(--surface); border-right:1px solid var(--border);
  display:flex; flex-direction:column; height:100%;
}
.sidebar-head{ padding:18px 16px 12px; display:flex; flex-direction:column; gap:10px; border-bottom:1px solid var(--border); }
.brand{ display:flex; align-items:center; gap:9px; margin-bottom:4px; }
.brand-mark{ font-size:20px; line-height:1; }
.brand-name{ font-family:var(--font-display); font-weight:600; font-size:19px; letter-spacing:-0.01em; }
.view-switch{ display:flex; gap:4px; background:var(--surface-2); border-radius:var(--radius-s); padding:3px; }
.view-switch-btn{
  flex:1; border:none; background:transparent; color:var(--text-muted); font-family:var(--font-body);
  font-size:12.5px; font-weight:600; padding:7px 8px; border-radius:calc(var(--radius-s) - 2px); cursor:pointer;
}
.view-switch-btn:hover{ color:var(--text); }
.view-switch-btn.active{ background:var(--bg-elevated); color:var(--accent-strong); box-shadow:var(--shadow-1,0 1px 2px rgba(0,0,0,0.08)); }
#search-input{
  width:100%; padding:8px 11px; border-radius:var(--radius-s); border:1px solid var(--border);
  background:var(--bg-elevated); color:var(--text); font-family:var(--font-body); font-size:13.5px;
}
#search-input:focus{ outline:2px solid var(--accent); outline-offset:1px; }
.filter-chip-row{ display:flex; gap:6px; flex-wrap:wrap; }
.filter-chip{
  appearance:none; border:1px solid var(--border-strong); background:var(--bg-elevated); color:var(--text-muted);
  padding:4px 10px; border-radius:999px; font-size:11.5px; font-weight:500; font-family:var(--font-body); cursor:pointer;
}
.filter-chip:hover{ background:var(--surface-2); }
.filter-chip.active{ background:var(--accent); border-color:var(--accent); color:var(--accent-contrast); }
.patient-list{ list-style:none; margin:0; padding:6px 8px; overflow-y:auto; flex:1; }
.patient-row{
  display:flex; align-items:center; gap:10px; padding:9px 8px; border-radius:var(--radius-s);
  cursor:pointer; margin-bottom:2px; border:1px solid transparent;
}
.patient-row:hover{ background:var(--surface-2); }
.patient-row.active{ background:var(--accent-soft); border-color:var(--accent); }
.avatar{
  width:34px; height:34px; border-radius:50%; background:var(--accent-soft); color:var(--accent-strong);
  display:flex; align-items:center; justify-content:center; font-weight:600; font-size:13px; flex:0 0 34px;
  font-family:var(--font-display);
}
.patient-row.active .avatar{ background:var(--accent); color:var(--accent-contrast); }
.patient-row-info{ min-width:0; flex:1; }
.patient-row-name{ font-weight:500; font-size:13.8px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.patient-row-meta{ font-size:11.5px; color:var(--text-muted); display:flex; align-items:center; gap:5px; }
.empty-list{ padding:22px 14px; color:var(--text-muted); font-size:13px; text-align:center; }
.save-indicator{
  padding:9px 14px; font-size:11.5px; color:var(--text-faint); border-top:1px solid var(--border);
  display:flex; align-items:center; gap:6px;
}
.save-indicator .dot{ width:6px; height:6px; border-radius:50%; background:var(--good); }
.save-indicator.saving .dot, .save-indicator.conflict .dot{ background:var(--warn); }
.save-indicator.readonly .dot, .save-indicator.local .dot{ background:var(--text-faint); }
.save-indicator.error .dot{ background:var(--danger); }

/* ---------- Main ---------- */
#main-panel{ flex:1; min-width:0; height:100%; overflow-y:auto; }
.panel-inner{ max-width:920px; margin:0 auto; padding:32px 36px 60px; }

.dashboard-hero{ margin-bottom:28px; }
.dashboard-hero h1{ font-family:var(--font-display); font-size:30px; font-weight:600; margin:0 0 6px; text-wrap:balance; }
.dashboard-hero p{ color:var(--text-muted); margin:0; font-size:14.5px; max-width:52ch; }
.stat-row{ display:grid; grid-template-columns:repeat(3,1fr); gap:14px; margin:26px 0 30px; }
.stat-card{
  background:var(--bg-elevated); border:1px solid var(--border); border-radius:var(--radius-m); padding:16px 18px;
}
.stat-value{ font-family:var(--font-mono); font-size:26px; font-weight:500; font-variant-numeric:tabular-nums; }
.stat-label{ font-size:12.5px; color:var(--text-muted); margin-top:3px; }
.dashboard-empty{
  border:1px dashed var(--border-strong); border-radius:var(--radius-l); padding:40px 30px; text-align:center; color:var(--text-muted);
}
.dash-widget{ margin-bottom:26px; }
.dash-widget:last-child{ margin-bottom:0; }
.dash-widget td a{ color:var(--text); font-weight:500; text-decoration:none; }
.dash-widget td a:hover{ color:var(--accent-strong); text-decoration:underline; }

.pain-chart-block{
  background:var(--bg-elevated); border:1px solid var(--border); border-radius:var(--radius-m); padding:16px 18px;
}
.pain-chart{ width:100%; height:auto; display:block; }
.chart-grid{ stroke:var(--border); stroke-width:1; }
.chart-axis-label{ fill:var(--text-faint); font-family:var(--font-mono); font-size:9.5px; }
.chart-line{ stroke:var(--accent); stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
.chart-dot{ fill:var(--accent); stroke:var(--bg-elevated); stroke-width:2; }
.chart-end-label{ fill:var(--text); font-family:var(--font-mono); font-size:12px; font-weight:600; }

/* ---------- Diario clinico: caselle ---------- */
.diario-grid{ display:grid; grid-template-columns:repeat(auto-fill, minmax(230px, 1fr)); gap:12px; }
.diario-box{
  border:1px solid var(--border); border-radius:var(--radius-m); background:var(--bg-elevated);
  padding:10px 12px 12px; display:flex; flex-direction:column; gap:6px;
}
.diario-box-head{ display:flex; align-items:center; justify-content:space-between; gap:6px; }
.diario-box-head-right{ display:flex; align-items:center; gap:6px; }
.diario-box-head .diario-box-date{
  border:none; background:none; padding:2px 0; width:auto; font-family:var(--font-mono); font-size:12px;
  font-weight:600; color:var(--text); min-height:0;
}
.diario-box-head-right .diario-box-pain{
  width:46px; padding:3px 6px; font-family:var(--font-mono); font-size:12px; text-align:center; min-height:0;
}
.diario-box-del{
  appearance:none; border:none; background:none; color:var(--text-faint); font-size:16px; line-height:1;
  cursor:pointer; padding:2px 4px; border-radius:var(--radius-s);
}
.diario-box-del:hover{ color:var(--danger); background:var(--surface-2); }
.diario-testo{ min-height:110px; resize:vertical; font-size:13px; line-height:1.5; }

/* ---------- Scala NPRS ---------- */
.nprs-scale{ display:flex; gap:4px; flex-wrap:wrap; }
.nprs-cell{
  flex:1 1 0; min-width:26px; appearance:none; border:2px solid transparent; font-family:var(--font-mono);
  font-size:13px; font-weight:600; padding:8px 0; border-radius:var(--radius-s); cursor:pointer; text-align:center;
  color:var(--text);
}
.nprs-cell.n-good{ background:var(--good-soft); }
.nprs-cell.n-warn{ background:var(--warn-soft); }
.nprs-cell.n-danger{ background:var(--danger-soft); }
.nprs-cell:hover{ filter:brightness(0.94); }
.nprs-cell.selected{ border-color:var(--text); }
.nprs-scale-labels{ display:flex; justify-content:space-between; font-size:11px; color:var(--text-faint); margin-top:6px; }
.nprs-current{ margin:10px 0 0; font-size:13px; color:var(--text-muted); }
.nprs-current strong{ color:var(--text); }

.body-map{ width:100%; max-width:210px; height:auto; display:block; margin:2px auto 14px; }
.silhouette-fill{ fill:var(--surface-2); stroke:var(--border-strong); stroke-width:1.5; }
.limb-line{ stroke:var(--surface-2); fill:none; stroke-linecap:round; }
.limb-fill{ fill:var(--surface-2); stroke:var(--border-strong); stroke-width:1.5; }
.joint-fill{ fill:var(--surface-2); stroke:none; }
.zone-shape{ fill:rgba(0,0,0,0.001); stroke:none; cursor:pointer; transition:fill 0.12s ease, opacity 0.12s ease; }
.zone-shape:hover{ fill:var(--accent); opacity:0.28; }
.zone-shape.selected{ fill:var(--accent); opacity:0.55; }
.dashboard-empty h2{ font-family:var(--font-display); font-size:19px; color:var(--text); font-weight:600; margin:0 0 8px; }

.mobile-only{ display:none; }

.patient-header{
  background:var(--bg-elevated); border:1px solid var(--border); border-radius:var(--radius-l);
  padding:22px 24px; margin-bottom:20px; box-shadow:var(--shadow);
}
.patient-header-top{ display:flex; justify-content:space-between; align-items:flex-start; gap:14px; flex-wrap:wrap; }
.patient-name{ font-family:var(--font-display); font-size:26px; font-weight:600; margin:0 0 4px; text-wrap:balance; }
.patient-sub{ color:var(--text-muted); font-size:13.5px; display:flex; flex-wrap:wrap; gap:4px 10px; align-items:center; }
.patient-sub .mono{ font-family:var(--font-mono); font-size:12.5px; }
.patient-actions{ display:flex; gap:8px; flex-wrap:wrap; }

.tabs{ display:flex; gap:2px; border-bottom:1px solid var(--border); margin-bottom:22px; overflow-x:auto; }
.tab-btn{
  appearance:none; background:none; border:none; border-bottom:2px solid transparent; padding:10px 14px;
  font-family:var(--font-body); font-size:13.5px; font-weight:500; color:var(--text-muted); cursor:pointer; white-space:nowrap;
}
.tab-btn:hover{ color:var(--text); }
.tab-btn.active{ color:var(--accent-strong); border-bottom-color:var(--accent); }

.section-block{ margin-bottom:26px; }
.section-block-head{ display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; gap:10px; }
.section-title{ font-family:var(--font-display); font-size:17px; font-weight:600; margin:0; }
.section-help{ font-size:12.5px; color:var(--text-faint); margin:2px 0 0; }

.info-grid{ display:grid; grid-template-columns:repeat(auto-fill,minmax(190px,1fr)); gap:16px; }
.info-field .k{ font-size:11.5px; color:var(--text-faint); text-transform:uppercase; letter-spacing:0.03em; margin-bottom:2px; }
.info-field .v{ font-size:14px; }
.info-field .v.mono{ font-family:var(--font-mono); font-size:13px; }

.tag-list{ display:flex; flex-wrap:wrap; gap:7px; margin-bottom:10px; }
.tag{
  display:inline-flex; align-items:center; gap:6px; padding:5px 10px; border-radius:999px; font-size:12.5px;
  background:var(--surface-2); border:1px solid var(--border);
}
.tag button{
  appearance:none; border:none; background:none; cursor:pointer; color:inherit; opacity:0.6; font-size:13px; line-height:1; padding:0;
}
.tag button:hover{ opacity:1; }
.tag-add{ display:flex; gap:8px; margin-top:4px; }
.tag-add input{ flex:1; }

textarea, input[type="text"], input[type="date"], input[type="time"], input[type="tel"], input[type="email"], input[type="number"], select{
  width:100%; padding:8px 11px; border-radius:var(--radius-s); border:1px solid var(--border);
  background:var(--bg-elevated); color:var(--text); font-family:var(--font-body); font-size:13.8px;
}
textarea:focus, input:focus, select:focus{ outline:2px solid var(--accent); outline-offset:1px; }
textarea{ min-height:88px; resize:vertical; font-family:var(--font-body); }
label{ font-size:12.5px; color:var(--text-muted); display:block; margin-bottom:5px; }
.field{ margin-bottom:14px; }
.form-grid{ display:grid; grid-template-columns:1fr 1fr; gap:14px 16px; }
.form-grid .full{ grid-column:1 / -1; }

.btn{
  appearance:none; border:1px solid var(--border-strong); background:var(--bg-elevated); color:var(--text);
  padding:8px 14px; border-radius:var(--radius-s); font-family:var(--font-body); font-size:13px; font-weight:500;
  cursor:pointer; display:inline-flex; align-items:center; gap:6px;
}
.btn:hover{ background:var(--surface-2); }
.btn-primary{ background:var(--accent); border-color:var(--accent); color:var(--accent-contrast); }
.btn-primary:hover{ background:var(--accent-strong); border-color:var(--accent-strong); }
.btn-ghost{ border-color:transparent; background:none; }
.btn-ghost:hover{ background:var(--surface-2); }
.btn-danger{ color:var(--danger); border-color:var(--danger-soft); }
.btn-danger:hover{ background:var(--danger-soft); }
.btn-block{ width:100%; justify-content:center; }
.btn-sm{ padding:5px 10px; font-size:12px; }
.btn:disabled{ opacity:0.5; cursor:not-allowed; }

.entry-list{ display:flex; flex-direction:column; gap:10px; }
.entry-card{ border:1px solid var(--border); border-radius:var(--radius-m); padding:14px 16px; background:var(--bg-elevated); }
.entry-card-top{ display:flex; justify-content:space-between; align-items:flex-start; gap:10px; }
.entry-date{ font-family:var(--font-mono); font-size:12.5px; color:var(--accent-strong); font-weight:500; }
.entry-title{ font-size:14.5px; font-weight:600; margin:2px 0 4px; }
.entry-detail{ font-size:13px; color:var(--text-muted); margin:2px 0; }
.entry-detail b{ color:var(--text); font-weight:500; }
.entry-actions{ display:flex; gap:6px; flex-shrink:0; }
.entry-title a{ color:var(--text); text-decoration:none; }
.entry-title a:hover{ color:var(--accent-strong); text-decoration:underline; }

/* ---------- Protocolli riabilitativi ---------- */
.protocol-card{ border:1px solid var(--border); border-radius:var(--radius-m); padding:14px 16px; background:var(--bg-elevated); margin-bottom:14px; }
.protocol-card:last-child{ margin-bottom:0; }
.protocol-meta{ font-size:12.5px; color:var(--text-muted); margin:2px 0 0; }
.phase-list{ display:flex; flex-direction:column; gap:8px; margin-top:12px; }
.phase-row{ border:1px solid var(--border); border-radius:var(--radius-s); padding:9px 11px; background:var(--surface); }
.phase-row.stato-completata{ opacity:0.68; }
.phase-row-top{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.phase-stato-select{ width:auto; min-width:118px; padding:4px 8px; font-size:12px; min-height:0; }
.phase-name{ font-weight:600; font-size:13.5px; flex:1 1 160px; }
.phase-durata{ font-family:var(--font-mono); font-size:11px; color:var(--text-faint); white-space:nowrap; }
.phase-actions{ display:flex; gap:2px; flex-shrink:0; margin-left:auto; }
.phase-detail{ font-size:12.5px; color:var(--text-muted); margin:6px 0 0; }
.phase-detail b{ color:var(--text); font-weight:500; }
.protocol-add-phase{ margin-top:10px; }

.calendar-day-group{ margin-bottom:20px; }
.calendar-day-group:last-child{ margin-bottom:0; }
.calendar-day-heading{ font-family:var(--font-display); font-size:15px; font-weight:600; margin:0 0 8px; text-transform:capitalize; color:var(--text-muted); }
.appt-card .entry-actions{ flex-wrap:wrap; }

.cal-subtoggle{ width:200px; }

.week-nav{ display:flex; align-items:center; justify-content:center; gap:14px; margin-bottom:14px; flex-wrap:wrap; }
.week-nav-label{ font-family:var(--font-display); font-size:15px; font-weight:600; min-width:220px; text-align:center; text-transform:capitalize; }
.week-grid-scroll{ overflow-x:auto; border:1px solid var(--border); border-radius:var(--radius-m); }
.week-grid{ display:grid; grid-template-columns:56px repeat(7, minmax(120px, 1fr)); min-width:760px; }
.week-grid-row{ display:contents; }
.week-grid-corner{ border-bottom:1px solid var(--border); border-right:1px solid var(--border); background:var(--bg-elevated); position:sticky; top:0; z-index:2; }
.week-day-head{
  border-bottom:1px solid var(--border); border-right:1px solid var(--border); background:var(--bg-elevated);
  padding:8px 10px; text-align:center; position:sticky; top:0; z-index:1;
}
.week-day-head.is-today{ background:var(--accent-soft, var(--surface-2)); }
.week-day-name{ font-size:11px; text-transform:uppercase; letter-spacing:0.03em; color:var(--text-faint); }
.week-day-num{ font-family:var(--font-display); font-size:14.5px; font-weight:600; margin-top:1px; }
.week-day-head.is-today .week-day-num{ color:var(--accent-strong); }
.week-day-add{
  appearance:none; border:none; background:none; color:var(--text-faint); cursor:pointer; font-size:14px;
  position:absolute; top:6px; right:6px; line-height:1; padding:2px 5px; border-radius:var(--radius-s);
}
.week-day-add:hover{ background:var(--surface-2); color:var(--accent-strong); }
.week-grid-time{
  border-right:1px solid var(--border); border-top:1px solid var(--border); background:var(--bg-elevated);
  font-family:var(--font-mono); font-size:10.5px; color:var(--text-faint); padding:4px 6px; text-align:right;
}
.week-grid-cell{
  border-right:1px solid var(--border); border-top:1px solid var(--border); min-height:44px; padding:2px;
  display:flex; flex-direction:column; gap:2px; cursor:pointer;
}
.week-grid-cell:hover{ background:var(--surface-2); }
.week-appt{
  border-radius:6px; padding:2px 6px; font-size:11px; line-height:1.35; cursor:pointer; overflow:hidden;
  white-space:nowrap; text-overflow:ellipsis;
}
.week-appt-time{ font-family:var(--font-mono); font-weight:600; margin-right:4px; }
.week-appt.good{ background:var(--good-soft); color:var(--good); }
.week-appt.muted{ background:var(--surface-2); color:var(--text-muted); }
.week-appt.warn{ background:var(--warn-soft); color:var(--warn-strong,var(--warn)); }
.week-appt.danger{ background:var(--danger-soft); color:var(--danger); }
@media (max-width:600px){
  .week-nav-label{ min-width:0; font-size:13.5px; }
}

table.data-table{ width:100%; border-collapse:collapse; font-size:13.5px; }
table.data-table th{ text-align:left; font-size:11.5px; text-transform:uppercase; letter-spacing:0.03em; color:var(--text-faint); padding:0 10px 8px; font-weight:500; }
table.data-table td{ padding:11px 10px; border-top:1px solid var(--border); vertical-align:top; }
.table-wrap{ overflow-x:auto; border:1px solid var(--border); border-radius:var(--radius-m); background:var(--bg-elevated); }
table.data-table tr:first-child td{ border-top:none; }

.badge{ display:inline-flex; align-items:center; padding:3px 9px; border-radius:999px; font-size:11.5px; font-weight:500; }
.badge.good{ background:var(--good-soft); color:var(--good); }
.badge.muted{ background:var(--surface-2); color:var(--text-muted); }
.badge.warn{ background:var(--warn-soft); color:var(--warn-strong,var(--warn)); }
.badge.danger{ background:var(--danger-soft); color:var(--danger); }

.sedute-pill{
  appearance:none; border:none; cursor:pointer; display:inline-flex; align-items:center;
  padding:3px 9px; border-radius:999px; font-size:11.5px; font-weight:500; font-family:var(--font-body);
}
.sedute-pill.good{ background:var(--good-soft); color:var(--good); }
.sedute-pill.muted{ background:var(--surface-2); color:var(--text-muted); }
.sedute-pill.warn{ background:var(--warn-soft); color:var(--warn-strong,var(--warn)); }
.sedute-pill:hover{ filter:brightness(0.96); }
.seduta-list{ display:flex; flex-direction:column; gap:2px; max-height:340px; overflow-y:auto; margin-bottom:4px; }
.seduta-row{
  display:flex; align-items:center; gap:10px; padding:8px 6px; border-radius:var(--radius-s); cursor:pointer;
}
.seduta-row:hover{ background:var(--surface-2); }
.seduta-row input[type="checkbox"]{ width:17px; height:17px; accent-color:var(--accent); flex-shrink:0; cursor:pointer; }
.seduta-num{ font-size:13.5px; flex:1; }
.seduta-row.done .seduta-num{ color:var(--text-muted); }
.seduta-date{ font-family:var(--font-mono); font-size:11.5px; color:var(--text-faint); }

.empty-hint{ color:var(--text-faint); font-size:13px; padding:14px 2px; }

/* ---------- Modal ---------- */
.modal-overlay{
  position:fixed; inset:0; background:rgba(20,17,12,0.42); display:flex; align-items:flex-start; justify-content:center;
  padding:40px 16px; overflow-y:auto; z-index:1000;
}
.modal-panel{
  background:var(--bg-elevated); border-radius:var(--radius-l); box-shadow:var(--shadow); width:100%; max-width:560px;
  padding:24px 26px 26px; border:1px solid var(--border);
}
.modal-head{ display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:16px; gap:10px; }
.modal-title{ font-family:var(--font-display); font-size:19px; font-weight:600; margin:0; }
.modal-close{ appearance:none; background:none; border:none; font-size:18px; cursor:pointer; color:var(--text-muted); line-height:1; padding:2px; }
.modal-actions{ display:flex; justify-content:flex-end; gap:8px; margin-top:20px; }
.modal-note{ font-size:13.5px; color:var(--text-muted); line-height:1.55; }

/* ---------- Consenso e firma digitale ---------- */
.signature-pad-wrap{ display:flex; flex-direction:column; align-items:flex-start; gap:8px; }
.signature-pad{
  width:100%; height:160px; border:1.5px dashed var(--border-strong); border-radius:var(--radius-m);
  background:var(--surface); cursor:crosshair; touch-action:none; display:block;
}
.consent-meta{ font-size:13px; color:var(--text-muted); margin:0 0 12px; }
.consent-text-view{
  font-size:13.5px; line-height:1.6; white-space:pre-wrap; background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius-m); padding:14px 16px; max-height:280px; overflow-y:auto; margin-bottom:16px;
}
.signature-preview{ border-top:1px solid var(--border); padding-top:12px; }
.signature-preview img{ max-width:220px; max-height:100px; display:block; background:var(--surface); border-radius:var(--radius-s); }
.signature-preview-label{ font-size:11.5px; color:var(--text-faint); margin:0 0 6px; text-transform:uppercase; letter-spacing:0.03em; }

#print-consent-content{ display:none; }
@media print{
  body.printing-consent > *:not(#print-consent-content){ display:none !important; }
  body.printing-consent #print-consent-content{
    display:block !important; padding:24px; color:#000; background:#fff; font-family:Georgia,serif;
  }
  body.printing-consent #print-consent-content h1{ font-size:19px; margin:0 0 14px; }
  body.printing-consent #print-consent-content p{ font-size:13px; margin:0 0 6px; }
  body.printing-consent .print-consent-text{ white-space:pre-wrap; line-height:1.55; margin:16px 0; font-size:12.5px; }
  body.printing-consent .print-consent-signature{ margin-top:24px; }
  body.printing-consent .print-consent-signature img{ max-width:240px; border-top:1px solid #999; padding-top:6px; }
}

@media (max-width:880px){
  #sidebar{ width:100%; flex:1 1 auto; border-right:none; }
  #app{ position:relative; }
  #app.show-detail #sidebar{ display:none; }
  #app:not(.show-detail) #main-panel{ display:none; }
  .mobile-only{ display:inline-flex; }
  .panel-inner{ padding:20px 16px 50px; }
  .form-grid{ grid-template-columns:1fr; }
  .stat-row{ grid-template-columns:1fr 1fr; }
}
@media (prefers-reduced-motion: reduce){ *{ animation:none !important; transition:none !important; } }

/* ============================================================
   Login / blocco / stati di caricamento — nuovi nel passaggio al
   backend (task #5): stesso linguaggio visivo dell'app (colori,
   bordi, radius, tipografia) applicato a schermate che prima non
   esistevano, perché prima non c'era autenticazione né una rete da
   attendere.
   ============================================================ */
.auth-screen{
  min-height:100vh; width:100%; display:flex; align-items:center; justify-content:center;
  background:var(--bg); padding:24px;
}
.auth-card{
  width:100%; max-width:380px; background:var(--bg-elevated); border:1px solid var(--border);
  border-radius:var(--radius-l); box-shadow:var(--shadow); padding:30px 28px 28px;
}
.auth-card .brand{ justify-content:center; margin-bottom:18px; }
.auth-card .brand-name{ font-size:21px; }
.auth-card h1{ font-family:var(--font-display); font-size:19px; font-weight:600; margin:0 0 6px; text-align:center; }
.auth-card p.auth-sub{ color:var(--text-muted); font-size:13.5px; text-align:center; margin:0 0 20px; }
.auth-error{
  background:var(--danger-soft); color:var(--danger); border-radius:var(--radius-s); padding:9px 12px;
  font-size:13px; margin-bottom:14px;
}
.auth-card .field{ margin-bottom:12px; }
.auth-card .btn-block{ margin-top:6px; }

/* Overlay di blocco: copre l'app (che resta montata sotto, dati in
   memoria) invece di smontarla — bloccare non deve far perdere una
   modifica in corso. */
#lock-overlay{
  position:fixed; inset:0; z-index:2000; background:rgba(20,17,12,0.55);
  display:flex; align-items:center; justify-content:center; padding:24px;
  backdrop-filter:blur(2px);
}
#lock-overlay .auth-card{ max-width:340px; }

/* Banner di stato (caricamento / errore / offline) mostrati al posto
   del contenuto di una sezione, senza far scomparire il resto
   dell'interfaccia intorno. */
.state-banner{
  display:flex; align-items:center; gap:10px; padding:14px 16px; border-radius:var(--radius-m);
  font-size:13.5px; margin:0 0 16px;
}
.state-banner.loading{ background:var(--surface-2); color:var(--text-muted); }
.state-banner.error{ background:var(--danger-soft); color:var(--danger); }
.state-banner.offline{ background:var(--warn-soft); color:var(--warn-strong,var(--warn)); }
.state-banner .spinner{
  width:14px; height:14px; border-radius:50%; border:2px solid currentColor; border-top-color:transparent;
  animation:spin 0.7s linear infinite; flex-shrink:0;
}
@keyframes spin{ to{ transform:rotate(360deg); } }
.state-banner .btn{ margin-left:auto; flex-shrink:0; }
.full-panel-state{ padding:60px 16px; display:flex; justify-content:center; }
.full-panel-state .state-banner{ margin:0; }

/* Banner di rete offline, persistente in cima all'app quando presente. */
#offline-banner{
  background:var(--warn-strong,var(--warn)); color:#fff; text-align:center; font-size:12.5px;
  padding:6px 10px; display:none;
}
#offline-banner.visible{ display:block; }

/* ---------- Allegati reali ---------- */
.attachment-list{ display:flex; flex-direction:column; gap:6px; margin:8px 0 4px; }
.attachment-row{
  display:flex; align-items:center; gap:8px; padding:6px 8px; border-radius:var(--radius-s);
  background:var(--surface); border:1px solid var(--border); font-size:12.5px;
}
.attachment-row a{ color:var(--text); font-weight:500; text-decoration:none; flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.attachment-row a:hover{ color:var(--accent-strong); text-decoration:underline; }
.attachment-row .attachment-size{ color:var(--text-faint); font-family:var(--font-mono); font-size:11px; flex-shrink:0; }
.file-drop-hint{ font-size:12px; color:var(--text-faint); margin-top:4px; }
.btn[disabled], button[disabled]{ opacity:0.55; cursor:not-allowed; }
