/* gpuwatch: banco prova. Chiaro/scuro con tema scelto a mano; colori dei livelli verificati per daltonismo. */
:root {
  --bg: #eceff3; --surface: #ffffff; --surface-2: #f4f6f9; --text: #161a20; --muted: #5d6675;
  --border: #dde1e8; --accent: #2f55d4; --accent-text: #ffffff; --shadow: 0 1px 2px rgba(20, 28, 40, .06), 0 6px 20px rgba(20, 28, 40, .06);
  --buy: #16a34a; --ok: #d97706; --new: #64748b; --neg-tier: #ea580c; --over: #cbd2dc;
  --neg-tier-bg: #ffedd5; --neg-tier-fg: #9a3412; --buy-bg: #dcfce7; --buy-fg: #166534; --ok-bg: #fef3c7; --ok-fg: #92400e;
  --pos: #15803d; --neg: #b91c1c; --err-bg: #fee2e2; --err-fg: #991b1b; --info-bg: #e0ecff; --info-fg: #1e3a8a;
  --font: "Bahnschrift", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0e1116; --surface: #161a21; --surface-2: #1c212a; --text: #e8ebf0; --muted: #9aa3b2;
  --border: #272d38; --accent: #7ba0ff; --accent-text: #0b1220; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --buy: #4ade80; --ok: #fbbf24; --new: #94a3b8; --neg-tier: #fb923c; --over: #343c4a;
  --neg-tier-bg: #3a1f0d; --neg-tier-fg: #fdba74; --buy-bg: #14361f; --buy-fg: #86efac; --ok-bg: #3b2f10; --ok-fg: #fcd34d;
  --pos: #4ade80; --neg: #f87171; --err-bg: #3b1515; --err-fg: #fca5a5; --info-bg: #172544; --info-fg: #bcd0ff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --surface: #161a21; --surface-2: #1c212a; --text: #e8ebf0; --muted: #9aa3b2;
    --border: #272d38; --accent: #7ba0ff; --accent-text: #0b1220; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --buy: #4ade80; --ok: #fbbf24; --new: #94a3b8; --neg-tier: #fb923c; --over: #343c4a;
    --neg-tier-bg: #3a1f0d; --neg-tier-fg: #fdba74; --buy-bg: #14361f; --buy-fg: #86efac; --ok-bg: #3b2f10; --ok-fg: #fcd34d;
    --pos: #4ade80; --neg: #f87171; --err-bg: #3b1515; --err-fg: #fca5a5; --info-bg: #172544; --info-fg: #bcd0ff;
  }
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
h1 { margin: 0; font-size: 19px; letter-spacing: .01em; }
h2 { font-size: 17px; margin: 22px 0 8px; }
h3 { font-size: 14px; margin: 16px 0 6px; }
.dialog-head h2 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
main { max-width: 1240px; margin: 0 auto; padding: 18px 18px 64px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--border); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); font-size: 13px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 4px 0; border-bottom: 1px solid var(--border); }
[hidden] { display: none !important; }

/* barra in alto */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand-mark { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.live { width: 10px; height: 10px; border-radius: 50%; background: var(--over); box-shadow: 0 0 0 3px color-mix(in srgb, var(--over) 30%, transparent); }
.live.live-ok { background: var(--buy); box-shadow: 0 0 0 3px color-mix(in srgb, var(--buy) 28%, transparent); }
.live.live-err { background: var(--neg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--neg) 28%, transparent); }

.banner { background: var(--info-bg); color: var(--info-fg); padding: 10px 14px; border-radius: 10px; margin: 0 0 12px; }
.banner-error { background: var(--err-bg); color: var(--err-fg); }
.empty { color: var(--muted); text-align: center; padding: 36px 12px; }

