:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6f6e69;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0f7a3d;
  --good-bg: #e3f4e9;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --bad: #b3261e;
  --bad-bg: #fbe6e4;
  --grid: #e7e6e1;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948; --s0: #9a9993;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #33332f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9c9b93;
    --accent: #3987e5; --accent-ink: #ffffff;
    --good: #5fd08f; --good-bg: #173524; --warn: #f2c25b; --warn-bg: #3a2e12; --bad: #f28b82; --bad-bg: #3d1d1a;
    --grid: #2b2b28;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767; --s0: #77766f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9c9b93;
  --accent: #3987e5; --accent-ink: #ffffff;
  --good: #5fd08f; --good-bg: #173524; --warn: #f2c25b; --warn-bg: #3a2e12; --bad: #f28b82; --bad-bg: #3d1d1a;
  --grid: #2b2b28;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767; --s0: #77766f;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
code { background: var(--surface-2); padding: .05rem .35rem; border-radius: 4px; font-size: .9em; word-break: break-all; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem;
  padding: .7rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.top nav { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem; }
.top nav a { color: var(--text-2); }
.top nav form { margin: 0; }
main { max-width: 1060px; margin: 0 auto; padding: 1.2rem 16px 3rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; }
.card.narrow { max-width: 440px; margin: 2rem auto; }
.card.empty { text-align: center; padding: 2.5rem 1rem; }
.head-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.head-row h1 { margin: 0; }
.head-row form { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { display: block; color: var(--muted); font-size: .83rem; font-weight: 400; margin-top: .25rem; }
.clip { max-width: 380px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Form */
.stack { display: grid; gap: .9rem; }
.narrow-form { max-width: 380px; }
label { display: grid; gap: .3rem; font-weight: 600; font-size: .92rem; }
label.check { display: flex; align-items: center; gap: .45rem; font-weight: 400; }
input, textarea, button, .button { font: inherit; }
input:not([type=checkbox]), textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .8rem 1rem; margin: 0; }
legend { font-weight: 600; padding: 0 .3rem; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem; }
.input-suffix { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
.input-suffix input { max-width: 9rem; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem; cursor: pointer;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); text-decoration: none; white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(.97); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button:disabled { opacity: .6; cursor: progress; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); }
.danger { color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; }
.actions form { margin: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; align-items: center; }
.inline-form input:not([type=checkbox]) { flex: 1 1 220px; width: auto; }
form.inline { display: inline; margin-left: .3rem; }
.danger-zone { margin-top: 1.2rem; padding-top: .8rem; border-top: 1px solid var(--border); }
.small-form { margin-top: .6rem; min-width: 240px; }
details summary { cursor: pointer; color: var(--accent); }

/* Messaggi e stati: colore sempre accompagnato da testo */
.flash { padding: .7rem 1rem; border-radius: 8px; margin: 0 0 1rem; background: var(--good-bg); color: var(--text); border-left: 4px solid var(--good); }
.flash.err { background: var(--warn-bg); border-left-color: var(--warn); }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .05rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); vertical-align: middle; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.status { display: inline-block; font-size: .8rem; font-weight: 600; padding: .05rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.status.ok { background: var(--good-bg); color: var(--good); }
.status.ok::before { content: "✓ "; }
.status.blocked, .status.error, .status.noprice { background: var(--bad-bg); color: var(--bad); }
.status.blocked::before, .status.error::before, .status.noprice::before { content: "✕ "; }
.status-text.bad { color: var(--bad); }

/* Tabelle */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .4rem .6rem; border-bottom: 1px solid var(--border); }
.list td { padding: .7rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.list tr:last-child td { border-bottom: 0; }
.list .num { text-align: right; white-space: nowrap; }
.list tr.inactive td { opacity: .55; }
.list td.actions { display: table-cell; }
.list td.actions form { display: inline-block; margin-right: .8rem; }
.price { font-variant-numeric: tabular-nums; font-weight: 700; }
.table-wrap > table.list { background: var(--surface); }
main > .table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1.4rem; }

/* Riquadri numerici */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem; margin-bottom: 1.1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; display: grid; gap: .1rem; }
.tile .label { font-size: .8rem; color: var(--muted); }
.tile .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Grafico */
.chart-box { position: relative; }
svg.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .target { stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .target-label { fill: var(--text-2); font-size: 11px; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; opacity: 0; }
.chart-box.hover .crosshair { opacity: .6; }
.chart .line.s0 { stroke: var(--s0); } .chart .dot.s0 { fill: var(--s0); }
.chart .line.s1 { stroke: var(--s1); } .chart .dot.s1 { fill: var(--s1); }
.chart .line.s2 { stroke: var(--s2); } .chart .dot.s2 { fill: var(--s2); }
.chart .line.s3 { stroke: var(--s3); } .chart .dot.s3 { fill: var(--s3); }
.chart .line.s4 { stroke: var(--s4); } .chart .dot.s4 { fill: var(--s4); }
.chart .line.s5 { stroke: var(--s5); } .chart .dot.s5 { fill: var(--s5); }
.chart .line.s6 { stroke: var(--s6); } .chart .dot.s6 { fill: var(--s6); }
.chart .line.s7 { stroke: var(--s7); } .chart .dot.s7 { fill: var(--s7); }
.chart .line.s8 { stroke: var(--s8); } .chart .dot.s8 { fill: var(--s8); }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; padding: 0; margin: .6rem 0 0; font-size: .88rem; color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: .4rem; }
.swatch { width: 14px; height: 3px; border-radius: 2px; background: var(--s0); }
.swatch.s1 { background: var(--s1); } .swatch.s2 { background: var(--s2); } .swatch.s3 { background: var(--s3); } .swatch.s4 { background: var(--s4); }
.swatch.s5 { background: var(--s5); } .swatch.s6 { background: var(--s6); } .swatch.s7 { background: var(--s7); } .swatch.s8 { background: var(--s8); }
.swatch.target { background: none; border-top: 2px dashed var(--text-2); height: 0; }
.tooltip {
  position: absolute; top: 0; pointer-events: none; z-index: 2; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem;
  box-shadow: 0 4px 14px rgb(0 0 0 / .12); font-size: .82rem; color: var(--text);
}
.tooltip .date { color: var(--muted); margin-bottom: .2rem; }
.tooltip .r { display: flex; align-items: center; gap: .4rem; justify-content: space-between; }
.tooltip .r span:first-child { display: flex; align-items: center; gap: .35rem; color: var(--text-2); }
.tooltip .v { font-variant-numeric: tabular-nums; font-weight: 600; }

.spark { width: 100px; height: 26px; display: block; }
.spark polyline { fill: none; stroke: var(--s1); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }

.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: .45rem; }
.steps { padding-left: 1.2rem; display: grid; gap: .8rem; }
dl.result { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 1rem 0 0; }
dl.result dt { color: var(--muted); }
dl.result dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 640px) {
  h1 { font-size: 1.3rem; }
  .card { padding: 1rem; }
  .clip { max-width: 150px; }
  .tile .value { font-size: 1.35rem; }
}
@media (max-width: 640px) {
  .hide-sm { display: none; }
}
@media (max-width: 640px) {
  /* Il grafico viene rimpicciolito di ~2,2×: testi più grandi in unità SVG e solo le date agli estremi. */
  .chart .tick, .chart .target-label { font-size: 30px; }
  .chart .x-mid { display: none; }
  .tiles { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .tile { padding: .6rem .6rem; }
  .tile .value { font-size: 1.05rem; }
  .tile .label { font-size: .72rem; }
}
.chart .y-label { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
