/* ==========================================================================
   Gestionale Tornei TCG — foglio di stile unico.
   Nessun font esterno, nessuna CDN: l'interfaccia deve funzionare anche
   quando la connessione del negozio è instabile.
   ========================================================================== */

:root {
  /* Superfici — grigio freddo con una punta di verde, come il feltro di un
     tappetino da gioco. Scuro perché il gestionale resta aperto per ore, ma
     mai nero pieno: sotto le luci del negozio il nero pieno abbaglia. */
  --ink:        #0e1310;
  --surface:    #161c19;
  --surface-2:  #1e2621;
  --surface-3:  #27312b;
  --line:       #33403a;
  --line-soft:  #232c27;

  /* Testo */
  --text:       #f0f3f1;
  --text-dim:   #a9b5ae;
  --text-mute:  #74827b;

  /* Accento ottone: l'unico colore caldo su un campo freddo, così l'azione
     da compiere si stacca sempre da tutto il resto senza bisogno di frecce. */
  --accent:      #e0a340;
  --accent-hot:  #f2b955;
  --accent-dim:  #b47f28;
  --accent-ink:  #1a1204;
  --accent-ghost: rgba(224, 163, 64, .13);

  /* Esiti: devono essere leggibili a colpo d'occhio da un metro di distanza.
     Il pareggio è azzurro acciaio e non ambra, per non confondersi con
     l'accento delle azioni. */
  --win:  #3ecf8e;
  --draw: #7fa8c9;
  --loss: #ff6b6b;
  --info: #6fb3e8;

  --win-ghost:  rgba(62, 207, 142, .14);
  --loss-ghost: rgba(255, 107, 107, .13);
  --draw-ghost: rgba(127, 168, 201, .14);

  --radius:    12px;
  --radius-sm: 8px;
  --radius-lg: 18px;

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

  /* Un solo passo di elevazione: tutto è piatto tranne ciò che galleggia. */
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.28);
  --shadow-lg: 0 2px 6px rgba(0,0,0,.45), 0 22px 60px rgba(0,0,0,.4);

  /* Bersagli: il gestionale si usa in piedi, di fretta, spesso da tablet. */
  --tap:      44px;
  --tap-lg:   56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--ui);
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Ogni numero dell'applicazione — codici, tavoli, tempi, punti — usa la stessa
   voce monospaziata a larghezza fissa: le colonne non ballano mai. */
.num, code, kbd, .code {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.15; letter-spacing: -0.022em; }
h1 { font-size: 1.9rem; font-weight: 780; }
h2 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.015em; }
h3 { font-size: .95rem; font-weight: 680; letter-spacing: -0.01em; }
p  { margin: 0 0 .85rem; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------- Struttura ---------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--surface);
  border-right: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 8px;
  background: var(--accent);
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--accent-ink);
}
.brand-name { font-weight: 650; font-size: .95rem; letter-spacing: -.01em; }
.brand-sub  { font-size: .7rem; color: var(--text-mute); font-family: var(--mono); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-mute); padding: 14px 8px 6px;
}
.nav a {
  display: block; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: .89rem; text-decoration: none;
  border-left: 2px solid transparent;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.is-active {
  background: var(--accent-ghost); color: var(--text);
  border-left-color: var(--accent);
}
.nav a.is-disabled { color: var(--text-mute); cursor: default; opacity: .55; }
.nav a.is-disabled:hover { background: none; color: var(--text-mute); }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line-soft); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Banda di stato: fuori torneo mostra il contesto, durante un torneo
   diventerà la riga con round, tempo e tavoli mancanti. */
.statusbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: .76rem; color: var(--text-dim);
}
.statusbar .sb-item { display: flex; align-items: center; gap: 7px; }
.statusbar .sb-key { color: var(--text-mute); text-transform: uppercase; letter-spacing: .06em; }
.statusbar .sb-val { color: var(--text); }
.statusbar .spacer { margin-left: auto; }

