/* ============================================================
   LumaLaser Gestione — CSS
   Tema scuro "blu notte" minimal, accenti laser blu/celeste.
   Sora per titoli e numeri, Inter per il testo.
   Mobile: top bar + tab bar in basso. Desktop (≥769px): sidebar.

   Per cambiare i colori basta toccare la sezione TOKEN qui sotto:
   il resto del file usa solo le variabili.
   ============================================================ */

/* ============================================================
   TOKEN
   ============================================================ */
:root {
  color-scheme: dark;

  /* Superfici (dal fondo verso l'alto) */
  --bg:            #0A0F1C;
  --surface:       #10182A;
  --surface-2:     #151F35;
  --surface-3:     #1B2741;
  --border:        rgba(148, 163, 184, .12);
  --border-strong: rgba(148, 163, 184, .22);

  /* Testo */
  --text:          #E7EDF6;
  --text-2:        #B8C4D6;
  --muted:         #8B98AD;
  --placeholder:   #6B7890;

  /* Laser */
  --laser:         #38BDF8;               /* celeste */
  --laser-cyan:    #22D3EE;
  --laser-blue:    #3B82F6;
  --laser-indigo:  #6366F1;
  --laser-soft:    rgba(56, 189, 248, .10);
  --laser-softer:  rgba(56, 189, 248, .06);
  --laser-line:    linear-gradient(90deg, transparent, rgba(56, 189, 248, .85) 30%, rgba(99, 102, 241, .85) 70%, transparent);
  --grad-btn:      linear-gradient(120deg, #0E7490 0%, #1D4ED8 55%, #4338CA 100%);
  --grad-btn-hi:   linear-gradient(120deg, #0891B2 0%, #2563EB 55%, #4F46E5 100%);
  --grad-mark:     linear-gradient(140deg, #22D3EE 0%, #3B82F6 55%, #6366F1 100%);

  /* Bagliori */
  --glow-sm:  0 0 0 1px rgba(56, 189, 248, .30), 0 4px 18px -6px rgba(56, 189, 248, .55);
  --glow-md:  0 0 0 1px rgba(56, 189, 248, .55), 0 6px 26px -6px rgba(56, 189, 248, .70), 0 0 44px -10px rgba(99, 102, 241, .55);
  --ring:     0 0 0 3px rgba(56, 189, 248, .22), 0 0 18px -4px rgba(56, 189, 248, .55);

  /* Stati */
  --success: #34D399;
  --danger:  #F87171;
  --warning: #FBBF24;
  --info:    #60A5FA;
  --success-soft: rgba(52, 211, 153, .12);
  --danger-soft:  rgba(248, 113, 113, .12);
  --warning-soft: rgba(251, 191, 36, .12);

  /* Alias usati negli stili in linea di HTML/JS (non toglierli) */
  --color-primary:       var(--laser);
  --color-primary-dk:    var(--laser);
  --color-primary-50:    var(--laser-soft);
  --color-primary-100:   rgba(56, 189, 248, .18);
  --color-primary-light: var(--laser);
  --color-bg:            var(--bg);
  --color-surface:       var(--surface);
  --color-surface-2:     var(--surface-2);
  --color-dark:          var(--text);
  --color-muted:         var(--muted);
  --color-border:        var(--border);
  --color-border-strong: var(--border-strong);
  --color-success:       var(--success);
  --color-danger:        var(--danger);
  --color-warning:       var(--warning);
  --color-info:          var(--info);

  /* Layout */
  --sidebar-w:   252px;
  --topbar-h:    58px;
  --tabbar-h:    66px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Forma ed elevazione */
  --radius:    16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow:    inset 0 1px 0 rgba(255, 255, 255, .03), 0 10px 30px -18px rgba(0, 0, 0, .8);
  --shadow-lg: inset 0 1px 0 rgba(255, 255, 255, .04), 0 24px 60px -20px rgba(0, 0, 0, .9);

  /* Tipografia */
  --font-display: 'Sora', 'Inter', system-ui, sans-serif;
  --font-body:    'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* Movimento */
  --ease-out:   cubic-bezier(.22, 1, .36, 1);
  --t-fast:     .16s var(--ease-out);
  --t:          .24s var(--ease-out);

  /* Livelli */
  --z-nav:   200;
  --z-sheet: 400;
  --z-modal: 500;
  --z-toast: 1000;
}

/* ============================================================
   BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  font-size: .95rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'cv11', 'ss01';
}

/* Sfondo: due aloni di luce molto tenui + griglia a puntini che sfuma,
   come il piano di lavoro di un incisore. Fisso, non scorre. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 520px at 100% -8%, rgba(56, 189, 248, .10), transparent 62%),
    radial-gradient(700px 480px at -10% 105%, rgba(99, 102, 241, .08), transparent 60%),
    radial-gradient(rgba(148, 163, 184, .07) 1px, transparent 1.2px) 0 0 / 22px 22px;
  -webkit-mask-image: linear-gradient(180deg, #000 0%, rgba(0, 0, 0, .55) 55%, rgba(0, 0, 0, .35) 100%);
          mask-image: linear-gradient(180deg, #000 0%, rgba(0, 0, 0, .55) 55%, rgba(0, 0, 0, .35) 100%);
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, a, input, select, textarea, label { touch-action: manipulation; }
button { font: inherit; color: inherit; }
strong { font-weight: 600; color: var(--text); }

::selection { background: rgba(56, 189, 248, .35); color: #fff; }

:focus-visible {
  outline: 2px solid var(--laser);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

[hidden] { display: none !important; }

/* Icone SVG (stile Lucide, tratto sottile) */
.ico     { width: 22px; height: 22px; flex-shrink: 0; }
.ico-sm  { width: 18px; height: 18px; }
.ico-xs  { width: 14px; height: 14px; }
.btn-icon { display: inline-flex; }
.btn-icon .ico { width: 16px; height: 16px; stroke-width: 2.1; }

/* ============================================================
   BRAND
   ============================================================ */
.brand { display: flex; align-items: center; gap: .7rem; }

.brand-mark {
  position: relative;
  width: 36px; height: 36px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: var(--grad-mark);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .12) inset, 0 6px 18px -6px rgba(56, 189, 248, .8);
}

.brand-text {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.05;
  color: var(--text);
}
.brand-text small {
  display: block;
  margin-top: 3px;
  font-family: var(--font-body);
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--laser);
}

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  flex-shrink: 0;
  background: var(--surface-3);
  color: var(--text);
  font-weight: 600;
  font-size: .9rem;
  border: 1px solid var(--border-strong);
}
.avatar-lg  { width: 48px; height: 48px; font-size: 1.15rem; }
.avatar-btn { width: 40px; height: 40px; cursor: pointer; transition: box-shadow var(--t), border-color var(--t); }
.avatar-btn:hover, .avatar-btn:focus-visible { border-color: rgba(56, 189, 248, .5); box-shadow: var(--glow-sm); }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: none;
  background: none;
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn .ico { width: 19px; height: 19px; }

