/*
 * Onboarding Medici — design system.
 *
 * Hand-written so the application has no build step and no CDN dependency:
 * a clinic can run it on an intranet with no outbound network access.
 */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --border: #e3e5ea;
  --border-strong: #cfd3db;
  --text: #171a20;
  --text-muted: #646b7a;
  --text-faint: #8b92a1;

  --accent: #1f5eff;
  --accent-dark: #1848c8;
  --accent-soft: #eaf0ff;

  --ok: #0f7b4a;
  --ok-soft: #e4f5ec;
  --warn: #9a6100;
  --warn-soft: #fdf1dc;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --info: #0b6a84;
  --info-soft: #e2f3f8;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(18, 22, 33, .06), 0 4px 14px rgba(18, 22, 33, .05);
  --shadow-lg: 0 8px 30px rgba(18, 22, 33, .12);

  --sidebar: 252px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1116;
    --surface: #171a21;
    --surface-2: #1d2029;
    --border: #282c36;
    --border-strong: #363b47;
    --text: #e8eaef;
    --text-muted: #a0a7b6;
    --text-faint: #767d8c;
    --accent: #6f95ff;
    --accent-dark: #8aa9ff;
    --accent-soft: #1b2440;
    --ok: #57c48a;
    --ok-soft: #14301f;
    --warn: #e5ad4e;
    --warn-soft: #33260e;
    --danger: #f0817a;
    --danger-soft: #3a1b18;
    --info: #63c2da;
    --info-soft: #11303a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 640; letter-spacing: -.011em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: .92rem; }
p { margin: 0 0 .9em; }

code, kbd, .mono { font-family: var(--mono); font-size: .86em; }

/* ---------------------------------------------------------------- layout */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px 28px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 16px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #7b3ff2);
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: .82rem; flex-shrink: 0;
}
.brand-name { font-weight: 650; font-size: .95rem; letter-spacing: -.01em; }
.brand-sub { font-size: .72rem; color: var(--text-faint); }

.nav-group { margin-top: 16px; }
.nav-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); font-weight: 650; padding: 0 10px; margin-bottom: 6px;
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .875rem; font-weight: 500;
  margin-bottom: 1px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.nav-item .count {
  font-size: .7rem; font-weight: 650; padding: 1px 6px; border-radius: 99px;
  background: var(--danger-soft); color: var(--danger);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 26px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }
.topbar-title { font-weight: 640; font-size: .98rem; }

.content { padding: 24px 26px 56px; max-width: 1400px; width: 100%; }

.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.page-head .spacer { flex: 1; }
.page-head p { color: var(--text-muted); margin: 2px 0 0; max-width: 68ch; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.card-head {
  padding: 13px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; background: var(--surface-2);
}
.card-head .spacer { flex: 1; }
.card-head h2, .card-head h3 { margin: 0; font-size: .95rem; }
.card-head .hint { font-size: .78rem; color: var(--text-faint); }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  background: var(--surface-2); display: flex; gap: 8px; align-items: center;
}

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }

/* ----------------------------------------------------------------- stats */

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 17px; box-shadow: var(--shadow);
  display: block;
}
a.stat:hover { border-color: var(--border-strong); text-decoration: none; }
.stat .label {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); font-weight: 650;
}
.stat .value { font-size: 1.85rem; font-weight: 680; letter-spacing: -.02em; margin-top: 3px; color: var(--text); }
.stat .meta { font-size: .78rem; color: var(--text-muted); }
.stat.danger .value { color: var(--danger); }
.stat.warn .value { color: var(--warn); }
.stat.ok .value { color: var(--ok); }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th {
  text-align: left; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-faint); font-weight: 650;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty { padding: 44px 20px; text-align: center; color: var(--text-muted); }
.empty .big { font-size: 1.6rem; margin-bottom: 6px; }

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px;
  font-size: .745rem; font-weight: 640; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent-dark); border-color: transparent; }
.badge .dot { width: 6px; height: 6px; border-radius: 99px; background: currentColor; }

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 7px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: .86rem; font-weight: 570; font-family: inherit;
  cursor: pointer; white-space: nowrap; line-height: 1.4;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled], .btn.disabled { opacity: .55; cursor: not-allowed; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 4px 10px; font-size: .79rem; }
