/*
 * Stile ufficiale Fidelia v2 — Mobile-First UX ("Zero-Scroll al Codice" + Navigazione in alto)
 * Tavolozza studio pulita AG WebLab: #ffffff, #f4f5f7, #111111, accento #ef702a / #b8542d.
 */

:root {
  color-scheme: light;
  --font-sans: 'Inter Tight', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --bg-page: #f4f5f7;
  --bg-surface: #ffffff;
  --bg-subtle: #ebecef;
  --bg-muted: #f7f8fa;
  --bg-dark: #111111;

  --ink: #111111;
  --ink-secondary: #434349;
  --ink-muted: #686870;

  --line: #e3e4e8;
  --line-strong: #c9cad2;

  --brand: #ef702a;
  --brand-deep: #b8542d;
  --brand-tint: #fff3ec;

  --ok: #146c43;
  --ok-tint: #eaf6f0;
  --ok-border: #b7dfc8;

  --warn: #9a5b13;
  --warn-tint: #fef7ec;
  --warn-border: #f3d6a7;

  --err: #b42318;
  --err-tint: #fef3f2;

  --shadow-sm: 0 2px 8px rgba(17, 17, 17, 0.04);
  --shadow-md: 0 12px 28px -10px rgba(17, 17, 17, 0.10);
  --shadow-card: 0 20px 44px -14px rgba(17, 17, 17, 0.22);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.num { font-variant-numeric: tabular-nums; }

.fd-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* =========================================================
   TESTATA UNICA PULITA CON NAVIGAZIONE IN ALTO
   ========================================================= */
.fd-appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.fd-appbar-top {
  max-width: 1180px;
  margin: 0 auto;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.fd-shop-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.fd-shop-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: #ffffff;
  display: grid;
  place-items: center;
  flex: none;
}

.fd-shop-name-wrap {
  min-width: 0;
}

.fd-shop-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fd-shop-role-sub {
  font-size: 0.73rem;
  color: var(--ink-muted);
  font-weight: 500;
  display: block;
}

/* Pulsante discreto Regia Demo (non ruba spazio all'interfaccia reale) */
.fd-demo-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--bg-dark);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  flex: none;
}
.fd-demo-trigger-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
}

/* Barra di navigazione primaria IN ALTO (a portata d'occhio immediata, zero scroll) */
.fd-topnav-wrap {
  background: var(--bg-surface);
  border-top: 1px solid var(--bg-subtle);
}

.fd-topnav {
  max-width: 1180px;
  margin: 0 auto;
  padding: 6px 12px 8px;
  display: grid;
  gap: 6px;
}
.fd-topnav.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fd-topnav.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.fd-topnav-btn {
  border: 1px solid transparent;
  background: var(--bg-muted);
  color: var(--ink-secondary);
  padding: 8px 6px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  transition: background 0.14s ease, color 0.14s ease;
}
.fd-topnav-btn.is-active {
  background: var(--ink);
  color: #ffffff;
}
.fd-topnav-count {
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--ok);
  color: #ffffff;
}

/* =========================================================
   CONTENITORE PRINCIPALE
   ========================================================= */
.fd-main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 12px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* Riempimento equilibrato a tutto schermo per le schermate iniziali (zero vuoto sotto, zero scroll!) */
.fd-fit-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

@media (min-width: 768px) {
  .fd-fit-screen {
    max-height: 760px;
  }
}