/* ============================================================
   NAVIGAZIONE — mobile di default
   ============================================================ */
.sidebar { display: none; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 1rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(10, 15, 28, .78);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
          backdrop-filter: saturate(1.4) blur(16px);
  z-index: var(--z-nav);
}
/* Il "raggio" sotto la barra superiore */
.topbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: var(--laser-line);
  opacity: .45;
}
.topbar .brand-mark { width: 32px; height: 32px; border-radius: 10px; font-size: .95rem; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 6px 6px var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(10, 15, 28, .88);
  -webkit-backdrop-filter: saturate(1.4) blur(18px);
          backdrop-filter: saturate(1.4) blur(18px);
  border-top: 1px solid var(--border);
  z-index: var(--z-nav);
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 52px;
  border: none;
  background: none;
  border-radius: 14px;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: .66rem;
  font-weight: 600;
  letter-spacing: .01em;
  cursor: pointer;
  transition: color var(--t-fast), transform .12s var(--ease-out);
}
.tab .ico { width: 23px; height: 23px; transition: filter var(--t), transform var(--t); }
.tab:active { transform: scale(.94); }
.tab.active { color: var(--text); }
.tab.active .ico {
  color: var(--laser);
  stroke-width: 2;
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, .75));
}
/* Linea laser sopra la voce attiva */
.tab.active::before {
  content: '';
  position: absolute;
  top: -6px;
  width: 28px; height: 2px;
  border-radius: 2px;
  background: var(--grad-mark);
  box-shadow: 0 0 10px rgba(56, 189, 248, .9), 0 0 2px rgba(56, 189, 248, 1);
}

/* Pannello "Altro" dal basso */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  display: flex;
  align-items: flex-end;
  background: rgba(3, 7, 18, .62);
  -webkit-backdrop-filter: blur(4px);
          backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s;
}
.sheet-backdrop.open { opacity: 1; visibility: visible; }
.sheet {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding: .5rem 1rem calc(1rem + var(--safe-bottom));
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform .28s var(--ease-out);
}
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; border-radius: 99px; background: var(--border-strong); margin: .3rem auto 1rem; }
.sheet-account {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: 0 .5rem 1rem;
  margin-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.sheet-list { display: flex; flex-direction: column; gap: 2px; }
.sheet-item {
  display: flex;
  align-items: center;
  gap: .85rem;
  width: 100%;
  min-height: 52px;
  padding: .5rem;
  border: none;
  background: none;
  border-radius: 14px;
  font-family: var(--font-body);
  font-size: .98rem;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast);
}
.sheet-item:hover, .sheet-item:active { background: var(--surface-2); }
.sheet-item > span:nth-child(2) { flex: 1; }
.sheet-item.active .sheet-ico { color: var(--laser); box-shadow: var(--glow-sm); }
.sheet-ico {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}
.sheet-ico .ico { width: 19px; height: 19px; }
.ico-freccia { width: 18px; height: 18px; color: var(--muted); }
.sheet-logout { margin-top: .5rem; border-top: 1px solid var(--border); border-radius: 0 0 14px 14px; padding-top: 1rem; color: var(--danger); }
.sheet-logout .sheet-ico { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.sidebar-user-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: .9rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-name small { display: block; font-weight: 400; font-size: .75rem; color: var(--muted); }

/* ============================================================
   CONTENUTO PRINCIPALE
   ============================================================ */
.main-content {
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  padding:
    calc(var(--topbar-h) + var(--safe-top) + 1.25rem)
    1rem
    calc(var(--tabbar-h) + var(--safe-bottom) + 1.5rem);
}
.main-content.full-width { padding: 0; }

.page-header { margin-bottom: 1.4rem; }
.page-header-flex {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .9rem;
}

.page-title {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -.025em;
  color: var(--text);
}
.page-subtitle { color: var(--muted); margin-top: .3rem; font-size: .9rem; }

.header-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.section-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--text);
  margin: 1.5rem 0 1rem;
}

