/* ==========================================================================
   Sushi Counter — stile (tema scuro, iPhone first)
   ========================================================================== */

:root {
  color-scheme: dark;
  --bg: #16161c;
  --surface: #20202a;
  --surface-2: #2a2a36;
  --line: #34343f;
  --text: #f5f1ea;
  --muted: #9b98a6;
  --accent: #f2875e;        /* salmone, dal logo */
  --accent-ink: #1b1210;
  --rice: #f3e3cf;
  --danger: #ff6b6b;
  --ok: #5fd39a;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --font: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* Pagina bloccata: niente scroll, niente rimbalzo, niente selezione/zoom. */
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body {
  position: fixed;
  inset: 0;
  touch-action: none;          /* niente pan/pinch/doppio-tap-zoom */
}

button { font: inherit; color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* --- Stage (area del contatore) ----------------------------------------- */
#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: pointer;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
.count-wrap { text-align: center; pointer-events: none; }
.count {
  font-size: min(44vw, 34vh, 300px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  will-change: transform;
}
.count-label {
  margin-top: .4rem;
  font-size: 1.1rem;
  letter-spacing: .3em;
  padding-left: .3em;              /* compensa lo spazio dopo l'ultima lettera */
  text-transform: uppercase;
  color: var(--muted);
}
.hint {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 22px);
  text-align: center;
  font-size: .85rem;
  color: var(--muted);
  opacity: .7;
  pointer-events: none;
  transition: opacity .6s;
}
.hint.gone { opacity: 0; }

/* Flash colorato a tutto schermo per il feedback */
#stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at var(--fx, 50%) var(--fy, 50%), var(--flash, var(--accent)) 0, transparent 55%);
}
#stage.flash::after { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .18; } to { opacity: 0; } }

/* --- Barra superiore ----------------------------------------------------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 12px) 0 calc(var(--safe-left) + 12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;            /* solo i figli catturano i tocchi */
}
.topbar > * { pointer-events: auto; }

.icon-btn {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: 0; border-radius: 14px;
  background: transparent;
  color: var(--text);
  touch-action: manipulation;
}
.icon-btn:active { background: var(--surface-2); }
.topbar .icon-btn { background: rgb(255 255 255 / .06); }

.sync-dot {
  width: 10px; height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--line);
  transition: background .3s;
}
.sync-dot[data-state="ok"]      { background: var(--ok); opacity: .55; }
.sync-dot[data-state="syncing"] { background: var(--accent); animation: pulse 1s infinite; }
.sync-dot[data-state="offline"] { background: var(--muted); }
.sync-dot[data-state="error"]   { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

/* --- Menu (pannello) ----------------------------------------------------- */
.menu { position: fixed; inset: 0; z-index: 10; }
.menu-backdrop {
  position: absolute; inset: 0;
  background: rgb(0 0 0 / .55);
  animation: fade-in .2s ease-out;
}
.sheet {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: min(100%, 460px);
  display: flex; flex-direction: column;
  background: var(--surface);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  box-shadow: 10px 0 40px rgb(0 0 0 / .4);
  animation: slide-in .24s cubic-bezier(.2, .8, .2, 1);
}
.menu.closing .sheet { animation: slide-out .18s ease-in forwards; }
.menu.closing .menu-backdrop { animation: fade-out .18s ease-in forwards; }
@keyframes slide-in  { from { transform: translateX(-100%); } }
@keyframes slide-out { to   { transform: translateX(-100%); } }
@keyframes fade-in   { from { opacity: 0; } }
@keyframes fade-out  { to   { opacity: 0; } }

.sheet-head {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 1.15rem; text-align: center; grid-column: 2; }
.sheet-head #back-btn { grid-column: 1; grid-row: 1; }
.sheet-head [data-close] { grid-column: 3; grid-row: 1; }

.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;             /* qui lo scroll verticale e' permesso */
  padding: 16px 16px calc(var(--safe-bottom) + 24px);
}
.sheet-body input, .sheet-body textarea { -webkit-user-select: text; user-select: text; }

.menu-hero {
  display: flex; align-items: center; gap: 14px;
  padding: 6px 4px 18px;
}
.menu-hero img { width: 84px; height: auto; }
.menu-hero-count { font-size: 1.5rem; font-weight: 700; }

.menu-list { display: grid; gap: 10px; }
.menu-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: 0; border-radius: 16px;
  background: var(--surface-2);
  text-align: left;
  touch-action: manipulation;
}
.menu-item:active { background: var(--line); }
.mi-icon { font-size: 1.5rem; width: 32px; text-align: center; }
.mi-text { display: grid; gap: 2px; }
.mi-text b { font-weight: 650; font-size: 1.05rem; }
.mi-text small { color: var(--muted); font-size: .85rem; }

/* --- Storico ------------------------------------------------------------- */
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 8px 12px 16px;
  border-radius: 14px;
  background: var(--surface-2);
}
.history-list .h-date { font-weight: 600; }
.history-list .h-time { color: var(--muted); font-size: .85rem; }
.history-list .h-count { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.history-list .h-count small { font-size: .75rem; font-weight: 500; color: var(--muted); margin-left: 3px; }
.history-list .pending { font-size: .75rem; color: var(--accent); }
.del-btn {
  width: 40px; height: 40px;
  border: 0; border-radius: 12px;
  background: transparent; color: var(--muted);
  display: grid; place-items: center;
}
.del-btn:active { background: rgb(255 107 107 / .15); color: var(--danger); }
.empty { text-align: center; color: var(--muted); margin-top: 40px; line-height: 1.6; }

/* --- Statistiche --------------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 22px; }
.stat {
  padding: 12px 10px;
  border-radius: 14px;
  background: var(--surface-2);
  text-align: center;
}
.stat .v { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .k { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.chart-title { margin: 0 0 4px; font-size: 1rem; }
.chart-sub { margin: 0 0 12px; color: var(--muted); font-size: .85rem; min-height: 1.2em; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar { fill: var(--accent); transition: opacity .15s; }
.chart .bar.dim { opacity: .35; }
.chart .hit { fill: transparent; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; opacity: .6; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart text.val { fill: var(--text); font-size: 12px; font-weight: 700; }

/* --- Impostazioni -------------------------------------------------------- */
.settings { display: grid; gap: 10px; }
.settings label { font-weight: 600; }
.settings input {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;                 /* >=16px: iOS non zooma sul focus */
}
.settings-status { margin: 22px 0 14px; display: grid; gap: 6px; }

.btn {
  padding: 14px 18px;
  border: 0; border-radius: 14px;
  background: var(--surface-2);
  font-weight: 650;
  touch-action: manipulation;
}
.btn:active { filter: brightness(1.2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger  { background: var(--danger); color: #1c0d0d; }

/* --- Dialogo di conferma ------------------------------------------------- */
.confirm {
  width: min(88vw, 360px);
  padding: 22px 20px 18px;
  border: 0; border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / .5);
}
.confirm::backdrop { background: rgb(0 0 0 / .6); }
.confirm h3 { margin: 0 0 8px; font-size: 1.2rem; }
.confirm p { margin: 0 0 20px; color: var(--muted); line-height: 1.45; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* --- Toast --------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 70px);
  transform: translateX(-50%);
  z-index: 30;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: .9rem;
  pointer-events: none;
  animation: fade-in .2s;
}

/* Checkbox "switch" invisibile usato solo per il feedback aptico su iOS */
.haptic { position: fixed; left: -100px; top: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