.btn.lg { padding: 11px 22px; font-size: .95rem; }
.btn.block { width: 100%; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ----------------------------------------------------------------- forms */

.field { margin-bottom: 15px; }
.field > label, .field-label {
  display: block; font-size: .8rem; font-weight: 620;
  margin-bottom: 5px; color: var(--text);
}
.field .help { font-size: .78rem; color: var(--text-faint); margin-top: 4px; }
.field .error { font-size: .79rem; color: var(--danger); margin-top: 4px; font-weight: 550; }
.required { color: var(--danger); font-weight: 700; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="tel"], input[type="url"],
input[type="search"], input[type="file"], select, textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: .88rem; line-height: 1.5;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[disabled], select[disabled], textarea[disabled] { background: var(--surface-2); color: var(--text-faint); }
textarea { min-height: 88px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%), linear-gradient(135deg, var(--text-faint) 50%, transparent 50%); background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

.check { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 9px; font-size: .86rem; }
.check input[type="checkbox"], .check input[type="radio"] { margin: 3px 0 0; width: 15px; height: 15px; accent-color: var(--accent); flex-shrink: 0; }
.check label { font-weight: 500; }
.check .help { font-size: .78rem; color: var(--text-faint); display: block; }

.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-3 .span-3 { grid-column: span 3; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 18px; }
legend { font-size: .78rem; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); padding: 0 7px; }

.filters { display: flex; gap: 9px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { margin: 0; min-width: 150px; }
.filters .grow { flex: 1; min-width: 220px; }

/* ---------------------------------------------------------------- alerts */

.alert {
  padding: 11px 15px; border-radius: var(--radius-sm);
  margin-bottom: 16px; font-size: .875rem; font-weight: 500;
  border: 1px solid transparent; display: flex; gap: 10px; align-items: flex-start;
}
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* ------------------------------------------------------------------ misc */

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .8rem; }
.tiny { font-size: .74rem; }
.strong { font-weight: 640; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex.between { justify-content: space-between; }
.flex.wrap { flex-wrap: wrap; }
.flex.top { align-items: flex-start; }
.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }

.avatar {
  width: 34px; height: 34px; border-radius: 99px; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent-dark);
  display: grid; place-items: center; font-weight: 660; font-size: .78rem;
}
.avatar.sm { width: 26px; height: 26px; font-size: .68rem; }
.avatar.lg { width: 52px; height: 52px; font-size: 1.05rem; }

.progress { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; min-width: 70px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.progress.ok > span { background: var(--ok); }
.progress.warn > span { background: var(--warn); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  padding: 8px 14px; font-size: .865rem; font-weight: 570;
  color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); font-weight: 640; }
.tab .count { font-size: .72rem; color: var(--text-faint); margin-left: 4px; }

.dl { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 7px 16px; font-size: .875rem; }
.dl dt { color: var(--text-faint); font-weight: 550; }
.dl dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative; padding: 0 0 15px 20px;
  border-left: 2px solid var(--border); margin-left: 5px;
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ''; position: absolute; left: -6px; top: 4px;
  width: 10px; height: 10px; border-radius: 99px;
  background: var(--surface); border: 2px solid var(--border-strong);
}
.timeline li.done::before { background: var(--ok); border-color: var(--ok); }
.timeline li.active::before { background: var(--accent); border-color: var(--accent); }
.timeline .when { font-size: .74rem; color: var(--text-faint); }

.pagination { display: flex; gap: 4px; align-items: center; padding: 14px 18px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 5px 10px; border-radius: var(--radius-sm); font-size: .82rem;
  border: 1px solid var(--border); color: var(--text-muted);
}
.pagination a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.pagination .current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 620; }
.pagination .disabled { opacity: .45; }
.pagination .info { border: 0; margin-left: auto; color: var(--text-faint); }

/* --------------------------------------------------------- public pages  */