.content { padding: 26px 24px 56px; max-width: 1180px; width: 100%; }
.page-head { margin-bottom: 22px; }
.page-head .eyebrow {
  font-family: var(--mono); font-size: .7rem; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-mute); margin-bottom: 4px;
}
.page-head p { color: var(--text-dim); margin: 0; }

/* ---------- Componenti --------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card-note { color: var(--text-dim); font-size: .85rem; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 14px 16px; border-left: 2px solid var(--accent); }
.stat-key { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-mute); }
.stat-val { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1.5rem; font-weight: 600; }
.stat-val.small { font-size: 1rem; font-weight: 500; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-mute); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line);
}
td { padding: 10px; border-bottom: 1px solid var(--line-soft); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  font-size: .72rem; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-3); color: var(--text-dim);
}
.badge.ok   { background: rgba(47,191,113,.14); color: var(--win); }
.badge.warn { background: rgba(224,169,59,.14); color: var(--draw); }
.badge.bad  { background: rgba(224,92,92,.14);  color: var(--loss); }
.badge.accent { background: var(--accent-ghost); color: #b3a8ff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--accent); color: #fff;
  font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--accent-dim); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-block { width: 100%; }

/* ---------- Form --------------------------------------------------------- */

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 5px; color: var(--text-dim); }
.field .hint { font-size: .76rem; color: var(--text-mute); margin-top: 4px; }

input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px;
  background: var(--ink); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; font-size: .9rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-ghost); }
input::placeholder { color: var(--text-mute); }

.field-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.checkline { display: flex; align-items: flex-start; gap: 9px; font-size: .85rem; color: var(--text-dim); }
.checkline input { margin-top: 3px; }

fieldset { border: none; padding: 0; margin: 0 0 26px; }
legend {
  font-family: var(--mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-mute); padding: 0 0 10px;
}

/* ---------- Messaggi ----------------------------------------------------- */

.alert {
  padding: 11px 14px; border-radius: var(--radius-sm);
  border-left: 3px solid var(--info); background: var(--surface-2);
  font-size: .87rem; margin-bottom: 14px;
}
.alert-success { border-left-color: var(--win); }
.alert-error   { border-left-color: var(--loss); }
.alert-info    { border-left-color: var(--info); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

.empty {
  padding: 28px 20px; text-align: center; color: var(--text-dim);
  border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface-2);
}
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- Pagine senza shell (login, install, errori) ------------------ */

.bare {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 32px 20px;
}
.bare-panel { width: 100%; max-width: 420px; }
.bare-panel.wide { max-width: 780px; }
.bare-head { text-align: center; margin-bottom: 22px; }
.bare-head .brand-mark { margin: 0 auto 12px; width: 42px; height: 42px; font-size: 16px; }
.bare-foot { text-align: center; margin-top: 18px; font-size: .75rem; color: var(--text-mute); font-family: var(--mono); }

.checklist { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.checklist li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid var(--line-soft);
}
.checklist li:last-child { border-bottom: none; }
.checklist .mark { font-family: var(--mono); font-weight: 700; flex: 0 0 auto; width: 16px; }
.checklist .ok   { color: var(--win); }
.checklist .no   { color: var(--loss); }
.checklist .warn { color: var(--draw); }
.checklist .detail { color: var(--text-mute); margin-left: auto; text-align: right; font-size: .78rem; }

.errorpage { text-align: center; max-width: 420px; }
.errorpage .code {
  font-size: 3.5rem; font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums; line-height: 1;
}

