:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f0f0ee;
  --line: #e2e2df;
  --text: #191919;
  --text-2: #666666;
  --text-3: #8a8a8a;
  --accent: #6f7d8c;
  --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600;
  --s5: #ee7fac; --s6: #008a17; --s7: #6a4ce2; --s8: #ec4647;
  --pos: #006c10; --neg: #c42b2c;
  --good: #0aac23; --warn: #fbb315; --serious: #f18a59; --crit: #dc3c3d;
  --div-neg: #ec4647; --div-mid: #efefef; --div-pos: #257de0;
  --grid: #ececea;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101010; --surface: #191919; --surface-2: #222222; --line: #2c2c2c;
    --text: #efefef; --text-2: #9c9c9c; --text-3: #767676; --accent: #a9b6c4;
    --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05;
    --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
    --pos: #3ccf55; --neg: #f07373;
    --div-neg: #eb6263; --div-mid: #383838; --div-pos: #338ced;
    --grid: #262626;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101010; --surface: #191919; --surface-2: #222222; --line: #2c2c2c;
  --text: #efefef; --text-2: #9c9c9c; --text-3: #767676; --accent: #a9b6c4;
  --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05;
  --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
  --pos: #3ccf55; --neg: #f07373;
  --div-neg: #eb6263; --div-mid: #383838; --div-pos: #338ced;
  --grid: #262626;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
.num, td.n, .tile .v { font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }

/* header */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #b9c2cc 45%, #6f7d8c); box-shadow: 0 0 0 1px var(--line); }
.meta { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 12px; }
.icon-btn { background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; width: 32px; height: 32px; font-size: 15px; cursor: pointer; }

/* bottom tabs */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none; border: 0; color: var(--text-3); font: 500 10.5px/1.2 Inter, sans-serif;
  padding: 8px 0 9px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
}
.tabs button i { font-style: normal; font-size: 18px; line-height: 1; }
.tabs button.on { color: var(--text); }
.tabs button.on i { color: var(--s1); }
@media (min-width: 900px) {
  .tabs { position: sticky; top: 53px; bottom: auto; max-width: 1180px; margin: 0 auto;
    border: 1px solid var(--line); border-radius: 0 0 14px 14px; }
  .tabs button { flex-direction: row; justify-content: center; font-size: 13px; padding: 11px 0; gap: 7px; }
  body { padding-bottom: 24px; }
}

main { max-width: 1180px; margin: 0 auto; padding: 14px 16px 24px; }
h2 { font-size: 20px; margin: 10px 0 2px; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 0; font-weight: 600; }
.lede { color: var(--text-2); margin: 0 0 14px; font-size: 13.5px; }

.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid.two { grid-template-columns: 1fr 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 14px 10px; min-width: 0;
}
.card-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.card .sub { color: var(--text-2); font-size: 12.5px; margin: 2px 0 0; }
.note { color: var(--text-3); font-size: 11.5px; margin: 6px 0 2px; }
.chart { width: 100%; height: 260px; }
.chart.tall { height: 340px; }
.chart.short { height: 170px; }
.chart.xs { height: 120px; }

/* chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2);
  border-radius: 999px; padding: 4px 10px; font: 500 12px Inter, sans-serif; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; position: sticky; top: 53px; z-index: 10;
  padding: 8px 0; background: var(--bg); }
@media (min-width: 900px) { .toolbar { top: 100px; } }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.tile .k { color: var(--text-2); font-size: 12px; }
.tile .v { font-size: 22px; font-weight: 500; margin-top: 2px; letter-spacing: -.02em; }
.tile .d { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.up { color: var(--pos); } .down { color: var(--neg); }

/* signals */
.sig { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.sig:first-child { border-top: 0; }
.sig .ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; }
.sig .ic.p { background: var(--good); } .sig .ic.n { background: var(--crit); } .sig .ic.z { background: var(--accent); }
.sig .area { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.sig .txt { font-size: 13.5px; }
.badge { display: inline-block; font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 6px;
  background: var(--warn); color: #191919; margin-left: 6px; vertical-align: 1px; }

/* tables */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-2); font-weight: 500; font-size: 11.5px; padding: 6px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.n, th.n { text-align: right; }
tr:last-child td { border-bottom: 0; }

.mtf { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.mtf span { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 12px; }

.empty { color: var(--text-2); font-size: 13px; padding: 24px 6px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }
.status-ok { color: var(--pos); } .status-err { color: var(--neg); }
.loading { color: var(--text-2); text-align: center; padding: 60px 0; }
details.method summary { cursor: pointer; color: var(--text-2); font-size: 13px; }
details.method p, details.method li { font-size: 13px; color: var(--text-2); }

/* ---- v2 additions ---- */
.tabs { grid-template-columns: none; display: flex; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 64px; }
@media (min-width: 900px) { .tabs button { flex: 1 0 auto; padding: 11px 10px; } }

.asof { display: inline-block; font-size: 11px; font-weight: 500; padding: 1px 7px; border-radius: 999px; margin: 3px 0 0;
  border: 1px solid var(--line); color: var(--text-2); background: var(--surface-2); white-space: nowrap; text-decoration: none; }
.asof::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; background: var(--text-3); }
.asof.fresh::before { background: var(--good); } .asof.aging::before { background: var(--warn); } .asof.old::before { background: var(--crit); }
.meta .asof { font-size: 11.5px; margin: 0; }
@media (max-width: 420px) { .brand { font-size: 14px; } .meta .asof { font-size: 10.5px; padding: 1px 6px; } }

.info { background: none; border: 0; color: var(--s1); cursor: pointer; font-size: 13px; padding: 0 0 0 5px; line-height: 1; vertical-align: 1px; }
.tile .k .info { font-size: 12px; }

dialog#dlg { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text);
  width: min(640px, calc(100vw - 24px)); max-height: 85vh; padding: 18px 18px 14px; overflow: auto; }
dialog#dlg::backdrop { background: rgba(0,0,0,.45); }
#dlg-body h3 { font-size: 17px; margin: 0 28px 8px 0; }
#dlg-body h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 14px 0 4px; }
#dlg-body p, #dlg-body li { font-size: 14px; line-height: 1.5; }
#dlg-body ul { padding-left: 18px; margin: 4px 0; }
#dlg-body pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap;
  font: 12.5px/1.5 "JetBrains Mono", monospace; margin: 4px 0; }
.dlg-x { position: sticky; float: right; top: 0; background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; width: 30px; height: 30px; cursor: pointer; }

.rangebar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rangebar .dates { display: flex; gap: 6px; font-size: 12px; color: var(--text-2); }
.rangebar input[type=date] { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 3px 6px; font: 12px Inter, sans-serif; max-width: 140px; }
.toolbar { flex-direction: column; align-items: stretch; }
@media (min-width: 760px) { .toolbar { flex-direction: row; align-items: center; justify-content: space-between; } }
.chips-col { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.chips { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
@media (min-width: 760px) { .chips { flex-wrap: wrap; } }

.tiles.mini { grid-template-columns: repeat(2, 1fr); margin: 8px 0; }
@media (min-width: 760px) { .tiles.mini { grid-template-columns: repeat(4, 1fr); } }
.tiles.mini .tile .v { font-size: 18px; }

.sticky1 table td:first-child, .sticky1 table th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
th.sortable { cursor: pointer; user-select: none; } th.sorted { color: var(--text); }
.qa-list { list-style: none; padding: 0; } .qa-list li { font-size: 12.5px; padding: 3px 0; color: var(--text-2); }
.qa { display: inline-block; min-width: 52px; text-align: center; font-size: 10.5px; font-weight: 600; border-radius: 6px; padding: 1px 5px; color: #191919; }
.qa.ok { background: var(--good); color: #fff; } .qa.info { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); }
.qa.avviso { background: var(--warn); } .qa.errore { background: var(--crit); color: #fff; }
.prose p, p.body { font-size: 14px; line-height: 1.55; color: var(--text); margin: 8px 0; }
ul.src { padding-left: 18px; } ul.src li { font-size: 13px; margin: 3px 0; } a { color: var(--s1); }
.lede .asof { margin-left: 4px; }
table.wrap td { white-space: normal; vertical-align: top; }
table.wrap td:first-child { min-width: 220px; }
