/* AnalgoCard — Clinical Precision System (design Stitch, reimplementato vanilla).
   Niente font esterni render-blocking: Inter se presente, altrimenti system-ui. */
:root {
  --navy: #1f4e79; --navy-deep: #00375e; --navy-700:#184974;
  --teal: #006a6a; --teal-bg: #cdeceb;
  --app-bg: #f7f9fb; --surface: #ffffff; --surface-2: #f1f5f9;
  --line: #e2e8f0; --line-strong: #cbd5e1;
  --ink: #191c1e; --sub: #42474f; --muted: #6b7280;
  --ok: #006a6a; --ok-bg: #cdeceb;
  --warn: #9a6b00; --warn-bg: #fdf2dc; --warn-line: #e6c265;
  --err: #ba1a1a;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
  --radius: 4px;
  --shadow: 0 1px 3px 0 rgba(16,24,40,.08), 0 1px 2px -1px rgba(16,24,40,.08);
  --sidebar-w: 240px;
  --fs-base: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: var(--fs-base);
  color: var(--ink); background: var(--app-bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* ===================== Shell: sidebar + main + bottomnav ===================== */
.shell { min-height: 100%; }
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--navy); color: #cfe0f3; display: flex; flex-direction: column;
  padding: 18px 12px; z-index: 40;
}
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.sb-logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 7px; background: rgba(255,255,255,.12); color: #fff; }
.sb-name { color: #fff; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; line-height: 1.05; display: flex; flex-direction: column; }
.sb-name small { font-weight: 500; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: #9bb6d6; margin-top: 3px; }
.sb-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.sb-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  border: none; background: none; cursor: pointer; text-align: left;
  color: #b9cbe2; padding: 10px 12px; border-radius: 6px;
  font-size: 14px; font-weight: 500; position: relative;
}
.sb-item svg { flex: 0 0 auto; opacity: .9; }
.sb-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.sb-item.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.sb-item.active::before { content: ""; position: absolute; left: -12px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: #7cd5d5; }
.sb-foot { margin-top: auto; padding: 12px 10px 4px; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: #7e9bbd; }

.main { margin-left: var(--sidebar-w); min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px;
  height: 60px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .spacer { flex: 1; }
.tb-search { display: flex; align-items: center; gap: 9px; flex: 1; max-width: 460px;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px; height: 38px; background: var(--surface); color: var(--muted); }
.tb-search:focus-within { border-color: var(--navy); }
.tb-search input { border: none; outline: none; flex: 1; font-size: 14px; font-family: var(--font); color: var(--ink); background: none; }
.tb-user { display: flex; align-items: center; gap: 12px; }
.tb-who { font-size: 13px; color: var(--sub); font-weight: 600; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.iconbtn { border: none; background: none; color: var(--muted); cursor: pointer; padding: 7px; border-radius: 6px; display: grid; place-items: center; }
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }

.app { flex: 1; padding: 24px; max-width: 1200px; width: 100%; }
/* Modalità confronto: usa TUTTA la larghezza dello schermo (niente cap a 1200px) */
.app:has(.confronto) { max-width: none; padding: 16px 20px; }
.bare { display: grid; place-items: center; min-height: 100%; padding: 24px; }
.loading { color: var(--muted); }

/* Bottom nav (mobile) */
.bottomnav { display: none; }
.bottomnav .navitem {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: none; background: none; cursor: pointer; padding: 9px 4px 8px; color: var(--muted); font-size: 11px; font-weight: 600;
}
.bottomnav .navitem.active { color: var(--navy); }

/* ===================== Tipografia & comuni ===================== */
h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.page-sub { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.section-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 16px; font-size: 14px; font-weight: 600; font-family: var(--font); background: var(--surface); color: var(--ink); cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-primary:hover { background: var(--navy-deep); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { flex: 0 0 auto; }

/* bottone-icona (es. cestino in lista). danger = azione distruttiva. */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border: 1px solid transparent; border-radius: var(--radius); background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.danger:hover { background: #fdecec; border-color: #f3b4b4; color: #b42318; }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }
.patient-table td.col-act { width: 44px; text-align: center; padding-left: 0; padding-right: 8px; }

/* spunta di validazione per-campo (modalità confronto) */
.vtick { margin-left: auto; flex: 0 0 auto; width: 22px; height: 22px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.vtick:hover { border-color: #2e7d4f; color: #2e7d4f; }
.vtick.on { background: #e9f5ee; border-color: #2e7d4f; color: #2e7d4f; }
.rfield.is-validated input, .rfield.is-validated select, .rfield.is-validated textarea { border-color: #bfe3cc; background: #f4fbf6; }

/* MODALE RIUSABILE — regola di design: mai alert/confirm/prompt del browser */
.modal-overlay { position: fixed; inset: 0; background: rgba(18,24,33,.45); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal { background: var(--surface); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.28); width: min(460px, 100%); max-height: 90vh; overflow: auto; }
.modal-h { padding: 14px 18px; font-weight: 700; font-size: 16px; border-bottom: 1px solid var(--line); }
.modal-b { padding: 16px 18px; color: var(--ink); font-size: 14px; line-height: 1.5; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }
.pdf-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pdf-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.pdf-list li .btn { padding: 5px 12px; }
.btn-danger { background: #b42318; color: #fff; border-color: #b42318; }
.btn-danger:hover { background: #962014; }

/* Burger + collapse sidebar (sfrutta lo schermo; auto in modalità confronto) */
.burger { display: grid; }
.shell.sidebar-collapsed .sidebar { display: none; }
.shell.sidebar-collapsed .main { margin-left: 0; }
@media (max-width: 900px) { .burger { display: none; } } /* su mobile naviga la bottom-nav */

/* Pannello "anteprima stampabile" — 3ª colonna a destra della replica, desktop largo */
.preview-pane { display: none; }
/* niente altezza fissa/sticky: l'iframe si auto-dimensiona al contenuto (no scroll interno);
   scorre la pagina, e il pannello risulta lungo quanto la replica */
.preview-pane .preview-doc { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.preview-pane iframe { display: block; border: 0; background: #fff; transform-origin: top left; }
.pv-refresh { font-size: 16px; line-height: 1; }
/* .shell .X per vincere sul cascade della .confronto base (2 colonne) definita più sotto */
@media (min-width: 1200px) {
  /* replica centrale più stretta; anteprima più larga (e si scala per stare intera) */
  .shell .confronto { grid-template-columns: minmax(0, 0.85fr) minmax(0, 0.95fr) minmax(0, 1.25fr); }
  .shell .preview-pane { display: block; }
  /* doc-pane collassato → colonna stretta di anteprime; review e anteprima a PARI larghezza */
  .shell .confronto:has(.doc-pane.collapsed) { grid-template-columns: 92px minmax(0, 1fr) minmax(0, 1fr); }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 20px 22px; box-shadow: var(--shadow); }

/* Page header (titolo + azione) */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }

/* ===================== KPI stat cards ===================== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 26px; font-weight: 600; margin-top: 6px; color: var(--ink); }

/* ===================== Tabella pazienti ===================== */
.tbl-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; }
.patient-table { width: 100%; border-collapse: collapse; }
.patient-table th { text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  background: #f8fafc; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.patient-table td { padding: 11px 16px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.patient-table tr:last-child td { border-bottom: none; }
.patient-table tbody tr[role=button] { cursor: pointer; }
.patient-table tbody tr[role=button]:hover { background: var(--surface-2); }
.patient-table .num { font-family: var(--mono); font-size: 13px; color: var(--sub); }
.cell-patient { display: flex; align-items: center; gap: 11px; }
.ini { width: 30px; height: 30px; border-radius: 50%; background: #e8eef6; color: var(--navy); display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: 0 0 auto; }
.cell-patient .nm { font-weight: 600; }
.empty { color: var(--muted); padding: 40px 16px; text-align: center; }
.empty .ico { display: grid; place-items: center; margin-bottom: 10px; color: var(--line-strong); }

/* Status pills */
.status { display: inline-block; font-size: 11px; font-weight: 700; border-radius: 3px; padding: 3px 9px; letter-spacing: .01em; }
.status-bozza { color: #475569; background: #eef2f6; }
.status-estratto { color: var(--teal); background: var(--teal-bg); }
.status-convalidato { color: var(--navy); background: #dbe7f6; }

/* ===================== Form ===================== */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.form-row input[type=text], .form-row input[type=password], .form-row input[type=date], .form-row input[type=search], .form-row textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 11px; font-size: 14px; font-family: var(--font); color: var(--ink); background: var(--surface); }
.form-row input:focus, .form-row textarea:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(31,78,121,.1); }
.form-row textarea { min-height: 60px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }

/* Dropzone */
.dropzone { border: 1.5px dashed var(--line-strong); border-radius: 6px; padding: 26px; text-align: center; color: var(--sub); background: #fbfcfe; cursor: pointer; font-size: 14px; }
.dropzone:hover, .dropzone.drag { border-color: var(--navy); background: #f3f7fc; }
.dropzone .dz-ico { color: var(--navy); margin-bottom: 8px; display: grid; place-items: center; }
.file-list { list-style: none; margin: 12px 0 0; padding: 0; font-size: 14px; }
.file-list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.file-list li:last-child { border-bottom: none; }
.file-list .sz { color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* Estrazione AI */
.extract-bar { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.extract-status { font-size: 13px; color: var(--sub); display: inline-flex; align-items: center; }
/* evidenza "AI sta scansionando": spinner + stato per-documento (spinner sul corrente, ✓ verde sui fatti) */
.ai-scan { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--navy); border-right-color: transparent; border-radius: 50%; animation: ai-spin .7s linear infinite; margin-right: 6px; vertical-align: -2px; }
.ai-scan.sm { width: 11px; height: 11px; border-width: 2px; margin: 0; }
.ai-scan.light { border-color: #fff; border-right-color: transparent; }
@keyframes ai-spin { to { transform: rotate(360deg); } }
.file-st { display: inline-flex; align-items: center; }
.file-ok { color: #2e7d4f; font-weight: 800; }
.file-retry { color: #b07a00; font-weight: 800; }
.file-list li { position: relative; overflow: hidden; transition: background .2s; }
.file-list li.fi-running { background: #eef4fb; }
.file-list li.fi-running::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 40%; background: linear-gradient(90deg, transparent, rgba(31,78,121,.18), transparent); animation: ai-scanline 1.1s linear infinite; }
.file-list li.fi-done { background: #f4fbf6; }
@keyframes ai-scanline { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }
/* stato analisi sulle thumbnail del confronto */
.thumb-status { position: absolute; top: 2px; left: 2px; min-width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; border-radius: 4px; z-index: 2; }
.doc-thumb.thumb-done .thumb-status { background: #2e7d4f; color: #fff; }
.doc-thumb.thumb-running .thumb-status { background: rgba(31,78,121,.9); padding: 2px 3px; }
.doc-thumb.thumb-done { box-shadow: 0 0 0 2px #2e7d4f inset; }
.fbadge { margin-left: 8px; font-size: 10px; font-weight: 700; border-radius: 3px; padding: 1px 7px; }
.form-row.is-ok .fbadge { color: var(--ok); background: var(--ok-bg); }
.form-row.is-uncertain .fbadge, .form-row.is-missing .fbadge { color: var(--warn); background: var(--warn-bg); }
.form-row.is-uncertain input { border-color: var(--warn-line); background: var(--warn-bg); }
.form-row.is-missing input { border-style: dashed; border-color: var(--warn-line); background: var(--warn-bg); }

/* Login */
.login-wrap { width: 100%; max-width: 380px; }
.login-brand { display: flex; align-items: center; gap: 11px; justify-content: center; margin-bottom: 6px; }
.login-brand .lg { width: 40px; height: 40px; border-radius: 9px; background: var(--navy); color: #fff; display: grid; place-items: center; }
.login-brand .nm { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; color: var(--navy); }
.login-wrap .sub { text-align: center; color: var(--muted); margin: 0 0 20px; font-size: 13px; }

/* Personalizzazioni */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg-btn { border: none; background: var(--surface); padding: 8px 18px; cursor: pointer; font-size: 14px; color: var(--ink); font-family: var(--font); }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.on { background: var(--navy); color: #fff; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-row label { margin-bottom: 0; }
.toggle-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--navy); }
.ai-state .chip { font-size: 11px; font-weight: 700; border-radius: 3px; padding: 3px 9px; }
.ai-state .chip.ok { color: var(--ok); background: var(--ok-bg); }
.ai-state .chip.warn { color: var(--warn); background: var(--warn-bg); }
.settings-saved { color: var(--ok); font-weight: 600; font-size: 13px; opacity: 0; transition: opacity .2s; margin-top: 8px; }
.settings-saved.show { opacity: 1; }

.link { color: var(--navy); background: none; border: none; cursor: pointer; font-size: 13px; padding: 0; font-family: var(--font); }
.error-msg { color: var(--err); font-size: 13px; margin: 8px 0; min-height: 1em; }
.crumb { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 14px; }
.muted { color: var(--muted); }

/* ===================== Modalità confronto (M3) ===================== */
.confronto { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; align-items: start; }
.pane-h { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.pane-h .spacer { flex: 1; }
.pane-h .btn { padding: 5px 12px; font-size: 12px; }
.tag-form { font-size: 10px; color: #fff; background: var(--navy); border-radius: 3px; padding: 2px 7px; letter-spacing: .02em; }
/* sinistra: documento sorgente, sticky */
.doc-pane { position: sticky; top: 76px; }
.doc-frame { border: 1px solid var(--line); border-radius: 6px; background: #fff; box-shadow: var(--shadow); height: 62vh; overflow: auto; cursor: grab; }
.doc-frame.grabbing { cursor: grabbing; }
.doc-pane.dragover .doc-frame { border-color: var(--navy); background: #eef4fb; box-shadow: 0 0 0 3px rgba(31,78,121,.12); }
/* miniature dei documenti del set (sotto il viewer) */
.doc-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.doc-thumb { position: relative; width: 60px; height: 60px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; cursor: pointer; background: #fff; display: grid; place-items: center; color: var(--muted); }
.doc-thumb .thumb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.doc-thumb.active { border-color: var(--navy); box-shadow: 0 0 0 2px rgba(31,78,121,.25); }
.doc-thumb:hover { border-color: var(--navy); }
.thumb-edit { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 4px;
  background: rgba(255,255,255,.92); color: #1c2430; font-size: 14px; line-height: 16px; cursor: pointer; display: none; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.doc-thumb:hover .thumb-edit { display: block; }
@media (hover: none) { .thumb-edit { display: block; } }
/* badge tipo documento (classificazione tassonomica del set) */
.thumb-type { position: absolute; left: 2px; right: 2px; bottom: 2px; background: rgba(31,78,121,.88); color: #fff; font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; text-align: center; border-radius: 3px; padding: 1px 2px; line-height: 1.25; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
/* tag di classificazione (modale file): tipi candidati con probabilità */
.class-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.class-tag { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 12px; background: #eef2f7; color: var(--ink); border: 1px solid var(--line); }
.class-tag.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.class-tag b { font-weight: 800; }
.doc-frame img { display: block; user-select: none; -webkit-user-drag: none; }
.doc-frame > .doc-empty { display: grid; place-items: center; height: 100%; }
.doc-frame iframe { width: 100%; height: 100%; border: none; }
.doc-empty { color: var(--muted); padding: 30px; font-size: 13px; }
.doc-nav { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.doc-nav .doc-name { flex: 1; font-size: 12px; color: var(--sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-nav .btn { padding: 6px 12px; }
/* collasso del doc-pane: si riduce a una colonna verticale di anteprime, lo spazio va al review */
.doc-collapse { width: 24px; height: 24px; flex: 0 0 auto; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--navy); font-size: 13px; line-height: 1; cursor: pointer; }
.doc-collapse:hover { border-color: var(--navy); }
.doc-pane.collapsed .doc-frame,
.doc-pane.collapsed .doc-nav,
.doc-pane.collapsed #add-doc,
.doc-pane.collapsed .dp-title,
.doc-pane.collapsed #doc-pos { display: none; }
.doc-pane.collapsed .pane-h { margin-bottom: 8px; justify-content: center; }
.doc-pane.collapsed .doc-thumbs { flex-direction: column; flex-wrap: nowrap; gap: 8px; margin-top: 8px; align-items: center; }
/* destra: replica */
.replica-pane { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); padding: 14px 16px; }
.replica-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.rpage { border-top: 2px solid var(--line-strong); margin-top: 12px; }
.rpage:first-child { border-top: none; margin-top: 0; }
.rpage-h { font-size: 12px; font-weight: 700; color: var(--navy); letter-spacing: .04em; text-transform: uppercase; margin: 10px 0 6px; }
.rsec { margin-bottom: 12px; }
.rsec-h { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 3px; margin-bottom: 8px; }
.rfields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.rfield { display: flex; flex-direction: column; gap: 3px; }
.rfield.wide { grid-column: 1 / -1; }
.rfield label { font-size: 10.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.rfield input, .rfield select, .rfield textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; font-size: 13px; font-family: var(--font); color: var(--ink); background: #fff; }
.rfield textarea { resize: vertical; min-height: 38px; }
.rfield input:focus, .rfield select:focus, .rfield textarea:focus { outline: none; border-color: var(--navy); }
/* campo con dato di provenienza nota: indicatore + doppio clic apre il documento sorgente */
.rfield.has-src > label::after { content: '↗'; font-size: 10px; color: var(--navy); margin-left: 4px; opacity: .65; }
.rfield.has-src { cursor: help; }
/* campo data: input testo gg/mm/aaaa + bottone calendario (datepicker nativo) */
.date-wrap { position: relative; display: flex; align-items: stretch; gap: 4px; width: 100%; }
.date-wrap .date-text { flex: 1 1 auto; min-width: 0; width: auto; }
.date-cal { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 32px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--muted); cursor: pointer; }
.date-cal:hover { border-color: var(--navy); color: var(--navy); }
/* input date nativo: in layout (per showPicker) ma visivamente nascosto, ancorato al bottone */
.date-wrap .date-native { position: absolute; right: 0; bottom: 0; width: 32px; height: 1px; opacity: 0; pointer-events: none; padding: 0; border: 0; }
.rfield.is-missing input, .rfield.is-missing select, .rfield.is-missing textarea { border-style: dashed; border-color: var(--warn-line); background: var(--warn-bg); }
.rfield.is-uncertain input, .rfield.is-uncertain select, .rfield.is-uncertain textarea { border-color: var(--warn-line); background: var(--warn-bg); }
.cls-tag { font-size: 9px; font-weight: 700; color: var(--sub); background: #eef2f6; border-radius: 3px; padding: 1px 5px; letter-spacing: .02em; }
.fbadge.b-ok { color: var(--ok); background: var(--ok-bg); }
.fbadge.b-warn, .fbadge.b-miss { color: var(--warn); background: var(--warn-bg); }
.fbadge.b-calc { color: var(--navy); background: #dbe7f6; }
.fbadge.b-man { color: #475569; background: #eef2f6; }
/* tabella lab — sempre scrollabile orizzontalmente (14 colonne non stanno in una colonna stretta) */
/* Valutazione preoperatoria: griglia a colonne OMOGENEE (5/riga), DATA a doppia larghezza
   (span 2) → 3 righe pulite, nessuno scroll, nessun campo stirato. Estetica = meno fatica visiva. */
.lab-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px 10px; align-items: end; }
.lab-cell { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lab-cell.lab-date { grid-column: span 2; } /* la data: doppia, ospita il datepicker */
@media (max-width: 640px) { .lab-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
/* set multipli (più giorni): ogni set è un blocco con header (data + valida + rimuovi) */
.lab-set { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; background: #fafbfc; }
.lab-set-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.lab-set-t { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.lab-set-tick { margin-left: auto; }
.lab-set-rm { flex: 0 0 auto; width: 26px; height: 26px; }
.lab-add { width: 100%; border-style: dashed; color: var(--navy); font-weight: 600; }
/* avviso CF duplicato (unicità: due pazienti non possono avere lo stesso codice fiscale) */
.cf-warn { background: var(--warn-bg); border: 1px solid var(--warn-line); color: #8a5300; border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 10px; }
.lab-cell > label { font-size: 9px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 3px; white-space: nowrap; min-height: 16px; }
.lab-cell > label .vtick { margin-left: auto; width: 18px; height: 18px; }
.lab-cell input, .lab-cell select { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 6px; font-size: 12px; font-family: var(--mono); color: var(--ink); background: #fff; }
.lab-cell input:focus, .lab-cell select:focus { outline: none; border-color: var(--navy); }
.lab-cell.is-validated input { border-color: #bfe3cc; background: #f4fbf6; }
.lab-cell.is-missing input { border-style: dashed; border-color: var(--warn-line); background: var(--warn-bg); }
.lab-cell .date-cal { width: 28px; }
.lab-cell .date-text { font-family: var(--mono); }
.replica-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.compl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.compl .chip { font-size: 11px; font-weight: 700; border-radius: 3px; padding: 2px 8px; }
.compl .chip.ok { color: var(--ok); background: var(--ok-bg); }
.compl .chip.warn { color: var(--warn); background: var(--warn-bg); }
.foot-actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 560px) { .foot-actions { width: 100%; } .foot-actions .btn { flex: 1 1 auto; } }

/* Anteprima stampabile (overlay) */
.preview-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(15,23,42,.55); display: flex; flex-direction: column; }
.preview-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
@media (max-width: 560px) { .preview-bar { padding: 8px 10px; } .preview-bar .btn { flex: 1 1 auto; } }
.preview-bar .spacer { flex: 1; }
.preview-bar .pv-title { font-weight: 600; font-size: 14px; color: var(--ink); }
.preview-frame { flex: 1; width: 100%; border: none; background: #e9edf1; }
@media (max-width: 560px) { .preview-bar .pv-title { display: none; } }

/* ===================== Responsive: mobile → bottom nav ===================== */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .app { padding: 16px; padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  /* il confronto ha selettore più specifico (.app:has(.confronto)) e azzererebbe il padding
     inferiore: qui lo ri-applichiamo così la bottom-nav fissa NON copre i bottoni in fondo */
  .app:has(.confronto) { padding: 16px; padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  .topbar { padding: 0 14px; height: 56px; }
  .tb-who { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex;
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .patient-table .col-upd { display: none; }
  .patient-table th, .patient-table td { padding: 10px 12px; }
  /* confronto: impila documento sopra, replica sotto. minmax(0,…) evita che l'immagine allarghi la colonna */
  .confronto { grid-template-columns: minmax(0, 1fr); }
  .doc-pane { position: static; }
  .doc-frame { height: 44vh; }
  .rfields { grid-template-columns: 1fr; }
}

/* Telefoni stretti: tabella -> schede impilate (niente overflow/clip orizzontale) */
@media (max-width: 560px) {
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .btn-primary { width: 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat .v { font-size: 22px; }

  .patient-table, .patient-table tbody, .patient-table tr, .patient-table td { display: block; }
  .patient-table thead { display: none; }
  .patient-table tr { position: relative; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .patient-table tr:last-child { border-bottom: none; }
  .patient-table td { padding: 0; border: none; }
  .patient-table td.col-upd { display: none; }
  /* riga 1: paziente; riga 2: meta inline con etichette */
  .patient-table td:nth-child(2), .patient-table td:nth-child(3) {
    display: inline-block; margin: 7px 14px 0 41px; font-size: 12px; color: var(--sub);
  }
  .patient-table td:nth-child(3) { margin-left: 0; }
  .patient-table td:nth-child(2)::before { content: "Nato: "; color: var(--muted); }
  .patient-table td:nth-child(3)::before { content: "Doc: "; color: var(--muted); }
  /* pill stato in alto a destra della scheda */
  .patient-table td:nth-child(4) { position: absolute; top: 12px; right: 14px; }
}

/* ===================== Personalizzazioni applicate (body) ===================== */
body.density-comfortable .card { padding: 26px 28px; }
body.density-comfortable .patient-table th, body.density-comfortable .patient-table td { padding: 14px 16px; }
body.density-comfortable .form-row { margin-bottom: 18px; }
body.text-large { --fs-base: 16px; }
body.text-large h1 { font-size: 25px; }
body.high-contrast { --line: #94a3b8; --line-strong: #64748b; --sub: #1f2937; --muted: #374151; --ink: #0a0e14; }
body.high-contrast .card, body.high-contrast .tbl-wrap, body.high-contrast .stat { border-width: 1.5px; }