/* ============================================================
   PULSANTI
   Primario: sfumatura blu laser con alone celeste e un riflesso
   che attraversa il tasto al passaggio. Gli altri restano sobri.
   ============================================================ */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-height: 44px;
  padding: .6rem 1.1rem;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: .9rem;
  font-weight: 600;
  letter-spacing: .005em;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--t), border-color var(--t), color var(--t), box-shadow var(--t), transform .12s var(--ease-out), filter var(--t);
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  overflow: hidden;
  isolation: isolate;
  background: var(--grad-btn);
  color: #fff;
  border-color: rgba(125, 211, 252, .35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), var(--glow-sm);
}
.btn-primary::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, .28) 50%, transparent 65%);
  transform: translateX(-120%);
  transition: transform .7s var(--ease-out);
}
.btn-primary:hover, .btn-primary:focus-visible {
  background: var(--grad-btn-hi);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), var(--glow-md);
}
.btn-primary:hover::after { transform: translateX(120%); }

.btn-outline {
  background: rgba(255, 255, 255, .02);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-outline:hover, .btn-outline:focus-visible {
  border-color: rgba(56, 189, 248, .55);
  background: var(--laser-softer);
  box-shadow: 0 0 18px -6px rgba(56, 189, 248, .55);
}

.btn-success { background: var(--success-soft); border-color: rgba(52, 211, 153, .28); color: #6EE7B7; }
.btn-success:hover { background: rgba(52, 211, 153, .2); box-shadow: 0 0 16px -6px rgba(52, 211, 153, .6); }
.btn-danger  { background: var(--danger-soft);  border-color: rgba(248, 113, 113, .28); color: #FCA5A5; }
.btn-danger:hover  { background: rgba(248, 113, 113, .2); box-shadow: 0 0 16px -6px rgba(248, 113, 113, .55); }
.btn-warning { background: var(--warning-soft); border-color: rgba(251, 191, 36, .28); color: #FCD34D; }
.btn-warning:hover { background: rgba(251, 191, 36, .2); box-shadow: 0 0 16px -6px rgba(251, 191, 36, .55); }

.btn-sm { min-height: 36px; padding: .35rem .8rem; font-size: .82rem; border-radius: 10px; }
.btn-full { width: 100%; }

.btn-icon-action { width: 36px; height: 36px; min-height: 36px; padding: 0; border-radius: 10px; }
.btn-icon-action .btn-label { display: none; }
.btn-icon-action:disabled {
  opacity: 1;
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--muted);
  box-shadow: none;
}

.action-group { display: flex; gap: .4rem; flex-wrap: wrap; }

#searchBtn { display: none; } /* la ricerca parte già mentre si scrive */

/* ============================================================
   CARD, KPI, RIEPILOGHI
   ============================================================ */
.card, .kpi-card, .stat-card, .chart-section, .table-wrap, .timeline-card, .login-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, .025), rgba(255, 255, 255, 0) 60%), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 1.25rem; }

/* Raggio laser sul bordo alto delle card "importanti" */
.kpi-card, .stat-card-totale, .kpi-hero, .login-card, .modal { position: relative; }
.kpi-card::before, .stat-card-totale::before, .kpi-hero::before, .login-card::before, .modal::before {
  content: '';
  position: absolute;
  top: -1px; left: 14%; right: 14%;
  height: 1px;
  background: var(--laser-line);
  box-shadow: 0 0 12px rgba(56, 189, 248, .55);
  pointer-events: none;
}

.stats-grid, .kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .65rem;
  margin-bottom: 1.25rem;
}
.kpi-grid { grid-template-columns: 1fr; }

.kpi-card, .stat-card { padding: 1rem 1.1rem; overflow: hidden; }

.kpi-label, .stat-label {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  margin-bottom: .45rem;
}
.kpi-value, .stat-value {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.1;
  color: var(--text);
}
.kpi-sub, .stat-sub { font-size: .76rem; color: var(--muted); margin-top: .35rem; }

.stat-card-totale { grid-column: 1 / -1; background: linear-gradient(160deg, rgba(56, 189, 248, .08), rgba(99, 102, 241, .04) 60%, transparent), var(--surface); }
.stat-card-totale .stat-value { font-size: 1.75rem; }
.stat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 8px currentColor; }

/* Dashboard mobile: una card con il margine in evidenza */
.kpi-hero { padding: 1.15rem; }
.kpi-hero-label { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.kpi-hero-value { font-family: var(--font-display); font-size: 2.1rem; font-weight: 600; letter-spacing: -.03em; line-height: 1.1; margin: .35rem 0 .15rem; }
.kpi-hero-sub { font-size: .76rem; color: var(--muted); margin-bottom: 1rem; }
.kpi-hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  padding-top: .85rem;
  border-top: 1px solid var(--border);
}
.kpi-hero-stat { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.kpi-hero-stat-label { font-size: .62rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.kpi-hero-stat-value { font-size: .95rem; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }

/* ============================================================
   GRAFICO
   ============================================================ */
.chart-section { padding: 1rem 1rem .75rem; margin-bottom: 1.25rem; }
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }
.chart-title { font-family: var(--font-display); font-size: 1rem; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
.chart-sub { font-size: .74rem; color: var(--muted); margin-top: .1rem; }
.chart-legend { display: flex; gap: .4rem; flex-wrap: wrap; }
.legend-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .25rem .6rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: .74rem; font-weight: 500; color: var(--muted);
}
.legend-chip strong { color: var(--text); font-weight: 700; }
.legend-dot { width: 8px; height: 8px; border-radius: 3px; box-shadow: 0 0 8px currentColor; }
#chartMensileWrap { position: relative; height: 160px; width: 100%; }

/* ============================================================
   ULTIME VENDITE
   ============================================================ */
.movimenti-list { display: flex; flex-direction: column; }
.movimento-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem .75rem;
  padding: .7rem .1rem;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
}
.movimento-row:last-child { border-bottom: none; }
.mov-badge {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px;
  border-radius: 8px;
  flex-shrink: 0;
  background: var(--success-soft);
  color: var(--success);
  font-size: .72rem;
  font-weight: 700;
}
.mov-nome { flex: 1 1 auto; min-width: 0; font-weight: 600; }
.mov-time { font-size: .76rem; color: var(--muted); white-space: nowrap; }
.mov-details { flex: 1 0 100%; font-size: .78rem; color: var(--muted); padding-left: calc(24px + .75rem); }

