:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1d1b16;
  --muted: #6b665b;
  --line: #e2ddd1;
  --accent: #1f6f50;
  --accent-text: #ffffff;
  --warn: #b25b00;
  --danger: #b3261e;
  --ok: #1f6f50;
  --new: #2456a6;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1e1d18;
    --surface-2: #2a2821;
    --text: #f1eee6;
    --muted: #a9a394;
    --line: #37342b;
    --accent: #4fbf8f;
    --accent-text: #0c1a13;
    --warn: #f0a24a;
    --danger: #ff8a80;
    --ok: #4fbf8f;
    --new: #7fa8ff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans SC", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
[hidden] { display: none !important; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; }

.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea.input { min-height: 70px; resize: vertical; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; z-index: 100; max-width: calc(100% - 32px);
}

/* Login staff */
.login { max-width: 380px; margin: 10vh auto; padding: 24px 16px; }
.login h1 { margin-bottom: 20px; }
/* Il logo sopra il titolo: si riconosce l'app prima ancora di leggere */
.login-logo { display: block; width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 16px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }

/* Barra in alto delle pagine staff */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin-right: auto; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); }
.page { padding: 16px; max-width: 1200px; margin: 0 auto; }

dialog {
  border: 0; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text);
  width: min(560px, calc(100% - 32px)); max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
/* Con tanto contenuto scorre il corpo, non la finestra: i pulsanti Salva e Annulla restano
   sempre in fondo, visibili. Prima uscivano dal riquadro e non si potevano premere.
   Vale sia per le finestre con un modulo dentro sia per quelle senza. */
dialog[open] { display: flex; flex-direction: column; }
/* Niente altezze in percentuale qui: Safari le calcola sull'altezza della finestra, che
   non è ancora decisa, e schiacciava tutto a zero (restava una lineetta a metà schermo).
   Il limite lo dà già la finestra (max-height); il modulo si stringe dentro e scorre il corpo. */
dialog > form { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.dialog-body { padding: 20px; overflow: auto; flex: 1 1 auto; min-height: 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; flex: none; }

/* Cliente riconosciuto al tavolo: barra in alto e pagina di accesso */
.g-guestbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 16px; font-size: 14px; }
.g-guestbar .g-tier { padding: 1px 8px; border-radius: 999px; background: #1d2d3d; color: #fff; font-weight: 600; font-size: 12px; }
.g-guestbar .g-coupon, .g-guestbar .g-visits { font-size: 12px; opacity: .75; }
.g-link { background: none; border: 0; padding: 2px 4px; font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; color: inherit; }
.g-gate { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgb(20 24 28 / 55%); }
.g-gate-card { width: min(420px, 100%); display: grid; gap: 10px; padding: 22px; background: #fff; border-radius: 10px; }
.g-gate-card h2 { margin: 0; font-size: 22px; }
.g-gate-sub { margin: 0 0 4px; font-size: 14px; opacity: .8; }
.g-input { width: 100%; padding: 11px 12px; font: inherit; border: 1px solid rgb(0 0 0 / 22%); border-radius: 8px; }
.g-check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.g-btn.primary { padding: 12px; font: inherit; font-weight: 600; color: #fff; background: #1d2d3d; border: 0; border-radius: 8px; cursor: pointer; }
.g-err { margin: 0; min-height: 18px; color: #b3261e; font-size: 13px; }
/* Stesso posto, ma è una buona notizia: "ti abbiamo mandato l'email" */
.g-err.g-ok { color: #1b6b3a; }

/* PIN rapido sul tablet di sala */
.pin-pad { display: grid; gap: 12px; justify-items: stretch; text-align: center; }
.pin-dots { display: flex; justify-content: center; gap: 12px; min-height: 22px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--text); }
.pin-dots i.on { background: var(--text); }
.pin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-key { min-height: 64px; font: inherit; font-size: 26px; font-weight: 700; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); border-radius: 12px; cursor: pointer; }
.pin-key.ok { background: var(--accent); color: var(--accent-text, #fff); border-color: var(--accent); font-size: 20px; }