/* ---------- Responsive --------------------------------------------------- */

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; flex-direction: row; align-items: center;
    gap: 12px; padding: 10px 14px; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--line-soft);
  }
  .brand { padding: 0; }
  .brand-text { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav-label { display: none; }
  .nav a { border-left: none; border-bottom: 2px solid transparent; white-space: nowrap; }
  .nav a.is-active { border-left: none; border-bottom-color: var(--accent); }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: none; }
  .content { padding: 18px 14px 48px; }
  .statusbar { padding: 8px 14px; gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Utilità di spaziatura ---------------------------------------
   La Content-Security-Policy non consente stili inline: ogni aggiustamento
   di margine passa da qui. */
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 14px; }
.mb-3 { margin-bottom: 18px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 16px; }
.center { margin-left: auto; margin-right: auto; }
.stat.is-ok   { border-left-color: var(--win); }
.stat.is-warn { border-left-color: var(--draw); }

/* ---------- Componenti introdotti con i moduli anagrafici ---------------- */

.thumb {
  width: 20px; height: 20px; border-radius: 4px; object-fit: contain;
  vertical-align: -4px; margin-right: 7px; background: var(--surface-3);
}
.preview {
  max-width: 140px; max-height: 70px; object-fit: contain;
  background: var(--surface-3); border-radius: var(--radius-sm); padding: 6px;
}
td.dim { color: var(--text-dim); }
td.right, th.right { text-align: right; }

/* Selettore negozio nella banda di stato */
.inline-form { display: inline-flex; align-items: center; gap: 6px; }
.mini-select {
  width: auto; padding: 3px 8px; font-size: .76rem; font-family: var(--mono);
  background: var(--surface-2); border-color: var(--line);
}
.mini-btn {
  padding: 3px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text-dim); font: inherit; font-size: .72rem; font-weight: 600;
}
.mini-btn:hover { background: var(--surface-3); color: var(--text); }
.mini-btn.on { background: rgba(47,191,113,.14); border-color: rgba(47,191,113,.35); color: var(--win); }

/* Barra di ricerca */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line-soft);
}
.toolbar input[type=text] { flex: 1 1 260px; }
.toolbar select { width: auto; flex: 0 0 auto; }

/* Riga di associazione ID ufficiale, una per gioco */
.identity-row {
  display: grid; gap: 12px; align-items: end;
  grid-template-columns: minmax(140px, 1fr) minmax(160px, 1.2fr) minmax(140px, 1fr);
  padding: 12px; margin-bottom: 8px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  border-left: 2px solid var(--line);
}
.identity-row .field { margin-bottom: 0; }
.identity-name { display: flex; align-items: center; font-size: .88rem; padding-bottom: 8px; }

.checkgrid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.form-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  padding-top: 16px; border-top: 1px solid var(--line-soft);
}

.pager { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 16px; }
.pager-item {
  min-width: 32px; padding: 5px 9px; text-align: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: .82rem; text-decoration: none;
}
.pager-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.pager-item.is-current { background: var(--accent); border-color: var(--accent); color: #fff; }

.page-head .eyebrow a { color: var(--text-mute); }
.page-head .eyebrow a:hover { color: var(--accent); }

@media (max-width: 700px) {
  .identity-row { grid-template-columns: 1fr; }
  .toolbar input[type=text] { flex: 1 1 100%; }
}

/* ---------- Componenti dei tornei ---------------------------------------- */

.chip {
  padding: 5px 13px; border-radius: 999px; text-decoration: none;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text-dim); font-size: .8rem; font-weight: 600;
}
.chip:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.chip.is-current { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.stat-sub { font-size: .75rem; color: var(--text-mute); font-weight: 400; }

/* Iscrizione rapida: nome, cognome, ID e conferma su una riga sola */
.quick-add {
  display: grid; gap: 12px; align-items: end;
  grid-template-columns: 1fr 1fr 1fr auto;
  padding: 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border-left: 2px solid var(--accent);
}
.quick-add .field { margin-bottom: 0; }

.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }

tr.is-out td { opacity: .55; }
tr.is-out td a { color: var(--text-dim); }

@media (max-width: 760px) {
  .quick-add { grid-template-columns: 1fr; }
  .row-actions { flex-wrap: wrap; }
}

