/* Resa: design system. Un accento (cobalto), verde e rosso solo per significato (profitto / perdita).
   Raggi: 12px card, 8px controlli, pillola per badge e chip. Numeri sempre in Geist Mono tabellare. */

@font-face { font-family: "Geist"; src: url("./assets/fonts/Geist-Variable.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Geist Mono"; src: url("./assets/fonts/GeistMono-Variable.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  --bg: #f6f6f7; --surface: #ffffff; --surface-2: #fafafb; --sunken: #f1f1f3;
  --border: #e4e4e8; --border-strong: #d4d4da;
  --text: #17171b; --text-2: #3f3f47; --muted: #6c6c77; --subtle: #9b9ba5;
  --accent: #2f5bd3; --accent-soft: #e8eefc; --accent-ink: #1e47b8; --accent-area: rgba(47, 91, 211, .10);
  --good: #13795b; --good-soft: #e6f4ee; --bad: #c4362c; --bad-soft: #fcebea; --warn: #9a5b00; --warn-soft: #fbf1df;
  --series-muted: #a9b4c9;
  --seg-0: #2f5bd3; --seg-1: #6f8fe4; --seg-2: #c4362c; --seg-3: #a9b4c9; --seg-4: #d9dde6;
  --shadow: 0 1px 2px rgba(23, 23, 27, .04), 0 1px 1px rgba(23, 23, 27, .03);
  --shadow-pop: 0 8px 28px rgba(23, 23, 27, .12), 0 2px 6px rgba(23, 23, 27, .06);
  --r-card: 12px; --r-ctl: 8px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --sidebar: 232px;
  font-family: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e11; --surface: #16161a; --surface-2: #1b1b20; --sunken: #121215;
    --border: #2a2a31; --border-strong: #383841;
    --text: #ededf0; --text-2: #c9c9d0; --muted: #9a9aa6; --subtle: #6d6d78;
    --accent: #7095ff; --accent-soft: #1c2647; --accent-ink: #a5bcff; --accent-area: rgba(112, 149, 255, .14);
    --good: #4cc49a; --good-soft: #12291f; --bad: #ff7b70; --bad-soft: #351816; --warn: #e6a94a; --warn-soft: #2f2412;
    --series-muted: #4a5671;
    --seg-0: #7095ff; --seg-1: #4b67b5; --seg-2: #ff7b70; --seg-3: #5d6a86; --seg-4: #353b48;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-pop: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; font-feature-settings: "ss01"; }
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.015em; }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.ico { flex: none; vertical-align: -0.15em; }
.ico.flip { transform: rotate(180deg); }
.num { font-family: "Geist Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.neg { color: var(--bad); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; text-decoration: none; }
a.strong:hover { color: var(--accent); }
.block { display: block; }
.pad { padding: 16px 20px; }

/* ---------- Guscio ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100dvh; }
.sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 4px; padding: 16px 12px; border-right: 1px solid var(--border); background: var(--surface-2); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 650; font-size: 15px; letter-spacing: -0.02em; }
.logo { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--text); color: var(--bg); font-weight: 700; font-size: 14px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r-ctl); color: var(--text-2); text-decoration: none; font-weight: 500; transition: background .15s var(--ease), color .15s var(--ease); }
.nav-item:hover { background: var(--sunken); color: var(--text); }
.nav-item.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow), inset 0 0 0 1px var(--border); }
.nav-item.on .ico { color: var(--accent); }
.nav-count { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 600; text-align: center; line-height: 18px; }
.privacy { display: flex; gap: 8px; padding: 12px 10px 0; font-size: 12px; color: var(--muted); line-height: 1.4; }
.privacy .ico { margin-top: 2px; color: var(--good); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; min-height: 60px; padding: 10px 28px; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(160%) blur(10px); border-bottom: 1px solid var(--border); }
.store { display: flex; align-items: center; gap: 8px; flex: none; max-width: 320px; }
.store strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-mid { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-end { margin-left: auto; display: flex; gap: 8px; }
.period { display: flex; align-items: center; gap: 6px; padding: 0 4px 0 10px; height: 32px; border: 1px solid var(--border); border-radius: var(--r-ctl); background: var(--surface); }
.period select, .select select { border: 0; background: transparent; height: 30px; padding-right: 4px; cursor: pointer; font-weight: 500; }
.period select:focus { outline: none; }
.period:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.period-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn.menu { display: none; }
.scrim { display: none; }

.view { padding: 24px 28px 64px; display: flex; flex-direction: column; gap: 16px; max-width: 1480px; width: 100%; outline: none; animation: enter .35s var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }

/* ---------- Bottoni, badge, campi ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--r-ctl); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease); }
.btn:hover { background: var(--sunken); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.primary:hover { background: var(--text-2); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--sunken); color: var(--text); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 40px; padding: 0 16px; font-size: 15px; }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-ctl); border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--sunken); color: var(--text-2); }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.est { margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--sunken); color: var(--muted); font-size: 11px; font-weight: 500; text-transform: none; letter-spacing: 0; }

.delta { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 600; font-family: "Geist Mono", monospace; letter-spacing: -0.02em; white-space: nowrap; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat, .delta.none { color: var(--subtle); font-weight: 500; font-family: inherit; letter-spacing: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 500; }
.field small { color: var(--muted); font-size: 12px; }
.field input[type="text"], .input-unit { height: 36px; border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface); }
.field input[type="text"] { padding: 0 10px; }
.input-unit { display: inline-flex; align-items: center; max-width: 180px; overflow: hidden; }
.input-unit input { width: 100%; min-width: 0; height: 100%; border: 0; padding: 0 10px; background: transparent; font-family: "Geist Mono", monospace; }
.input-unit input:focus { outline: none; }
.input-unit:focus-within, .field input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input-unit span { padding: 0 10px; height: 100%; display: grid; place-items: center; background: var(--sunken); color: var(--muted); border-left: 1px solid var(--border); font-size: 12px; }
.input-unit.sm { height: 30px; max-width: 110px; margin-left: auto; }
.select { display: inline-flex; align-items: center; height: 32px; padding: 0 6px 0 10px; border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface); max-width: 220px; }
.select select { max-width: 200px; }

/* ---------- Pagina ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-weight: 500; width: fit-content; }
.back:hover { color: var(--text); }
.pill-alert { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; background: var(--bad-soft); color: var(--bad); font-weight: 600; text-decoration: none; }
.footnote { color: var(--muted); font-size: 12px; max-width: 90ch; }
.footnote a { color: var(--accent); }

.grid { display: grid; gap: 16px; }
.grid.top { align-items: start; }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.g-1-1, .g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr); }
.grid.tight { gap: 12px; }
.stack-v { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.sticky { position: sticky; top: 76px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-head.pad { margin: 0; padding: 16px 20px 12px; }
.link { color: var(--accent); text-decoration: none; font-weight: 500; font-size: 13px; }
.link:hover { text-decoration: underline; }
.sub-h { font-size: 12px; font-weight: 600; color: var(--muted); margin: 4px 0 8px; }

/* ---------- KPI ---------- */
.kpi-main { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow); overflow: hidden; }
.kpi { position: relative; padding: 18px 20px 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi + .kpi { border-left: 1px solid var(--border); }
.kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; }
.kpi-value { font-size: 28px; font-weight: 500; line-height: 1.1; letter-spacing: -0.04em; }
.kpi-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; min-width: 0; }
.kpi-foot .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-spark { position: absolute; top: 16px; right: 16px; opacity: .9; }
.kpi-sub { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi-sub.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi-sub.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi-mini { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 8px; padding: 12px 16px; border-radius: var(--r-card); background: var(--surface); border: 1px solid var(--border); min-width: 0; }
.kpi-mini .kpi-label { grid-column: 1 / -1; }
.kpi-mini .v { font-size: 19px; font-weight: 500; letter-spacing: -0.03em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-mini .v.strong { font-family: inherit; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.kpi-mini .sub { grid-column: 1 / -1; font-size: 12px; }
.kpi-mini.bad { background: linear-gradient(var(--bad-soft), var(--bad-soft)) padding-box; border-color: color-mix(in srgb, var(--bad) 22%, var(--border)); }
.kpi-mini.bad .v { color: var(--bad); }

/* ---------- Grafici ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.line-chart { height: auto; }
.fill-row { height: 0; min-height: 100%; display: flex; flex-direction: column; }
.fill-row .insights { overflow-y: auto; min-height: 0; margin-right: -8px; padding-right: 8px; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .grid.faint { stroke-dasharray: 2 4; }
.chart .axis-zero { stroke: var(--border-strong); stroke-width: 1; }
.chart .axis-one { stroke: var(--subtle); stroke-dasharray: 3 3; }
.chart .tick { fill: var(--subtle); font-size: 11px; font-family: "Geist Mono", monospace; }
.chart .line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.chart .line.accent, .spark.accent path { stroke: var(--accent); }
.chart .line.muted, .spark.muted path { stroke: var(--series-muted); }
.chart .area.muted { fill: var(--accent-area); }
.chart .area.accent { fill: var(--accent-area); }
.chart .dot { stroke: var(--surface); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.chart .dot.accent { fill: var(--accent); }
.chart .dot.muted { fill: var(--series-muted); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:hover { fill: var(--accent-area); }
.chart-empty { display: grid; place-items: center; min-height: 160px; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--r-ctl); }
.chart-note { margin-top: 10px; font-size: 12.5px; color: var(--text-2); }
.legend-inline { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend-inline span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--subtle); flex: none; }
.sw.accent { background: var(--accent); }
.sw.muted { background: var(--series-muted); }
.sw.s0, .seg.s0 { background: var(--seg-0); } .sw.s1, .seg.s1 { background: var(--seg-1); } .sw.s2, .seg.s2 { background: var(--seg-2); } .sw.s3, .seg.s3 { background: var(--seg-3); } .sw.s4, .seg.s4 { background: var(--seg-4); }

.spark { display: block; }
.spark path { fill: none; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.spark.bad path { stroke: var(--bad); }
.spark .axis-zero { stroke: var(--border-strong); stroke-dasharray: 2 2; }
.spark-empty { color: var(--subtle); }

.dbars { display: flex; flex-direction: column; gap: 2px; }
.dbar { display: grid; grid-template-columns: minmax(110px, 160px) minmax(0, 1fr) 80px; align-items: center; gap: 12px; padding: 5px 6px; border-radius: 6px; text-decoration: none; }
.dbar:hover { background: var(--sunken); }
.dbar-label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dbar-track { display: grid; grid-template-columns: 1fr 2fr; height: 14px; }
.dbar-neg { display: flex; justify-content: flex-end; border-right: 1px solid var(--border-strong); }
.dbar-neg i { background: var(--bad); border-radius: 3px 0 0 3px; }
.dbar-pos i { display: block; height: 100%; background: var(--accent); border-radius: 0 3px 3px 0; }
.dbar-neg i { display: block; height: 100%; }
.dbar-value { text-align: right; font-size: 13px; }

.stack { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; margin: 4px 0 14px; }
.seg { display: block; height: 100%; min-width: 3px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 40px; gap: 8px; align-items: center; font-size: 13px; }
.legend .muted { text-align: right; }

.scatter .danger-zone { fill: var(--bad-soft); }
.scatter .zone-label { fill: var(--bad); font-size: 10.5px; font-weight: 600; }
.scatter .pt { stroke: var(--surface); stroke-width: 1.5; cursor: pointer; transition: r .15s var(--ease); }
.scatter .pt:hover { r: 7; }
.scatter .pt.pos { fill: var(--accent); }
.scatter .pt.neg { fill: var(--subtle); }
.scatter .pt.trap { fill: var(--bad); }

.waterfall { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.waterfall li { display: grid; grid-template-columns: 170px minmax(0, 1fr) 100px; gap: 12px; align-items: center; font-size: 13px; }
.waterfall .num { text-align: right; }
.wf-track { position: relative; height: 16px; }
.wf-zero { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--border-strong); }
.wf-track i { display: block; height: 100%; border-radius: 3px; min-width: 2px; }
.wf-track i.in { background: var(--series-muted); }
.wf-track i.out { background: color-mix(in srgb, var(--bad) 75%, var(--surface)); }
.wf-track i.total { background: var(--accent); }
.wf-total { padding-top: 8px; border-top: 1px solid var(--border); font-weight: 600; }

.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.hbars li { display: grid; grid-template-columns: 200px minmax(0, 1fr) 60px; gap: 12px; align-items: center; }
.hbar i { display: block; height: 10px; border-radius: 3px; background: var(--series-muted); }
.hbars .num { text-align: right; }

/* ---------- Insight e avvisi ---------- */
.insights { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.insights li { display: grid; grid-template-columns: 28px minmax(0, 1fr) 20px; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border); }
.insights li:first-child { border-top: 0; padding-top: 0; }
.insights b { font-weight: 600; display: block; line-height: 1.35; }
.insights p { color: var(--muted); font-size: 13px; margin-top: 3px; }
.ins-ico { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--sunken); color: var(--text-2); }
.insights .bad .ins-ico { background: var(--bad-soft); color: var(--bad); }
.insights .good .ins-ico { background: var(--good-soft); color: var(--good); }
.insights .neutral .ins-ico { background: var(--accent-soft); color: var(--accent-ink); }
.ins-link { color: var(--subtle); align-self: center; }
.ins-link:hover { color: var(--accent); }

.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-item { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 14px 20px; border-top: 1px solid var(--border); }
.alert-item .sev { color: var(--warn); padding-top: 1px; }
.alert-item.critical .sev { color: var(--bad); }
.alert-top { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.alert-type { font-size: 12px; color: var(--muted); font-weight: 500; }
.alert-body p { margin-top: 2px; }
.alert-body p.muted { font-size: 13px; }

.thresholds .field { margin-bottom: 14px; }

/* ---------- Tabelle ---------- */
.table-block { display: flex; flex-direction: column; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar-end { display: flex; gap: 8px; margin-left: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 500; color: var(--text-2); }
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip .count { font-family: "Geist Mono", monospace; font-size: 11px; opacity: .7; }
.search { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface); color: var(--muted); }
.search input { border: 0; background: transparent; width: 160px; color: var(--text); }
.search input:focus { outline: none; }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); white-space: nowrap; padding: 0; }
th > button { display: inline-flex; align-items: center; gap: 4px; width: 100%; padding: 9px 12px; border: 0; background: none; color: inherit; cursor: pointer; font-weight: inherit; font-size: inherit; text-align: inherit; }
th.r > button { justify-content: flex-end; }
th:not(:has(button)) { padding: 9px 12px; }
th.sorted { color: var(--text); }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
td small { display: block; font-size: 11.5px; line-height: 1.2; }
td.r, th.r { text-align: right; }
td.r small { text-align: right; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s var(--ease); }
tr[data-href] { cursor: pointer; }
tr[data-href]:hover { background: var(--surface-2); }
.table-empty { padding: 40px; text-align: center; color: var(--muted); }
.table-foot { padding: 8px 16px; color: var(--subtle); font-size: 12px; border-top: 1px solid var(--border); }

/* ---------- Creator: confronto ---------- */
.compare .vs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare .vs > div { display: flex; flex-direction: column; gap: 4px; padding: 14px; border-radius: 10px; background: var(--sunken); }
.compare .vs b { font-size: 30px; font-weight: 500; letter-spacing: -0.04em; }
.compare .vs small { font-size: 12px; }
.verdict { display: flex; gap: 8px; align-items: flex-start; margin-top: 14px; font-weight: 500; }
.compare.trap .verdict { color: var(--bad); }
.compare:not(.trap) .verdict .ico { color: var(--good); }

/* ---------- Simulatore ---------- */
.field.inline { margin-bottom: 18px; }
.pick { list-style: none; margin: 0; padding: 0; max-height: 330px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-ctl); }
.pick li + li { border-top: 1px solid var(--border); }
.pick label { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 2px 8px; align-items: center; padding: 8px 10px; cursor: pointer; }
.pick label:hover { background: var(--surface-2); }
.pick small { grid-column: 2 / -1; font-size: 11.5px; }
.pick input { accent-color: var(--accent); }
.scenarios { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.scenario { display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 10px; background: var(--sunken); }
.scenario b { font-size: 21px; font-weight: 500; letter-spacing: -0.03em; }
.scenario.up b { color: var(--good); }
.scenario.down b { color: var(--bad); }
.scenario small { color: var(--muted); font-size: 11.5px; line-height: 1.3; margin-top: 4px; }
.scenario .muted { font-size: 12px; }
.breakdown { margin: 14px 0 0; display: flex; flex-direction: column; gap: 6px; }
.breakdown > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--border); }
.breakdown dt { color: var(--muted); }
.breakdown dd { margin: 0; text-align: right; }
.assumptions ul { margin: 0; padding-left: 18px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.assumptions h2 .ico { color: var(--accent); }

/* ---------- Report ---------- */
.report-card { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 14px; }
.report-ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-ink); }
.report-card p { margin: 4px 0 14px; }

