:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e0e4e9;
  --text: #1c2530;
  --text-muted: #667085;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- LOGIN ---------- */
.login-body {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1d4ed8, #0f172a);
}
.login-card {
  background: var(--surface);
  padding: 2.5rem 2rem;
  border-radius: var(--radius);
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; text-align: center; }
.login-card .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.login-card label { display: block; margin-bottom: 1rem; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.login-card input {
  display: block; width: 100%; margin-top: 0.35rem;
  padding: 0.65rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem;
}
.login-card button {
  width: 100%; padding: 0.7rem; border: none; border-radius: 8px;
  background: var(--primary); color: white; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.login-card button:hover { background: var(--primary-dark); }
.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.75rem; }

/* ---------- LAYOUT APP ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem; position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.main-nav { display: flex; gap: 0.4rem; flex: 1; flex-wrap: wrap; }
.main-nav button {
  background: none; border: 1px solid transparent; padding: 0.4rem 0.8rem;
  border-radius: 8px; cursor: pointer; font-size: 0.9rem; color: var(--text-muted); font-weight: 600;
}
.main-nav button.active { background: #eaf1ff; color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
.user-label { font-size: 0.85rem; color: var(--text-muted); }
.conn-status { font-size: 0.75rem; }
.conn-status.online { color: var(--success); }
.conn-status.offline { color: var(--danger); }
.queue-status {
  font-size: 0.75rem; font-weight: 700; color: var(--warning);
  background: #fef3c7; padding: 0.2rem 0.55rem; border-radius: 999px;
}

main#app { padding: 1rem 1.25rem 3rem; max-width: 1200px; margin: 0 auto; }
.view.hidden, [hidden] { display: none !important; }

.offline-note {
  background: #fef3c7; border: 1px solid #fcd34d; color: #92400e;
  padding: 0.6rem 0.75rem; border-radius: 8px; font-size: 0.85rem; line-height: 1.4;
  margin: 0 0 1rem;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-ordinato { background: #dcfce7; color: #15803d; }
tbody tr.status-row-ordinato { background: #f0fdf4; }
.muted { color: var(--text-muted); }

/* Codice articolo sempre visibile quando, dal telefono, si scorre la tabella verso destra
   per raggiungere i pulsanti. La cella eredita il colore della riga per non "staccare". */
#articlesTable td:first-child, #ordiniTable td:first-child, #adminArticlesTable td:first-child,
#articlesTable th:first-child, #ordiniTable th:first-child, #adminArticlesTable th:first-child {
  position: sticky; left: 0; z-index: 1;
  background-color: inherit;
  box-shadow: 1px 0 0 var(--border);
  white-space: nowrap;
  width: 1%; /* larga quanto il codice, non di più: lascia spazio ai pulsanti */
}
#articlesTable td:first-child, #ordiniTable td:first-child, #adminArticlesTable td:first-child {
  font-weight: 600;
  /* i codici lunghi (fino a ~18 caratteri) vanno a capo invece di allargare la colonna */
  white-space: normal; max-width: 7.5rem; min-width: 5.5rem; overflow-wrap: anywhere;
}
#articlesTable thead th:first-child, #ordiniTable thead th:first-child, #adminArticlesTable thead th:first-child {
  z-index: 3; background: #fafbfc;
}
tbody tr.op-rifiutata { background: #fef2f2; }
tbody tr.op-rifiutata td { color: #991b1b; }
tbody tr.op-rifiutata td:nth-child(4) { font-weight: 700; }

.load-error {
  background: #fef3c7; border: 1px solid #fcd34d; color: #92400e;
  padding: 0.7rem 0.9rem; border-radius: var(--radius); margin-bottom: 1rem;
  font-size: 0.88rem; display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap;
}

.subnav {
  display: flex; gap: 0.4rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.subnav button {
  background: none; border: none; padding: 0.55rem 0.9rem; cursor: pointer; font-size: 0.88rem;
  font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subnav button.active { color: var(--primary); border-bottom-color: var(--primary); }

.toolbar {
  display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.toolbar input[type="search"], .toolbar input[type="date"], .toolbar select {
  padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem;
}
.toolbar .spacer { flex: 1; }
.count-badge { color: var(--text-muted); font-size: 0.85rem; }
.hint { color: var(--text-muted); font-size: 0.85rem; }

button.btn-primary, button.btn-secondary, button.btn-ghost, button.btn-danger {
  padding: 0.5rem 0.9rem; border-radius: 8px; font-size: 0.88rem; font-weight: 600; cursor: pointer; border: 1px solid transparent;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
button:disabled, button:disabled:hover { opacity: 0.45; cursor: not-allowed; }
.btn-primary:disabled:hover { background: var(--primary); }
.btn-secondary { background: #eef1f5; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #e3e7ec; }
.btn-ghost { background: none; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { background: #fdeaea; color: var(--danger); }
.btn-danger:hover { background: #fbdada; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* ---------- TABELLE ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 640px; }
thead th {
  text-align: left; padding: 0.6rem 0.8rem; background: #fafbfc; border-bottom: 1px solid var(--border);
  color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em;
  position: sticky; top: 0;
}
tbody td { padding: 0.6rem 0.8rem; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { background: var(--surface); }
tbody tr:hover { background: #fafbfc; }
tbody tr.status-row-da_ordinare { background: #fff8ec; }
tbody tr.status-row-in_prelievo { background: #eef6ff; }

.badge {
  display: inline-block; padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700;
}
.badge-normale { background: #eef2f6; color: var(--text-muted); }
.badge-da_ordinare { background: #fef3c7; color: var(--warning); }
.badge-in_prelievo { background: #dbeafe; color: var(--primary); }
.badge-yes { background: #dcfce7; color: var(--success); }
.badge-no { background: #fee2e2; color: var(--danger); }

.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.status-by { font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 0.15rem; }

/* ---------- MODALI ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 1.5rem;
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-top: 0; }
.modal-article { color: var(--text-muted); font-size: 0.85rem; margin-top: -0.5rem; }
.modal label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.9rem; }
.modal input, .modal textarea, .modal select {
  display: block; width: 100%; margin-top: 0.35rem; padding: 0.55rem 0.7rem;
  border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; font-family: inherit;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }

.import-form { display: flex; gap: 0.5rem; align-items: center; }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: #1c2530; color: white; padding: 0.7rem 1.2rem; border-radius: 8px; font-size: 0.9rem; z-index: 100;
}

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { padding: 0.6rem 0.8rem; }
  main#app { padding: 0.75rem 0.75rem 3rem; }
}

/* ---------- LETTURA CODICE DA FOTO ---------- */
.scan-btn { white-space: nowrap; }
.scan-anteprima { display: block; max-width: 100%; max-height: 170px; margin: 0 auto 0.6rem; border-radius: 8px; object-fit: contain; background: #f1f3f6; }
.scan-candidati { display: flex; flex-direction: column; gap: 0.45rem; margin-bottom: 0.6rem; }
.candidato {
  text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 0.75rem; cursor: pointer; font: inherit; color: var(--text);
}
.candidato:hover { border-color: var(--primary); background: #f5f8ff; }
.candidato .cand-codice { font-weight: 700; font-size: 1rem; }
.candidato .cand-desc { display: block; font-size: 0.82rem; color: var(--text-muted); margin-top: 0.1rem; }
.candidato .cand-motivo { display: block; font-size: 0.75rem; margin-top: 0.25rem; }
.cand-certo .cand-motivo { color: var(--success); }
.cand-dubbio .cand-motivo { color: var(--warning); }
.scan-associa { border-top: 1px dashed var(--border); padding-top: 0.6rem; margin-bottom: 0.4rem; font-size: 0.85rem; }
.scan-associa .riga-associa { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin: 0.35rem 0; flex-wrap: wrap; }
.scan-associa code { background: #f1f3f6; padding: 0.1rem 0.35rem; border-radius: 4px; }

/* ---------- SCELTA ARTICOLO ---------- */
.pick-risultati { max-height: 300px; overflow-y: auto; margin-top: 0.6rem; border: 1px solid var(--border); border-radius: 8px; }
.pick-item { display: block; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid #f0f2f5; padding: 0.55rem 0.7rem; cursor: pointer; font: inherit; color: var(--text); }
.pick-item:last-child { border-bottom: none; }
.pick-item:hover { background: #f5f8ff; }
.pick-item small { display: block; color: var(--text-muted); }

/* ---------- DOCUMENTI DDT ---------- */
.nav-badge { display: inline-block; min-width: 1.2rem; padding: 0 0.35rem; margin-left: 0.25rem; border-radius: 999px; background: var(--danger); color: white; font-size: 0.72rem; font-weight: 700; line-height: 1.2rem; text-align: center; }
.doc-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 0.8rem; overflow: hidden; }
.doc-card.doc-da_verificare { border-color: #fcd34d; }
.doc-card.doc-errore { border-color: #fca5a5; }
.doc-testa { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.8rem; padding: 0.65rem 0.8rem; background: #fafbfc; border-bottom: 1px solid var(--border); font-size: 0.86rem; }
.doc-testa .doc-titolo { font-weight: 700; }
.doc-testa .spacer { flex: 1; }
.doc-motivo { padding: 0.5rem 0.8rem; font-size: 0.85rem; color: #92400e; background: #fffbeb; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.doc-card.doc-errore .doc-motivo { color: #991b1b; background: #fef2f2; }
.doc-card table { min-width: 560px; }
.badge-applicato, .badge-applicata { background: #dcfce7; color: #15803d; }
.badge-da_verificare { background: #fef3c7; color: #92400e; }
.badge-errore, .badge-ignorata { background: #f1f3f6; color: var(--text-muted); }
.badge-errore { background: #fee2e2; color: var(--danger); }
.badge-tipo { background: #e0e7ff; color: #3730a3; }
.riga-motivo { display: block; font-size: 0.75rem; color: #92400e; margin-top: 0.15rem; }

/* ---------- UTENTE IN ALTO ---------- */
.user-label { display: inline-flex; align-items: center; gap: 0.5rem; }
.avatar {
  width: 2rem; height: 2rem; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: #e0e7ff; color: #1e3a8a; font-weight: 700; font-size: 0.8rem;
}
.user-nome { display: flex; flex-direction: column; line-height: 1.15; color: var(--text); font-weight: 600; font-size: 0.85rem; }
.user-nome small { color: var(--text-muted); font-weight: 500; font-size: 0.72rem; }

/* ---------- SCHERMATA INIZIALE ---------- */
.home { max-width: 640px; margin: 0 auto; }
.home-saluto { font-size: 1.6rem; font-weight: 500; margin: 0.4rem 0 1.1rem; letter-spacing: -0.01em; }
.home-saluto strong { font-weight: 700; }
.home-azioni { display: grid; gap: 0.8rem; margin-bottom: 1.2rem; }
.azione-grande {
  display: flex; align-items: center; gap: 1rem; width: 100%; text-align: left;
  padding: 1.15rem 1.2rem; border: none; border-radius: 12px; cursor: pointer; color: white;
  font: inherit; box-shadow: 0 4px 14px rgba(15, 23, 42, 0.14); transition: transform 0.08s ease, filter 0.15s ease;
}
.azione-grande:hover { filter: brightness(1.07); }
.azione-grande:active { transform: scale(0.985); }
.azione-grande.blu { background: #1e3a6b; }
.azione-grande.verde { background: #2f6b38; }
.azione-grande.ambra { background: #9a5b0f; }
.azione-grande.viola { background: #5b3a8c; }
.azione-icona svg { width: 2.4rem; height: 2.4rem; display: block; }
.azione-titolo { display: block; font-size: 1.08rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.02em; }
.azione-sotto { display: block; font-size: 0.86rem; opacity: 0.88; margin-top: 0.15rem; }

.home-card {
  background: var(--surface); border-radius: 12px; padding: 1rem 1.1rem 1.1rem; margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}
.home-card h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
.home-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem 0.8rem; }
.tile {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.35rem; border-radius: 8px;
  background: none; border: none; text-align: left; font: inherit; color: var(--text);
}
button.tile { cursor: pointer; }
button.tile:hover { background: #f3f5f9; }
.tile-icona { color: #1e3a6b; flex: none; }
.tile-icona svg { width: 1.45rem; height: 1.45rem; display: block; }
.tile-testo { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.tile-etichetta { font-size: 0.8rem; color: var(--text-muted); }
.tile-valore { font-size: 1.15rem; }
.tile.tono-avviso .tile-icona, .tile.tono-avviso .tile-valore { color: #b45309; }
.tile.tono-errore .tile-icona, .tile.tono-errore .tile-valore { color: var(--danger); }

/* ---------- BARRA IN BASSO (solo telefono) ---------- */
.bottom-nav { display: none; }
@media (max-width: 767px) {
  .main-nav { display: none; }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 0.3rem 0.2rem calc(0.3rem + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
  }
  .bottom-nav button {
    flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
    background: none; border: none; padding: 0.3rem 0.1rem; font: inherit; font-size: 0.68rem; font-weight: 600;
    color: var(--text-muted); cursor: pointer; min-width: 0;
  }
  .bottom-nav button svg { width: 1.45rem; height: 1.45rem; }
  .bottom-nav button.active { color: #1e3a6b; }
  .bottom-nav button.tab-azione { color: #2f6b38; }
  .bottom-nav .nav-badge { position: absolute; top: 0; left: 55%; margin: 0; }
  main#app { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(5rem + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 2rem); }
  .topbar { flex-wrap: nowrap; }
  .brand { font-size: 1rem; white-space: nowrap; }
  .topbar-right { gap: 0.5rem; }
  .user-nome small { display: none; }
  .home-saluto { font-size: 1.45rem; }
}

/* ---------- LETTURA CODICE: STATO DI ATTESA ---------- */
.scan-foto { position: relative; margin-bottom: 0.7rem; }
.scan-foto .scan-anteprima { margin-bottom: 0; }
.scan-velo {
  position: absolute; inset: 0; border-radius: 8px;
  background: rgba(15, 23, 42, 0.55); color: white;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.6rem;
  font-size: 1.05rem;
}
.spinner {
  width: 2.6rem; height: 2.6rem; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.35); border-top-color: white;
  animation: gira 0.8s linear infinite;
}
@keyframes gira { to { transform: rotate(360deg); } }

.scan-attesa { margin-bottom: 0.4rem; }
.scan-fasi { list-style: none; padding: 0; margin: 0 0 0.7rem; display: grid; gap: 0.35rem; }
.scan-fasi li { display: flex; align-items: center; gap: 0.55rem; font-size: 0.92rem; color: var(--text-muted); }
.fase-segno {
  width: 1.35rem; height: 1.35rem; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--border); font-size: 0.78rem; font-weight: 800;
}
.scan-fasi li.fase-in-corso { color: var(--text); font-weight: 700; }
.scan-fasi li.fase-in-corso .fase-segno { border-color: var(--primary); border-top-color: transparent; animation: gira 0.8s linear infinite; }
.scan-fasi li.fase-fatta { color: var(--text); }
.scan-fasi li.fase-fatta .fase-segno { border-color: var(--success); background: var(--success); color: white; }
.scan-fasi li.fase-saltata .fase-segno { color: var(--text-muted); }
.scan-fasi li.fase-saltata { text-decoration: line-through; }

.scan-barra { height: 0.55rem; background: #e8ecf2; border-radius: 999px; overflow: hidden; }
.scan-barra > div {
  height: 100%; width: 3%; border-radius: 999px; transition: width 0.35s ease;
  background: repeating-linear-gradient(45deg, var(--primary) 0 10px, #3b82f6 10px 20px);
  background-size: 28px 28px; animation: scorri 0.9s linear infinite;
}
@keyframes scorri { to { background-position: 28px 0; } }
.scan-dettaglio { font-size: 0.85rem; color: var(--text); margin: 0.45rem 0 0.15rem; min-height: 1.2em; }
.scan-avviso-attesa { font-size: 0.8rem; color: var(--text-muted); margin: 0; }
.scan-stato { font-size: 0.9rem; color: var(--text); font-weight: 600; margin: 0.2rem 0 0.6rem; }
.scan-modal.in-lettura .modal-actions { justify-content: center; }

@media (prefers-reduced-motion: reduce) {
  .spinner, .scan-fasi li.fase-in-corso .fase-segno, .scan-barra > div { animation: none; }
}

/* Primo incontro con un EAN del produttore: è il passaggio principale, non un errore */
.nuovo-codice { border: 1px solid #bfdbfe; background: #eff6ff; border-radius: 10px; padding: 0.85rem 0.9rem; }
.nuovo-codice-numero { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.25rem; font-weight: 700; letter-spacing: 0.06em; margin-bottom: 0.4rem; }
.nuovo-codice p { margin: 0 0 0.5rem; font-size: 0.86rem; line-height: 1.4; }
.nuovo-codice-btn { width: 100%; padding: 0.7rem; font-size: 0.95rem; margin-top: 0.2rem; }

/* ---------- RITAGLIO DELLA FOTO ---------- */
/* Mentre si ritaglia, nella finestra resta solo il ritaglio */
.scan-modal.in-ritaglio > :not(h3):not(#scanRitaglio) { display: none !important; }
.ritaglio-area {
  position: relative; border-radius: 8px; margin: 0.4rem auto 0.6rem; padding: 0;
  width: 100%; display: flex; justify-content: center; background: #0f172a;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.ritaglio-area canvas { display: block; }
/* tela e riquadro hanno la stessa origine: le coordinate del riquadro coincidono con la foto */
.ritaglio-tela { position: relative; overflow: hidden; }
.ritaglio-rett {
  position: absolute; border: 2px solid white; cursor: move;
  /* oscura tutto ciò che sta fuori dal riquadro */
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.6);
}
.maniglia {
  position: absolute; width: 26px; height: 26px; border-radius: 50%;
  background: white; border: 3px solid var(--primary); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.maniglia[data-angolo="nw"] { left: -14px; top: -14px; cursor: nwse-resize; }
.maniglia[data-angolo="ne"] { right: -14px; top: -14px; cursor: nesw-resize; }
.maniglia[data-angolo="sw"] { left: -14px; bottom: -14px; cursor: nesw-resize; }
.maniglia[data-angolo="se"] { right: -14px; bottom: -14px; cursor: nwse-resize; }
#scanAzioniFine, .ritaglio-azioni { flex-wrap: wrap; }

/* ---------- SCARICO DA DDT FOTOGRAFATO ---------- */
.ddt-modal { max-width: 560px; }
.ddt-anteprima { display: block; max-width: 100%; max-height: 140px; margin: 0 auto 0.6rem; border-radius: 8px; object-fit: contain; background: #f1f3f6; }
.ddt-attesa { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; text-align: center; padding: 0.8rem 0; }
.ddt-campi { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.8rem; }
.ddt-campi label { margin-bottom: 0.6rem; }
.ddt-righe { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.4rem; }
.ddt-riga {
  display: grid; grid-template-columns: 1fr 5.2rem auto; gap: 0.2rem 0.6rem; align-items: start;
  border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.7rem;
}
.ddt-riga.con-errore { border-color: #f3b4b4; background: #fff7f7; }
.ddt-articolo { min-width: 0; font-size: 0.9rem; }
.ddt-articolo small { display: block; color: var(--text-muted); font-size: 0.78rem; overflow-wrap: anywhere; }
.ddt-disp { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 0.15rem; }
.ddt-avviso { color: var(--warning); font-weight: 600; }
.ddt-scelte { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.modal label.ddt-qta { margin: 0; font-size: 0.75rem; }
.modal label.ddt-qta input { margin-top: 0.15rem; padding: 0.45rem 0.5rem; font-size: 1.05rem; font-weight: 700; text-align: center; }
.ddt-togli { color: var(--text-muted); }
.ddt-riga-avviso { grid-column: 1 / -1; margin: 0.1rem 0 0; font-size: 0.8rem; color: var(--warning); }
.ddt-riga-avviso.errore { color: var(--danger); font-weight: 600; }
.ddt-azioni { grid-column: 1 / -1; align-items: center; }
.ddt-verificato { align-self: center; color: var(--success, #15803d); font-weight: 700; font-size: 0.85rem; }
.verifica-ko { border: 1px solid #f3b4b4; background: #fff7f7; border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.88rem; }
.verifica-ko p { margin: 0.25rem 0; }
.ddt-rif-avviso { margin: -0.2rem 0 0.7rem; padding: 0.5rem 0.7rem; border-radius: 8px; background: #fdeaea; color: var(--danger); font-size: 0.85rem; font-weight: 600; }
#ddtAzioniFine { flex-wrap: wrap; }
@media (max-width: 640px) {
  .ddt-campi { grid-template-columns: 1fr; }
}

/* ---------- TORNA INDIETRO ---------- */
.barra-indietro { margin: 0 0 0.6rem; }
.btn-indietro {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.5rem 0.9rem 0.5rem 0.6rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
  font: inherit; font-size: 0.92rem; font-weight: 600; color: #1e3a6b;
}
.btn-indietro:hover { background: #f3f5f9; }

/* Codici alternativi sotto il codice dell'articolo */
.codici-alt { display: block; font-size: 0.72rem; font-weight: 500; color: var(--text-muted); }

/* Avviso di nuova versione (quando non si può ricaricare da soli) */
.avviso-versione {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60; display: flex; align-items: center; justify-content: center; gap: 0.8rem;
  padding: 0.6rem 1rem; background: #fef3c7; color: #78350f; font-size: 0.9rem; font-weight: 600;
}

/* Registro aperto da un riquadro della schermata iniziale */
.filtro-attivo {
  display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap;
  margin: 0 0 0.8rem; padding: 0.6rem 0.9rem; border-radius: 10px;
  background: #e8eefb; color: #1e3a6b; font-weight: 700; font-size: 0.95rem;
}

/* Articolo sotto la soglia di riordino calcolata */
.sotto-soglia { display: block; font-size: 0.72rem; font-weight: 700; color: #b45309; white-space: nowrap; }