.public {
  min-height: 100vh; display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px 64px;
  background: var(--bg);
}
.public-inner { width: 100%; max-width: 760px; }
.public-inner.narrow { max-width: 430px; }
.public-head { text-align: center; margin-bottom: 26px; }
.public-head .brand-mark { margin: 0 auto 12px; width: 44px; height: 44px; font-size: 1rem; }
.public-head h1 { font-size: 1.4rem; }
.public-head p { color: var(--text-muted); }

.otp-input {
  font-family: var(--mono); font-size: 1.85rem; letter-spacing: .42em;
  text-align: center; padding: 14px 10px 14px 20px; font-weight: 600;
}

.doc-preview {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); width: 100%; height: 520px;
}
.doc-fallback { padding: 40px; text-align: center; color: var(--text-muted); }

.signed-doc {
  white-space: pre-wrap; font-size: .9rem; line-height: 1.7;
  padding: 18px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  max-height: 420px; overflow-y: auto;
}

.hash {
  font-family: var(--mono); font-size: .76rem; word-break: break-all;
  color: var(--text-muted); background: var(--surface-2);
  padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
}

.field-row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px;
  align-items: center; padding: 11px 0; border-bottom: 1px solid var(--border);
}
.field-row:last-child { border-bottom: 0; }

/* ---------------------------------------------------------------- mobile */

@media (max-width: 1080px) {
  .grid.cols-4, .grid.cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.side { grid-template-columns: minmax(0, 1fr); }
}

/* Il pulsante del menu esiste solo sul telefono. */
.menu-toggle { display: none; }
.solo-telefono { display: none !important; }
.sidebar-velo[hidden] { display: none; }

@media (max-width: 860px) {
  /* Il menu laterale diventa un pannello che entra da sinistra: la pagina
     comincia subito con il lavoro, e le voci sono a un tocco. */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    width: min(290px, 84vw); height: 100%;
    transform: translateX(-102%); transition: transform .2s ease;
    box-shadow: var(--shadow-lg); padding: 16px 12px 32px;
  }
  body.menu-aperto { overflow: hidden; }
  body.menu-aperto .sidebar { transform: none; }
  .sidebar-velo {
    position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .45);
  }
  .nav-item { padding: 10px 12px; font-size: .95rem; }

  .menu-toggle {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 38px; height: 38px; padding: 0 9px; flex-shrink: 0;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); cursor: pointer;
  }
  .menu-toggle span { display: block; height: 2px; border-radius: 2px; background: var(--text); }

  .solo-schermo-largo { display: none !important; }
  .solo-telefono { display: inline-flex !important; }
  .topbar { gap: 10px; padding: 9px 14px; }
  .topbar-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .content { padding: 16px 14px 44px; }
  .page-head { gap: 10px; margin-bottom: 16px; }
  .page-head h1 { font-size: 1.28rem; }
  .page-head .btn-row, .page-head > .flex { flex-wrap: wrap; }

  /* Sotto i 16px iOS ingrandisce la pagina a ogni tocco su un campo. */
  input[type="text"], input[type="email"], input[type="password"], input[type="number"],
  input[type="date"], input[type="datetime-local"], input[type="tel"], input[type="url"],
  input[type="search"], select, textarea { font-size: 16px; }

  /* Le tabelle scorrono di lato dentro la loro scheda, senza spingere la
     pagina; le schede senza contenitore scorrono anch'esse. */
  .card-body { overflow-x: auto; }
  table.data th, table.data td { padding: 9px 10px; }
  table.data .actions { flex-wrap: wrap; justify-content: flex-start; }

  table.data.a-schede thead { display: none; }
  table.data.a-schede, table.data.a-schede tbody, table.data.a-schede tr, table.data.a-schede td {
    display: block; width: 100%;
  }
  table.data.a-schede tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  table.data.a-schede tr:last-child { border-bottom: 0; }
  /* Il nome della colonna sta a sinistra, il valore scorre a destra così
     com'è, con tutto quello che contiene. */
  table.data.a-schede td {
    border: 0; padding: 4px 0 4px 38%; text-align: left; position: relative; min-height: 24px;
  }
  table.data.a-schede td::before {
    content: attr(data-label); position: absolute; left: 0; top: 6px; width: 35%;
    font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; line-height: 1.3;
    color: var(--text-faint); font-weight: 650;
  }
  table.data.a-schede td:not([data-label]), table.data.a-schede td[data-label=""],
  table.data.a-schede td:first-child { padding-left: 0; }
  table.data.a-schede td:not([data-label])::before, table.data.a-schede td[data-label=""]::before,
  table.data.a-schede td:first-child::before { display: none; }
  table.data.a-schede td:first-child { font-size: .95rem; padding-bottom: 6px; }
  table.data.a-schede td:empty { display: none; }
  table.data.a-schede .actions { justify-content: flex-start; }
  .card-head { flex-wrap: wrap; padding: 12px 14px; }
  .card-body { padding: 14px; }
  .card-foot { flex-wrap: wrap; }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .dl dd { margin-bottom: 8px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; }
  .filters .field { min-width: 0; flex: 1 1 calc(50% - 9px); }
  .filters .grow { flex-basis: 100%; }
  .doc-preview { height: 60vh; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.cols-5 { grid-template-columns: minmax(0, 1fr); }
  .form-grid, .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2, .form-grid.cols-3 .span-3 { grid-column: span 1; }
  .public { padding: 22px 16px 48px; }
}

