:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #16181d;
  --muted: #5f6672;
  --faint: #8b929e;
  --accent: #3b5bdb;
  --accent-soft: #e8edff;
  --ok: #147a46;
  --ok-soft: #e3f5ea;
  --info: #1f6fb2;
  --info-soft: #e3f0fb;
  --warn: #a35b00;
  --warn-soft: #fdf1dd;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --purple: #6941c6;
  --purple-soft: #f1ebfd;
  --teal: #0a7356;
  --teal-soft: #ddf4ec;
  --orange: #b4470f;
  --orange-soft: #fdeadf;
  --slate: #4a5568;
  --slate-soft: #eceff3;
  --pink: #b0256c;
  --pink-soft: #fce8f2;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* Schemi di mapping */
  --flow: #c2410c;
  --flow-soft: #fff4ec;
  --flow-ring: #fbd5bd;
  --flow-line-muted: #c3c8d0;
  --flow-card-border: #e3e6eb;
  --flow-muted-soft: #f0f2f5;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #181b20;
    --surface-2: #1f2329;
    --border: #2b3038;
    --text: #e8eaee;
    --muted: #a3aab6;
    --faint: #737b87;
    --accent: #8ea2ff;
    --accent-soft: #1f2747;
    --ok: #5fd39a;
    --ok-soft: #12291d;
    --info: #74b4ef;
    --info-soft: #132433;
    --warn: #f1b45a;
    --warn-soft: #2e2311;
    --danger: #f2877d;
    --danger-soft: #331715;
    --purple: #b59cf5;
    --purple-soft: #241b38;
    --teal: #4fd1a5;
    --teal-soft: #10291f;
    --orange: #f59a62;
    --orange-soft: #36200f;
    --slate: #b3bdca;
    --slate-soft: #232830;
    --pink: #f28cc0;
    --pink-soft: #33172a;
    --shadow: none;
    --flow: #fb923c;
    --flow-soft: #3a2416;
    --flow-ring: #6b3a1c;
    --flow-line-muted: #4a515c;
    --flow-card-border: #2e333b;
    --flow-muted-soft: #23272e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317;
  --surface: #181b20;
  --surface-2: #1f2329;
  --border: #2b3038;
  --text: #e8eaee;
  --muted: #a3aab6;
  --faint: #737b87;
  --accent: #8ea2ff;
  --accent-soft: #1f2747;
  --ok: #5fd39a;
  --ok-soft: #12291d;
  --info: #74b4ef;
  --info-soft: #132433;
  --warn: #f1b45a;
  --warn-soft: #2e2311;
  --danger: #f2877d;
  --danger-soft: #331715;
  --purple: #b59cf5;
  --purple-soft: #241b38;
  --teal: #4fd1a5;
  --teal-soft: #10291f;
  --orange: #f59a62;
  --orange-soft: #36200f;
  --slate: #b3bdca;
  --slate-soft: #232830;
  --pink: #f28cc0;
  --pink-soft: #33172a;
  --shadow: none;
  --flow: #fb923c;
  --flow-soft: #3a2416;
  --flow-ring: #6b3a1c;
  --flow-line-muted: #4a515c;
  --flow-card-border: #2e333b;
  --flow-muted-soft: #23272e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 8px; }

.layout { display: grid; grid-template-columns: 276px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 25;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 650; font-size: 18px; padding: 4px 12px 20px; }
.brand picture, .brand img { display: block; width: 46px; height: 46px; flex: none; }
.brand-text { line-height: 1.3; }
.brand-text span { display: block; font-weight: 450; color: var(--muted); font-size: 13.5px; }
.sidebar a {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 11px 12px;
  border-radius: 9px;
  color: var(--text);
  font-weight: 500;
  font-size: 16px;
}
.sidebar a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar svg { width: 23px; height: 23px; flex: none; }
.sidebar-footer { margin-top: auto; padding: 10px 12px; font-size: 13px; color: var(--muted); }
/* Tasto tondo sul bordo del menu: riduce il menu alle sole icone e lo riapre. */
.sidebar-toggle { position: absolute; top: 28px; right: -14px; width: 28px; height: 28px; padding: 0; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--muted); box-shadow: var(--shadow); cursor: pointer; }
.sidebar-toggle:hover { color: var(--accent); border-color: var(--accent); background: var(--surface); }
.sidebar-toggle svg { width: 16px; height: 16px; }

/* Menu ridotto alle icone (solo sopra gli schermi stretti, dove il menu è una barra in alto). */
@media (min-width: 761px) {
  :root[data-nav-collapsed] .layout { grid-template-columns: 76px 1fr; }
  :root[data-nav-collapsed] .sidebar { padding: 18px 8px; }
  :root[data-nav-collapsed] .brand { padding: 4px 0 20px; justify-content: center; }
  :root[data-nav-collapsed] .brand-text, :root[data-nav-collapsed] .sidebar-footer { display: none; }
  :root[data-nav-collapsed] .sidebar a { position: relative; justify-content: center; padding: 12px 0; font-size: 0; }
  :root[data-nav-collapsed] .sidebar a .nav-chip { position: absolute; top: 2px; right: 6px; min-width: 17px; height: 17px; padding: 0 4px; font-size: 10.5px; margin: 0; }
  /* Ridotto, restano solo i contatori che chiedono attenzione: gli altri (totali) escono dal pulsante. */
  :root[data-nav-collapsed] .sidebar a .nav-chip:not(.warn) { display: none; }
  :root[data-nav-collapsed] .sidebar-toggle svg { transform: rotate(180deg); }
}
@media (max-width: 760px) { .sidebar-toggle { display: none; } }