/* ---------- Importazione ---------- */
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 150px; padding: 24px; border: 1.5px dashed var(--border-strong); border-radius: var(--r-card); background: var(--surface); cursor: pointer; text-align: center; transition: border-color .15s var(--ease), background .15s var(--ease); }
.dropzone .ico { color: var(--accent); }
.dropzone b { font-size: 16px; }
.dropzone:hover, .dropzone.over, .slot.over { border-color: var(--accent); background: var(--accent-soft); }
.slot { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; transition: border-color .15s var(--ease); }
.slot header { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.slot-ico { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--sunken); color: var(--muted); }
.slot.ok .slot-ico { background: var(--good-soft); color: var(--good); }
.slot.warn .slot-ico { background: var(--warn-soft); color: var(--warn); }
.slot.error { border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.slot.error .slot-ico { background: var(--bad-soft); color: var(--bad); }
.slot h3 { font-size: 14px; }
.slot-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-2); }
.slot-meta span { display: inline-flex; align-items: center; gap: 6px; }
.mapped { display: flex; flex-wrap: wrap; gap: 4px; }
.mapped span { padding: 1px 8px; border-radius: 999px; background: var(--sunken); font-size: 11.5px; color: var(--text-2); }
.slot-drop { display: flex; flex-direction: column; gap: 4px; padding: 16px; border: 1px dashed var(--border-strong); border-radius: var(--r-ctl); color: var(--text-2); cursor: pointer; text-align: center; }
.slot-drop small { color: var(--muted); font-size: 12px; }
.slot-drop:hover { border-color: var(--accent); }
.slot-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.issues li { display: flex; gap: 8px; align-items: flex-start; }
.issues li .ico { margin-top: 3px; }
.issues li.error { color: var(--bad); }
.issues li.warning .ico { color: var(--warn); }
.issues li.info { color: var(--muted); }
.issues li .btn { margin-left: auto; }
.preview { border: 1px solid var(--border); border-radius: var(--r-ctl); }
.preview table { font-size: 12px; }
.preview th, .preview td { padding: 6px 8px; }
.preview .used { background: var(--accent-soft); color: var(--accent-ink); }
.preview small { display: block; padding: 6px 8px; }
.quality { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.quality li { display: grid; grid-template-columns: 116px 190px minmax(0, 1fr); gap: 10px; align-items: center; font-size: 13px; }
.inline-error { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--bad); font-weight: 500; margin: 12px 0; }