@media print {
  .sidebar, .topbar, .btn, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .content { padding: 0; }
}

/* Incarichi con la loro decorrenza, uno per riga: la data sta accanto
   all'incarico a cui appartiene, perché altrimenti non si capisce di chi è. */
.incarichi-griglia {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr));
    gap: 6px 24px;
}

.incarico-riga {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 32px;
}

.incarico-riga .check {
    flex: 1;
    min-width: 0;
}

.incarico-riga .incarico-data {
    width: 148px;
    flex: none;
    padding: 4px 8px;
    font-size: 13px;
}

/* Il listino delle prestazioni si corregge dove lo si legge: le caselle stanno
   dentro la tabella e non somigliano a caselle finché non le si tocca, così la
   tabella resta leggibile come tabella. */
table.listino td { padding-block: 5px; }

table.listino input[type="text"] {
    width: 100%;
    padding: 5px 8px;
    font-size: 13.5px;
    border-color: transparent;
    background: transparent;
}

table.listino tr:hover input[type="text"] { border-color: var(--border); }

table.listino input[type="text"]:focus {
    border-color: var(--accent);
    background: var(--surface);
}

table.listino .col-stretta { width: 130px; }
table.listino .col-stretta input { font-variant-numeric: tabular-nums; }

/* I campi che tocca compilare al professionista, visti dall'ufficio: lo sfondo
   grigio dice di chi è il dato senza bisogno di una legenda per ogni riga. */
.campo-suo label,
.campo-suo legend { color: var(--text); }

.campo-suo input,
.campo-suo select,
.campo-suo textarea {
    background: var(--surface-2);
    border-style: dashed;
}

.campo-suo input:focus,
.campo-suo select:focus,
.campo-suo textarea:focus {
    background: var(--surface);
    border-style: solid;
}

.campo-suo-esempio {
    display: inline-block;
    padding: 0 6px;
    border: 1px dashed var(--border-strong);
    border-radius: 4px;
    background: var(--surface-2);
}

/* I segnaposto scrivibili nel testo di un modulo: si scelgono da un elenco,
   perché ricopiarli a memoria è il modo più rapido per scriverne uno sbagliato
   e accorgersene nel PDF già firmato. */
details.variabili { margin-top: 10px; }

details.variabili summary {
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.variabili-elenco {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
}

button.variabile {
    font-family: var(--mono);
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 99px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: pointer;
}

button.variabile:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--surface);
}

