/* --------------------------------------------------------------------
   Un solo principio cromatico: il colore significa esclusivamente
   "stato del biglietto". L'interfaccia non ha un colore di marca, così
   il verde e il rosso non possono essere confusi con nient'altro.
   -------------------------------------------------------------------- */

:root {
  --bg:        #0F141A;
  --panel:     #19212A;
  --panel-2:   #222C38;
  --line:      #2E3A47;
  --text:      #E9EFF5;
  --muted:     #8797A8;

  --ok:        #00A85C;
  --ok-deep:   #00743F;
  --dup:       #D62839;
  --dup-deep:  #8E1620;
  --unknown:   #E08A00;
  --void:      #7B5CD6;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--sans);
  overscroll-behavior: none;
}

body {
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.hidden { display: none !important; }

/* ---------------- barra di stato ---------------- */

.rail {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.conn { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.conn[data-state="online"]  .dot { background: var(--ok); }
.conn[data-state="offline"] .dot { background: var(--unknown); }
.conn[data-state="syncing"] .dot { background: var(--muted); animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.rail .count { margin-left: auto; font-variant-numeric: tabular-nums; }
.rail .count b { font-weight: 600; }
.rail .count span { color: var(--muted); }

.queue-pill {
  padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.queue-pill[data-pending="yes"] { color: var(--unknown); border-color: var(--unknown); }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 4px; color: var(--muted);
}
.icon-btn[aria-pressed="true"] { color: var(--bg); background: var(--text); border-color: var(--text); }

/* ---------------- mirino ---------------- */

.viewfinder {
  position: relative; flex: 1 1 auto; min-height: 180px;
  background: #05080B; overflow: hidden;
}
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }

.reticle {
  position: absolute; inset: 0; display: grid; place-items: center;
  pointer-events: none;
}
.reticle i {
  display: block; width: min(62vw, 240px); aspect-ratio: 1;
  border: 0; position: relative;
}
.reticle i::before, .reticle i::after,
.reticle b::before, .reticle b::after {
  content: ''; position: absolute; width: 26px; height: 26px;
  border: 3px solid rgba(255,255,255,.85);
}
.reticle i::before { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.reticle i::after  { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.reticle b { position: absolute; inset: 0; }
.reticle b::before { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.reticle b::after  { bottom: 0; right: 0; border-left: 0; border-top: 0; }

.cam-error {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 24px; text-align: center; color: var(--muted); font-size: 14px;
}

/* ---------------- esito ---------------- */

.verdict {
  flex: 0 0 auto; min-height: 132px;
  padding: 18px 18px 22px;
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.verdict-title {
  font-size: clamp(28px, 9vw, 44px);
  font-weight: 700; letter-spacing: -.025em; line-height: 1.02;
}
.verdict-code {
  font-family: var(--mono); font-size: 15px; letter-spacing: .04em;
  opacity: .92; word-break: break-all;
}
.verdict-meta { font-size: 14px; opacity: .8; }

.verdict[data-state="idle"]    { color: var(--muted); }
.verdict[data-state="idle"] .verdict-title { font-size: 22px; font-weight: 500; letter-spacing: 0; }
.verdict[data-state="ok"]      { background: var(--ok);      color: #041B10; border-color: var(--ok); }
.verdict[data-state="dup"]     { background: var(--dup);     color: #fff;    border-color: var(--dup); }
.verdict[data-state="unknown"] { background: var(--unknown); color: #1C1200; border-color: var(--unknown); }
.verdict[data-state="void"]    { background: var(--void);    color: #fff;    border-color: var(--void); }

/* Il momento a schermo intero: l'addetto legge un colore, non un testo. */
.verdict.full {
  position: fixed; inset: 0; z-index: 40; min-height: 0;
  justify-content: center; padding: 32px; gap: 10px;
  border: 0;
}
.verdict.full .verdict-title { font-size: clamp(44px, 15vw, 96px); }
.verdict.full .verdict-code  { font-size: 18px; }
.verdict.full .verdict-meta  { font-size: 17px; }

@media (prefers-reduced-motion: no-preference) {
  .verdict.full { animation: slam .16s ease-out; }
  @keyframes slam { from { opacity: 0; transform: scale(1.04); } }
}

/* ---------------- barra azioni ---------------- */

.actions {
  flex: 0 0 auto; display: flex; gap: 10px; padding: 12px 14px 16px;
  border-top: 1px solid var(--line);
}
.actions button {
  flex: 1; padding: 15px 12px; border-radius: 4px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 15px; font-weight: 500;
}
.actions button:active { background: var(--line); }
.actions .badge {
  display: inline-block; margin-left: 7px; padding: 1px 7px; border-radius: 999px;
  background: var(--dup); color: #fff; font-size: 12px; font-weight: 600;
}

/* ---------------- pannelli ---------------- */

.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg); display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.sheet-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 16px 12px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.sheet-head button { margin-left: auto; color: var(--muted); font-size: 15px; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 0 24px; }

.row {
  display: flex; align-items: baseline; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.row .code { font-family: var(--mono); font-size: 14px; }
.row .when { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.row .tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 3px; }
.tag[data-r="ok"]              { background: var(--ok-deep);  color: #CFF5E2; }
.tag[data-r="already_scanned"] { background: var(--dup-deep); color: #FFD9DC; }
.tag[data-r="not_found"]       { background: #6B4A00;         color: #FFE9BF; }
.tag[data-r="void"]            { background: #3E2C70;         color: #E2D8FF; }
.tag[data-r="in-coda"]         { background: var(--panel-2);  color: var(--muted); }

.empty { padding: 48px 24px; text-align: center; color: var(--muted); font-size: 15px; line-height: 1.5; }

/* ---------------- accesso e inserimento manuale ---------------- */

.center { margin: auto; width: 100%; max-width: 340px; padding: 24px; }
.center h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 6px; }
.center p.sub { margin: 0 0 26px; color: var(--muted); font-size: 15px; line-height: 1.45; }

label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
input {
  width: 100%; padding: 14px; margin-bottom: 16px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px;
  font-size: 16px; font-family: inherit;
}
input.mono { font-family: var(--mono); letter-spacing: .06em; text-transform: uppercase; }
input:focus { border-color: var(--muted); outline: none; }

.primary {
  width: 100%; padding: 15px; border-radius: 4px;
  background: var(--text); color: var(--bg); font-size: 16px; font-weight: 600;
}
.primary:disabled { opacity: .45; }

.msg { margin-top: 14px; font-size: 14px; color: var(--dup); min-height: 20px; }
.msg[data-kind="info"] { color: var(--muted); }

/* ---------------- avviso conflitto ---------------- */

.toast {
  position: fixed; left: 12px; right: 12px; z-index: 60;
  bottom: calc(12px + env(safe-area-inset-bottom));
  padding: 13px 15px; border-radius: 4px;
  background: var(--panel-2); border: 1px solid var(--dup);
  font-size: 14px; line-height: 1.4;
}
.toast b { color: var(--dup); }

/* La schermata di accesso occupa tutta l'altezza disponibile */
#login { flex: 1; display: flex; }
#login.hidden { display: none; }
