/* FP Shop — foglio di stile unico.
   Mobile-first e a una mano: le azioni stanno in basso, dove arriva il pollice.
   Niente build step: è una PWA che deve restare deployabile copiando una cartella. */

/* Brand Francesco Passeri: bianco e nero, nero caldo #2b2724, nessun colore
   d'accento. Gli asset di riferimento stanno sul NAS, non sul sito.
   L'unica eccezione è un rosso spento riservato a errori e azioni distruttive:
   è una convenzione di sistema (la stessa di wp-admin), non un accento di brand.
   In scuro il "primario" si inverte in avorio su nero — resta bianco e nero. */

:root {
  --bg: #ffffff;
  --surface: #f7f6f4;
  --surface-2: #edebe7;
  --text: #2b2724;
  /* Il grigio precedente (#7a736c) stava a 4,32 sul fondo delle schede: sotto
     la soglia AA, e le schede sono ovunque. Questo tiene 5,00 lì e 4,54 sul
     grigio più scuro, mantenendo la tinta calda del brand. */
  --muted: #706962;
  --line: #dedad4;
  --accent: #2b2724;
  --accent-text: #ffffff;
  --danger: #a3352f;
  --radius: 14px;
  --tap: 46px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1816;
    --surface: #232120;
    --surface-2: #302d2a;
    --text: #f2efec;
    --muted: #a49c94;
    --line: #3a3733;
    --accent: #f2efec;
    --accent-text: #2b2724;
    --danger: #e08b86;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body { padding-top: calc(52px + var(--safe-t)); padding-bottom: calc(62px + var(--safe-b)); }
body.no-chrome { padding-top: var(--safe-t); padding-bottom: var(--safe-b); }

/* ---------- topbar ---------- */

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(52px + var(--safe-t));
  padding: var(--safe-t) 6px 0;
  display: flex;
  align-items: center;
  gap: 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  z-index: 40;
}

.store-switch {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: none;
  border: 0;
  color: var(--text);
  font: 600 16px/1.2 inherit;
  height: var(--tap);
  padding: 0 8px;
  cursor: pointer;
}
.store-switch #store-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.caret { color: var(--muted); font-size: 12px; }

.thumb {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  object-fit: cover;
  flex: 0 0 auto;
  background: var(--surface-2);
}

.store-logo {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  object-fit: cover;
  flex: 0 0 auto;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- tabbar ---------- */

#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(62px + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  z-index: 40;
}
#tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
#tabbar a span { font-size: 19px; line-height: 1; }
#tabbar a[aria-current="page"] { color: var(--accent); }

/* ---------- layout ---------- */

main { padding: 12px 14px 20px; max-width: 720px; margin: 0 auto; }

h1 { font-size: 22px; margin: 6px 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 20px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack > * + * { margin-top: 10px; }

/* ---------- liste ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

.item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  padding: 13px 2px;
  cursor: pointer;
}
.item:active { background: var(--surface-2); }
.item-title { font-weight: 600; }
.item-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.item-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- badge stato ---------- */

/* Senza colore, lo stato si codifica con peso e contrasto: pieno = richiede
   un'azione adesso, contornato = in attesa, tenue = chiuso. Si legge in un
   colpo d'occhio anche in bianco e nero, che è il punto. */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.processing { background: var(--accent); color: var(--accent-text); }
.badge.on-hold, .badge.pending { background: transparent; border-color: var(--text); color: var(--text); }
.badge.completed { background: var(--surface-2); color: var(--muted); }
.badge.cancelled, .badge.failed, .badge.refunded {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------- filtri ---------- */

.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ---------- form ---------- */

input, select, textarea, button { font: inherit; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

input[type=text], input[type=search], input[type=number], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg);
  color: var(--text);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- fuoco da tastiera ---------- */

/* Prima esisteva solo sui campi: ogni pulsante dell'app — righe della lista
   ordini, schede in basso, filtri, opzioni del foglio — riceveva il fuoco
   senza mostrarlo. Il foglio modale sposta il fuoco al suo interno: senza un
   indicatore visibile, chi naviga da tastiera non sa dove si trova.
   `:focus-visible` mostra l'anello solo a chi naviga da tastiera, non a ogni
   tocco o clic. */
/* L'anello usa `--text`, non `--accent`.
   L'accento è il colore del cliente e non sappiamo che colore sia: un brand
   chiaro su tema chiaro darebbe un anello invisibile, cioè esattamente il
   guasto che questa regola dovrebbe evitare. `--text` invece contrasta con lo
   sfondo per costruzione, in entrambi i temi. È lo stesso motivo per cui
   `readableOn()` non guarda il tema dell'app. */
:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: 6px;
}
.item:focus-visible { outline-offset: -2px; }

/* ---------- movimento ridotto ---------- */

/* Chi ha impostato la preferenza di sistema riceve la stessa app, ferma. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { color: var(--danger); }
.btn-block { display: flex; width: 100%; }

/* ---------- stepper stock ---------- */

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: var(--tap); height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font-size: 21px;
  cursor: pointer;
}
.stepper .qty {
  min-width: 62px;
  text-align: center;
  font-weight: 700;
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}

/* ---------- incassi ---------- */

.metric { text-align: center; padding: 22px 12px; }
.metric .value { font-size: 38px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.metric .label { color: var(--muted); font-size: 13px; margin-top: 4px; }
.metric-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; text-align: center; }
.metric-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.metric-row .l { color: var(--muted); font-size: 12px; }

/* ---------- sheet ---------- */

.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-panel {
  position: relative;
  width: 100%;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b));
  border-top: 1px solid var(--line);
}
.sheet-panel h2 { margin: 0 0 12px; text-transform: none; letter-spacing: 0; font-size: 18px; color: var(--text); }

/* ---------- toast ---------- */

/* Resta sempre nel DOM come regione live: si nasconde alla vista, non agli
   screen reader. `hidden` lo toglierebbe anche a loro. */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 17px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 500;
  z-index: 70;
  max-width: 88vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.toast.is-visible { opacity: 1; }
.toast.err { background: var(--danger); color: #fff; }

/* ---------- barra azione fissa ---------- */

/* L'azione principale non deve stare in coda a uno scorrimento che carica in
   asincrono: resta a portata di pollice. */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(62px + var(--safe-b));
  padding: 10px 14px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  z-index: 35;
}
.action-bar .btn { margin: 0; max-width: 720px; margin-inline: auto; }

/* Compensa l'altezza della barra, altrimenti coprirebbe l'ultima sezione. */
.action-spacer { height: 76px; }

/* ---------- trascina per aggiornare ---------- */

.pull-indicator {
  position: fixed;
  top: calc(52px + var(--safe-t));
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 6px;
  z-index: 38;
  pointer-events: none;
}

/* ---------- stati ---------- */

.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 10px; }

.skeleton { background: var(--surface-2); border-radius: 8px; height: 15px; animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }

.banner {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  margin-bottom: 12px;
}
.banner.warn { border-left-color: var(--muted); }
.banner.err { border-left-color: var(--danger); }

.offline-bar {
  position: fixed;
  top: calc(52px + var(--safe-t));
  left: 0; right: 0;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 5px;
  z-index: 39;
}

/* ---------- onboarding ---------- */

.hero { text-align: center; padding: 30px 10px 18px; }
.hero .logo { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.hero p { color: var(--muted); margin: 8px 0 0; }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; position: relative; padding: 0 0 14px 34px; }
.steps li::before {
  content: counter(s);
  position: absolute; left: 0; top: 0;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
}

@media (min-width: 640px) {
  .metric .value { font-size: 44px; }
}