/* ============================================================
   MODULI
   ============================================================ */
.form-group { margin-bottom: 1.15rem; }

label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: .4rem;
}

input[type="text"],
input[type="search"],
input[type="number"],
input[type="password"],
input[type="date"],
select,
textarea,
.search-compact {
  width: 100%;
  min-height: 44px;
  padding: .62rem .9rem;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px; /* niente zoom automatico su iPhone */
  outline: none;
  -webkit-appearance: none;
          appearance: none;
  transition: border-color var(--t-fast), box-shadow var(--t), background var(--t-fast);
}
textarea { resize: vertical; min-height: 72px; }
select {
  padding-right: 2.4rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238B98AD' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .85rem center;
}
select option { background: var(--surface); color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--placeholder); }
input:hover, select:hover, textarea:hover { border-color: rgba(148, 163, 184, .34); }
input:focus, select:focus, textarea:focus, .search-compact:focus {
  border-color: rgba(56, 189, 248, .75);
  background-color: var(--surface-3);
  box-shadow: var(--ring);
}

.form-hint { font-size: .76rem; color: var(--muted); margin-top: .35rem; }

.checkbox-label { display: flex; align-items: center; gap: .55rem; cursor: pointer; font-weight: 500; color: var(--text); }
.checkbox-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--laser); flex-shrink: 0; }

.file-input-wrap { position: relative; }
.file-input-wrap input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-input-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 52px;
  padding: .65rem .9rem;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .88rem;
  transition: border-color var(--t-fast), color var(--t-fast), box-shadow var(--t);
}
.file-input-wrap:hover .file-input-label { border-color: rgba(56, 189, 248, .6); color: var(--text); box-shadow: 0 0 18px -8px rgba(56, 189, 248, .6); }

/* Storico prezzi e vendite (modifica prodotto) */
.storico-prezzo-prec { color: var(--laser); font-weight: 600; }
.storico-riepilogo { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; font-size: .84rem; margin-bottom: .6rem; color: var(--muted); }
.storico-lista {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.storico-riga {
  display: grid;
  grid-template-columns: 5.5rem 1fr auto;
  gap: .75rem;
  align-items: baseline;
  padding: .55rem .8rem;
  font-size: .84rem;
  border-bottom: 1px solid var(--border);
}
.storico-riga:last-child { border-bottom: none; }
.storico-data { color: var(--muted); white-space: nowrap; }
.storico-evento small { display: block; color: var(--muted); font-size: .74rem; }
.storico-importo { font-weight: 600; white-space: nowrap; text-align: right; }
.storico-riga.vendita  .storico-importo { color: var(--success); }
.storico-riga.prezzo   .storico-importo { color: var(--laser); }
.storico-riga.quantita .storico-importo { color: var(--info); }
.storico-vuoto { padding: .8rem; font-size: .84rem; color: var(--muted); }

/* ============================================================
   TABELLE, FILTRI, ETICHETTE
   ============================================================ */
.table-wrap { overflow: hidden; }

.filter-bar {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--border);
}
.filter-bar input, .filter-bar select { flex: 1; min-width: 0; width: auto; }

.filters-wrap {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--border);
}
.filters-wrap .filter-bar { padding: 0; border: none; }

.cat-tabs { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.cat-tab {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: 0 .9rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-body);
  font-size: .82rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast), box-shadow var(--t);
}
.cat-tab:hover { border-color: rgba(56, 189, 248, .5); color: var(--text); }
.cat-tab.active {
  background: var(--laser-soft);
  border-color: rgba(56, 189, 248, .6);
  color: #E0F2FE;
  box-shadow: 0 0 14px -4px rgba(56, 189, 248, .55);
}

.table-expand-bar { display: none; }