/* Pulsanti e Campi */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 11px;
  padding: 10px 15px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  text-decoration: none;
  transition: transform 0.1s ease, background 0.14s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary { background: var(--ink); color: #ffffff; }
.btn-brand { background: var(--brand); color: #ffffff; }
.btn-ok { background: var(--ok); color: #ffffff; }
.btn-secondary { background: var(--bg-surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost { background: transparent; color: var(--ink-secondary); }
.btn-sm { padding: 6px 11px; font-size: 0.8rem; border-radius: 9px; }
.btn-lg { padding: 13px 18px; font-size: 0.98rem; border-radius: 13px; }

.fd-field { display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; }
.fd-field label { font-size: 0.8rem; font-weight: 600; color: var(--ink-secondary); }
.fd-input, .fd-select {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--bg-surface);
  color: var(--ink);
  font-size: 0.94rem;
}

.fd-panel {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.fd-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
}
.fd-badge-ok { background: var(--ok-tint); color: var(--ok); border: 1px solid var(--ok-border); }
.fd-badge-warn { background: var(--warn-tint); color: var(--warn); border: 1px solid var(--warn-border); }
.fd-badge-neutral { background: var(--bg-subtle); color: var(--ink-secondary); }

/* =========================================================
   1. VISTA CLIENTE — PRIMA SCHERMATA "ZERO-SCROLL AL CODICE"
   ========================================================= */
.fd-mobile-col {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Biglietto principale tutto-in-una-schermata a piena altezza */
.fd-pass-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.fd-pass-hero.is-bright {
  box-shadow: 0 0 0 3px var(--brand), 0 20px 50px rgba(0, 0, 0, 0.22);
}

.fd-pass-strip {
  padding: 16px 18px;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.fd-pass-holder {
  font-weight: 700;
  font-size: 1.08rem;
  line-height: 1.2;
}
.fd-pass-code-sub {
  font-size: 0.78rem;
  opacity: 0.84;
  margin-top: 2px;
}

.fd-pass-pill-bal {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.28);
  padding: 7px 13px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.96rem;
  white-space: nowrap;
}

.fd-pass-qr-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 18px;
  text-align: center;
  background: #ffffff;
}

.fd-pass-qr-box {
  width: clamp(148px, 26dvh, 232px);
  height: clamp(148px, 26dvh, 232px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border-radius: 20px;
  border: 1.5px solid var(--line);
  background: #ffffff;
  box-shadow: 0 6px 20px rgba(17, 17, 17, 0.05);
}

@media (max-height: 720px) {
  .fd-pass-strip { padding: 12px 16px; }
  .fd-pass-qr-body { padding: 10px 14px; gap: 6px; }
  .fd-pass-footer { padding: 11px 14px 13px; gap: 8px; }
  .fd-mini-dot { height: 27px; }
}
.fd-pass-qr-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.fd-pass-barcode-box {
  width: 100%;
  max-width: 286px;
  margin: 2px auto 0;
  padding: 8px 14px 4px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.fd-pass-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--ink);
}

/* Piede del pass: bollini ben visibili + azione premi */
.fd-pass-footer {
  padding: 15px 18px 17px;
  background: var(--bg-muted);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fd-mini-dots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-width: 290px;
  width: 100%;
  margin: 0 auto;
}

.fd-mini-dot {
  height: 32px;
  border-radius: 10px;
  border: 1.5px dashed var(--line-strong);
  background: #ffffff;
  color: var(--ink-muted);
  font-size: 0.78rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.fd-mini-dot.is-on {
  border-style: solid;
  border-color: transparent;
  color: #ffffff;
}

.fd-mini-bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
}
.fd-mini-bar-fill {
  height: 100%;
  border-radius: 999px;
}

/* Tessera grafica completa (usata nella scheda Premi e nell'anteprima Titolare) */
.fd-loyalty-card {
  border-radius: 20px;
  padding: 18px;
  color: #ffffff;
  box-shadow: var(--shadow-card);
}

.fd-stamps-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 14px;
  margin-top: 14px;
}

.fd-stamp-slot {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1.5px dashed rgba(255, 255, 255, 0.35);
  display: grid;
  place-items: center;
  font-size: 0.76rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.6);
}
.fd-stamp-slot.is-filled {
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.9);
  color: #ffffff;
}

/* =========================================================
   2. VISTA CASSA SMARTPHONE (PIENO SCHERMO A PORTATA DI POLLICE)
   ========================================================= */
.fd-cassa-col {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fd-cassa-hero-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  padding: 20px 18px;
  border-radius: 22px;
}

.fd-scan-bar {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 10px;
}

.fd-video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 210px;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
}
.fd-video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.fd-scan-reticle {
  position: absolute;
  inset: 18%;
  border: 2px solid var(--brand);
  border-radius: 14px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.38);
  pointer-events: none;
}