/* L'anteprima del modulo: si guarda come un foglio, non come codice. */
.anteprima-modulo {
    margin-top: 14px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.anteprima-testo {
    word-break: break-word;
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.6;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    margin: 8px 0;
    max-height: 420px;
    overflow: auto;
}

/* La guida: testo lungo da leggere, non una tabella da scorrere. */
.guida-elenco,
.guida-passi { margin: 8px 0 14px; padding-left: 22px; }
.guida-elenco li,
.guida-passi li { margin-bottom: 6px; line-height: 1.55; }

.guida-definizioni dt { padding-top: 9px; }
.guida-definizioni dd { line-height: 1.55; }

/* Il logo della struttura, dove si carica e dove si mostra. */
.logo-prova {
    margin-top: 10px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 50% / 16px 16px;
    text-align: center;
}

.logo-prova img { max-height: 90px; max-width: 100%; }

.brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    object-fit: contain;
    background: #fff;
}

/* L'editor del testo dei moduli: una barra e un foglio su cui scrivere. */
.editor-barra {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: var(--surface-2);
}

.editor-strumento {
    min-width: 28px;
    padding: 4px 8px;
    font-size: 12.5px;
    line-height: 1.2;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}

.editor-strumento:hover { background: var(--surface); border-color: var(--border); }
.editor-strumento.attivo { background: var(--surface); border-color: var(--accent); color: var(--accent); }

.editor-separa {
    width: 1px;
    height: 18px;
    margin: 0 3px;
    background: var(--border);
}

.editor-area {
    min-height: 240px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    background: var(--surface);
    font-size: 13.5px;
    line-height: 1.6;
    overflow-y: auto;
    max-height: 520px;
}

.editor-area:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.editor-area p { margin: 0 0 10px; }
.editor-area h2 { font-size: 17px; margin: 14px 0 8px; }
.editor-area h3 { font-size: 14.5px; margin: 12px 0 6px; }
.editor-area ul, .editor-area ol { margin: 0 0 10px; padding-left: 22px; }
.editor-area li { margin-bottom: 4px; }

.anteprima-testo p { margin: 0 0 9px; }
.anteprima-testo h2 { font-size: 16px; margin: 12px 0 7px; }
.anteprima-testo h3 { font-size: 14px; margin: 10px 0 5px; }
.anteprima-testo ul, .anteprima-testo ol { margin: 0 0 9px; padding-left: 22px; }
.anteprima-logo { max-height: 70px; max-width: 60%; }

/* Una casella di scelta piccola, per le righe fitte come quelle dei campi. */
select.sm, input.sm {
    padding: 4px 8px;
    font-size: .8rem;
}

/* Chi è entrato con un account, sulle pagine pubbliche: nome e uscita. */
.public-utente {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 10px;
    font-size: .82rem;
    color: var(--text-muted);
}

/* Gli allegati di un check, raggruppati per anno. */
.allegati-check {
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.allegati-anno {
    display: flex;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px dashed var(--border);
}

.allegati-anno:last-child { border-bottom: 0; }

.allegati-etichetta {
    flex-shrink: 0;
    width: 62px;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
    padding-top: 3px;
}

/*
 * Le scadenze passate.
 *
 * «danger» era già scritto in mezze pagine, ma nessuna regola lo colorava: la
 * riga diceva «scaduto» con lo stesso grigio di «scade fra tre anni», e la
 * differenza si vedeva solo aprendo l'allegato. La riga intera si tinge,
 * perché in un elenco di venti check l'occhio cerca il blocco rosso, non la
 * parola.
 */
.danger { color: var(--danger); }
.tiny.danger, .small.danger { color: var(--danger); font-weight: 600; }

.riga-scaduta { background: var(--danger-soft); }
.riga-scaduta > summary .strong { color: var(--danger); }

/* Il passaggio del mouse non deve cancellare il rosso: la riga evidenziata
   tornava bianca appena ci si passava sopra, cioè proprio mentre la si stava
   guardando. */
table.data tbody tr.riga-scaduta,
table.data tbody tr.riga-scaduta:hover { background: var(--danger-soft); }

/* Branche: una riga per branca, con le sedi per cui è accreditata. */
.branca-riga { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.branca-riga:last-child { border-bottom: 0; }
.branca-sedi { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }

@media (max-width: 860px) {
  .incarico-riga .incarico-data { width: 132px; font-size: 16px; }
  fieldset { padding: 12px; }
}