/* ---------- Stati ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 56px 24px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r-card); }
.empty-state.small { border: 0; padding: 40px 20px; }
.empty-state h3 { color: var(--text); font-size: 15px; }
.empty-state p { max-width: 48ch; }
.welcome { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 40px; align-items: center; padding: 48px 8px; max-width: 1100px; }
.welcome h1 { font-size: clamp(30px, 3.4vw, 44px); line-height: 1.08; letter-spacing: -0.04em; font-weight: 600; }
.welcome-copy p { margin: 16px 0 24px; font-size: 16px; color: var(--text-2); max-width: 46ch; }
.welcome-steps { list-style: none; margin: 0; padding: 0; counter-reset: s; display: flex; flex-direction: column; gap: 10px; }
.welcome-steps li { counter-increment: s; display: grid; grid-template-columns: 32px 1fr; gap: 2px 12px; padding: 16px; border-radius: var(--r-card); background: var(--surface); border: 1px solid var(--border); }
.welcome-steps li::before { content: counter(s); grid-row: span 2; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; font-family: "Geist Mono", monospace; }
.welcome-steps span { color: var(--muted); font-size: 13px; }
.skeleton-page { display: flex; flex-direction: column; gap: 16px; }
.sk { border-radius: var(--r-card); background: linear-gradient(90deg, var(--sunken) 0%, var(--surface-2) 50%, var(--sunken) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.sk-kpis { height: 112px; } .sk-chart { height: 280px; } .sk-row { height: 200px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.tooltip { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; min-width: 160px; max-width: 280px; padding: 10px 12px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 12.5px; box-shadow: var(--shadow-pop); display: flex; flex-direction: column; gap: 4px; }
.tooltip b { font-weight: 600; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row em { margin-left: auto; font-style: normal; font-family: "Geist Mono", monospace; padding-left: 12px; }
.tip-row.muted { color: color-mix(in srgb, var(--bg) 65%, transparent); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 500; box-shadow: var(--shadow-pop); animation: enter .3s var(--ease); }
.print-root { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1240px) {
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-3 .span-2-md { grid-column: 1 / -1; }
  .kpi-sub.five { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1080px) {
  .g-2-1 { grid-template-columns: minmax(0, 1fr); }
  .fill-row { height: auto; min-height: 0; }
  .sticky { position: static; }
  .kpi-main { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(3) { border-left: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--border); }
  .kpi-sub { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .period-sub { display: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .25s var(--ease); box-shadow: var(--shadow-pop); }
  .nav-open .sidebar { transform: none; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .3); }
  .icon-btn.menu { display: grid; }
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .topbar-mid { order: 3; width: 100%; }
  .topbar-end .btn span { display: none; }
  .store .badge { display: none; }
  .view { padding: 16px 16px 48px; }
  .g-1-1, .g-2, .g-3, .welcome { grid-template-columns: minmax(0, 1fr); }
  .kpi-value { font-size: 23px; }
  .kpi-spark { display: none; }
  .kpi-sub.five, .kpi-sub.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dbar { grid-template-columns: 100px minmax(0, 1fr) 64px; gap: 8px; }
  .waterfall li { grid-template-columns: 120px minmax(0, 1fr) 84px; }
  .hbars li { grid-template-columns: 120px minmax(0, 1fr) 50px; }
  .quality li { grid-template-columns: 100px minmax(0, 1fr); }
  .quality li .muted { grid-column: 2; }
  .scenarios { grid-template-columns: minmax(0, 1fr); }
  .search input { width: 110px; }
  .chart .tick { font-size: 16px; }
  .scatter .tick { font-size: 13px; }
  .welcome { padding: 16px 0; gap: 24px; }
}
@media (max-width: 480px) {
  .chart .tick { font-size: 21px; }
  .scatter .tick { font-size: 16px; }
  .kpi-main, .kpi-sub, .kpi-sub.five, .kpi-sub.three { grid-template-columns: minmax(0, 1fr); }
  .kpi + .kpi { border-left: 0; border-top: 1px solid var(--border); }
  .compare .vs { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Stampa (PDF) ---------- */
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  body.printing > :not(.print-root) { display: none !important; }
  body.printing .print-root { display: block; }
  body.printing { background: #fff; color: #111; font-size: 10.5pt; }
  .sheet { color: #111; }
  .sheet-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 10px; border-bottom: 1.5px solid #111; margin-bottom: 14px; }
  .sheet-head > div { display: flex; align-items: center; gap: 8px; }
  .sheet-head .r { flex-direction: column; align-items: flex-end; gap: 0; font-size: 9.5pt; }
  .sheet-head .logo { background: #111; color: #fff; width: 22px; height: 22px; font-size: 12px; }
  .sheet h1 { font-size: 17pt; margin-bottom: 6px; }
  .sheet h2 { font-size: 11pt; margin: 16px 0 6px; }
  .sheet-note { color: #8a5300; font-size: 9pt; margin-bottom: 8px; }
  .sheet-kpis { width: 100%; border-collapse: separate; border-spacing: 6px 0; margin: 8px -6px; }
  .sheet-kpis td { border: 1px solid #ccc; border-radius: 6px; padding: 8px 10px; vertical-align: top; white-space: normal; }
  .sheet-kpis span { display: block; font-size: 8.5pt; color: #555; }
  .sheet-kpis b { display: block; font-size: 14pt; font-weight: 600; font-family: "Geist Mono", monospace; }
  .sheet-kpis small { font-size: 8pt; color: #555; }
  .sheet-table { width: 100%; font-size: 9pt; border-collapse: collapse; }
  .sheet-table th { position: static; background: #f2f2f2; color: #333; font-size: 8.5pt; padding: 5px 6px; }
  .sheet-table td { padding: 4px 6px; border-bottom: 1px solid #e3e3e3; white-space: nowrap; }
  .sheet-table .r { text-align: right; font-family: "Geist Mono", monospace; }
  .sheet-table .neg { color: #b42318; }
  .sheet-list { margin: 0; padding-left: 16px; font-size: 9.5pt; }
  .sheet-list li { margin-bottom: 3px; }
  .sheet-small { font-size: 8.5pt; color: #555; margin-top: 8px; }
  .sheet-foot { margin-top: 18px; padding-top: 8px; border-top: 1px solid #ccc; font-size: 8pt; color: #666; }
  .sheet section { break-inside: avoid; }
  .sheet section.break { break-inside: auto; }
  .sheet tr { break-inside: avoid; }
}