.fd-quick-stamps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.fd-stamp-btn {
  min-height: 76px;
  padding: 12px 8px;
  border-radius: 16px;
  border: 1.5px solid var(--line-strong);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-weight: 700;
  transition: transform 0.16s cubic-bezier(0.16, 1, 0.3, 1), background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.fd-stamp-btn:active { transform: scale(0.95); }
.fd-stamp-btn.is-selected {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
  transform: translateY(-2px);
  box-shadow: 0 10px 22px -8px rgba(17, 17, 17, 0.35);
}

/* Stato 1 Cassa: Pronta per il prossimo cliente */
.fd-cassa-idle {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  padding: 26px 20px 20px;
  border-radius: 24px;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.fd-idle-reticle {
  width: clamp(92px, 15dvh, 124px);
  height: clamp(92px, 15dvh, 124px);
  border-radius: 28px;
  background: var(--bg-muted);
  border: 2px dashed var(--line-strong);
  display: grid;
  place-items: center;
  color: var(--ink);
  margin: 0 auto 14px;
}

/* Riquadro riepilogo Prima -> Dopo prima di confermare */
.fd-delta-box {
  background: var(--bg-muted);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
}

/* Stato 3 Cassa: Grande schermata animata di operazione riuscita */
.fd-success-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  padding: 28px 20px 20px;
  border-radius: 24px;
  background: #ffffff;
  border: 2px solid var(--ok-border);
  box-shadow: var(--shadow-md);
  animation: fdFadeScale 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.fd-success-circle {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--ok);
  color: #ffffff;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  box-shadow: 0 14px 28px -8px rgba(20, 108, 67, 0.42);
  animation: fdPopCheck 0.36s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fdPopCheck {
  0% { transform: scale(0.45); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes fdFadeScale {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* Animazione live sul telefono del cliente quando arrivano punti/timbri dalla cassa */
.fd-live-banner {
  background: var(--ok);
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.86rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-shadow: 0 10px 24px -6px rgba(20, 108, 67, 0.4);
  animation: fdPopCheck 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.fd-mini-dot.is-just-added {
  animation: fdPopCheck 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 0 0 3px rgba(239, 112, 42, 0.35);
}

/* =========================================================
   3. VISTA TITOLARE (RESPONSIVE SENZA TABELLE ORIZZONTALI SU MOBILE)
   ========================================================= */
.fd-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.fd-kpi {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}
.fd-kpi-label { font-size: 0.76rem; font-weight: 600; color: var(--ink-muted); }
.fd-kpi-val { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.03em; margin: 4px 0 2px; line-height: 1.1; }
.fd-kpi-foot { font-size: 0.74rem; color: var(--ink-secondary); }

.fd-two-col {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
}

.fd-settings-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 18px;
  align-items: start;
}

/* Schede lista mobile-friendly (niente scorrimento orizzontale!) */
.fd-list-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fd-item-card {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.fd-age-row {
  display: grid;
  grid-template-columns: 88px 1fr 34px;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  margin-bottom: 8px;
}
.fd-age-track {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
}
.fd-age-fill {
  height: 100%;
  border-radius: 999px;
}

/* Pannello a comparsa "Regia Demo" e Modali */
.fd-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 17, 0.56);
  z-index: 90;
  display: grid;
  place-items: end center;
  padding: 0;
}
@media (min-width: 640px) {
  .fd-modal-backdrop {
    place-items: center;
    padding: 16px;
  }
}

.fd-sheet {
  background: var(--bg-surface);
  width: 100%;
  max-width: 480px;
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-card);
  max-height: 88dvh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .fd-sheet {
    border-radius: 22px;
    padding: 22px;
  }
}

.fd-toast {
  position: fixed;
  top: 108px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 95;
  background: #111111;
  color: #ffffff;
  padding: 9px 16px;
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  font-size: 0.83rem;
  font-weight: 600;
  width: max-content;
  max-width: calc(100vw - 24px);
  white-space: normal;
  text-align: center;
  line-height: 1.35;
  pointer-events: none;
}
.fd-toast.is-err { background: var(--err); }

@media (max-width: 860px) {
  .fd-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fd-two-col, .fd-settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .fd-topnav-btn { font-size: 0.76rem; padding: 7px 4px; }
}
