:root {
  --bg: #eceff2; --surface: #fff; --ink: #1d2329; --muted: #667080; --line: #d6dbe1;
  --accent: #2b3a4a; --accent-ink: #fff; --warn: #b3261e; --ok: #1f7a4d;
  --shadow: 0 1px 2px rgba(20,30,40,.08);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14181d; --surface: #1d232a; --ink: #e8ecf0; --muted: #94a0ae; --line: #313a44;
    --accent: #cdd6df; --accent-ink: #14181d; --warn: #ff8a80; --ok: #6fd3a0; --shadow: none; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.4; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 14px; font-weight: 650; margin-bottom: 10px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
:focus-visible { outline: 3px solid #4c8dff; outline-offset: 2px; }

.btn { font: inherit; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; min-height: 40px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .4; cursor: default; }

/* Accesso */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--surface); padding: 28px 24px; border-radius: 14px;
  border: 1px solid var(--line); display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 24px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; min-height: 40px; width: 100%; }
.error { color: var(--warn); margin: 0; font-size: 14px; }

/* Intestazione */
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.who { display: grid; line-height: 1.2; min-width: 0; margin-right: auto; }
.who span { font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 9px; }
.tabs button { font: inherit; border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 7px; cursor: pointer; min-height: 36px; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 650; box-shadow: var(--shadow); }

/* Filtri */
.bar { padding: 12px 16px 4px; display: grid; gap: 10px; max-width: 1200px; margin: 0 auto; }
.seg { display: flex; gap: 6px; overflow-x: auto; }
.seg button { font: inherit; white-space: nowrap; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; min-height: 38px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.f { min-width: 130px; flex: 0 1 170px; }
.f.grow { flex: 1 1 160px; }
.f.dates { display: flex; gap: 8px; min-width: 0; flex: 0 1 auto; }
.f.dates label { min-width: 140px; }
.notice { max-width: 1200px; margin: 8px auto; padding: 10px 14px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--warn); }

/* Foto: schede a scontrino */
#photosView, #statsView { max-width: 1200px; margin: 0 auto; padding: 8px 16px 40px; }
.count { margin: 6px 0 10px; font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; padding: 0;
  text-align: left; font: inherit; color: inherit; cursor: pointer; box-shadow: var(--shadow); display: block; width: 100%; }
.card:hover { border-color: var(--muted); }
.card .ph { aspect-ratio: 4 / 3; background: var(--line); display: block; width: 100%; object-fit: cover; }
.card .meta { padding: 10px 12px 12px; border-top: 2px dashed var(--line); position: relative; display: grid; gap: 4px; }
.card .meta::before, .card .meta::after { content: ""; position: absolute; top: -8px; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line); }
.card .meta::before { left: -8px; } .card .meta::after { right: -8px; }
.card .n { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; overflow-wrap: anywhere; line-height: 1.1; }
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
.chip::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--muted)); }
.flag { color: var(--warn); font-weight: 650; }
.prep { font-variant-numeric: tabular-nums; }
.prep.slow { color: var(--warn); font-weight: 650; }
.more { text-align: center; margin-top: 18px; }
.empty { grid-column: 1 / -1; text-align: center; padding: 48px 12px; color: var(--muted); }

/* Statistiche */
.slow { margin: 8px 0 12px; }
.slow label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.slow input { width: 70px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile span { font-size: 12.5px; color: var(--muted); }
.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel svg { width: 100%; height: auto; display: block; overflow: visible; }
svg .grid { stroke: var(--line); stroke-width: 1; }
svg .tick { fill: var(--muted); font-size: 11px; }
svg .bar:hover rect:not(:last-child) { opacity: .8; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; }
.rows { display: grid; gap: 8px; }
.r { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.r .track { display: block; background: var(--bg); height: 10px; border-radius: 5px; overflow: hidden; }
.r .fill { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 5px; }
.r .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.r.link { cursor: pointer; grid-template-columns: 70px 1fr auto auto; }

/* Da verificare */
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--warn); color: #fff; font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; margin-left: 4px; }
.vedit { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding: 4px 16px 14px; }
.vedit .error, .vedit .erow { grid-column: 1 / -1; }
.erow { display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.btn.danger { color: var(--warn); border-color: var(--warn); }

/* Contestazioni, report, strumenti */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0 12px; }
.toolbar .grow { flex: 1 1 260px; margin: 0; }
.vtools { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 16px 10px; }
.claims { display: grid; gap: 8px; }
.claim { display: grid; grid-template-columns: 90px 1fr auto auto; gap: 4px 12px; align-items: center; text-align: left; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; cursor: pointer; width: 100%; }
.claim:hover { border-color: var(--muted); }
.claim .cn { font-weight: 700; font-variant-numeric: tabular-nums; }
.claim .cm { grid-column: 2 / -1; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.claim .ca { font-weight: 650; font-variant-numeric: tabular-nums; }
.cbadge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 650; color: var(--c); }
.cbadge::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.claimdlg { border: 0; border-radius: 14px; padding: 20px; width: min(440px, 100vw); background: var(--surface); color: var(--ink); }
.claimdlg::backdrop { background: rgba(8,12,16,.7); }
.claimdlg form { display: grid; gap: 12px; }
.claimdlg textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; resize: vertical; }