/* ---------- Tavoli e inserimento risultati ------------------------------- */

.match {
  display: grid; gap: 14px; align-items: center;
  grid-template-columns: 52px minmax(200px, 1fr) auto;
  padding: 10px 12px; margin-bottom: 6px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  border-left: 3px solid var(--draw);
}
.match.is-done { border-left-color: var(--win); background: var(--surface); }

.match-table {
  font-size: 1.5rem; font-weight: 700; text-align: center;
  color: var(--text-dim); line-height: 1;
}

.match-players { display: grid; gap: 4px; }
.side { display: flex; align-items: baseline; gap: 8px; }
.side-name { font-size: .95rem; }
.side-code { font-size: .72rem; color: var(--text-mute); }
.side.is-winner .side-name { font-weight: 700; color: var(--win); }
.side.is-bye .side-name { color: var(--text-mute); font-style: italic; }

.match-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.result-form { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.result-form .reason { width: 170px; padding: 5px 8px; font-size: .78rem; }

/* Bersagli ampi: durante un evento si tocca in fretta, spesso da tablet */
.score-btn {
  min-width: 58px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-3); color: var(--text);
  font: inherit; font-family: var(--mono); font-size: .85rem; font-weight: 600;
  cursor: pointer;
}
.score-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.score-btn.is-draw:hover { background: var(--draw); border-color: var(--draw); color: #14161f; }

.standings td.strong { font-weight: 700; font-size: 1rem; }

@media (max-width: 720px) {
  .match { grid-template-columns: 40px 1fr; }
  .match-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .score-btn { min-width: 52px; padding: 11px 12px; }
}

/* ---------- Timer del turno --------------------------------------------- */

.timer-card { padding: 0; overflow: hidden; }

.timer-block {
  padding: 22px 20px;
  text-align: center;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-soft);
  border-left: 4px solid var(--line);
}
.timer-block.state-running  { border-left-color: var(--win); }
.timer-block.state-paused   { border-left-color: var(--draw); }
.timer-block.state-expired  { border-left-color: var(--loss); background: rgba(224,92,92,.12); }
.timer-block.state-finished { border-left-color: var(--text-mute); }

.timer-meta {
  display: flex; justify-content: center; gap: 14px; align-items: baseline;
  font-family: var(--mono); font-size: .72rem;
  text-transform: uppercase; letter-spacing: .09em; color: var(--text-mute);
  margin-bottom: 6px;
}
.timer-state { color: var(--text-dim); }
.state-expired .timer-state { color: var(--loss); font-weight: 700; }

