:root {
  --bg: #f5f4f0; --card: #ffffff; --ink: #1d1d1b; --mute: #6b6a64; --line: #e3e1da; --line2: #cfcdc4;
  --accent: #2a5d5a; --accent-ink: #ffffff; --up: #a3341f; --down: #1f6b3a; --warn: #8a5a00; --chip: #ecebe4;
  --chart: #2a5d5a; --grid: #ebe9e2; --focus: #1b6fd1;
  --r: 6px; --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614; --card: #1e1e1b; --ink: #ecebe5; --mute: #9b9a92; --line: #2f2f2a; --line2: #44443d;
    --accent: #6fb3ad; --accent-ink: #0e1a19; --up: #e58a77; --down: #7fc995; --warn: #e0b45a; --chip: #2a2a26;
    --chart: #6fb3ad; --grid: #2a2a26; --focus: #6aa8ff;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; color: var(--mute); font-weight: 600; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.mute { color: var(--mute); } .small { font-size: 13px; }
.hidden { display: none !important; }

/* barra superiore */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1080px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 18px; }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); letter-spacing: -0.02em; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 10px; border-radius: var(--r); text-decoration: none; color: var(--mute); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--chip); }
.who { color: var(--mute); font-size: 13px; }
main { max-width: 1080px; margin: 0 auto; padding: 20px 16px 90px; }

/* controlli */
.btn { border: 1px solid var(--line2); background: var(--card); padding: 7px 12px; border-radius: var(--r); cursor: pointer; }
.btn:hover { border-color: var(--mute); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--up); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--mute); }
.btn[disabled] { opacity: .55; cursor: default; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--mute); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select {
  width: 100%; padding: 8px 10px; background: var(--card); border: 1px solid var(--line2); border-radius: var(--r);
}
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.err { color: var(--up); font-size: 14px; min-height: 1.3em; }
.ok { color: var(--down); font-size: 14px; }
.note { border-left: 3px solid var(--line2); padding: 6px 10px; color: var(--mute); font-size: 13px; background: var(--card); }
.note.warn { border-color: var(--warn); color: var(--ink); }

/* schermate di accesso */
.auth { max-width: 400px; margin: 9vh auto 0; padding: 0 16px; }
.auth h1 { margin-bottom: 4px; } .auth .sub { color: var(--mute); margin-bottom: 20px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.qr { width: 200px; height: 200px; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: #fff; }
.qr svg { display: block; width: 100%; height: 100%; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .04em; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; padding: 12px; border: 1px dashed var(--line2); border-radius: var(--r); }

/* intestazione dashboard */
.sum { display: flex; flex-wrap: wrap; gap: 6px 22px; color: var(--mute); font-size: 13px; margin: 6px 0 16px; }
.sum b { color: var(--ink); font-weight: 600; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--mute); }
.dot.ok { background: var(--down); } .dot.bad { background: var(--up); } .dot.warn { background: var(--warn); }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 160px; }
.toolbar select { width: auto; }

/* elenco prodotti */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.item { display: grid; grid-template-columns: 52px minmax(0, 1fr) 110px 120px 92px; gap: 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit; }
.item:first-child { border-top: 0; }
.item:hover { background: color-mix(in srgb, var(--chip) 55%, transparent); }
.thumb { width: 52px; height: 52px; border-radius: 4px; background: var(--chip); object-fit: contain; }
.item .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .vr { color: var(--mute); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .pr { font-size: 17px; font-weight: 600; text-align: right; }
.item .ch { font-size: 13px; text-align: right; color: var(--mute); }
.up { color: var(--up); } .down { color: var(--down); }
.spark { width: 92px; height: 34px; display: block; }
.spark path { fill: none; stroke: var(--chart); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.tag { font-size: 11.5px; padding: 1px 7px; border-radius: 10px; background: var(--chip); color: var(--mute); }
.tag.good { background: color-mix(in srgb, var(--down) 16%, transparent); color: var(--down); }
.tag.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.empty { padding: 36px 18px; text-align: center; color: var(--mute); }

/* dettaglio */
.back { display: inline-block; margin-bottom: 10px; color: var(--mute); text-decoration: none; font-size: 14px; }
.head { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 16px; margin-bottom: 14px; }
.head img { width: 96px; height: 96px; object-fit: contain; background: var(--chip); border-radius: var(--r); }
.big { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; margin: 14px 0; }
.stat { background: var(--card); padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--mute); } .stat .v { font-weight: 600; font-size: 16px; }
.tabs { display: flex; gap: 2px; margin-bottom: 8px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; color: var(--mute); padding: 5px 10px; border-radius: var(--r); cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--chip); color: var(--ink); font-weight: 600; }
.chartbox { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 6px 4px; }
.chartbox svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); padding: 5px 8px; border-radius: 4px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -100%); }
.chart-msg { padding: 40px 12px; text-align: center; color: var(--mute); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--mute); padding: 4px 8px 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 5px; }
.log { font-size: 13px; color: var(--mute); }
.log li { margin: 2px 0; }

/* modale */
.veil { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow: auto; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 8px; width: 100%; max-width: 620px; padding: 16px; }
.res { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.res img { width: 44px; height: 44px; object-fit: contain; background: var(--chip); border-radius: 4px; }

/* chat */
.chatbtn { position: fixed; right: 16px; bottom: 16px; z-index: 8; }
.chat { position: fixed; right: 16px; bottom: 16px; z-index: 9; width: min(380px, calc(100vw - 24px)); height: min(520px, calc(100vh - 90px)); display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line2); border-radius: 8px; }
.chat-h { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.chat-m { flex: 1; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 92%; padding: 7px 10px; border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.bot { align-self: flex-start; background: var(--chip); }
.msg .meta { display: block; margin-top: 4px; font-size: 11.5px; color: var(--mute); }
.chat-f { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }

table.plain { width: 100%; border-collapse: collapse; font-size: 14px; }
table.plain td, table.plain th { text-align: left; padding: 6px 4px; border-top: 1px solid var(--line); }
section.block { margin-top: 26px; }
section.block > h2 { margin-bottom: 10px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 6px; z-index: 30; font-size: 14px; }

@media (max-width: 720px) {
  .item { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; padding: 10px; }
  .item .thumb { width: 44px; height: 44px; }
  .item .chg, .item .spark-wrap { display: none; }
  .head { grid-template-columns: 64px minmax(0, 1fr); } .head img { width: 64px; height: 64px; }
  .big { font-size: 26px; } .who { display: none; }
  .nav a { padding: 6px 8px; }
}
.l-price { border-color: var(--chart); } .l-min { border-color: var(--down); border-top-style: dashed; } .l-thr { border-color: var(--warn); border-top-style: dotted; }
.row .grow, .toolbar .grow { flex: 1; }