/* Stampa: prova e report */
.printhost { display: none; }
.proof, .report { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #111; background: #fff; }
.proof h1, .report h1 { font-size: 22px; margin: 0 0 4px; }
.report h2 { font-size: 15px; margin: 18px 0 6px; }
.psub { margin: 0 0 12px; color: #444; }
.pimg { display: block; max-width: 100%; max-height: 420px; margin: 0 auto 12px; border: 1px solid #bbb; }
.ptable { border-collapse: collapse; width: 100%; font-size: 13px; }
.ptable th, .ptable td { border: 1px solid #ccc; padding: 5px 8px; text-align: left; }
.ptable th { background: #f1f1f1; font-weight: 650; width: 40%; }
.pnote { font-size: 11px; color: #444; margin-top: 12px; }
@media print {
  @page { margin: 14mm; }
  body.printing { background: #fff; }
  body.printing > :not(#print) { display: none !important; }
  body.printing #print { display: block !important; }
}

/* Visualizzatore */
.viewer { border: 0; padding: 0; background: var(--surface); color: var(--ink); width: min(980px, 100vw); max-width: 100vw;
  max-height: 100dvh; border-radius: 14px; overflow: auto; }
.viewer::backdrop { background: rgba(8,12,16,.7); }
.vbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; gap: 10px; }
.vbar .num { font-size: 22px; }
.vimg { background: #0e1114; display: grid; place-items: center; }
.vimg img { max-width: 100%; max-height: 62dvh; display: block; }
.vinfo { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 16px; margin: 0; padding: 14px 16px; }
.vinfo dt { font-size: 12px; color: var(--muted); }
.vinfo dd { margin: 0; font-weight: 600; }
.vnav { display: flex; gap: 8px; padding: 0 16px 16px; justify-content: space-between; flex-wrap: wrap; }

@media (max-width: 640px) {
  .panels { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card .n { font-size: 17px; }
  .f { flex: 1 1 140px; }
  .viewer { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .r { grid-template-columns: 96px 1fr auto; }
  .claim { grid-template-columns: 1fr auto; }
  .claim .cm { grid-column: 1 / -1; }
  svg .tick { font-size: 17px; }
}
@media (prefers-reduced-motion: no-preference) {
  .card { transition: border-color .15s; }
}

.cperiods { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin-bottom: 14px; }
.cperiod { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.cperiod h3 { margin: 0 0 8px; font-size: 14px; }
.cperiod h3 span { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.cperiod dl { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; margin: 0; font-size: 13.5px; }
.cperiod dt { color: var(--muted); }
.cperiod dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.brand { display: flex; align-items: center; gap: 9px; font-size: 17px; letter-spacing: -.2px; white-space: nowrap; }
.brand b { font-weight: 800; }
.brand span { font-weight: 400; }
.brand.big { font-size: 26px; margin-bottom: 6px; }
.brand img { border-radius: 8px; flex: none; }
@media (max-width: 720px) { .top .brand span { display: none; } }

.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand small { font-size: 11px; font-weight: 400; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
.brand.big small { font-size: 13px; }
.brand .nm { font-style: normal; white-space: nowrap; }

.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; padding: 8px 0 0; align-self: center; }

.selrow { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.card.sel { outline: 3px solid #d64545; outline-offset: -3px; }
.card.sel::after { content: "✓"; position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%; background: #d64545; color: #fff; font-weight: 800; display: grid; place-items: center; }
.card { position: relative; }
.selbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; align-items: center; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(0,0,0,.35); }
.selbar span { flex: 1; font-weight: 700; }

.devlist { display: grid; gap: 8px; }
.devrow { display: grid; grid-template-columns: 1.2fr 1fr 1.4fr 1.4fr; gap: 8px; align-items: center; font-size: 14px; }
.devrow .chip.old { background: #fde9d9; color: #8a3b00; }
@media (max-width: 640px) { .devrow { grid-template-columns: 1fr 1fr; } }