/* Grande abbastanza da leggersi dall'altra parte della sala */
.timer-value {
  font-size: clamp(2.6rem, 9vw, 4.2rem);
  font-weight: 700; line-height: 1;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.state-expired .timer-value { color: var(--loss); }
.state-paused .timer-value  { color: var(--draw); }

.timer-overtime { margin-top: 6px; font-size: .95rem; color: var(--loss); font-weight: 600; }
.timer-sync { margin-top: 8px; font-size: .76rem; color: var(--draw); }

.timer-controls {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 14px 20px;
}
.minutes-input { width: 68px; padding: 8px 10px; font-family: var(--mono); }

@media (max-width: 600px) {
  .timer-controls { padding: 12px 14px; }
  .timer-controls .btn { flex: 1 1 auto; }
}

/* ---------- Gestione delle schermate pubbliche --------------------------- */

.display-row {
  display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap;
  padding: 14px; margin-bottom: 10px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent);
}
.display-info { flex: 1 1 320px; min-width: 0; }
.display-label { font-size: .98rem; font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.display-meta { font-size: .8rem; color: var(--text-mute); margin-top: 3px; }
.display-link { margin-top: 7px; }
.display-link code {
  display: inline-block; max-width: 100%; overflow-x: auto;
  padding: 5px 9px; border-radius: var(--radius-sm);
  background: var(--ink); border: 1px solid var(--line);
  font-size: .78rem; color: var(--text-dim); white-space: nowrap;
}
.display-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.display-actions .mini-btn { text-decoration: none; }

/* ---------- Indicatori di andamento nel ranking -------------------------- */
.trend { font-size: .72rem; font-weight: 700; }
.trend.up   { color: var(--win); }
.trend.down { color: var(--loss); }
.trend.flat { color: var(--text-mute); }


/* ---------- Grafico di andamento ----------------------------------------
   Le larghezze sono classi e non attributi style: la Content-Security-Policy
   non consente stili inline. Passi del 5%: più che sufficienti a occhio. */
.chart { display: flex; flex-direction: column; gap: 7px; }
.chart-row { display: grid; grid-template-columns: 68px 1fr 132px; gap: 12px; align-items: center; }
.chart-label { font-size: .78rem; color: var(--text-mute); }
.chart-track { height: 20px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.chart-bar { height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); border-radius: 4px; min-width: 2px; }
.chart-value { font-size: .82rem; }

@media (max-width: 640px) {
  .chart-row { grid-template-columns: 54px 1fr 96px; gap: 8px; }
  .chart-value { font-size: .74rem; }
}
.chart-bar.w-0 { width: 0%; }
.chart-bar.w-5 { width: 5%; }
.chart-bar.w-10 { width: 10%; }
.chart-bar.w-15 { width: 15%; }
.chart-bar.w-20 { width: 20%; }
.chart-bar.w-25 { width: 25%; }
.chart-bar.w-30 { width: 30%; }
.chart-bar.w-35 { width: 35%; }
.chart-bar.w-40 { width: 40%; }
.chart-bar.w-45 { width: 45%; }
.chart-bar.w-50 { width: 50%; }
.chart-bar.w-55 { width: 55%; }
.chart-bar.w-60 { width: 60%; }
.chart-bar.w-65 { width: 65%; }
.chart-bar.w-70 { width: 70%; }
.chart-bar.w-75 { width: 75%; }
.chart-bar.w-80 { width: 80%; }
.chart-bar.w-85 { width: 85%; }
.chart-bar.w-90 { width: 90%; }
.chart-bar.w-95 { width: 95%; }
.chart-bar.w-100 { width: 100%; }

/* ---------- Pannello del codice QR --------------------------------------- */
.qr-panel { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.qr-image {
  flex: 0 0 auto; padding: 10px; border-radius: var(--radius-sm);
  background: #fff; line-height: 0;
}
.qr-image img { display: block; }
.qr-text { flex: 1 1 260px; min-width: 0; }
.qr-text p { margin: 0 0 8px; }
.display-qr { flex: 0 0 auto; border-radius: 6px; background: #fff; padding: 5px; }

/* Il tavolo corrente durante l'inserimento risultati */
.match.is-focused {
  border-left-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-ghost);
}
.kbd-hint {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
  padding: 10px 14px; margin-bottom: 14px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  font-size: .8rem; color: var(--text-dim);
}
.kbd-hint kbd {
  padding: 2px 7px; border-radius: 4px;
  background: var(--surface-3); border: 1px solid var(--line);
  font-family: var(--mono); font-size: .76rem; color: var(--text);
}

/* ---------- Sicurezza: codici e chiavi ----------------------------------- */
.code-input {
  font-family: var(--mono); font-size: 1.6rem; letter-spacing: .35em;
  text-align: center; padding: 12px;
}
.secret-key {
  display: inline-block; padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--ink); border: 1px solid var(--line);
  font-family: var(--mono); font-size: .95rem; letter-spacing: .06em;
  word-break: break-all;
}
.recovery-grid {
  display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.recovery-grid code {
  padding: 9px 12px; text-align: center; border-radius: var(--radius-sm);
  background: var(--ink); border: 1px solid var(--line);
  font-size: .92rem; letter-spacing: .08em;
}

/* ---------- Stato della connessione e coda di invio ---------------------- */

.connection {
  padding: 3px 11px; border-radius: 999px;
  font-family: var(--mono); font-size: .72rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-dim);
}
.connection.is-online  { color: var(--win);  border-color: rgba(47,191,113,.35); background: rgba(47,191,113,.12); }
.connection.is-pending { color: var(--draw); border-color: rgba(224,169,59,.35); background: rgba(224,169,59,.12); }
.connection.is-offline { color: var(--loss); border-color: rgba(224,92,92,.4);  background: rgba(224,92,92,.14); }

/* Un tavolo in attesa di invio resta visibilmente distinto da uno confermato */
.match.is-queued { border-left-color: var(--draw); }
.match.is-failed { border-left-color: var(--loss); background: rgba(224,92,92,.08); }

.queue-note { font-size: .74rem; color: var(--text-mute); }
.match.is-queued .queue-note { color: var(--draw); }
.match.is-failed .queue-note { color: var(--loss); font-weight: 600; }

.queue-hint { color: var(--text-mute); }

/* ---------- Tabellone della fase finale ---------------------------------- */

.bracket-round { margin-bottom: 16px; }
.bracket-title {
  font-family: var(--mono); font-size: .72rem; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-mute); margin-bottom: 7px;
}
.bracket-match {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 9px 12px; margin-bottom: 5px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  border-left: 2px solid var(--line);
}
.bracket-side { display: inline-flex; align-items: baseline; gap: 7px; font-size: .93rem; }
.bracket-seed {
  min-width: 20px; text-align: center; padding: 1px 5px; border-radius: 4px;
  background: var(--surface-3); color: var(--text-mute); font-size: .72rem;
}
.bracket-side.is-winner { font-weight: 700; color: var(--win); }
.bracket-side.is-winner .bracket-seed { background: rgba(47,191,113,.16); color: var(--win); }
.bracket-side.is-out { opacity: .5; text-decoration: line-through; }
.bracket-vs { font-size: .72rem; color: var(--text-mute); text-transform: uppercase; letter-spacing: .08em; }