table { width: 100%; border-collapse: collapse; }
thead th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  background: rgba(255, 255, 255, .015);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--t-fast); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--laser-softer); }
td { padding: .75rem 1rem; font-size: .88rem; vertical-align: middle; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: .24rem .65rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip-green { background: var(--success-soft); color: #6EE7B7; border-color: rgba(52, 211, 153, .22); }
.chip-gray  { background: rgba(148, 163, 184, .1); color: var(--text-2); border-color: var(--border); }
.chip-rosso { background: var(--danger-soft); color: #FCA5A5; border-color: rgba(248, 113, 113, .22); }

.cat-label { display: inline-flex; align-items: center; gap: .45rem; }

/* Miniature prodotto */
.thumb-wrap { position: relative; display: inline-block; vertical-align: middle; }
.td-thumb, .td-thumb-placeholder {
  width: 44px; height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.td-thumb-placeholder { display: grid; place-items: center; }

/* Bandierine "New" / "Sconto" sopra la foto */
.badge-new {
  position: absolute;
  top: 0; left: 3px;
  z-index: 2;
  padding: 1px 3px 4px;
  background: #EF4444;
  color: #fff;
  font-size: .45rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  line-height: 1.2;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 70%, 0 100%);
  pointer-events: none;
}
.badge-new-inline { position: static; display: inline-block; vertical-align: middle; margin-left: .35rem; font-size: .55rem; }
.badge-sconto { background: var(--laser-blue); }
.badge-destra { left: auto; right: 3px; }

.tag-nascosto { display: inline-flex; vertical-align: -2px; margin-left: .35rem; color: var(--muted); }
.tag-nascosto .ico { width: 15px; height: 15px; }
.tag-nascosto-desktop { display: none; }

/* Stato vuoto */
.empty-state { text-align: center; padding: 2.75rem 1.5rem; color: var(--muted); }
.empty-state p { margin-top: .9rem; font-size: .9rem; }
.empty-state a { color: var(--laser); font-weight: 600; }
.empty-icon {
  width: 60px; height: 60px;
  margin: 0 auto;
  display: grid; place-items: center;
  border-radius: 18px;
  background: var(--surface-2);
  border: 1px solid rgba(56, 189, 248, .25);
  color: var(--laser);
  box-shadow: 0 0 28px -10px rgba(56, 189, 248, .8);
}
.empty-icon .ico { width: 26px; height: 26px; }

/* ── Tabelle che su mobile diventano schede ── */
.table-wrap:has(.table-prodotti, .table-inventario, .table-utenti, .table-analisi) {
  background: transparent;
  border: none;
  box-shadow: none;
  overflow: visible;
}
.table-wrap:has(.table-prodotti, .table-inventario, .table-utenti, .table-analisi) > .filter-bar,
.table-wrap:has(.table-prodotti) > .filters-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: .8rem;
}
.table-prodotti, .table-prodotti tbody,
.table-inventario, .table-inventario tbody,
.table-utenti, .table-utenti tbody,
.table-analisi, .table-analisi tbody { display: block; }
.table-prodotti thead, .table-inventario thead, .table-utenti thead, .table-analisi thead { display: none; }
.table-prodotti tbody tr, .table-inventario tbody tr, .table-utenti tbody tr, .table-analisi tbody tr {
  margin-bottom: .6rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, .025), transparent 60%), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.table-prodotti tbody tr:hover, .table-inventario tbody tr:hover,
.table-utenti tbody tr:hover, .table-analisi tbody tr:hover { background: var(--surface); }
.table-prodotti td, .table-inventario td, .table-utenti td, .table-analisi td { padding: 0; }

/* Prodotti */
.table-prodotti tbody tr {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  grid-template-areas:
    "thumb nome   stato"
    "thumb prezzo azioni";
  align-items: center;
  column-gap: .75rem;
  row-gap: .3rem;
  padding: .65rem .75rem;
}
.table-prodotti td:nth-child(1) { grid-area: thumb; }
.table-prodotti td:nth-child(2) {
  grid-area: nome;
  min-width: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: .9rem;
  line-height: 1.3;
}
.table-prodotti td:nth-child(4) { grid-area: prezzo; font-size: .92rem; }
.table-prodotti td:nth-child(9) { grid-area: stato; justify-self: end; }
.table-prodotti td:nth-child(10) { grid-area: azioni; justify-self: end; }
.table-prodotti td:nth-child(3), .table-prodotti td:nth-child(5), .table-prodotti td:nth-child(6),
.table-prodotti td:nth-child(7), .table-prodotti td:nth-child(8) { display: none; }
.table-prodotti .td-thumb, .table-prodotti .td-thumb-placeholder { width: 48px; height: 48px; }
.table-prodotti .chip { padding: .18rem .55rem; font-size: .68rem; }
.table-prodotti .action-group { flex-wrap: nowrap; gap: .35rem; }
.table-prodotti .btn-icon-action { width: 38px; height: 38px; min-height: 38px; }

/* Inventario */
.table-inventario tbody tr {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  grid-template-areas:
    "nome   nome   nome   costo"
    "cat    qta    .      stato"
    "note   note   note   note"
    "azioni azioni azioni azioni";
  align-items: center;
  gap: .45rem .75rem;
  padding: .9rem;
}
.table-inventario td:nth-child(1) { grid-area: nome; font-size: .98rem; }
.table-inventario td:nth-child(2) { grid-area: cat; color: var(--text-2); }
.table-inventario td:nth-child(3) { grid-area: qta; }
.table-inventario td:nth-child(4) { grid-area: costo; justify-self: end; font-size: 1rem; }
.table-inventario td:nth-child(5) { grid-area: stato; justify-self: end; }
.table-inventario td:nth-child(6) { grid-area: note; max-width: none !important; font-size: .8rem; }
.table-inventario td:nth-child(6):empty { display: none; }
.table-inventario td:nth-child(7) { grid-area: azioni; padding-top: .55rem; border-top: 1px solid var(--border); }
.table-inventario .action-group { flex-wrap: nowrap; }
.table-inventario .action-group .btn { flex: 1; min-height: 42px; }
.table-inventario .action-group .btn-outline,
.table-inventario .action-group .btn-danger { flex: 0 0 42px; padding: 0; }
.table-inventario .btn-label { display: none; }

/* Utenti */
.utente-nome { display: inline-flex; align-items: center; gap: .6rem; }
.utente-nome .avatar { width: 32px; height: 32px; font-size: .82rem; }
.table-utenti tbody tr {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "nome   ruolo"
    "data   data"
    "azioni azioni";
  gap: .5rem;
  padding: .9rem;
}
.table-utenti td:nth-child(1) { grid-area: nome; }
.table-utenti td:nth-child(2) { grid-area: ruolo; justify-self: end; align-self: center; }
.table-utenti td:nth-child(3) { grid-area: data; font-size: .8rem !important; color: var(--muted); }
.table-utenti td:nth-child(3)::before { content: 'Registrato il '; }
.table-utenti td:nth-child(4) { grid-area: azioni; padding-top: .55rem; border-top: 1px solid var(--border); }
.table-utenti .action-group { flex-wrap: nowrap; }
.table-utenti .action-group .btn { flex: 1; min-height: 42px; }
.table-utenti .action-group .btn-danger { flex: 0 0 42px; padding: 0; }
.table-utenti .btn-label { display: none; }

/* Analisi vendite: etichetta a sinistra, valore a destra */
.analisi-nome { display: inline-flex; align-items: center; gap: .45rem; }
.analisi-info { display: block; font-size: .74rem; color: var(--muted); font-weight: 400; }
.table-analisi tbody tr { display: block; padding: .85rem .95rem; }
.table-analisi td { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .22rem 0; }
.table-analisi td:first-child { display: block; padding-bottom: .55rem; margin-bottom: .3rem; border-bottom: 1px solid var(--border); }
.table-analisi td.num { text-align: right; white-space: nowrap; }
.table-analisi td.num::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 500; }
.table-analisi td.num small { display: inline; margin-left: .35rem; }

