/* MIRA — foglio di stile
 *
 * Stesso linguaggio visivo di AESTIMETRUM: intestazione scura con le schede,
 * pannelli bianchi su fondo grigio chiaro, un solo inchiostro per le azioni
 * principali. Il colore del rischio non è mai l'unico portatore di significato:
 * ogni livello ha etichetta testuale e indicatore a tacche (WCAG 1.4.1).
 */

:root {
  --ink: #16181d;
  --ink-2: #4a505c;
  --ink-3: #7b8190;
  --line: #e2e4e9;
  --line-2: #cfd3da;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --accent: #1d4ed8;
  --accent-soft: #e8eefc;
  --warn: #9a3412;
  --warn-soft: #fff4ec;
  --ok: #166534;
  --ok-soft: #e7f6ec;
  --amber: #8a5a00;
  --amber-soft: #fff7e0;
  --danger: #991b1b;
  --danger-soft: #fde8e8;
  --radius: 10px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;

  /* Livelli di rischio */
  --lv-negligible: #5b6475;
  --lv-low: #15803d;
  --lv-moderate: #a16207;
  --lv-high: #c2410c;
  --lv-critical: #b91c1c;

  /* Serie dei grafici: palette categoriale validata (slot 1 e 2). */
  --series-1: #2a78d6;
  --series-2: #eb6834;

  /* Alias usati dai componenti */
  --surface: var(--panel);
  --paper: var(--bg);
  --line-strong: var(--line-2);
  --focus: #1d4ed8;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 28px; --s7: 40px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg);
  font-size: 14px; line-height: 1.45; font-variant-numeric: tabular-nums;
}
[x-cloak] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0 0 .5rem; letter-spacing: -.01em; line-height: 1.25; }
h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
.muted { color: var(--ink-3); }
.small { font-size: .8rem; font-weight: 400; }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: .8rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--panel); padding: .4rem .7rem; z-index: 60; border-radius: 6px; }
.skip:focus { left: 8px; }