/* ==========================================================================
   Interfaccia di servizio — revisione grafica
   Pensata per chi la usa in piedi, di fretta, con la sala che aspetta.
   Tre principi: l'azione da compiere si vede da lontano, i bersagli si
   colpiscono col pollice, i numeri non ballano mai.
   ========================================================================== */

/* ---------- Il prossimo passo -------------------------------------------
   L'elemento centrale del gestionale: dice sempre, nella stessa posizione,
   qual è l'unica cosa da fare adesso. Nasce da un problema reale — chiuso un
   turno non c'era nulla che indicasse come proseguire. */

.next-step {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 20px 22px;
  margin-bottom: 22px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.next-step-body { flex: 1 1 260px; min-width: 0; }
.next-step-eyebrow {
  font-family: var(--mono); font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .16em;
  color: var(--accent); margin-bottom: 6px;
}
.next-step-label {
  font-size: 1.35rem; font-weight: 760; letter-spacing: -.022em;
  line-height: 1.2; margin-bottom: 3px;
}
.next-step-hint { color: var(--text-dim); font-size: .9rem; margin: 0; }
.next-step .btn { flex: 0 0 auto; }

.next-step.is-quiet {
  border-left-color: var(--line);
  background: var(--surface);
}
.next-step.is-quiet .next-step-eyebrow { color: var(--text-mute); }

/* ---------- Pulsanti ------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: var(--tap);
  padding: 11px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: inherit; font-size: .94rem; font-weight: 660;
  letter-spacing: -.006em;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s ease, transform .06s ease, box-shadow .12s ease;
}
.btn:hover { background: var(--accent-hot); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled {
  opacity: .45; cursor: not-allowed; transform: none;
}

/* L'azione principale di una pagina: più alta, più larga, impossibile da
   mancare anche guardando lo schermo di sfuggita. */
.btn-lead {
  min-height: var(--tap-lg);
  padding: 0 30px;
  font-size: 1.05rem; font-weight: 720;
  border-radius: var(--radius);
  box-shadow: 0 2px 0 var(--accent-dim);
}
.btn-lead:active { box-shadow: 0 1px 0 var(--accent-dim); }

.btn-ghost {
  background: transparent; color: var(--text);
  border-color: var(--line);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--text-mute); }