/* ============================================================
   CATEGORIE (pannello di gestione)
   ============================================================ */
.btn-categorie { width: 44px; padding: 0; }
.btn-categorie .btn-label { display: none; }

.cat-gestione-lista {
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
}
.cat-gestione-riga {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
}
.cat-gestione-riga:last-child { border-bottom: none; }
.cat-gestione-riga input { flex: 1; min-width: 0; min-height: 38px; padding: .4rem .7rem; }
.cat-gestione-riga .action-group { flex-wrap: nowrap; }
.cat-gestione-nome { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.cat-gestione-nome small { display: block; font-weight: 400; font-size: .74rem; color: var(--muted); }
.cat-gestione-vuota { padding: .9rem; font-size: .86rem; color: var(--muted); }
.cat-gestione-nuova { display: flex; gap: .5rem; }
.cat-gestione-nuova input { flex: 1; min-width: 0; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2.25rem 1.5rem 1.75rem;
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
}
.login-logo-text { display: flex; justify-content: center; margin-bottom: 1.1rem; }
.brand-mark-xl {
  width: 64px; height: 64px;
  border-radius: 20px;
  font-size: 1.9rem;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .14) inset, 0 10px 36px -8px rgba(56, 189, 248, .9), 0 0 60px -14px rgba(99, 102, 241, .8);
  animation: alone 4.5s ease-in-out infinite;
}
@keyframes alone {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 255, 255, .14) inset, 0 10px 36px -8px rgba(56, 189, 248, .8), 0 0 50px -16px rgba(99, 102, 241, .7); }
  50%      { box-shadow: 0 0 0 1px rgba(255, 255, 255, .18) inset, 0 10px 44px -6px rgba(56, 189, 248, 1),  0 0 70px -12px rgba(99, 102, 241, .9); }
}
.login-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -.02em;
  text-align: center;
  color: var(--text);
  margin-bottom: 1.75rem;
  line-height: 1.3;
}
.login-title span {
  font-family: var(--font-body);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--laser);
}

/* ============================================================
   NOTIFICHE (toast)
   ============================================================ */
.flash-container {
  position: fixed;
  top: calc(var(--topbar-h) + var(--safe-top) + .5rem);
  left: 1rem; right: 1rem;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1rem;
  border-radius: 14px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--laser);
  color: var(--text);
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: comparsa .2s var(--ease-out);
}
.flash-success { border-left-color: var(--success); }
.flash-error   { border-left-color: var(--danger); }
.flash-info    { border-left-color: var(--laser); }
.flash-warning { border-left-color: var(--warning); }
.flash-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: .9rem; padding: .2rem; flex-shrink: 0; }
.flash-close:hover { color: var(--text); }

@keyframes comparsa {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* ============================================================
   FINESTRE (modal) — su mobile salgono dal basso
   ============================================================ */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  align-items: flex-end;
  justify-content: center;
  background: rgba(3, 7, 18, .7);
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
}
.modal-backdrop.open { display: flex; }

.modal {
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding-bottom: var(--safe-bottom);
  box-shadow: var(--shadow-lg);
  animation: dalBasso .28s var(--ease-out);
}
@keyframes dalBasso { from { transform: translateY(100%); } to { transform: none; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem .9rem;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
.modal-close {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 1.1rem 1.25rem; }
.modal-footer {
  display: flex;
  gap: .65rem;
  justify-content: flex-end;
  padding: .9rem 1.25rem 1.15rem;
  border-top: 1px solid var(--border);
}
.modal-footer .btn { flex: 1; }
.modal-product-name { font-size: .92rem; color: var(--text-2); margin-bottom: 1rem; font-weight: 500; }
.modal-hint { font-size: .78rem; color: var(--muted); margin-bottom: 1.1rem; }
.modal-price-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.modal-price-row span { font-size: 1.1rem; color: var(--muted); font-weight: 600; }
.modal-price-row input {
  max-width: 160px;
  text-align: right;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--laser);
}

/* ============================================================
   CRONOLOGIA
   ============================================================ */
.timeline { position: relative; padding-left: 1.75rem; }
.timeline::before {
  content: '';
  position: absolute;
  left: .55rem; top: .5rem; bottom: .5rem;
  width: 1px;
  background: linear-gradient(180deg, rgba(56, 189, 248, .6), rgba(99, 102, 241, .25) 40%, var(--border) 80%);
}
.timeline-item { position: relative; margin-bottom: .8rem; }
.timeline-dot {
  position: absolute;
  left: -1.48rem; top: 1rem;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  box-shadow: 0 0 10px currentColor;
}
.timeline-card { padding: .85rem 1rem; border-radius: 14px; }
.timeline-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .4rem; }
.timeline-badge {
  display: inline-block;
  padding: .18rem .6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  font-size: .66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.timeline-time { font-size: .76rem; color: var(--muted); white-space: nowrap; }
.timeline-body { font-size: .88rem; color: var(--text-2); line-height: 1.5; }
.timeline-body em { color: var(--text); font-style: normal; font-weight: 500; }
.timeline-details { margin-top: .3rem; font-size: .78rem; color: var(--muted); }

/* ============================================================
   GALLERIA + VISUALIZZATORE FOTO
   ============================================================ */
.gallery-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.gallery-item {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow var(--t), transform var(--t);
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.gallery-item:hover { box-shadow: 0 0 0 1px rgba(56, 189, 248, .6), 0 0 22px -6px rgba(56, 189, 248, .7); }
.gallery-item .badge-new { left: 5px; font-size: .5rem; padding: 2px 4px 5px; }

.lightbox-backdrop, .gallery-viewer {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(3, 7, 18, .95);
}
.lightbox-backdrop { z-index: 600; gap: .75rem; padding: 1rem; }
.gallery-viewer { z-index: 700; }
.lightbox-backdrop.open, .gallery-viewer.open { display: flex; animation: dissolvenza .18s ease; }
@keyframes dissolvenza { from { opacity: 0; } to { opacity: 1; } }

.lightbox-img, .gallery-viewer-img {
  max-width: 94vw;
  max-height: 78dvh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .06), 0 20px 60px rgba(0, 0, 0, .6);
}
.gallery-viewer-img { user-select: none; -webkit-user-drag: none; touch-action: pan-y; will-change: transform, opacity; }
.lightbox-caption { color: var(--text-2); font-size: .9rem; text-align: center; }

.gallery-viewer-stage { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; }

.lightbox-close, .gallery-viewer-close, .gallery-nav-arrow {
  position: fixed;
  z-index: 2;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .06);
  color: #fff;
  cursor: pointer;
  transition: background var(--t-fast), box-shadow var(--t);
}
.lightbox-close, .gallery-viewer-close { top: calc(1rem + var(--safe-top)); right: 1rem; }
.lightbox-close:hover, .gallery-viewer-close:hover, .gallery-nav-arrow:hover { background: rgba(56, 189, 248, .14); box-shadow: var(--glow-sm); }
.gallery-nav-arrow { top: 50%; transform: translateY(-50%); }
.gallery-nav-arrow:disabled { opacity: .25; cursor: default; box-shadow: none; }
.gallery-nav-prev { left: .5rem; }
.gallery-nav-next { right: .5rem; }

