/* Sala — base e componenti condivisi. Ogni colore viene dai token (tokens.css). */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs-md) / var(--lh-text) var(--font-ui);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); text-underline-offset: 3px; }
h1, h2, h3 { line-height: var(--lh-title); margin: 0; text-wrap: balance; }
p { margin: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.display { font-family: var(--font-display); font-weight: 400; letter-spacing: -0.005em; }
.muted { color: var(--ink-2); }
.t-xs { font-size: var(--fs-xs); }
.t-sm { font-size: var(--fs-sm); }
.t-lg { font-size: var(--fs-lg); }
.num { font-variant-numeric: tabular-nums; }
.stack { display: grid; gap: var(--s-4); }
.row { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ---- Pulsanti ---------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--tap); padding: 0 var(--s-4);
  border: 1.5px solid transparent; border-radius: var(--r-control);
  font: 700 var(--fs-sm) / 1.1 var(--font-ui); text-decoration: none; white-space: nowrap;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover { background: var(--raised); border-color: var(--ink-3); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--sunken); }
.btn-danger { background: var(--bad); color: var(--on-bad); }
.btn-danger:hover { background: color-mix(in srgb, var(--bad) 88%, #000); }
.btn-danger-quiet { background: var(--surface); border-color: var(--bad-line); color: var(--bad); }
.btn-danger-quiet:hover { background: var(--bad-bg); }
.btn-lg { min-height: 52px; padding: 0 var(--s-6); font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn-icon { width: var(--tap); padding: 0; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn[aria-busy="true"] { position: relative; color: transparent !important; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--accent-ink); border-right-color: transparent; animation: spin 0.7s linear infinite;
}
.btn-secondary[aria-busy="true"]::after, .btn-ghost[aria-busy="true"]::after { border-color: var(--ink); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Campi ---------------------------------------------------------------------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-weight: 700; font-size: var(--fs-sm); }
.field-label .opt { font-weight: 400; color: var(--ink-2); }
.field-hint { color: var(--ink-2); font-size: var(--fs-xs); }
.field-error { color: var(--bad); font-size: var(--fs-xs); font-weight: 700; }
.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1.5px solid var(--line-strong); border-radius: var(--r-control);
  background: var(--surface); color: var(--ink);
  font: 400 var(--fs-md) / 1.3 var(--font-ui);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.input::placeholder { color: var(--ink-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); }
.input[aria-invalid="true"] { border-color: var(--bad); }
textarea.input { min-height: 88px; resize: vertical; }
select.input {
  appearance: none; padding-right: 40px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%;
  background-size: 6px 6px; background-repeat: no-repeat;
}
.input[type="color"] { padding: 4px; cursor: pointer; }
.check { display: flex; gap: var(--s-3); align-items: flex-start; cursor: pointer; font-size: var(--fs-sm); }
.check input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: var(--accent); cursor: pointer; }

/* ---- Scelte a pillola (radio) ---------------------------------------------------- */
.choices { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.choice { position: relative; display: inline-flex; }
.choice input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.choice span {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: var(--tap); min-height: var(--tap); padding: 0 var(--s-4);
  border: 1.5px solid var(--line-strong); border-radius: var(--r-pill); background: var(--surface);
  font-weight: 700; font-size: var(--fs-md); user-select: none;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.choice:hover span { border-color: var(--ink-3); }
.choice input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.choice input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.choice input:disabled { cursor: not-allowed; }
.choice input:disabled + span { color: var(--ink-3); border-style: dashed; border-color: var(--line); background: transparent; }

/* Segmento: scelta tra poche opzioni equivalenti */
.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: calc(var(--r-control) + 3px); background: var(--sunken); flex-wrap: wrap; }
.seg label { position: relative; display: inline-flex; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 var(--s-4);
  border-radius: var(--r-control); font-weight: 700; font-size: var(--fs-sm); color: var(--ink-2); user-select: none;
}
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }

/* Interruttore */
.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; font-weight: 700; font-size: var(--fs-sm); min-height: var(--tap); }
.switch input {
  appearance: none; flex: none; width: 46px; height: 28px; margin: 0; border-radius: var(--r-pill);
  background: var(--line-strong); position: relative; cursor: pointer; transition: background-color var(--t-fast) var(--ease);
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / 0.25); transition: transform var(--t-fast) var(--ease);
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

/* Stepper persone */
.stepper { display: inline-flex; align-items: stretch; border: 1.5px solid var(--line-strong); border-radius: var(--r-control); overflow: hidden; background: var(--surface); }
.stepper button { width: 52px; min-height: 52px; border: 0; background: var(--raised); font-size: 24px; font-weight: 700; cursor: pointer; color: var(--ink); }
.stepper button:hover { background: var(--sunken); }
.stepper input {
  width: 64px; border: 0; text-align: center; font-size: var(--fs-xl); font-weight: 700; background: var(--surface);
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }

/* ---- Chip di stato ------------------------------------------------------------------ */
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 10px;
  border-radius: var(--r-pill); background: var(--info-bg); color: var(--ink);
  font-size: var(--fs-xs); font-weight: 700; white-space: nowrap;
}
.chip svg { width: 14px; height: 14px; }
.chip-wait { background: var(--wait-bg); color: var(--wait); }
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-bad { background: var(--bad-bg); color: var(--bad); }
.chip-accent { background: var(--accent-soft); color: var(--accent-text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

/* ---- Card prenotazione --------------------------------------------------------------- */
.bk {
  display: flex; align-items: center; gap: var(--s-3); min-height: 56px; width: 100%;
  padding: var(--s-2) var(--s-3) var(--s-2) var(--s-2); text-align: left; cursor: pointer;
  border: 1.5px solid var(--line); border-radius: var(--r-control); background: var(--surface); color: var(--ink);
  position: relative; transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.bk:hover { border-color: var(--line-strong); }
.bk[aria-pressed="true"], .bk[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.bk-party {
  display: grid; place-items: center; flex: none; min-width: 40px; height: 40px; padding: 0 6px;
  border-radius: var(--r-control); background: var(--sunken); font-size: var(--fs-lg); font-weight: 700;
}
.bk-main { min-width: 0; flex: 1 1 auto; display: grid; gap: 1px; }
.bk-name { font-weight: 700; font-size: var(--fs-md); line-height: 1.25; overflow-wrap: anywhere; }
.bk-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--ink-2); font-size: var(--fs-xs); }
.bk-meta svg { width: 14px; height: 14px; }
.bk-note { flex: none; width: 22px; height: 22px; color: var(--wait); }
.bk.is-pending { background: var(--wait-bg); border-color: var(--wait-line); }
.bk.is-pending .bk-party { background: color-mix(in srgb, var(--wait-line) 45%, var(--wait-bg)); }
.bk.is-arrived { background: var(--ok-bg); border-color: var(--ok-line); }
.bk.is-arrived .bk-party { background: color-mix(in srgb, var(--ok-line) 45%, var(--ok-bg)); }
.bk.is-no_show, .bk.is-cancelled { opacity: 0.7; border-style: dashed; }
.bk.is-cancelled .bk-name { text-decoration: line-through; }

/* ---- Posti a pallini: il segno distintivo -------------------------------------------- */
.seats { display: grid; grid-template-columns: repeat(10, 9px); gap: 4px; }
.seat { width: 9px; height: 9px; border-radius: 50%; background: var(--seat-off); }
.seat.on { background: var(--seat-on); }
.seat.over { background: var(--bad); }
.seats-bar { height: 9px; border-radius: 5px; background: var(--seat-off); overflow: hidden; }
.seats-bar > i { display: block; height: 100%; background: var(--seat-on); border-radius: inherit; }
.seats-bar > i.over { background: var(--bad); }

/* Curva della serata: una colonna di pallini per orario, si vede dove si concentra la cucina */
.curve { display: flex; align-items: flex-end; gap: 10px; overflow-x: auto; padding: 2px 2px 0; scrollbar-width: thin; }
.curve-col { display: grid; justify-items: center; gap: 6px; flex: none; }
.curve-dots { display: flex; flex-direction: column-reverse; gap: 3px; }
.curve-dots .seat { width: 10px; height: 10px; }
.curve-time { font-size: 11px; font-weight: 700; color: var(--ink-2); }
.curve-col.is-now .curve-time { color: var(--accent-text); }

/* ---- Dialoghi e foglio dal basso ----------------------------------------------------------- */
dialog.dialog, dialog.sheet {
  border: 0; padding: 0; color: var(--ink); background: var(--surface);
  box-shadow: var(--shadow-float); max-height: calc(100dvh - 32px);
}
dialog.dialog { border-radius: var(--r-sheet); width: min(560px, calc(100vw - 24px)); }
dialog.dialog.narrow { width: min(420px, calc(100vw - 24px)); }
dialog::backdrop { background: var(--scrim); }
dialog.sheet {
  margin: auto auto 0; width: 100%; max-width: 640px; border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (min-width: 720px) {
  dialog.sheet { margin: auto; border-radius: var(--r-sheet); width: min(600px, calc(100vw - 32px)); }
}
.dlg-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.dlg-head h2 { font-size: var(--fs-lg); flex: 1 1 auto; }
.dlg-body { padding: var(--s-5); display: grid; gap: var(--s-5); }
.dlg-foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--s-2);
  padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface);
}
.dlg-foot .spacer { flex: 1 1 auto; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 10px auto 0; }
@media (min-width: 720px) { .sheet-grip { display: none; } }
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: dlg-in var(--t-med) var(--ease); }
  dialog.sheet[open] { animation: sheet-in 220ms var(--ease); }
  @media (min-width: 720px) { dialog.sheet[open] { animation: dlg-in var(--t-med) var(--ease); } }
}
@keyframes dlg-in { from { opacity: 0; transform: translateY(6px) scale(0.985); } }
@keyframes sheet-in { from { transform: translateY(40%); opacity: 0.4; } }