.btn {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 12px; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-small { padding: 3px 9px; font-size: 13px; }
.btn:focus-visible, .tab:focus-visible, .sort:focus-visible, .input:focus-visible, select:focus-visible,
.seg:focus-visible, .thumb-btn:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* occasioni migliori */
.section-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0 0 10px; }
.best { margin-bottom: 20px; }
.best-list { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.deal-hero { padding: 16px; gap: 12px; }
.deal-hero .deal-photo { height: 190px; }
.deal-hero .deal-price { font-size: 34px; }

/* schede degli annunci */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.deal {
  display: flex; flex-direction: column; gap: 10px; min-width: 0; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.deal.is-hidden { opacity: .55; }
.deal-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.deal-platform { font-weight: 600; font-size: 13px; }
.deal-when { margin-left: auto; }
.deal-photo-btn { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 10px; overflow: hidden; }
.deal-photo, .deal-photo-btn .photo-empty { display: block; width: 100%; height: 150px; object-fit: cover; border-radius: 10px; background: var(--border); }
.deal-photo-btn .photo-empty { width: 100%; height: 40px; font-size: 12px; }
.deal-model { font-size: 13px; color: var(--muted); }
.deal-title { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.deal-money { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.deal-price { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.deal.tier-compra_ora .deal-price { color: var(--buy); }
.deal.tier-entro_max .deal-price { color: var(--ok); }
.deal.tier-da_trattare .deal-price { color: var(--neg-tier); }
.deal-profit { font-size: 14px; }
.deal-reason { margin-left: auto; font-size: 12px; }
.deal-actions { margin-top: auto; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-buy { background: var(--buy-bg); color: var(--buy-fg); }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-neg { background: var(--neg-tier-bg); color: var(--neg-tier-fg); }
.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }

/* righello dei prezzi: la cosa da ricordare della pagina */
.ruler { padding: 0 14px; }
.ruler-rail { position: relative; padding-top: 26px; }
.ruler-track { display: flex; gap: 2px; height: 9px; }
.ruler-zone { display: block; flex: 0 1 auto; width: var(--w); min-width: 3px; height: 100%; border-radius: 4px; }
.zone-compra_ora { background: var(--buy); }
.zone-entro_max { background: var(--ok); }
.zone-da_trattare { background: var(--neg-tier); }
.zone-oltre { background: var(--over); }
.ruler-marker {
  position: absolute; top: 22px; bottom: -4px; left: 0; width: 2px; margin-left: -1px; background: var(--text);
  border-radius: 2px; transition: left .9s cubic-bezier(.2, .8, .2, 1);
}
.ruler.ready .ruler-marker { left: var(--pos); }
.ruler-flag {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); margin-bottom: 2px;
  background: var(--text); color: var(--bg); font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 6px; white-space: nowrap;
}
.ruler-ticks { position: relative; height: 18px; margin-top: 5px; }
.ruler-tick { position: absolute; left: var(--pos); transform: translateX(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; text-align: center; display: flex; flex-direction: column; }
.ruler-tick b { font-weight: 600; color: var(--text); }
.ruler-large .ruler-ticks { height: 34px; }
.ruler-large .ruler-track { height: 12px; }
.ruler-tick-name { font-size: 10px; }

/* riepilogo */
.readout { display: flex; flex-wrap: wrap; align-items: stretch; gap: 10px; margin-bottom: 16px; }
.stat {
  flex: 1 1 130px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; min-width: 0;
}
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 1px; }
.stat .value.small { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.stat-buy .value { color: var(--buy); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; flex-basis: 100%; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px 5px 10px; font-size: 13px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--buy); flex: none; }
.chip.chip-error { border-color: var(--neg); color: var(--err-fg); background: var(--err-bg); }
.chip.chip-error .dot { background: var(--neg); }

/* sezioni */
.tabs { display: flex; gap: 4px; margin-bottom: 14px; padding: 4px; width: fit-content; max-width: 100%; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.tab { border: 0; background: none; color: var(--muted); padding: 7px 16px; border-radius: 9px; cursor: pointer; font: inherit; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.filters .grow { flex: 1 1 220px; }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 8px; }
select, .input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 6px 8px; min-width: 140px; width: 100%;
}
.filters select { width: auto; }
.filters input[type="search"] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px; width: 100%; }
textarea.input { resize: vertical; }
.view-toggle { display: inline-flex; margin-left: auto; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.seg { font: inherit; font-size: 13px; color: var(--muted); background: none; border: 0; padding: 4px 12px; border-radius: 7px; cursor: pointer; }
.seg.active { background: var(--surface-2); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }

/* tabella */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
td.title { white-space: normal; min-width: 220px; max-width: 420px; overflow-wrap: anywhere; }
th { font-size: 12px; font-weight: 600; color: var(--muted); }
tr:last-child td { border-bottom: none; }
.num { text-align: right; }
.sort { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.sort.active { color: var(--text); font-weight: 700; }
.sort.active[data-direction="asc"]::after { content: " \25B2"; }
.sort.active[data-direction="desc"]::after { content: " \25BC"; }

/* grafici */
.chart-box { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .line-price { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .dot { fill: var(--accent); }
.chart .threshold { stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .line-buy { stroke: var(--buy); }
.chart .line-max { stroke: var(--ok); }
.chart rect.bar-buy { fill: var(--buy); }
.chart rect.bar-ok { fill: var(--ok); }
.chart rect.bar-neg { fill: var(--neg-tier); }
.chart rect.bar-new { fill: var(--new); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.bar-buy { background: var(--buy); }
.swatch.bar-ok { background: var(--ok); }
.swatch.bar-neg { background: var(--neg-tier); }
.swatch.bar-new { background: var(--new); }

/* moduli */
.form { display: grid; gap: 16px; max-width: 720px; }
.fieldset { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); padding: 12px 16px 16px; display: grid; gap: 14px; }
.fieldset legend { padding: 0 6px; font-weight: 600; }
.field { display: grid; gap: 4px; }
.field-label { font-size: 13px; }
.field-check { grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.field-check .hint { grid-column: 2; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.problems { background: var(--err-bg); color: var(--err-fg); border-radius: 10px; padding: 10px 14px 10px 30px; margin: 12px 0; }
.adder { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 6px; }
.adder .input { width: 180px; min-width: 0; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.price-table .input { min-width: 0; }
.price-table .input-num { text-align: right; max-width: 130px; }
.price-table tr.invalid { background: var(--err-bg); }

/* finestra dello storico */
.dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); width: min(740px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 18px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(5, 8, 12, .6); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.dialog .ruler { margin: 10px 0 4px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100vw - 32px); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
}

/* foto */
td.photo { width: 76px; padding-right: 0; }
.thumb-btn { display: block; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 8px; }
.photo-holder { display: block; }
.photo-img { display: block; width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--border); }
.photo-empty {
  display: flex; align-items: center; justify-content: center; text-align: center; width: 64px; height: 64px;
  border-radius: 8px; background: var(--border); color: var(--muted); font-size: 10px; line-height: 1.2; padding: 4px;
}
.photo-large-box { margin: 4px 0 10px; }
.photo-large-box .photo-img, .photo-img.photo-large { width: 100%; height: auto; max-height: 300px; object-fit: contain; }
.photo-large-box .photo-empty { width: 100%; height: 120px; font-size: 13px; }

/* nascondi / elimina */
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-danger { color: var(--neg); }
.btn-danger:hover:not(:disabled) { border-color: var(--neg); }
.btn-danger.armed { background: var(--neg); border-color: var(--neg); color: var(--accent-text); }
tr.row-hidden td:not(:last-child) { opacity: .5; }

@media (prefers-reduced-motion: reduce) {
  .ruler-marker { transition: none; }
}

/* telefono: schede a tutta larghezza, sezioni in basso come in un'app */
@media (max-width: 760px) {
  main { padding: 12px 12px 96px; }
  .topbar { padding: 8px 12px; }
  .topbar-right #updated { display: none; }
  .view-toggle { margin-left: 0; }
  .deal-hero .deal-photo { height: 170px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; width: auto; margin: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0; border-width: 1px 0 0; justify-content: space-between; overflow: visible;
  }
  .tab { flex: 1; padding: 10px 4px; font-size: 13px; text-align: center; }
  .toast { bottom: 84px; }

  .table-wrap { border: 0; background: none; overflow: visible; }
  table.responsive thead, table.price-table thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td,
  table.price-table, table.price-table tbody, table.price-table tr, table.price-table td { display: block; }
  table.responsive tr, table.price-table tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; padding: 6px 0;
  }
  table.responsive td, table.price-table td {
    border: 0; padding: 4px 12px; display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
    white-space: normal; text-align: right;
  }
  table.responsive td::before, table.price-table td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none;
  }
  td.title { min-width: 0; max-width: none; }
  .price-table .input-num { max-width: 140px; }
  .adder .input { width: 100%; }
  table.responsive td.photo { width: auto; padding: 0 12px 4px; display: block; }
  table.responsive td.photo::before { display: none; }
  td.photo .photo-img, td.photo .photo-empty { width: 100%; height: 180px; }
  td.photo .thumb-btn { width: 100%; }
}

/* accesso e utente connesso */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); margin: 0; padding: 26px 24px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 18px; }
.login-form { display: grid; gap: 14px; }
.login-form .btn-primary { padding: 9px 12px; }
.who { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.role-badge { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; color: var(--text); }
@media (max-width: 760px) { .who-name { display: none; } }