.gallery-viewer-info {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 1.25rem 1.5rem calc(1.25rem + var(--safe-bottom));
  background: linear-gradient(to top, rgba(3, 7, 18, .9), transparent);
  text-align: center;
  pointer-events: none;
}
.gallery-viewer-name { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; color: #fff; margin-bottom: .2rem; }
.gallery-viewer-price { font-size: .95rem; font-weight: 600; color: var(--laser); }
.gallery-viewer-status { margin-top: .3rem; font-size: .8rem; font-weight: 500; color: var(--success); }
.gallery-viewer-status-check {
  display: inline-grid; place-items: center;
  width: 15px; height: 15px;
  margin-right: .2rem;
  border-radius: 50%;
  background: var(--success);
  color: var(--bg);
  font-size: .6rem;
}

/* ============================================================
   DESKTOP (≥769px): sidebar fissa, tabelle vere, modali centrali
   ============================================================ */
@media (min-width: 769px) {
  .topbar, .tabbar, .sheet-backdrop { display: none; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    z-index: var(--z-nav);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem 1rem;
    background: rgba(10, 15, 28, .72);
    -webkit-backdrop-filter: saturate(1.4) blur(16px);
            backdrop-filter: saturate(1.4) blur(16px);
    border-right: 1px solid var(--border);
  }
  .sidebar .brand { padding: 0 .5rem 1.75rem; }
  .sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }

  .nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: .8rem;
    min-height: 42px;
    padding: .55rem .85rem;
    border-radius: 11px;
    font-size: .9rem;
    font-weight: 500;
    color: var(--muted);
    transition: background var(--t-fast), color var(--t-fast);
  }
  .nav-item .ico { width: 19px; height: 19px; transition: color var(--t-fast), filter var(--t); }
  .nav-item:hover { color: var(--text); background: rgba(255, 255, 255, .03); }
  .nav-item.active {
    color: var(--text);
    background: linear-gradient(90deg, rgba(56, 189, 248, .12), rgba(56, 189, 248, .02));
  }
  .nav-item.active .ico { color: var(--laser); filter: drop-shadow(0 0 6px rgba(56, 189, 248, .7)); }
  /* Linea laser a sinistra della voce attiva */
  .nav-item.active::before {
    content: '';
    position: absolute;
    left: -1rem; top: 9px; bottom: 9px;
    width: 2px;
    border-radius: 0 2px 2px 0;
    background: linear-gradient(180deg, var(--laser-cyan), var(--laser-indigo));
    box-shadow: 0 0 12px rgba(56, 189, 248, .9);
  }

  .sidebar-user {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .9rem .5rem .2rem;
    margin-top: .75rem;
    border-top: 1px solid var(--border);
  }

  .main-content {
    margin-left: var(--sidebar-w);
    max-width: calc(1240px + var(--sidebar-w));
    padding: 2.25rem 2.25rem 3rem;
  }
  .main-content.full-width { margin-left: 0; max-width: none; padding: 0; }

  .page-header { margin-bottom: 1.75rem; }
  .page-title { font-size: 2rem; }

  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
  .stat-card-totale { grid-column: auto; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); gap: 1rem; }
  .kpi-card, .stat-card { padding: 1.25rem 1.35rem; }
  .kpi-value { font-size: 2rem; }
  .stat-value { font-size: 1.6rem; }
  .card { padding: 1.5rem; }
  .chart-section { padding: 1.15rem 1.35rem .9rem; margin-bottom: 1.5rem; }
  #chartMensileWrap { height: 190px; }

  .btn-categorie { width: auto; padding: .6rem 1rem; }
  .btn-categorie .btn-label { display: inline; }

  .filter-bar input, .filter-bar select { flex: 0 1 260px; }
  .search-compact { width: 220px; flex: none; }

  .flash-container { top: 1rem; left: auto; right: 1rem; max-width: 360px; }

  .modal-backdrop { align-items: center; padding: 1rem; }
  .modal {
    max-width: 440px;
    max-height: 90vh;
    border-bottom: 1px solid var(--border-strong);
    border-radius: 20px;
    padding-bottom: 0;
    animation: comparsa .22s var(--ease-out);
  }
  .modal-footer .btn { flex: none; }

  .gallery-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .gallery-nav-prev { left: 1rem; }
  .gallery-nav-next { right: 1rem; }

  .login-card { padding: 2.5rem 2.25rem 2rem; }
  .login-title { font-size: 1.65rem; }

  .mov-details { flex: 1 1 auto; padding-left: 0; order: 1; }
  .mov-nome { flex: 0 1 auto; }
  .mov-time { order: 2; margin-left: auto; }
}