/* ---- Avvisi (toast) ---------------------------------------------------------------------- */
.toasts {
  position: fixed; z-index: 90; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--toast-offset, 16px) + env(safe-area-inset-bottom, 0px));
  display: grid; gap: var(--s-2); width: min(520px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s-3); padding: 12px 12px 12px 16px; pointer-events: auto;
  border-radius: var(--r-surface); background: var(--ink); color: var(--surface); box-shadow: var(--shadow-float);
  font-size: var(--fs-sm); font-weight: 700;
}
.toast span { flex: 1 1 auto; }
.toast button {
  flex: none; min-height: 36px; padding: 0 12px; border-radius: var(--r-control); cursor: pointer;
  border: 1.5px solid color-mix(in srgb, var(--surface) 45%, transparent); background: transparent; color: var(--surface); font-weight: 700;
}
.toast.is-new { background: var(--accent); color: var(--accent-ink); }
.toast.is-new button { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent-ink) 45%, transparent); }
.toast.is-error { background: var(--bad); color: var(--on-bad); }
.toast.is-error button { color: var(--on-bad); border-color: color-mix(in srgb, var(--on-bad) 45%, transparent); }
@media (prefers-reduced-motion: no-preference) { .toast { animation: toast-in 180ms var(--ease); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---- Stati vuoti e caricamento ------------------------------------------------------------ */
.empty { display: grid; justify-items: center; gap: var(--s-3); padding: var(--s-10) var(--s-6); text-align: center; color: var(--ink-2); border: 1.5px dashed var(--line-strong); border-radius: var(--r-surface); }
.empty svg { width: 32px; height: 32px; color: var(--ink-3); }
.empty h3 { color: var(--ink); font-size: var(--fs-lg); }
.empty p { max-width: 46ch; }

.skel { display: block; border-radius: var(--r-control); background: var(--sunken); min-height: 14px; }
.skel-text { height: 14px; margin: 6px 0; }
.skel-title { height: 28px; width: 40%; }
.skel-block { height: 120px; border-radius: var(--r-surface); }
@media (prefers-reduced-motion: no-preference) {
  .skel { background: linear-gradient(90deg, var(--sunken) 0%, var(--raised) 50%, var(--sunken) 100%); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Superfici ---------------------------------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-surface); }
.kbd { display: inline-block; min-width: 22px; padding: 0 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--raised); font-size: var(--fs-xs); font-weight: 700; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