.btn-quiet {
  background: var(--surface-2); color: var(--text-dim); border-color: var(--line-soft);
}
.btn-quiet:hover { background: var(--surface-3); color: var(--text); }

.btn-danger { background: var(--loss); color: #2a0808; }
.btn-danger:hover { background: #ff8585; }

.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 13px; font-size: .85rem; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Percorso a passi --------------------------------------------
   Le operazioni lunghe (creare un torneo, iscrivere i giocatori, avviare)
   diventano una sequenza dichiarata invece di una pagina sola piena di
   riquadri. La numerazione qui è legittima: è un ordine reale, e sapere
   quanto manca cambia il modo in cui si lavora. */

.steps {
  display: flex; align-items: stretch; gap: 0;
  margin-bottom: 24px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.step {
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; gap: 11px;
  padding: 13px 16px;
  border-right: 1px solid var(--line-soft);
  color: var(--text-mute);
  text-decoration: none;
  position: relative;
}
.step:last-child { border-right: 0; }
.step:hover { text-decoration: none; }
a.step:hover { background: var(--surface-2); }

.step-mark {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  font-family: var(--mono); font-size: .74rem; font-weight: 700;
}
.step-text { min-width: 0; }
.step-name {
  font-size: .88rem; font-weight: 620; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.step-note {
  font-family: var(--mono); font-size: .68rem;
  color: var(--text-mute); letter-spacing: .04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.step.is-done { color: var(--win); }
.step.is-done .step-mark { background: var(--win-ghost); border-color: var(--win); }
.step.is-current {
  color: var(--text);
  background: var(--accent-ghost);
}
.step.is-current .step-mark {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.step.is-current .step-name { font-weight: 720; }
.step.is-current::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0;
  height: 2px; background: var(--accent);
}

/* ---------- Gettone del tavolo ------------------------------------------
   Il numero del tavolo è la cosa che si cerca con gli occhi più spesso di
   ogni altra, sia dall'organizzatore sia dal giocatore. Ha la forma di un
   segnaposto fisico, non di una cella di tabella. */

.table-chip {
  display: inline-grid; place-items: center;
  min-width: 44px; height: 44px; padding: 0 10px;
  border-radius: 10px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  font-family: var(--mono); font-size: 1.15rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.table-chip.is-done { background: var(--win-ghost); border-color: var(--win); color: var(--win); }
.table-chip.is-bye  { background: var(--surface-2); color: var(--text-mute); font-size: .74rem; }

/* ---------- Riquadri ------------------------------------------------------ */

.card {
  border-radius: var(--radius);
  border-color: var(--line-soft);
}
.card-head h2 { margin-bottom: 0; }
.card-note {
  font-family: var(--mono); font-size: .72rem;
  color: var(--text-mute); letter-spacing: .04em;
}

/* ---------- Numeri in evidenza ------------------------------------------- */

.stat {
  border-radius: var(--radius);
  border: 1px solid var(--line-soft);
  background: var(--surface);
  padding: 15px 17px;
}
.stat-key {
  font-family: var(--mono); font-size: .68rem; text-transform: uppercase;
  letter-spacing: .13em; color: var(--text-mute); margin-bottom: 7px;
}
.stat-val {
  font-size: 1.9rem; font-weight: 760; letter-spacing: -.03em; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat.is-ok   { border-color: rgba(62,207,142,.32); }
.stat.is-warn { border-color: rgba(224,163,64,.34); }
.stat.is-ok .stat-val   { color: var(--win); }
.stat.is-warn .stat-val { color: var(--accent); }

/* ---------- Etichette ----------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-family: var(--mono); font-size: .7rem; font-weight: 600;
  letter-spacing: .04em;
  background: var(--surface-3); color: var(--text-dim);
  border: 1px solid transparent;
}
.badge.ok     { background: var(--win-ghost);  color: var(--win);  border-color: rgba(62,207,142,.3); }
.badge.warn   { background: var(--accent-ghost); color: var(--accent); border-color: rgba(224,163,64,.3); }
.badge.bad    { background: var(--loss-ghost); color: var(--loss); border-color: rgba(255,107,107,.3); }
.badge.accent { background: var(--draw-ghost); color: var(--draw); border-color: rgba(127,168,201,.3); }

/* ---------- Campi --------------------------------------------------------- */

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="search"], select, textarea {
  min-height: var(--tap);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--ink);
  color: var(--text);
  font-family: inherit; font-size: .95rem;
  padding: 10px 13px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-ghost);
  outline-offset: 0;
}
.field label {
  display: block; margin-bottom: 6px;
  font-size: .82rem; font-weight: 620; color: var(--text-dim);
}
.hint { font-size: .78rem; color: var(--text-mute); margin-top: 5px; }

/* ---------- Navigazione --------------------------------------------------- */

.nav a { min-height: 38px; display: flex; align-items: center; font-size: .9rem; }
.nav a.is-active { border-left-color: var(--accent); font-weight: 620; }

/* ---------- Tabelle ------------------------------------------------------- */

table { border-collapse: separate; border-spacing: 0; width: 100%; }
th {
  font-family: var(--mono); font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .11em;
  color: var(--text-mute); text-align: left;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.is-out td { opacity: .5; }

/* ---------- Movimento con misura ----------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Schermi stretti: tablet al banco ------------------------------ */

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; flex-direction: row; align-items: center;
             gap: 12px; overflow-x: auto; padding: 10px 14px; }
  .nav { flex-direction: row; }
  .nav-label, .sidebar-foot { display: none; }
  .content { padding: 18px 14px 80px; }
  .next-step { flex-direction: column; align-items: stretch; }
  .next-step .btn { width: 100%; }
  .steps { flex-direction: column; }
  .step { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  h1 { font-size: 1.5rem; }
}

/* ---------- Iscrizioni: la ricerca è l'azione principale ------------------
   Quaranta persone entrano dalla porta in dieci minuti. Il campo di ricerca
   deve essere la cosa più grande della pagina e già a fuoco. */

.search-lead { display: flex; gap: 10px; margin-bottom: 18px; }
.search-lead input[type="search"] {
  flex: 1; min-height: var(--tap-lg);
  font-size: 1.05rem; padding: 0 18px;
  border-radius: var(--radius);
}
.search-lead .btn { min-height: var(--tap-lg); padding: 0 26px; }

/* Ogni risultato è una riga cliccabile alta, non una cella di tabella. */
.pick-list { display: flex; flex-direction: column; gap: 8px; }
.pick {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}
.pick:hover { border-color: var(--accent); }
.pick-name { flex: 1; min-width: 0; font-size: 1rem; font-weight: 620; }
.pick-code { color: var(--text-mute); font-size: .82rem; }

.quick-new > summary {
  cursor: pointer; padding: 11px 0;
  font-weight: 620; color: var(--text-dim);
  list-style: none;
}
.quick-new > summary::-webkit-details-marker { display: none; }
.quick-new > summary::before { content: '+ '; color: var(--accent); font-weight: 700; }
.quick-new > summary:hover { color: var(--text); }
.quick-new[open] > summary { color: var(--text); margin-bottom: 6px; }

.quick-add {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  align-items: end;
}