/* ============================================================
   SCHERMI LARGHI (≥1181px): le schede tornano tabelle vere.
   Sotto questa larghezza restano schede, così non serve mai
   scorrere di lato.
   ============================================================ */
@media (min-width: 1181px) {
  .tag-nascosto-desktop { display: inline-flex; }
  .tag-nascosto-mobile { display: none; }

  /* ── Tabelle: di nuovo tabelle vere ── */
  .table-wrap:has(.table-prodotti, .table-inventario, .table-utenti, .table-analisi) {
    background: linear-gradient(180deg, rgba(255, 255, 255, .025), rgba(255, 255, 255, 0) 60%), var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .table-wrap:has(.table-prodotti, .table-inventario, .table-utenti, .table-analisi) > .filter-bar,
  .table-wrap:has(.table-prodotti) > .filters-wrap {
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    margin-bottom: 0;
  }
  .table-prodotti, .table-inventario, .table-utenti, .table-analisi { display: table; }
  .table-prodotti tbody, .table-inventario tbody, .table-utenti tbody, .table-analisi tbody { display: table-row-group; }
  .table-prodotti thead, .table-inventario thead, .table-utenti thead, .table-analisi thead { display: table-header-group; }
  .table-prodotti tbody tr, .table-inventario tbody tr, .table-utenti tbody tr, .table-analisi tbody tr {
    display: table-row;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
  }
  .table-prodotti tbody tr:last-child, .table-inventario tbody tr:last-child,
  .table-utenti tbody tr:last-child, .table-analisi tbody tr:last-child { border-bottom: none; }
  .table-prodotti tbody tr:hover, .table-inventario tbody tr:hover,
  .table-utenti tbody tr:hover, .table-analisi tbody tr:hover { background: var(--laser-softer); }
  .table-prodotti td, .table-inventario td, .table-utenti td, .table-analisi td,
  .table-prodotti td:nth-child(n), .table-inventario td:nth-child(n), .table-utenti td:nth-child(n) {
    display: table-cell;
    padding: .7rem .9rem;
    border: none;
  }
  /* Prodotti ha 10 colonne: spaziature più strette per farle stare tutte */
  .table-prodotti th, .table-prodotti td:nth-child(n) { padding: .5rem .5rem; }
  .table-prodotti th { white-space: normal; line-height: 1.3; }
  .table-prodotti td:nth-child(2) { -webkit-line-clamp: unset; min-width: 140px; }
  .table-prodotti th:first-child, .table-prodotti td:first-child { width: 60px; padding-left: 1rem; }
  .table-prodotti th:last-child, .table-prodotti td:last-child { padding-right: 1rem; }
  .table-prodotti .td-thumb, .table-prodotti .td-thumb-placeholder { width: 40px; height: 40px; }
  .table-prodotti .btn-icon-action { width: 34px; height: 34px; min-height: 34px; }
  .table-inventario td:nth-child(6):empty { display: table-cell; }
  .table-inventario .action-group .btn { flex: none; min-height: 34px; }
  .table-inventario .action-group .btn-outline,
  .table-inventario .action-group .btn-danger { width: 34px; padding: 0; }
  .table-inventario td:nth-child(6) { max-width: 180px; color: var(--muted); font-size: .8rem; }
  .table-inventario th, .table-inventario td:nth-child(n) { padding: .6rem .6rem; }
  .table-inventario th { white-space: normal; line-height: 1.3; }
  .table-inventario th:first-child, .table-inventario td:first-child { padding-left: 1rem; }
  .table-inventario th:last-child, .table-inventario td:last-child { padding-right: 1rem; }
  .table-utenti td:nth-child(3)::before { content: none; }
  .table-utenti .action-group .btn { flex: none; min-height: 34px; }
  .table-utenti .btn-label { display: inline; }

  .table-analisi td, .table-analisi td:first-child { display: table-cell; padding: .75rem .9rem; margin: 0; border: none; }
  .table-analisi th.num, .table-analisi td.num { text-align: right; }
  .table-analisi td.num::before { content: none; }
  .table-analisi td.num small { display: block; margin-left: 0; }
}

@media (min-width: 1100px) {
  .gallery-grid { grid-template-columns: repeat(8, 1fr); }
}

/* Tabella Prodotti su schermi larghi ma non larghissimi: via Ricavo e
   Aggiunto, così le 10 colonne non escono di lato. */
@media (min-width: 1181px) and (max-width: 1360px) {
  .table-prodotti th:nth-child(7), .table-prodotti td:nth-child(7),
  .table-prodotti th:nth-child(8), .table-prodotti td:nth-child(8) { display: none; }
}

/* ============================================================
   MOVIMENTO RIDOTTO
   ============================================================ */
@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-primary::after { display: none; }
}