main { padding: 28px 32px 64px; min-width: 0; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header .subtitle { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card-header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-header h2 { margin: 0; }
.card-header .hint { color: var(--muted); font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .note { color: var(--faint); font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 550; font-size: 12px; background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.table-wrap table th:first-child, .table-wrap table td:first-child { padding-left: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.teal { background: var(--teal-soft); color: var(--teal); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.slate { background: var(--slate-soft); color: var(--slate); }
.badge.pink { background: var(--pink-soft); color: var(--pink); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

button, .button {
  font: inherit;
  font-weight: 550;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--surface-2); }
a.button:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled), .button.primary:hover { filter: brightness(1.07); background: var(--accent); }
/* Colore = significato. Verde: crea o conferma. Rosso: elimina, non si torna indietro. Arancione: azione delicata ma rimediabile. */
.primary.ok { background: var(--ok); border-color: var(--ok); color: var(--surface); }
button.primary.ok:hover:not(:disabled), .button.primary.ok:hover { filter: none; background: var(--ok); }
button.ok:not(.primary), .button.ok:not(.primary) { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
button.ok:not(.primary):hover:not(:disabled), .button.ok:not(.primary):hover { background: var(--ok-soft); }
button.danger, .button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
button.danger:hover:not(:disabled), .button.danger:hover { background: var(--danger-soft); }
button.warn:not(.primary), .button.warn:not(.primary) { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
button.warn:not(.primary):hover:not(:disabled), .button.warn:not(.primary):hover { background: var(--warn-soft); }
button.small { padding: 4px 10px; font-size: 12.5px; }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; min-height: 80px; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 12.5px; min-height: 360px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.field > span { font-weight: 550; }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.form-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: none; background: none; border-radius: 0; padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs button:hover { background: none; color: var(--text); }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone strong { color: var(--text); }

.detail-layout { display: grid; grid-template-columns: minmax(320px, 2fr) minmax(0, 3fr); gap: 18px; align-items: start; }
@media (max-width: 1200px) { .detail-layout { grid-template-columns: 1fr; } }
.pdf-pane { position: sticky; top: 50px; height: calc(100vh - 66px); }
.pdf-pane iframe { width: 100%; height: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.pdf-pane .empty { height: 100%; display: grid; place-items: center; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); padding: 20px; text-align: center; }
/* Su schermi stretti l'anteprima sta sopra le schede: non resta fissa e non occupa tutto lo schermo. */
@media (max-width: 1200px) { .pdf-pane { position: static; height: 70vh; } }

.criterion { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; background: var(--surface); }
.criterion.pending { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn-soft) inset; }
.criterion-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.criterion-head h3 { margin: 0; }
.criterion-head .id { color: var(--faint); font-family: var(--mono); font-size: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 13px; margin: 10px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv.facts .gap { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.scope .kv { margin-top: 0; }
/* Più liste nello stesso riquadro: chiavi in colonna di larghezza comune. */
.kv-aligned .kv { grid-template-columns: min(14em, 38%) minmax(0, 1fr); }
/* Elementi annidati sotto una riga: guida a sinistra e chiavi più strette. */
.kv-tree { margin-top: 6px; display: flex; flex-direction: column; gap: 10px; }
.kv-tree .kv, .kv-aligned .kv-tree .kv { margin: 0; padding-left: 12px; border-left: 2px solid var(--border); grid-template-columns: min(9em, 40%) minmax(0, 1fr); }
.scope + .scope { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 12px; }
.reasons { margin: 8px 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.evidence {
  border-left: 3px solid var(--accent-soft);
  padding: 6px 10px;
  margin: 6px 0;
  font-size: 13px;
  background: var(--surface-2);
  border-radius: 0 6px 6px 0;
}
.evidence.handwritten { border-left-color: var(--warn); }
.evidence .meta { color: var(--faint); font-size: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.evidence-label { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; font-size: 11px; }
.evidence-quote { margin: 4px 0 0; font-style: italic; }
.evidence-plain { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.ok { color: var(--ok); }
.small { font-size: 12.5px; }
.stack > * + * { margin-top: 10px; }
details summary { cursor: pointer; color: var(--muted); font-weight: 550; padding: 4px 0; }
details[open] summary { margin-bottom: 6px; }

.alert { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; border: 1px solid transparent; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert.danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert.info { background: var(--info-soft); color: var(--info); }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.progress.warn > div { background: var(--warn); }
.progress.danger > div { background: var(--danger); }

.job { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.job:last-child { border-bottom: none; }
.spinner { display: inline-block; vertical-align: -2px; box-sizing: border-box; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.outcome-group { margin: 8px 0 4px; }
.outcome-group h4 { margin: 10px 0 6px; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.outcome-item { padding: 6px 0 6px 12px; border-left: 2px solid var(--border); margin-left: 4px; font-size: 13px; }

#toast { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18); max-width: 420px; font-size: 13.5px; }
.toast.error { background: var(--danger); color: #fff; }

.grid-editor input, .grid-editor select { width: 100%; padding: 4px 6px; font-size: 12.5px; }
.grid-editor td { padding: 3px 4px; }
.grid-editor input[type="checkbox"] { width: auto; }
/* Simulazione del contratto: le colonne tengono la larghezza minima dichiarata nell'intestazione e la tabella
   scorre di lato invece di comprimere menu e campi. */
.sim-grid table { width: max-content; min-width: 100%; }
.sim-grid th { white-space: nowrap; }
.sim-grid th.center, .sim-grid td.center { text-align: center; vertical-align: middle; }
.sim-grid input.num { text-align: right; font-variant-numeric: tabular-nums; }
.mermaid-box { overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; }
.spacer { flex: 1; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }
pre.block { background: var(--surface-2); border-radius: 8px; padding: 10px; overflow: auto; font-size: 12px; max-height: 360px; margin: 0; }

/* ---- Schemi di mapping ---- */

/* Barra laterale in alto sugli schermi stretti: nessuno scroll orizzontale a 375px. */
@media (max-width: 760px) {
  /* Senza righe esplicite la griglia (alta almeno 100vh) allunga anche la barra quando la pagina è corta. */
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar {
    position: sticky;
    z-index: 20;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 8px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-footer, .brand-text { display: none; }
  .brand { padding: 0 6px 0 0; }
  .brand { font-size: 15px; }
  .brand picture, .brand img { width: 28px; height: 28px; }
  .sidebar a { flex: none; padding: 6px 10px; font-size: 14px; gap: 10px; }
  .sidebar svg { width: 18px; height: 18px; }
  main { padding: 18px 16px 48px; }
  .detail-layout { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 14px; }
}

.flow-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.flow-toolbar-plain { background: none; border: none; box-shadow: none; padding: 0; margin-bottom: 16px; }
.flow-toolbar-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 550; color: var(--muted); min-width: 0; max-width: 100%; }
.flow-toolbar-field select { max-width: 100%; }
.btn-icon { width: 16px; height: 16px; flex: none; }

.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.segmented button { border: none; background: none; padding: 5px 12px; border-radius: 7px; color: var(--muted); font-size: 13px; }
.segmented button:hover:not(:disabled) { background: none; color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow), 0 0 0 1px var(--border); }

/* Sezione per contratto */
.flow-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px 26px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.flow-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.flow-toggle {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: none;
  background: none;
  padding: 2px 0;
  color: var(--text);
  text-align: left;
  white-space: normal;
}
.flow-toggle:hover:not(:disabled) { background: none; }
.flow-toggle:hover .flow-section-title { color: var(--flow); }
.flow-chevron { width: 20px; height: 20px; flex: none; margin-top: 4px; color: var(--muted); transform: rotate(-90deg); transition: transform 0.15s; }
.flow-toggle[aria-expanded="true"] .flow-chevron { transform: none; }
.flow-toggle-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.flow-section-title { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.flow-section-sub { color: var(--muted); font-size: 13.5px; font-weight: 450; overflow-wrap: anywhere; }
.flow-section-file { display: inline-flex; align-items: center; gap: 5px; color: var(--faint); font-size: 12.5px; font-weight: 450; overflow-wrap: anywhere; }
.flow-section-file svg { width: 14px; height: 14px; flex: none; }
.flow-section-aside { display: flex; align-items: center; justify-content: flex-end; gap: 10px 16px; flex-wrap: wrap; }
.flow-section-total { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.flow-section-total:empty { display: none; }
.flow-section-total-label, .flow-criterion-total span { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.1em; }
.flow-section-total-value { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.flow-section-total-note { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.flow-section-body { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); min-width: 0; }
.flow-empty-page { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 48px 24px; }
.flow-empty-page h2 { margin: 6px 0 0; }

.flow-run { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 16px; font-size: 12.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.flow-run .flow-toolbar-field { flex-direction: row; align-items: center; gap: 8px; }
.flow-warnings ul { margin: 0; padding-left: 18px; }

/* Intestazioni di colonna in maiuscoletto */
.flow-col-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 10px; margin-bottom: 12px; }
.flow-col-title { font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }
.flow-col-counter { font-size: 12.5px; color: var(--faint); }

/* Perimetro cliente */
.flow-perimeter { display: grid; gap: 14px; margin-bottom: 20px; }
.flow-erp-group { margin: -6px 0 10px; }
.flow-members { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 10px; }
.flow-member {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1.5px solid var(--flow-card-border);
  border-radius: 14px;
}
.flow-member.is-inactive { border-style: dashed; border-color: var(--flow-line-muted); }
.flow-member .flow-tile { width: 34px; height: 34px; border-radius: 10px; }
.flow-member .flow-tile svg { width: 18px; height: 18px; }
.flow-member-body { flex: 1; min-width: 0; }
.flow-member-name { font-weight: 600; overflow-wrap: anywhere; }
.flow-member-code { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 4px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.flow-member-code .num { margin-left: auto; color: var(--text); }
.flow-member details summary { font-size: 12.5px; padding: 2px 0; }

/* Blocco di un criterio */
.flow-criterion { padding: 18px 0 10px; min-width: 0; }
.flow-criterion + .flow-criterion { border-top: 1px dashed var(--border); }
.flow-criterion-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 14px; }
.flow-criterion-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin-bottom: 6px; }
.flow-criterion-title h3 { margin: 0; font-size: 16px; }
.flow-criterion-total { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.flow-criterion-total strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.flow-criterion-muted .flow-criterion-total strong, .flow-criterion-blocked .flow-criterion-total strong { color: var(--muted); }

/* Schema a tre colonne */
.flow { container-type: inline-size; min-width: 0; }
.flow-canvas { position: relative; }
.flow-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr) minmax(0, 1fr); column-gap: 60px; }
.flow-col { display: flex; flex-direction: column; min-width: 0; }
.flow-col-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.flow-vsep { display: none; }
.flow-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 2; }
.flow-empty { padding: 14px; border: 1.5px dashed var(--flow-line-muted); border-radius: 14px; color: var(--faint); font-size: 13px; text-align: center; }

.flow-card {
  min-width: 0;
  padding: 13px 14px;
  background: var(--surface);
  border: 1.5px solid var(--flow-card-border);
  border-radius: 14px;
}
.flow-card.is-inactive { border-style: dashed; border-color: var(--flow-line-muted); }
.flow-card-main { display: flex; align-items: flex-start; gap: 12px; }
.flow-tile { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: var(--flow-soft); color: var(--flow); }
.flow-tile svg { width: 21px; height: 21px; }
.flow-card .flow-tile { width: 38px; height: 38px; }
.is-warning .flow-tile { background: var(--warn-soft); color: var(--warn); }
.is-inactive .flow-tile { background: var(--flow-muted-soft); color: var(--faint); }
.flow-card-body { flex: 1; min-width: 0; }
.flow-card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; }
.flow-card-title { min-width: 0; font-size: 15.5px; font-weight: 550; line-height: 1.3; overflow-wrap: anywhere; }
.flow-card-status { margin-top: 2px; font-size: 12.5px; color: var(--faint); overflow-wrap: anywhere; }
.flow-status { color: var(--flow); font-weight: 550; }
.is-warning .flow-status { color: var(--warn); }
.is-inactive .flow-status { color: var(--muted); }
.flow-card-value { margin-left: auto; font-size: 15px; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.flow-card-value small { font-size: 12px; font-weight: 450; color: var(--faint); }
.is-inactive .flow-card-value { color: var(--muted); }
.flow-branch { padding: 0 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 600; line-height: 18px; white-space: nowrap; }
.flow-meta, .csv-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.flow-meta { margin-top: 10px; }
.flow-meta code, .csv-chips code {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}
.flow-lines { margin-top: 10px; padding-top: 4px; border-top: 1px dashed var(--border); }
.flow-lines summary { padding: 2px 0; font-size: 12.5px; }
.flow-mini { font-size: 12.5px; }
.flow-mini th, .flow-mini td { position: static; padding: 3px 0; background: none; border-bottom: 1px solid var(--border); font-size: 12.5px; font-weight: 450; }
.flow-mini th { color: var(--muted); }
.flow-mini td { padding-left: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.flow-mini tr:last-child th, .flow-mini tr:last-child td { border-bottom: none; }

/* Scheda centrale della regola */
.flow-rule { border-color: var(--flow-ring); box-shadow: 0 0 0 4px var(--flow-soft); }
.flow-rule.is-inactive { border-color: var(--flow-line-muted); }
.flow-tone-muted .flow-rule, .flow-tone-blocked .flow-rule, .flow-rule.is-inactive { box-shadow: none; }
.flow-tone-muted .flow-rule:not(.is-inactive), .flow-tone-blocked .flow-rule:not(.is-inactive) { border-color: var(--flow-card-border); }
.flow-rule .flow-card-title { font-weight: 600; }
.flow-rule-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.flow-clause { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.flow-clause strong { color: var(--text); font-weight: 600; }
.flow-params { display: grid; grid-template-columns: fit-content(55%) minmax(0, 1fr); gap: 4px 14px; margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.flow-params dt { color: var(--muted); }
.flow-params dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.flow-evidence { display: grid; gap: 8px; margin-top: 12px; }
.flow-evidence details summary { font-size: 12.5px; }
.flow-evidence details .flow-quote { margin-top: 8px; }
.flow-quote { margin: 0; padding: 8px 12px; border-left: 3px solid var(--flow-ring); border-radius: 0 8px 8px 0; background: var(--surface-2); font-size: 13px; }
.flow-quote.handwritten { border-left-color: var(--warn); }
.flow-quote-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; font-size: 12px; color: var(--faint); }
.flow-quote-text { display: block; overflow-wrap: anywhere; }
.flow-quote-text.clamped { display: -webkit-box; -webkit-line-clamp: 4; line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.flow-questions { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); font-size: 13px; }
.flow-questions-title { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; color: var(--warn); font-weight: 600; }
.flow-questions-title svg { width: 16px; height: 16px; }
.flow-question { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: start; padding: 5px 0; }
.flow-question + .flow-question { border-top: 1px solid color-mix(in srgb, var(--warn) 20%, transparent); }

/* Connettori */
.flow-link { fill: none; stroke-width: 1.6; }
.flow-link-active { stroke: var(--flow); stroke-dasharray: 6 5; animation: flow-dash 1.1s linear infinite; }
.flow-link-warn { stroke: var(--warn); stroke-dasharray: 6 5; }
.flow-link-muted { stroke: var(--flow-line-muted); }
.flow-link-off { stroke: var(--flow-line-muted); stroke-dasharray: 3 5; }
.flow-svg marker path { stroke: none; }
.flow-marker-active path { fill: var(--flow); }
.flow-marker-warn path { fill: var(--warn); }
.flow-marker-muted path, .flow-marker-off path { fill: var(--flow-line-muted); }
.flow-port { fill: var(--surface); stroke-width: 1.6; }
.flow-port-active { stroke: var(--flow); }
.flow-port-warn { stroke: var(--warn); }
.flow-port-muted, .flow-port-off { stroke: var(--flow-line-muted); }
@keyframes flow-dash { to { stroke-dashoffset: -22; } }
@media (prefers-reduced-motion: reduce) {
  .flow-link-active { animation: none; }
  .flow-chevron { transition: none; }
}

/* Contenitore medio (es. dettaglio contratto accanto al PDF): schede compatte. */
@container (max-width: 939px) {
  .flow-grid { column-gap: 44px; }
  .flow-card { padding: 12px; }
  .flow-card-main { gap: 10px; }
  .flow-card-value { font-size: 14px; }
  .flow-card .flow-tile { width: 32px; height: 32px; border-radius: 9px; }
  .flow-card .flow-tile svg { width: 18px; height: 18px; }
  .flow-card-title { font-size: 14.5px; }
}
/* Colonne impilate: frecce verticali al posto dei connettori. */
@container (max-width: 679px) {
  .flow-grid { grid-template-columns: minmax(0, 1fr); }
  .flow-vsep { display: flex; justify-content: center; padding: 8px 0 10px; color: var(--flow); }
  .flow-tone-muted .flow-vsep, .flow-tone-blocked .flow-vsep { color: var(--flow-line-muted); }
  .flow-vsep svg { width: 22px; height: 22px; }
  .flow-svg { display: none; }
}
@media (max-width: 999px) {
  .flow-grid { grid-template-columns: minmax(0, 1fr); }
  .flow-vsep { display: flex; justify-content: center; padding: 8px 0 10px; color: var(--flow); }
  .flow-tone-muted .flow-vsep, .flow-tone-blocked .flow-vsep { color: var(--flow-line-muted); }
  .flow-vsep svg { width: 22px; height: 22px; }
  .flow-svg { display: none; }
}
@media (max-width: 760px) {
  .flow-section { padding: 16px; border-radius: 16px; }
  .flow-section-title { font-size: 18px; }
  .flow-section-aside { justify-content: flex-start; }
}

/* Tabelle sotto lo schema */
.flow-tables { margin-top: 18px; }
.flow-table-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.flow-table-head h3 { margin: 0; }

/* Pagina Dati */
tr.selected td { background: var(--accent-soft); }
.warn-text { color: var(--warn); font-weight: 550; }
.coverage { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 4px; min-width: 80px; }
.coverage .progress { width: 80px; height: 6px; }
.open-questions { padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); border-radius: 10px; background: var(--warn-soft); }
.open-questions h3 { color: var(--warn); }
/* Variante positiva: caratteristiche già confermate. */
.open-questions.confirmed { border-color: color-mix(in srgb, var(--ok) 30%, transparent); background: var(--ok-soft); }
.open-questions.confirmed h3 { color: var(--ok); }
.open-question { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; padding: 4px 0; font-size: 13px; }
.link-group { margin-top: 18px; }
.link-group-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin-bottom: 8px; }
.link-group-head h3 { margin: 0; }
.link-item { margin-bottom: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; min-width: 0; }
.link-item.link-status-ambiguous { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.link-item.link-status-not_found { border-style: dashed; }
.link-item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.link-item-head > div { min-width: 0; overflow-wrap: anywhere; }
.link-item-head > .badge { flex: none; }
.link-linked { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 8px; }
.link-code { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 8px; background: var(--ok-soft); font-size: 12.5px; }
.link-candidates { margin-top: 10px; }
.link-notes { margin: 8px 0 0; padding-left: 18px; font-size: 12px; color: var(--faint); }


/* ---- Barra dell'attività in alto ---- */
.content { min-width: 0; display: flex; flex-direction: column; }
/* Barra in alto: attività e pulsante del tema; resta visibile scorrendo la pagina. */
.topbar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: stretch; background: var(--surface); border-bottom: 1px solid var(--border);
}
.activity-bar {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex-wrap: wrap;
  padding: 10px 12px 10px 32px; background: var(--surface); color: var(--muted);
  font-size: 13px; min-height: 46px;
}
.topbar:has(.activity-bar[hidden]) { justify-content: flex-end; }
.theme-switch {
  flex: none; align-self: center; display: inline-flex; gap: 2px; margin: 0 24px 0 6px; padding: 3px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.theme-switch button {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 28px; padding: 0;
  border: none; border-radius: 7px; background: transparent; color: var(--muted);
}
.theme-switch button:hover { color: var(--text); background: transparent; }
.theme-switch button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 0 0 1px var(--border); }
.theme-switch svg { width: 16px; height: 16px; }
/* Logo: versione scura per il tema chiaro e bianca per il tema scuro, scelto o del sistema. */
.brand .logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand .logo-light { display: none; }
  :root:not([data-theme="light"]) .brand .logo-dark { display: block; }
}
:root[data-theme="dark"] .brand .logo-light { display: none; }
:root[data-theme="dark"] .brand .logo-dark { display: block; }
.activity-bar.busy { background: var(--flow-soft, var(--accent-soft)); color: var(--text); }
.topbar:has(.activity-bar.busy) { background: var(--flow-soft, var(--accent-soft)); border-bottom-color: color-mix(in srgb, var(--flow, var(--accent)) 30%, transparent); }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.activity-items { justify-content: flex-end; }
.activity-bar[hidden] { display: none; }
.activity-title { font-weight: 650; color: var(--flow, var(--accent)); }
.activity-pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--flow, var(--accent)); animation: activity-pulse 1.4s ease-in-out infinite; flex: none; }
@keyframes activity-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.7); } }
.activity-items { display: flex; gap: 8px; flex-wrap: wrap; min-width: 0; }
.activity-item { display: inline-flex; gap: 8px; align-items: baseline; padding: 3px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); max-width: 100%; }
.activity-item:hover { text-decoration: none; border-color: var(--flow, var(--accent)); }
.activity-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-meta { color: var(--muted); font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .activity-pulse { animation: none; } }
@media (max-width: 760px) { .topbar { position: static; } .activity-bar { padding: 10px 8px 10px 16px; } .theme-switch { margin-right: 12px; } }

/* ---- Editor Markdown della conoscenza ---- */
.md-editor { margin-bottom: 20px; }
.md-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.md-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 6px; border: 1px solid var(--border); border-bottom: none; border-radius: 10px 10px 0 0; background: var(--surface-2); }
.md-tool { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px; padding: 0 6px; border: 1px solid transparent; background: none; border-radius: 7px; color: var(--muted); }
.md-tool:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.md-tool svg { width: 17px; height: 17px; }
.md-tool-text { font-weight: 650; font-size: 12.5px; }
.md-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.md-toolbar-spacer { flex: 1; }
.md-panes { display: grid; border: 1px solid var(--border); border-radius: 0 0 10px 10px; height: min(70vh, 720px); min-height: 360px; overflow: hidden; }
.md-panes.mode-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.md-panes.mode-write, .md-panes.mode-preview { grid-template-columns: minmax(0, 1fr); }
.md-panes.mode-write .md-preview, .md-panes.mode-preview .md-input { display: none; }
.md-input { resize: none; border: none; border-radius: 0; padding: 16px 18px; font: 13.5px/1.6 var(--mono); background: var(--surface); color: var(--text); height: 100%; outline: none; tab-size: 2; }
.md-panes.mode-split .md-input { border-right: 1px solid var(--border); }
.md-preview { overflow: auto; padding: 16px 22px; background: var(--surface); line-height: 1.6; }
.md-preview h1 { font-size: 22px; margin: 4px 0 12px; }
.md-preview h2 { font-size: 18px; margin: 20px 0 10px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.md-preview h3 { font-size: 15px; margin: 16px 0 8px; }
.md-preview p, .md-preview ul, .md-preview ol { margin: 0 0 10px; }
.md-preview ul, .md-preview ol { padding-left: 22px; }
.md-preview li > input[type="checkbox"] { margin-right: 6px; }
.md-preview blockquote { margin: 0 0 12px; padding: 6px 14px; border-left: 3px solid var(--border); color: var(--muted); background: var(--surface-2); border-radius: 0 6px 6px 0; }
.md-preview code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md-preview pre { background: var(--surface-2); padding: 12px 14px; border-radius: 8px; overflow: auto; }
.md-preview pre code { background: none; padding: 0; }
.md-preview table { border-collapse: collapse; margin: 0 0 12px; width: 100%; font-size: 13px; }
.md-preview th, .md-preview td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.md-preview th { background: var(--surface-2); }
.md-preview hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.md-preview img { max-width: 100%; }
.md-footer { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.md-note { width: 240px; max-width: 100%; }
@media (max-width: 900px) {
  .md-panes.mode-split { grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr 1fr; }
  .md-panes.mode-split .md-input { border-right: none; border-bottom: 1px solid var(--border); }
}

/* Chip con i numeri nel menu laterale */
.sidebar a .nav-chip { margin-left: auto; min-width: 22px; padding: 0 8px; height: 22px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.sidebar a.active .nav-chip { background: var(--surface); color: var(--accent); }
.sidebar a .nav-chip.warn { background: var(--warn-soft); color: var(--warn); }
@media (max-width: 760px) { .sidebar a .nav-chip { margin-left: 6px; } }

/* Colonna delle caselle di selezione */
td.check-col, th:first-child:has(input[type="checkbox"]) { width: 36px; }
td.check-col input, th input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* Schede a link (pagina Dati) */
.tabs a.tab { padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs a.tab:hover { color: var(--text); text-decoration: none; }
.tabs a.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-count { font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

/* ---- Esplora i dati ---- */
.explore-controls { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.explore-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.explore-row select, .explore-row input[type="date"] { width: auto; }
.explore-add { position: relative; }
.explore-picker { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; width: 360px; max-width: 90vw; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(16, 24, 40, 0.14); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.explore-picker[hidden] { display: none; }
.explore-picker-head { display: flex; justify-content: space-between; align-items: baseline; }
.explore-picker-list { max-height: 280px; overflow: auto; display: flex; flex-direction: column; }
.explore-picker-item { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 4px 2px; border-radius: 6px; cursor: pointer; }
.explore-picker-item:hover { background: var(--surface-2); }
.explore-filters { margin-bottom: 8px; }
.chip-filter { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); font-size: 12.5px; }
.chip-x { border: none; background: none; padding: 0 6px; color: var(--muted); font-size: 15px; line-height: 1; }
.chip-x:hover { color: var(--danger); background: none; }
.explore-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0 10px; font-size: 13px; }
.explore-crumbs .link.current { color: var(--text); font-weight: 600; }
.explore-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.explore-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.explore-table th.sorted { color: var(--accent); }
.explore-table tfoot td { border-top: 2px solid var(--border); background: var(--surface-2); }
.explore-key { display: flex; flex-direction: column; }
.explore-bar { height: 3px; background: var(--surface-2); border-radius: 2px; margin-top: 4px; max-width: 220px; }
.explore-bar span { display: block; height: 100%; background: var(--flow, var(--accent)); border-radius: 2px; }

/* Viste preferite dell'esplorazione */
.explore-favorites { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.explore-fav-title { font-weight: 600; color: var(--warn); margin-right: 4px; }
.chip-fav { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.chip-fav.active { border-color: var(--accent); background: var(--accent-soft); }
.chip-fav-name { border: none; background: none; padding: 3px 4px 3px 11px; font-size: 12.5px; color: var(--text); }
.chip-fav-name:hover { background: none; color: var(--accent); }

/* ---- Righe del gestionale con il loro ruolo (simulatore) ---- */
.stripe { display: inline-block; width: 4px; height: 18px; border-radius: 2px; vertical-align: middle; background: var(--border); }
.stripe.threshold { background: var(--info); }
.stripe.payout { background: var(--ok); }
.stripe.off { background: var(--danger); }
.stripe.na { background: repeating-linear-gradient(180deg, var(--border) 0 3px, transparent 3px 5px); }
.stripe.none { background: repeating-linear-gradient(180deg, var(--faint) 0 2px, transparent 2px 5px); opacity: 0.6; }
.row-stripes { display: inline-flex; gap: 3px; }
.stripe-cell { width: 22px; padding-right: 0; }
.rows-table tr.role-excluded td { background: color-mix(in srgb, var(--danger) 5%, transparent); }
.rows-table tr.role-not_relevant td { color: var(--faint); }
/* Riquadro delle righe: modalità di calcolo con la sua spiegazione, poi i filtri in colonne con etichetta. */
.rows-mode-box { display: flex; flex-direction: column; gap: 6px; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.rows-mode { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.rows-label { font-size: 12.5px; font-weight: 550; color: var(--muted); }
.rows-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 12px; margin-bottom: 16px; }
.rows-filters .field { min-width: 0; }
.rows-filters select, .rows-filters input { width: 100%; }
.row-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px; color: var(--muted); }
.row-legend .stripe { height: 12px; margin-right: 2px; }
.row-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.summary-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: 13px; }
.summary-pill.active { border-color: var(--accent); background: var(--accent-soft); }
.summary-pill .stripe { height: 14px; }

/* ---- Riquadro "Come funziona" (Home) ---- */
.guide { margin-bottom: 20px; }
.guide-steps { list-style: none; margin: 4px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.guide-step { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.guide-step.done { border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
.guide-step.todo { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.guide-num { flex: none; width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; background: var(--accent-soft); color: var(--accent); }
.guide-step.done .guide-num { background: var(--ok-soft); color: var(--ok); }
.guide-step.todo .guide-num { background: var(--warn-soft); color: var(--warn); }
.guide-text { min-width: 0; }
.guide-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.guide-text ul { margin: 0 0 8px; padding-left: 18px; font-size: 13px; color: var(--muted); }
.guide-text li + li { margin-top: 3px; }
.guide-note { margin: 12px 0 0; }

/* Caricamento evidente per le elaborazioni più lunghe (esplorazione, righe del contratto) */
.loading-block { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 28px 16px; color: var(--muted); text-align: center; }
.loading-block .spinner { width: 28px; height: 28px; border-width: 3px; }
.loading-block strong { color: var(--text); font-weight: 600; }
.loading-skeleton { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.loading-skeleton span { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: skeleton 1.2s ease-in-out infinite; }
@keyframes skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .loading-skeleton span { animation: none; } }

/* ---- Pagina del contratto con l'assistente (chat a destra, un terzo della pagina) ---- */
.contract-workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
.contract-workspace.chat-open { grid-template-columns: minmax(0, 2fr) minmax(340px, 1fr); }
.contract-workspace.chat-closed { grid-template-columns: minmax(0, 1fr) 48px; }
.contract-main { min-width: 0; container-type: inline-size; }
@container (max-width: 1050px) {
  .detail-layout { grid-template-columns: minmax(0, 1fr); }
  .pdf-pane { position: static; height: 62vh; }
}
.detail-layout.pdf-hidden { grid-template-columns: 48px minmax(0, 1fr); }
.detail-layout.pdf-hidden .pdf-pane { display: none; }
/* Barra sopra il PDF con il comando per comprimerlo; compresso, resta una linguetta come quella dell'assistente. */
.pdf-pane { display: flex; flex-direction: column; gap: 6px; }
.pdf-pane iframe { flex: 1; min-height: 0; height: auto; }
.pdf-pane .empty { flex: 1; min-height: 0; height: auto; }
.pdf-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pdf-rail { display: none; position: sticky; top: 50px; writing-mode: vertical-rl; align-items: center; gap: 10px; padding: 14px 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.pdf-rail:hover { border-color: var(--accent); color: var(--accent); }
.detail-layout.pdf-hidden .pdf-rail { display: inline-flex; justify-self: start; }
/* Colonna unica: il PDF compresso lascia una barra orizzontale sopra le schede. */
@container (max-width: 1050px) {
  .detail-layout.pdf-hidden { grid-template-columns: minmax(0, 1fr); }
  .detail-layout.pdf-hidden .pdf-rail { writing-mode: horizontal-tb; position: static; justify-self: stretch; padding: 8px 12px; }
}
.tabs .tabs-tool { margin-left: auto; align-self: center; white-space: nowrap; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; }

.chat-panel { position: sticky; top: 50px; height: calc(100vh - 66px); min-height: 420px; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.contract-workspace.chat-closed .chat-panel { height: auto; min-height: 0; border: none; background: none; box-shadow: none; overflow: visible; }
.chat-rail { writing-mode: vertical-rl; display: inline-flex; align-items: center; gap: 10px; padding: 14px 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.chat-rail:hover { border-color: var(--accent); color: var(--accent); }
.chat-rail svg { width: 18px; height: 18px; color: var(--accent); }
.chat-rail-count { writing-mode: horizontal-tb; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: 11.5px; display: inline-flex; align-items: center; justify-content: center; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-title { display: flex; gap: 10px; align-items: center; min-width: 0; }
.chat-title svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.chat-head-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.chat-settings { padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.chat-settings[hidden] { display: none; }
.chat-settings .form-row { flex-wrap: wrap; }
.chat-todo { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.chat-todo:empty { display: none; }
.chat-todo-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-progress { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.chat-progress span { display: block; height: 100%; background: var(--ok); }
.chat-questions { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-q { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border)); background: var(--warn-soft); color: var(--warn); font-size: 12px; font-weight: 650; }
.chat-q.blocking { border-color: var(--warn); }
.chat-q.done { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); background: var(--ok-soft); color: var(--ok); padding-right: 3px; }
.chat-q-x { border: none; background: none; padding: 0 5px; color: inherit; font-size: 12px; }
.chat-q-x:hover { background: none; color: var(--text); }
.chat-todo-cta { align-self: flex-start; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 16px; }
.chat-msg.user { align-self: flex-end; max-width: 88%; }
.chat-bubble { background: var(--accent-soft); color: var(--text); border-radius: 14px 14px 4px 14px; padding: 8px 12px; white-space: pre-wrap; font-size: 13.5px; }
.chat-msg.assistant { max-width: 100%; }
.chat-reply { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; padding: 10px 12px; }
.chat-reply .chat-md > :last-child { margin-bottom: 0; }
.chat-md { font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.chat-md p, .chat-md ul, .chat-md ol { margin: 0 0 8px; }
.chat-md ul, .chat-md ol { padding-left: 18px; }
.chat-md h1, .chat-md h2, .chat-md h3 { font-size: 14px; margin: 10px 0 6px; }
.chat-md code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.chat-md table { border-collapse: collapse; width: 100%; font-size: 12.5px; margin: 0 0 8px; }
.chat-md th, .chat-md td { border: 1px solid var(--border); padding: 4px 6px; text-align: left; }
.chat-md blockquote { margin: 0 0 8px; padding: 4px 10px; border-left: 3px solid var(--border); color: var(--muted); }
.chat-ref, .cite-ref { display: inline-flex; align-items: center; gap: 3px; margin: 0 2px; padding: 0 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--accent); font: 600 11.5px/1.6 var(--mono); vertical-align: baseline; }
button.chat-ref:hover, button.cite-ref:hover { border-color: var(--accent); background: var(--accent-soft); }
.chat-ref-arrow { font-size: 10px; }
.chat-q-ref { display: inline-block; padding: 0 7px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border)); background: var(--warn-soft); color: var(--warn); font-size: 0.92em; font-weight: 650; line-height: 1.5; white-space: nowrap; }
.chat-q-ref.done { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); background: var(--ok-soft); color: var(--ok); }
.chat-tip {
  position: fixed; z-index: 60; max-width: 320px; padding: 8px 11px; border-radius: 9px;
  background: var(--surface); color: var(--text); border: 1px solid var(--accent);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28); font-size: 12.5px; line-height: 1.45;
  pointer-events: none; animation: chat-tip-in 0.08s ease-out;
}
.chat-tip[hidden] { display: none; }
.chat-tip-head { font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); margin-bottom: 3px; }
.chat-tip-body.quote { font-style: italic; }
.chat-tip::after {
  content: ""; position: absolute; left: var(--arrow-x, 50%); width: 9px; height: 9px;
  background: var(--surface); border: 1px solid var(--accent); transform: translateX(-50%) rotate(45deg);
}
.chat-tip[data-placement="above"]::after { bottom: -5.5px; border-top: none; border-left: none; }
.chat-tip[data-placement="below"]::after { top: -5.5px; border-bottom: none; border-right: none; }
@keyframes chat-tip-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .chat-tip { animation: none; } }
.chat-sources { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); font-size: 12px; }
.chat-proposals { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: var(--surface); }
.chat-proposals.pending { border: 1.5px solid var(--accent); background: var(--accent-soft); }
.chat-proposals-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.chat-proposals-head strong { font-weight: 650; }
.chat-proposals.pending .chat-proposals-head strong { color: var(--accent); }
.chat-proposals-icon { width: 17px; height: 17px; flex: none; color: var(--muted); }
.chat-proposals.pending .chat-proposals-icon { color: var(--accent); }
.chat-proposals-head .link { margin-left: auto; }
.chat-proposal { border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.chat-proposal.status-applied { border-left-color: var(--ok); }
.chat-proposal.status-failed { border-left-color: var(--danger); }
.chat-proposal.status-dismissed { opacity: 0.55; border-left-color: var(--border); }
.chat-proposal-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chat-proposal .actions { justify-content: flex-start; }
.chat-patches { margin: 4px 0 0; padding-left: 16px; }
.chat-patches code { font-size: 11.5px; word-break: break-all; }
.chat-followups { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chat-chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; color: var(--text); text-align: left; }
.chat-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--surface); }
.chat-meta { font-size: 11.5px; margin-top: 8px; }
.chat-typing { display: inline-flex; gap: 4px; margin-bottom: 6px; }
.chat-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: chat-dot 1.2s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.chat-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 18px 6px; }
.chat-empty-icon svg { width: 34px; height: 34px; color: var(--accent); }
.chat-empty .chat-followups { justify-content: center; }
.chat-compose { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.chat-compose-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-compose textarea { flex: 1; resize: none; min-height: 40px; max-height: 180px; font: inherit; }
.chat-send { flex: none; width: 40px; height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.chat-send svg { width: 18px; height: 18px; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); font-weight: 550; }
@media (prefers-reduced-motion: reduce) { .chat-typing span { animation: none; } }

/* Schermi stretti: l'assistente diventa un pannello sovrapposto, chiuso da un pulsante flottante. */
@media (max-width: 1100px) {
  .contract-workspace.chat-open, .contract-workspace.chat-closed { grid-template-columns: minmax(0, 1fr); }
  .contract-workspace.chat-open .chat-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); height: 100vh; z-index: 50; border-radius: 0; box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18); }
  .contract-workspace.chat-closed .chat-panel { position: fixed; right: 16px; bottom: 16px; top: auto; z-index: 50; }
  .contract-workspace.chat-closed .chat-rail { writing-mode: horizontal-tb; border-radius: 999px; box-shadow: var(--shadow), 0 4px 14px rgba(0, 0, 0, 0.15); }
}

/* Schede del contratto: con PDF e assistente affiancati vanno a capo invece di scorrere. */
.detail-layout .tabs { flex-wrap: wrap; overflow-x: visible; }
.detail-layout .tabs button { padding: 8px 10px; }

/* Costi AI nascosti (Impostazioni → Mostra costi AI): restano registrati, non si mostrano. */
:root[data-ai-costs="hidden"] .ai-cost { display: none !important; }

.toggle-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); cursor: pointer; }
.toggle-row input { margin-top: 3px; width: 16px; height: 16px; flex: none; }
.toggle-row > span { display: flex; flex-direction: column; gap: 2px; }

/* ---- Impostazioni ---- */
/* Indice delle sezioni in alto; sugli schermi larghi diventa una colonna fissa a sinistra. */
.settings-layout { display: flex; flex-direction: column; gap: 18px; }
.settings-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.settings-nav-link { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 500; text-align: left; }
.settings-nav-link:hover { color: var(--text); background: var(--surface-2); }
.settings-nav-link.active { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: stretch; min-width: 0; }
.settings-section { min-width: 0; scroll-margin-top: 56px; }
.settings-section > .card { margin: 0; height: 100%; }
.settings-section:empty { display: none; }
/* Due colonne: le sezioni brevi a coppie, tabelle e editor su tutta la riga. */
@media (min-width: 1400px) {
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-section.wide { grid-column: 1 / -1; }
}
@media (min-width: 1700px) {
  .settings-layout { display: grid; grid-template-columns: 168px minmax(0, 1fr); align-items: start; gap: 24px; }
  .settings-nav { position: sticky; top: 56px; flex-direction: column; gap: 2px; }
  .settings-nav-link { border: none; background: none; border-radius: 8px; padding: 7px 10px; }
}
.auto-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px 18px; }
.picker-cell .form-row > .field:first-child { flex: 1; min-width: 0; }
.picker-cell .form-row select { max-width: 100%; }
.prompt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 620px), 1fr)); gap: 14px; }
.prompt-grid > .criterion { margin: 0; min-width: 0; }
/* Etichette in cima: i suggerimenti di lunghezza diversa non disallineano i campi. */
.settings-section .form-grid { align-items: start; }
/* Nelle card affiancate il pulsante Salva resta in fondo, alla stessa altezza. */
.settings-section > .card { display: flex; flex-direction: column; }
.settings-section > .card > .stack { flex: 1; display: flex; flex-direction: column; }
.settings-section > .card > .stack > .actions:last-child { margin-top: auto; padding-top: 10px; }

/* ---- Rendiconto del premio ---- */
/* Foglio A4 a schermo; in stampa restano solo il foglio e i colori chiari. */
.statement-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; max-width: 210mm; margin: 0 auto 16px; }
.statement-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; padding-bottom: 6px; }
.statement {
  max-width: 210mm;
  margin: 0 auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 36px 28px;
  font-size: 13px;
}
.statement h1 { font-size: 22px; }
.statement h2 { font-size: 15px; margin: 18px 0 8px; }
.statement h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 16px 0 6px; }
.statement-eyebrow { font-size: 12px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.statement-counterparty { font-size: 15px; color: var(--muted); margin-top: 2px; }
.statement-head { padding-bottom: 16px; border-bottom: 2px solid var(--text); }
.statement-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px 20px; margin: 14px 0 0; }
.statement-meta dt { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; }
.statement-meta-item { min-width: 0; }
.statement-meta dd { margin: 0; overflow-wrap: anywhere; }
.statement-banner { border: 1px solid var(--warn); background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 10px 14px; margin-bottom: 18px; }
.statement-banner ul { margin: 4px 0 0; padding-left: 18px; }
.statement-section { padding: 16px 0 8px; border-bottom: 1px solid var(--border); }
.statement-section:last-of-type { border-bottom: none; }
.statement-totals { display: flex; flex-wrap: wrap; gap: 12px; }
.statement-total { display: flex; flex-direction: column; padding: 12px 16px; border-radius: 8px; background: var(--accent-soft); min-width: 220px; }
.statement-total span { font-size: 12px; color: var(--muted); }
.statement-total strong { font-size: 24px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.statement-total.secondary { background: var(--surface-2); }
.statement-scroll { overflow-x: auto; }
.statement-table { font-size: 12.5px; }
.statement-table th { background: none; position: static; border-bottom: 1.5px solid var(--text); font-size: 0.95em; }
/* Nel foglio i testi secondari scalano con il corpo del documento (più piccolo in stampa). */
.statement .small { font-size: 0.92em; }
.statement-table tbody tr:last-child td { border-bottom: 1px solid var(--border); }
.statement-table tfoot td { border-bottom: none; font-weight: 650; }
.statement-formula { font-family: var(--mono); font-size: 10.5px; color: var(--faint); white-space: normal; }
.statement-table .nowrap { white-space: nowrap; }
.statement-criterion-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.statement-criterion-head h2 { margin: 0 0 2px; }
.statement-criterion-total { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.statement-terms { display: grid; grid-template-columns: minmax(140px, max-content) minmax(0, 1fr); gap: 3px 16px; margin: 0; }
.statement-terms > div { display: contents; }
.statement-terms dt { color: var(--muted); }
.statement-terms dd { margin: 0; overflow-wrap: anywhere; }
.statement-list { margin: 4px 0 8px; padding-left: 18px; }
.statement-evidence { list-style: none; margin: 4px 0 8px; padding: 0; display: grid; gap: 6px; }
.statement-evidence li { padding-left: 10px; border-left: 3px solid var(--border); }
.statement-evidence q { font-style: italic; }
.statement-status { font-weight: 600; }
.statement-status.ok { color: var(--ok); }
.statement-status.warn { color: var(--warn); }
.statement-note.warn { color: var(--warn); font-size: 12.5px; margin-bottom: 6px; }
.statement-internal-box { margin-top: 12px; padding: 10px 14px; border: 1px dashed var(--border); border-radius: 8px; background: var(--surface-2); }
.statement-internal-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--purple); margin-bottom: 4px; }
.statement.hide-internal .statement-internal { display: none; }
.statement-foot { margin-top: 18px; font-size: 11px; color: var(--faint); }
@media (max-width: 760px) {
  .statement { padding: 20px 16px; }
  .statement-terms { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .statement-terms dt { margin-top: 6px; }
  .statement-total { min-width: 0; flex: 1; }
}
/* ---- Moduli: errori per campo, anteprima degli importi, caselle e dialoghi ---- */

/* Un campo errato si riconosce da bordo, titolo e messaggio (non solo dal colore: il messaggio è sempre scritto). */
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 5%, var(--surface));
}
input[aria-invalid="true"]:focus, select[aria-invalid="true"]:focus, textarea[aria-invalid="true"]:focus { outline-color: var(--danger); }
.field.error > span:first-child { color: var(--danger); }
.field-msg { display: block; color: var(--danger); font-size: 12.5px; font-weight: 550; line-height: 1.35; }
.field-preview { display: block; min-height: 1.35em; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.amount-field { display: flex; flex-direction: column; gap: 3px; }
.amount-input { text-align: right; font-variant-numeric: tabular-nums; }

/* Casella con la sua etichetta su una riga (si trova nelle barre dei filtri e nei moduli). */
label.checkbox { display: inline-flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; }
label.checkbox input { width: 16px; height: 16px; margin: 0; flex: none; cursor: pointer; }

/* Raggruppamenti, filtri e percorso della pagina Contratti. */
.contracts-nav { margin-bottom: 10px; }
.contracts-nav:empty { display: none; }

/* Dialoghi (web/js/dialog.js): <dialog> nativo; il modulo riempie tutta l'area, così un clic sul <dialog> è un clic sullo sfondo. */
dialog.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 48px rgba(16, 24, 40, 0.28);
}
dialog.modal.wide { width: min(960px, calc(100vw - 32px)); }
dialog.modal.tone-danger { border-top: 3px solid var(--danger); }
dialog.modal.tone-warn { border-top: 3px solid var(--warn); }
dialog.modal::backdrop { background: rgba(16, 24, 40, 0.5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
dialog.modal[open] { animation: modal-in 0.16s ease-out; }
dialog.modal[open]::backdrop { animation: modal-fade 0.16s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes modal-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  dialog.modal[open], dialog.modal[open]::backdrop { animation: none; }
}
.modal [hidden] { display: none !important; }
.modal-head { display: flex; align-items: center; gap: 12px; }
.modal-icon { flex: none; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; }
.modal-icon svg { width: 18px; height: 18px; }
.modal-icon.danger { background: var(--danger-soft); color: var(--danger); }
.modal-icon.warn { background: var(--warn-soft); color: var(--warn); }
.modal-form { display: flex; flex-direction: column; gap: 12px; padding: 20px 22px 18px; max-height: calc(100vh - 54px); max-height: calc(100dvh - 54px); }
.modal-form h2 { margin: 0; }
/* Il riempimento negativo lascia spazio all'anello del focus, che l'overflow altrimenti taglierebbe. */
.modal-body { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: auto; padding: 4px; margin: -4px; }
.modal-text { margin: 0; white-space: pre-line; color: var(--muted); }
.modal-error { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
/* Bloccato: grigio e con il cursore di divieto, non un verde più spento. */
button.primary.ok:disabled:not(.done) { opacity: 1; cursor: not-allowed; background: var(--surface-2); color: var(--muted); border-color: var(--border); filter: none; }
/* Già accettata: verde chiaro, è uno stato e non un comando. */
button.primary.ok.done:disabled { opacity: 1; cursor: default; background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
button.primary.danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
button.primary.danger:hover:not(:disabled) { background: var(--danger); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) dialog.modal { box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6); }
  :root:not([data-theme="light"]) dialog.modal::backdrop { background: rgba(0, 0, 0, 0.66); }
}
:root[data-theme="dark"] dialog.modal { box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6); }
:root[data-theme="dark"] dialog.modal::backdrop { background: rgba(0, 0, 0, 0.66); }
@media (max-width: 760px) {
  .modal-form { padding: 16px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { justify-content: center; }
}

/* ---- Registro delle liquidazioni: badge delle tipologie, saldi D/A, consolidamento ---- */

/*
 * Tipologia di operazione (web/js/views/settlements/labels.js): badge squadrato con glifo ed etichetta, mai il
 * solo colore. Tre varianti: pieno (fondo tinto), .outline (solo bordo) e .dashed (bordo tratteggiato, per le
 * stime e i movimenti di sistema). Il bordo c'è sempre, così la stampa in bianco e nero resta leggibile.
 */
.op-badge {
  --op-fg: var(--muted);
  --op-bg: var(--surface-2);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px 0 6px;
  border: 1px solid var(--op-fg);
  border-radius: 4px;
  background: var(--op-bg);
  color: var(--op-fg);
  font-size: 12px;
  font-weight: 600;
  line-height: 18px;
  white-space: nowrap;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.op-badge.outline { background: transparent; }
.op-badge.dashed { background: transparent; border-style: dashed; }
.op-glyph { display: inline-block; min-width: 1em; text-align: center; font-weight: 700; }
.op-badge.fam-teal { --op-fg: var(--teal); --op-bg: var(--teal-soft); }
.op-badge.fam-orange { --op-fg: var(--orange); --op-bg: var(--orange-soft); }
.op-badge.fam-slate { --op-fg: var(--slate); --op-bg: var(--slate-soft); }
.op-badge.fam-ok { --op-fg: var(--ok); --op-bg: var(--ok-soft); }
.op-badge.fam-info { --op-fg: var(--info); --op-bg: var(--info-soft); }
.op-badge.fam-warn { --op-fg: var(--warn); --op-bg: var(--warn-soft); }
.op-badge.fam-danger { --op-fg: var(--danger); --op-bg: var(--danger-soft); }
.op-badge.fam-purple { --op-fg: var(--purple); --op-bg: var(--purple-soft); }
.op-badge.fam-accent { --op-fg: var(--accent); --op-bg: var(--accent-soft); }
/* Pillola di stato provvisoria: stesso testo, bordo tratteggiato. */
.badge.dashed { padding: 0 7px; border: 1px dashed currentColor; background: transparent; }
.alert.compact { padding: 7px 12px; margin: 8px 0 0; font-size: 13px; }
.alert.compact ul { margin: 4px 0 0; padding-left: 18px; }

/* Saldo di una posizione: importo, lato D/A e dicitura in chiaro (il lato non si legge dal solo segno). */
.balance-cell { display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1.25; font-variant-numeric: tabular-nums; }
.balance-amount { display: inline-flex; align-items: baseline; gap: 5px; font-weight: 650; white-space: nowrap; }
.balance-side { min-width: 1.6em; padding: 0 4px; border: 1px solid currentColor; border-radius: 3px; font-size: 11px; font-weight: 700; line-height: 15px; text-align: center; }
.balance-note { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.balance-cell.side-D .balance-amount { color: var(--purple); }
.balance-cell.side-PARI .balance-amount { color: var(--muted); }

/* Scheda "Liquidazioni" del contratto. */
.settle-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 14px; }
.settle-subject { color: var(--muted); font-size: 13px; }
.cell-sub { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.35; }
.pos-flags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.settle-table td { vertical-align: middle; }
/* La scheda sta accanto al PDF e all'assistente: sotto gli 820 px le colonne di dettaglio passano in una riga di sintesi. */
.settle-root { container-type: inline-size; container-name: settle; min-width: 0; }
.settle-root .narrow-only { display: none; }
@container settle (max-width: 820px) {
  .settle-root .col-detail { display: none; }
  .settle-root .narrow-only { display: block; }
  .settle-root .narrow-only .badge { white-space: normal; }
  .settle-root .balance-note { max-width: 15ch; white-space: normal; text-align: right; }
}
.settle-table .actions { justify-content: flex-end; flex-wrap: nowrap; }

/* Dialogo "Consolida maturato": un riquadro per periodo con la tabella società × importo. */
.accrual-intro { display: flex; flex-direction: column; gap: 6px; }
.accrual-intro select { width: 100%; }
.accrual-meta { color: var(--muted); font-size: 12.5px; }
.accrual-periods { display: flex; flex-direction: column; gap: 12px; }
.accrual-period { min-width: 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.accrual-period.is-blocked { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.accrual-period.is-unchanged { background: var(--surface-2); }
.accrual-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.accrual-head label.checkbox strong { font-size: 15px; }
.accrual-sub { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }
.accrual-period .table-wrap { margin: 8px 0 0; }
.accrual-total td { background: var(--surface-2); font-weight: 650; }
.accrual-period details { margin-top: 8px; }
.accrual-period details summary { font-size: 12.5px; }
.accrual-list { margin: 4px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.delta { font-variant-numeric: tabular-nums; }
.delta.is-zero { color: var(--faint); }
.ack-list { margin: 0; padding: 10px 14px; border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border)); border-radius: 10px; background: var(--warn-soft); }
.ack-list legend { padding: 0 6px; color: var(--warn); font-weight: 650; }
.ack-item { display: flex; align-items: flex-start; gap: 8px; padding: 4px 0; color: var(--text); }
.ack-item label { cursor: pointer; }
.ack-item input { width: 16px; height: 16px; margin: 2px 0 0; flex: none; cursor: pointer; }
.ack-item small { display: block; color: var(--muted); }

@media print {
  @page { size: A4; margin: 14mm 12mm; }
  :root, :root[data-theme] {
    --bg: #fff;
    --surface: #fff;
    --surface-2: #f4f5f7;
    --border: #d5d9df;
    --text: #111318;
    --muted: #4b5260;
    --faint: #6b7280;
    --accent: #2f4bc4;
    --accent-soft: #eef1fd;
    --ok: #147a46;
    --ok-soft: #e3f5ea;
    --info: #1f6fb2;
    --info-soft: #e3f0fb;
    --warn: #8a4b00;
    --warn-soft: #fdf1dd;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --purple: #5b34b0;
    --purple-soft: #f1ebfd;
    --teal: #0a7356;
    --teal-soft: #ddf4ec;
    --orange: #b4470f;
    --orange-soft: #fdeadf;
    --slate: #4a5568;
    --slate-soft: #eceff3;
    --pink: #b0256c;
    --pink-soft: #fce8f2;
    --shadow: none;
    color-scheme: light;
  }
  body { background: #fff; }
  .layout { display: block; }
  .sidebar, .topbar, .activity-bar, .statement-toolbar, #toast { display: none !important; }
  main { padding: 0; }
  .statement { max-width: none; border: none; border-radius: 0; box-shadow: none; padding: 0; font-size: 11px; }
  .statement-scroll { overflow: visible; }
  .statement-table { font-size: 10.5px; }
  .statement-table thead { display: table-header-group; }
  .statement-table tr, .statement-evidence li, .statement-total, .statement-internal-box { break-inside: avoid; }
  .statement h2, .statement h3, .statement-criterion-head { break-after: avoid; }
  .statement-banner, .statement-total, .statement-internal-box { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .statement a { color: inherit; }
}

/* Tabella annidata in una cella (valori di fasce e minimi): compatta, senza riquadro proprio. */
.sub-table { border-collapse: collapse; font-size: 13px; }
.sub-table th { text-align: left; font-weight: 600; color: var(--muted); padding: 2px 24px 4px 0; border-bottom: 1px solid var(--border); white-space: nowrap; }
.sub-table td { padding: 3px 24px 3px 0; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sub-table th:last-child, .sub-table td:last-child { padding-right: 0; }
.sub-table td.num { font-weight: 600; }

/* Grafo: numero e nome in evidenza, operatore in corsivo, descrizione più piccola. */
.mermaid-box .nodeLabel b { font-size: 13px; font-weight: 650; }
.mermaid-box .nodeLabel i { display: inline-block; margin: 2px 0 3px; font-family: var(--mono, ui-monospace, monospace); font-style: normal; font-size: 10.5px; letter-spacing: 0.04em; opacity: 0.75; }
.mermaid-box .nodeLabel small { font-size: 11.5px; line-height: 1.35; opacity: 0.9; }
.mermaid-box .cluster rect { rx: 12; ry: 12; }

/* Contatore sulle schede. */
.tabs button .badge { margin-left: 6px; padding: 0 6px; font-size: 11px; line-height: 1.5; }

/* Riquadro comprimibile (details): il titolo è il comando per aprirlo. */
.card.collapsible > summary { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 0; list-style: none; color: inherit; font-weight: inherit; cursor: pointer; }
.card.collapsible > summary::-webkit-details-marker { display: none; }
.card.collapsible > summary h2 { margin: 0; white-space: nowrap; }
.card.collapsible > summary h2::before { content: "›"; display: inline-block; margin-right: 8px; color: var(--muted); transition: transform 0.15s; }
.card.collapsible[open] > summary h2::before { transform: rotate(90deg); }
.card.collapsible[open] > summary { margin-bottom: 12px; }