/* ── intestazione ───────────────────── */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1.25rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .7rem; color: #fff; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand strong { display: block; letter-spacing: .02em; }
.brand small { display: block; color: #aab0bc; font-size: .72rem; }
.mark {
  width: 32px; height: 32px; border-radius: 7px; background: #fff; color: var(--ink);
  display: grid; place-items: center; font-weight: 800; flex: none;
}
.top-right { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; align-items: center; }
.top > .tabs { order: 3; flex-basis: 100%; margin: .1rem -.3rem -.1rem; padding-top: .45rem; border-top: 1px solid #ffffff1a; }
.tabs > a, .tab-menu > summary {
  color: #c9ced8; border: 0; padding: .45rem .8rem; border-radius: 6px; font: inherit; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: .3rem; list-style: none; white-space: nowrap;
}
.tab-menu > summary::-webkit-details-marker { display: none; }
.tab-menu > summary::after { content: ""; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid currentColor; opacity: .7; }
.tabs > a:hover, .tab-menu > summary:hover { color: #fff; background: #ffffff14; text-decoration: none; }
.tabs > a[aria-current="page"], .tab-menu.current > summary { color: var(--ink); background: #fff; font-weight: 600; }
.tab-menu { position: relative; }
.menu-pop {
  position: absolute; left: 0; top: calc(100% + 6px); background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px #0002;
  min-width: 220px; padding: .4rem; z-index: 30; display: flex; flex-direction: column;
}
.menu-pop a { color: var(--ink); padding: .5rem .6rem; border-radius: 6px; text-decoration: none; }
.menu-pop a:hover { background: var(--bg); text-decoration: none; }
.menu-pop a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.menu-pop hr { margin: .3rem 0; }

.top select, .lang select {
  background: #ffffff14; color: #fff; border: 1px solid #ffffff33; border-radius: 6px;
  padding: .35rem .5rem; font: inherit; font-size: .84rem; cursor: pointer; width: auto; max-width: 280px;
}
.top select option { color: var(--ink); background: #fff; }
.top form { margin: 0; }

.user-menu { position: relative; }
.user-menu > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: .45rem;
  background: #ffffff14; color: #fff; border: 1px solid #ffffff33; border-radius: 7px;
  padding: .25rem .6rem .25rem .3rem; font-size: .84rem; max-width: 240px;
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover { background: #ffffff22; }
.user-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: #fff; color: var(--ink); display: inline-grid; place-items: center; font-size: .7rem; font-weight: 800; flex: none; }
.user-pop { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px #0002; min-width: 250px; padding: .4rem; z-index: 30; display: flex; flex-direction: column; }
.user-pop-head { display: flex; flex-direction: column; gap: .15rem; padding: .5rem .6rem .6rem; border-bottom: 1px solid var(--line); margin-bottom: .3rem; }
.user-pop-head .status { align-self: flex-start; margin-top: .2rem; }
.user-pop a, .user-pop button { display: flex; width: 100%; border: 0; background: none; justify-content: flex-start; padding: .5rem .6rem; border-radius: 6px; font: inherit; font-weight: 500; color: var(--ink); text-decoration: none; cursor: pointer; }
.user-pop a:hover, .user-pop button:hover { background: var(--bg); text-decoration: none; }
.user-pop form { margin: 0; }

/* ── struttura ──────────────────────── */
.main { max-width: 1440px; margin: 0 auto; padding: 1.25rem; min-width: 0; }
.page { min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; display: flex; align-items: center; gap: .1rem; flex-wrap: wrap; }
.page-head .meta { margin-top: .2rem; color: var(--ink-2); font-size: .88rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.section { margin-top: 1.5rem; }
.section > h2 { margin-bottom: .6rem; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; }
.split-wide { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.25rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; }
.panel + .panel { margin-top: 1rem; }
.foot {
  max-width: 1440px; margin: 1rem auto 0; padding: 1rem 1.25rem 2rem; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem;
  font-size: .76rem; color: var(--ink-3); border-top: 1px solid var(--line);
}

/* Frase di sintesi (dashboard, FAIR) */
.statement { font-size: 1.25rem; font-weight: 650; line-height: 1.35; max-width: 46em; margin: 0 0 1rem; letter-spacing: -.01em; }
.statement strong { color: var(--danger); }
.statement .calm { color: var(--ok); }

/* ── pulsanti e moduli ──────────────── */
.btn, button.btn {
  font: inherit; font-weight: 550; padding: .5rem .9rem; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line-2); background: #fff; color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; line-height: 1.3;
}
.btn:hover { border-color: var(--ink-3); color: var(--ink); text-decoration: none; }
.btn-primary, button.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover, button.btn-primary:hover { background: #000; color: #fff; border-color: #000; }
.btn-danger, button.btn-danger { color: var(--warn); }
.btn-danger:hover { border-color: var(--warn); }
.btn-link { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; font-weight: 550; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }
.btn-small { padding: .25rem .55rem; font-size: .8rem; }
.btn.wide, button.wide { width: 100%; justify-content: center; padding: .65rem; }

form.stack { display: grid; gap: .8rem; max-width: 820px; }
form.stack.wide { max-width: 1040px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem .9rem; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .65rem .9rem; align-items: start; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .65rem .9rem; align-items: start; }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field > label, .field > .label { font-size: .82rem; color: var(--ink-2); font-weight: 550; }
.field .hint { font-size: .78rem; color: var(--ink-3); }
.field .error, .error { font-size: .8rem; color: var(--warn); font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=url],
select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line-2);
  border-radius: 7px; padding: .45rem .55rem; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--ink); }
textarea { min-height: 84px; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: .8rem; min-height: 420px; }
select[multiple] { min-height: 140px; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--warn); background: var(--warn-soft); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem 1rem; margin: 0; background: var(--panel); }
legend { font-weight: 650; padding: 0 .3rem; font-size: .9rem; }
.check { display: flex; gap: .5rem; align-items: center; font-size: .86rem; }
.form-actions { display: flex; gap: .5rem; align-items: center; padding-top: .8rem; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* Scala 1..N come gruppo di radio */
.scale { display: flex; gap: 0; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; width: max-content; background: #fff; }
.scale label { position: relative; cursor: pointer; }
.scale input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.scale span { display: block; min-width: 38px; padding: .35rem .6rem; text-align: center; border-right: 1px solid var(--line); font-weight: 600; }
.scale label:last-child span { border-right: 0; }
.scale input:checked + span { background: var(--ink); color: #fff; }
.scale input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.rating-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: .75rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.rating-row:last-child { border-bottom: 0; }
.rating-row .weight { font-size: .74rem; color: var(--ink-3); }

/* ── messaggi ───────────────────────── */
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; font-size: .88rem; }
.flash-ok { background: #ecfdf3; color: var(--ok); border-color: #b7e4c7; }
.flash-err { background: var(--warn-soft); color: var(--warn); border-color: #f3c7a8; }
.flash-warn { background: var(--amber-soft); color: var(--amber); border-color: #f0d9a0; }
.empty { color: var(--ink-3); text-align: center; padding: 2.5rem 1rem; background: var(--panel); border: 1px dashed var(--line-2); border-radius: var(--radius); }
.empty p:last-child { margin-bottom: 0; }

/* ── tabelle ────────────────────────── */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.table th, .table td { padding: .5rem .6rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.table thead th { font-size: .72rem; color: var(--ink-3); font-weight: 650; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; background: #fafbfc; position: sticky; top: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfc; }
.table .code { font-weight: 650; white-space: nowrap; }
.table th a { color: inherit; text-decoration: none; }
.table th a[aria-sort] { color: var(--ink); }
.table th a[aria-sort="ascending"]::after { content: " ↑"; }
.table th a[aria-sort="descending"]::after { content: " ↓"; }
.table td.wide { min-width: 240px; }
.table .code .small { font-weight: 400; }
dl.props { display: grid; grid-template-columns: fit-content(15rem) 1fr; gap: .3rem .9rem; margin: 0; font-size: .86rem; }
dl.props dt { color: var(--ink-3); }
dl.props dd { margin: 0; font-weight: 600; }

.filters { display: flex; gap: .6rem .9rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; padding: .8rem 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.filters .field { min-width: 150px; }
.filters .field.grow { flex: 1 1 220px; }

/* ── livello di rischio: etichetta + tacche ── */
.risk { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 650; font-size: .82rem; color: var(--lv); }
.notches { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.notches i { display: block; width: 4px; background: var(--line-2); border-radius: 1px; }
.notches i.on { background: var(--lv); }
.notches i:nth-child(1) { height: 5px; } .notches i:nth-child(2) { height: 7px; } .notches i:nth-child(3) { height: 9px; }
.notches i:nth-child(4) { height: 11px; } .notches i:nth-child(5) { height: 13px; } .notches i:nth-child(n+6) { height: 14px; }
.lv-negligible, .lv-very_low { --lv: var(--lv-negligible); }
.lv-low { --lv: var(--lv-low); }
.lv-moderate { --lv: var(--lv-moderate); }
.lv-high { --lv: var(--lv-high); }
.lv-critical, .lv-very_high { --lv: var(--lv-critical); }
.risk.none { color: var(--ink-3); font-weight: 400; }
:where(.risk, .cell, .dist li) { --lv: var(--ink-3); }

/* Etichette di stato (come le .status di AESTIMETRUM) */
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 5px; background: #eef0f3; color: var(--ink-2); white-space: nowrap; vertical-align: 1px; }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-warn { background: var(--amber-soft); color: var(--amber); }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.status { font-size: .74rem; font-weight: 700; padding: 2px 7px; border-radius: 5px; background: #eef0f3; color: var(--ink-2); }
.count { display: inline-block; min-width: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); font-size: .8rem; text-align: center; vertical-align: middle; }
.delta-up { color: var(--warn); font-weight: 650; }
.delta-down { color: var(--ok); font-weight: 650; }

/* ── indicatori (kpi) ───────────────── */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kv > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; display: flex; flex-direction: column-reverse; justify-content: flex-end; }
.kv > div:first-child { background: var(--ink); border-color: var(--ink); color: #fff; }
.kv > div:first-child .k { color: #c4c9d3; }
.kv .v { font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; margin-top: .2rem; line-height: 1.15; }
.kv .k { font-size: .72rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; font-weight: 650; }
.kv a { color: inherit; text-decoration: none; }
.kv a:hover .k { text-decoration: underline; }
.kv .alert .v { color: var(--danger); }

/* ── heatmap ────────────────────────── */
.heat { display: grid; grid-template-columns: auto repeat(var(--n, 5), minmax(54px, 1fr)); gap: 4px; align-items: stretch; }
.heat .axis { font-size: .74rem; color: var(--ink-2); display: flex; align-items: center; }
.heat .axis-l { justify-content: flex-end; text-align: right; padding-right: .5rem; }
.heat .axis-i { justify-content: center; text-align: center; padding-top: .25rem; }
.heat .corner { font-size: .72rem; color: var(--ink-3); display: flex; align-items: flex-end; justify-content: flex-end; padding: 0 .5rem .25rem 0; }
.cell {
  position: relative; aspect-ratio: 1.35; border: 1px solid color-mix(in srgb, var(--lv) 35%, white);
  background: color-mix(in srgb, var(--lv) 9%, white); border-radius: 6px;
  font: inherit; color: var(--ink); cursor: default; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.cell.has { background: color-mix(in srgb, var(--lv) 26%, white); cursor: pointer; }
.cell.has:hover { background: color-mix(in srgb, var(--lv) 38%, white); }
.cell.on { outline: 2px solid var(--ink); outline-offset: 1px; }
.cell .count { background: none; color: var(--ink); font-weight: 800; font-size: 1.35rem; line-height: 1; padding: 0; }
.cell .lvl { position: absolute; left: 5px; top: 3px; font-size: .62rem; color: var(--ink-2); }
.heat-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .75rem; }
.heat-legend span { display: inline-flex; align-items: center; gap: 6px; }
.heat-detail { margin-top: 1rem; }
.heat.n3 { --n: 3; } .heat.n4 { --n: 4; } .heat.n5 { --n: 5; } .heat.n6 { --n: 6; }
.heat.n7 { --n: 7; } .heat.n8 { --n: 8; } .heat.n9 { --n: 9; } .heat.n10 { --n: 10; }
.matrix .cell { aspect-ratio: auto; min-height: 40px; cursor: default; }
.matrix .cell .lvl { position: static; font-size: .74rem; color: var(--ink); }

/* Distribuzione per livello */
.dist { display: grid; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.dist li { display: grid; grid-template-columns: 130px 1fr 40px; gap: .75rem; align-items: center; font-size: .84rem; }
.dist svg { width: 100%; height: 14px; display: block; }
.dist .bar { fill: var(--lv); }
.dist .track { fill: #f0f1f4; }

.trend > svg { width: 100%; height: auto; display: block; }
.trend .total { fill: #dfe2e8; }
.trend .above { fill: var(--lv-critical); }
.trend text { font-size: 11px; fill: var(--ink-2); font-family: var(--font); }

/* ── scenario ───────────────────────── */
.chain { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.chain > div { padding: .75rem .9rem; border-right: 1px solid var(--line); position: relative; }
.chain > div:last-child { border-right: 0; }
.chain > div:not(:last-child)::after {
  content: ""; position: absolute; right: -6px; top: 50%; width: 10px; height: 10px; margin-top: -5px;
  background: var(--panel); border-top: 1px solid var(--line); border-right: 1px solid var(--line); transform: rotate(45deg); z-index: 1;
}
.chain .k { font-size: .72rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; font-weight: 650; }
.chain .v { font-weight: 600; }
.compare { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: center; }
.compare .arrow { color: var(--ink-3); font-size: 20px; }
.rating-big { font-size: 1.2rem; }
.rating-big .risk { font-size: 1.1rem; gap: 12px; }
.rating-big .notches { transform: scale(1.4); transform-origin: left bottom; margin-right: 6px; }
.trace { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.trace li { padding: .75rem 0 .75rem 36px; border-bottom: 1px solid var(--line); position: relative; counter-increment: step; }
.trace li::before { content: counter(step); position: absolute; left: 0; top: .75rem; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: #fff; font-size: .72rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.trace .formula, .formula { font-family: var(--mono); font-size: .75rem; color: var(--ink-2); background: #f5f6f8; padding: .3rem .5rem; border-radius: 6px; display: inline-block; }
.todo { list-style: none; margin: 0; padding: 0; }
.todo li { display: grid; grid-template-columns: auto 1fr auto; gap: .75rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.todo s { color: var(--ink-3); }
.actions a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.sticky { position: sticky; top: 72px; align-self: start; }

/* Metodologie predefinite */
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.preset { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.preset h3 { font-size: 1rem; }
.preset p { margin: 0; }
.preset.current { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }
.preset dl.props { grid-template-columns: 1fr auto; gap: 2px .75rem; margin-top: auto; }
.preset dl.props dd { text-align: right; }
.preset form { margin-top: .5rem; }

/* ── FAIR ───────────────────────────── */
.section-tight { margin: .5rem 0 .75rem; }
.est-row { display: grid; grid-template-columns: minmax(220px, 1.6fr) repeat(3, minmax(90px, 1fr)); gap: .75rem; align-items: end; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.est-row:last-child { border-bottom: 0; }
.est-label { display: grid; gap: 2px; }
.est-label .label { font-weight: 650; font-size: .86rem; }
.est-label .hint { font-size: .78rem; color: var(--ink-3); }
.est-in { display: grid; gap: 2px; font-size: .74rem; color: var(--ink-3); }
.est-row.invalid input { border-color: var(--warn); }
.est-error { grid-column: 1 / -1; font-size: .8rem; color: var(--warn); font-weight: 600; }
.chart { width: 100%; height: auto; display: block; font-family: var(--font); }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--line-2); stroke-width: 1; }
.chart .tick { font-size: 11px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart .axis-title { font-size: 12px; fill: var(--ink-2); }
.chart .note { font-size: 12px; fill: var(--ink-2); }
.chart .note.strong { fill: var(--ink); font-weight: 600; paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--series-1); }
.chart .line.s2 { stroke: var(--series-2); }
.chart .dot { stroke: var(--panel); stroke-width: 2; }
.chart .dot.s1 { fill: var(--series-1); }
.chart .threshold { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .crosshair { stroke: var(--ink-3); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.lec-wrap { position: relative; max-width: 980px; }
.chart-wrap { max-width: 980px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .9rem; }
.cards .panel h3 { margin: 0 0 .4rem; }
.ind-chart .line { stroke: var(--series-1); }
.ind-chart .limit { stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 6 4; }
.ind-chart .warn { stroke: var(--amber); stroke-width: 1; }
.ind-chart .note { paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }
.ind-chart .note.limit-t { fill: var(--danger); font-weight: 600; }
.ind-chart .pt { fill: var(--panel); stroke: var(--series-1); stroke-width: 2; }
.ind-chart .pt.warning { fill: var(--amber); stroke: var(--panel); }
.ind-chart .pt.breach { fill: var(--danger); stroke: var(--panel); }
.ind-chart .target { fill: transparent; }
.tag-cat { background: #eef2ff; color: #3730a3; }
.chart-tip { position: absolute; top: 8px; min-width: 180px; max-width: 220px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; padding: .5rem .7rem; font-size: .8rem; pointer-events: none; box-shadow: 0 8px 24px #0002; }
.chart-tip .tip-head { color: var(--ink-2); margin-bottom: 4px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 8px; }
.legend { display: flex; gap: .4rem 1rem; flex-wrap: wrap; font-size: .78rem; color: var(--ink-2); margin-bottom: .5rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 16px; height: 2px; border-radius: 1px; }
.key.s1 { background: var(--series-1); }
.key.s2 { background: var(--series-2); }
.key.thr { height: 0; border-top: 1px dashed var(--ink-3); }
.reset summary { color: var(--accent); }
details > summary { cursor: pointer; font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }
.htmx-request.loading-dim, .htmx-request .loading-dim { opacity: .55; transition: opacity .15s; }

/* ── guida ──────────────────────────── */
.guide { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.guide-toc { position: sticky; top: 72px; display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; }
.guide-toc h2 { font-size: .74rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; margin: .6rem 0 .3rem; }
.guide-toc ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.guide-toc a { display: block; color: var(--ink-2); text-decoration: none; padding: .25rem .5rem; border-radius: 6px; }
.guide-toc a:hover { background: #eef0f3; color: var(--ink); }
.guide .prose { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.5rem; }
.prose { max-width: 820px; font-size: .92rem; line-height: 1.6; }
.prose h1 { margin-bottom: 1rem; }
.prose h2 { margin: 2rem 0 .6rem; padding-top: 1rem; border-top: 1px solid var(--line); scroll-margin-top: 80px; }
.prose h2:first-of-type { border-top: 0; margin-top: 1rem; padding-top: 0; }
.prose h3 { margin: 1.2rem 0 .4rem; scroll-margin-top: 80px; }
.prose p, .prose ul, .prose ol { margin: 0 0 .75rem; }
.prose li { margin-bottom: .3rem; }
.prose code { font-family: var(--mono); font-size: .8rem; background: #f5f6f8; padding: 2px 5px; border-radius: 4px; }
.prose pre { background: #f5f6f8; border-radius: 8px; padding: .7rem .9rem; overflow-x: auto; }
.prose pre code { padding: 0; }
.prose .table-wrap { margin: .75rem 0 1rem; }
.prose blockquote, .prose aside.note { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: .6rem .9rem; margin: 1rem 0; border-radius: 0 8px 8px 0; }
.guide-pdf { margin-bottom: .5rem; }

/* ── aiuto in linea ─────────────────── */
.help-btn {
  display: inline-grid; place-items: center; width: 20px; height: 20px; padding: 0; margin-left: .45rem;
  border-radius: 50%; border: 1px solid var(--line-2); background: #fff; color: var(--ink-2);
  font: 700 11px/1 var(--font); cursor: pointer; vertical-align: middle; letter-spacing: 0;
}
.help-btn:hover, .help-btn:focus-visible { background: var(--ink); color: #fff; border-color: var(--ink); }
dialog#help-dlg {
  max-width: 680px; width: calc(100% - 2rem); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.2rem 1.4rem; box-shadow: 0 20px 60px #0004; color: var(--ink);
}
dialog#help-dlg::backdrop { background: #16181d66; }
#help-dlg-body { font-size: .9rem; line-height: 1.55; max-height: 62vh; overflow: auto; }
#help-dlg-body h2, #help-dlg-body h3 { margin-top: 0; border: 0; padding: 0; }
.dlg-actions { display: flex; justify-content: flex-end; align-items: center; gap: .75rem; margin-top: 1rem; }

/* ── accesso e registrazione ────────── */
.auth-body { min-height: 100vh; display: flex; flex-direction: column; }
.auth-main { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 3rem 16px 2rem; width: 100%; }
.auth-card { width: 100%; max-width: 420px; padding: 1.6rem 1.6rem 1.3rem; box-shadow: 0 10px 30px #0000000d; }
.auth-form { display: flex; flex-direction: column; gap: .8rem; }
.auth-form h1 { font-size: 1.35rem; margin: 0; }
.auth-form > p { margin: 0; }
.auth-form .form-actions { border: 0; padding-top: .2rem; }
.auth-links { display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; font-size: .86rem; }
.auth-links a { font-weight: 550; }
.auth-card .flash { margin: 0; }

/* ── amministrazione, piano ─────────── */
.reg-settings { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; padding: .8rem 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.plan-approval p { margin: 0 0 .5rem; }
.plan-approval p:last-child { margin-bottom: 0; }
.plan-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.table.plan td { vertical-align: top; }

/* ── responsive ─────────────────────── */
@media (max-width: 1100px) {
  .split, .split-wide { grid-template-columns: 1fr; }
  .chain { grid-template-columns: 1fr; }
  .chain > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .chain > div::after { display: none; }
  .sticky { position: static; }
  .guide { grid-template-columns: 1fr; }
  .guide-toc { position: static; }
}
@media (max-width: 860px) {
  .main { padding: .75rem; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .statement { font-size: 1.1rem; }
  .est-row { grid-template-columns: repeat(3, 1fr); }
  .est-label { grid-column: 1 / -1; }
  .cell .lvl { display: none; }
  .cell .count { font-size: 1.1rem; }
  .heat { gap: 3px; grid-template-columns: auto repeat(var(--n, 5), minmax(36px, 1fr)); }
  .heat .axis { font-size: .68rem; }
  .user-label { display: none; }
  .menu-pop, .user-pop { position: fixed; left: 12px; right: 12px; top: auto; min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  .top, .actions, .filters, .form-actions, .foot, .help-btn { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; max-width: none; }
  .panel, .kv > div { break-inside: avoid; border-color: #bbb; }
  .kv > div:first-child { background: #fff; color: #000; border: 2px solid #000; }
}
@media (max-width: 860px) {
  .top > .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .top > .tabs::-webkit-scrollbar { display: none; }
  .menu-pop { top: 120px; }
}
.cards > .panel { margin: 0; }
.auth-foot { margin-top: 1.4rem; font-size: .78rem; color: var(--ink-3); text-align: center; }
.covbar { width: 100%; height: 10px; display: block; margin: .5rem 0; border-radius: 4px; overflow: hidden; }
.covbar .gap { fill: var(--danger-soft); }
.covbar .covered { fill: var(--ok); }
.covbar .partial { fill: #d4a017; }
.covbar .planned { fill: #6366f1; }
.fw-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.fw-head h2 { margin: 0; font-size: 1.05rem; }
.fw-off { opacity: .8; }
.table tr.grp th { background: var(--paper, #f7f8fa); text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }

/* 0.8: registri, BIA, rischio quantistico */
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .35rem .9rem; margin: .3rem 0; }
.bia-grid select { min-width: 4.2rem; }
.bia-grid tfoot td, .bia-grid tfoot th { border-top: 2px solid var(--line); }
.cards > article.panel h2 { font-size: 1.05rem; margin: 0 0 .4rem; }
.split > .panel + .panel, .split-wide > .panel + .panel { margin-top: 0; }
