/* ========================================
   Eagle - Terminale Magazzino PWA
   ======================================== */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #F5F7FA;
  color: #1F2933;
  min-height: 100vh;
  line-height: 1.4;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #125CBF;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.header img {
  height: 32px;
  width: auto;
}

.header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
}

.header-logout {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #FFFFFF;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.header-logout:active {
  background: rgba(255,255,255,0.35);
}

/* Container */
.container {
  padding: 16px;
  max-width: 480px;
  margin: 0 auto;
}

/* Step show/hide */
.step {
  display: none;
}

.step.active {
  display: block;
}

.step-title {
  font-size: 1rem;
  font-weight: 600;
  color: #1F2933;
  margin-bottom: 16px;
  text-align: center;
}

/* Bottoni touch-friendly */
.btn-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 14px 20px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-primary {
  background: #125CBF;
  color: #FFFFFF;
}

.btn-primary:hover, .btn-primary:active {
  background: #0F4EA3;
}

.btn:disabled,
.btn[disabled] {
  background: #CBD2D9 !important;
  color: #7B8794 !important;
  cursor: not-allowed;
  opacity: 1;
}

/* Bottone azione a piena larghezza (es. update prezzo, crea articolo) */
.btn-full {
  width: 100%;
}

/* Quando un .btn-full e' figlio di .form-actions (grid 2 colonne) deve occupare entrambe */
.form-actions > .btn-full {
  grid-column: 1 / -1;
}

/* select con stile coerente al .form-input */
select.form-input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23125CBF'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 36px;
  cursor: pointer;
}

.btn-secondary {
  background: #E8F0FB;
  color: #125CBF;
}

.btn-secondary:hover, .btn-secondary:active {
  background: #DCE8FA;
}

.btn-neutral {
  background: #F1F4F8;
  color: #1F2933;
}

.btn-neutral:hover, .btn-neutral:active {
  background: #E4E7EB;
}

/* Bottone indietro */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: #125CBF;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 0;
  margin-bottom: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-back::before {
  content: '\2190';
  font-size: 1.1rem;
}

/* Griglia 2 colonne per modalità */
.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-grid .btn {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Loader */
.loader {
  text-align: center;
  padding: 32px 0;
  color: #52606D;
  font-size: 0.9rem;
}

.loader::before {
  content: '';
  display: block;
  width: 28px;
  height: 28px;
  border: 3px solid #D9E2EC;
  border-top-color: #125CBF;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Errore */
.error-msg {
  background: #FDE8E8;
  color: #D64545;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 12px;
}

/* Riepilogo selezioni */
.selection-summary {
  background: #E8F0FB;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: #52606D;
}

.selection-summary strong {
  color: #1F2933;
}

/* Form */
.form-group {
  margin-bottom: 14px;
}

/* Due form-group affiancati a larghezza identica */
.form-row {
  display: flex;
  gap: 12px;
}

.form-row > .form-group {
  flex: 1 1 0;
  min-width: 0;
}

/* Input con bottone azione affiancato (es. scan EAN + verifica) */
.input-with-action {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.input-with-action > .form-input {
  flex: 1 1 auto;
  min-width: 0;
}

.btn-icon {
  flex-shrink: 0;
  width: 50px;
  border: none;
  border-radius: 8px;
  background: #125CBF;
  color: #FFFFFF;
  font-size: 1.3rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-icon:hover, .btn-icon:active {
  background: #0F4EA3;
}

.btn-icon:disabled {
  background: #CBD2D9;
  color: #7B8794;
  cursor: not-allowed;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #52606D;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #D9E2EC;
  border-radius: 8px;
  font-size: 1rem;
  background: #F1F4F8;
  color: #1F2933;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: #125CBF;
  background: #FFFFFF;
}

.form-input::placeholder {
  color: #9AA5B1;
}

/* Contatore quantità */
.qty-counter {
  display: flex;
  align-items: center;
  gap: 0;
}

.qty-counter button {
  width: 52px;
  height: 52px;
  border: 1.5px solid #D9E2EC;
  background: #E8F0FB;
  color: #125CBF;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.qty-counter button:first-child {
  border-radius: 8px 0 0 8px;
}

.qty-counter button:last-child {
  border-radius: 0 8px 8px 0;
}

.qty-counter button:active {
  background: #DCE8FA;
}

.qty-counter input {
  width: 72px;
  height: 52px;
  border: 1.5px solid #D9E2EC;
  border-left: none;
  border-right: none;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: #1F2933;
  background: #FFFFFF;
  outline: none;
}

/* Griglia bottoni form */
.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #FFFFFF;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
}

.toast-success {
  background: #2E9B4F;
}

.toast-error {
  background: #D64545;
}

/* Login box */
.login-box {
  margin-top: 32px;
}

/* Riga fattura (lista invoice_mode) */
.btn-row {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 12px 14px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  background: #F1F4F8;
  color: #1F2933;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  border-left: 5px solid #D9E2EC;
  line-height: 1.3;
}

.btn-row:active {
  background: #E4E7EB;
}

.btn-row.stato-0 { border-left-color: #D9E2EC; }
.btn-row.stato-1 { border-left-color: #F0B429; }
.btn-row.stato-2 { border-left-color: #2E9B4F; }
.btn-row.stato-3 { border-left-color: #D64545; }

/* Modale generica (overlay + contenuto) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  overflow-y: auto;
}

.modal-content {
  background: #FFFFFF;
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #125CBF;
  margin: 0 0 14px 0;
  text-align: center;
}

/* Log ultimi inserimenti (single_mode) */
.log-title {
  margin: 24px 0 8px 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #52606D;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #E4E7EB;
  background: #FFFFFF;
}

.log-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #F1F4F8;
  font-size: 0.9rem;
  color: #1F2933;
}

.log-item:last-child {
  border-bottom: none;
}

.log-item:first-child {
  background: #F0F7FF; /* evidenzia l'ultimo inserimento */
}

.log-ts {
  color: #7B8794;
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.log-code {
  flex: 1 1 auto;
  min-width: 0;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-qty {
  flex-shrink: 0;
  font-weight: 600;
  color: #125CBF;
  font-variant-numeric: tabular-nums;
}

/* --- Multi Mode --- */

.scan-counter {
  display: flex;
  justify-content: space-around;
  gap: 12px;
  background: #F1F4F8;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: #52606D;
}

.scan-counter strong {
  color: #125CBF;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

.scan-list {
  max-height: 320px;
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid #E4E7EB;
  background: #FFFFFF;
  margin-bottom: 14px;
}

.scan-empty {
  padding: 18px 14px;
  text-align: center;
  color: #7B8794;
  font-size: 0.9rem;
}

.scan-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #F1F4F8;
  font-size: 0.9rem;
  transition: background 0.4s;
}

.scan-item:last-child { border-bottom: none; }

.scan-item-flash {
  background: #FFF9C4;
}

.scan-tag {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.4px;
}

.scan-tag-ean {
  background: #DBEAFE;
  color: #125CBF;
}

.scan-tag-cod {
  background: #FCE7F3;
  color: #9D174D;
}

.scan-code {
  flex: 1 1 auto;
  min-width: 0;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scan-qty {
  flex-shrink: 0;
  font-weight: 600;
  color: #125CBF;
  font-variant-numeric: tabular-nums;
}

/* Lista editabile in step-summary */
.summary-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.summary-row {
  background: #FFFFFF;
  border: 1px solid #E4E7EB;
  border-radius: 8px;
  padding: 12px;
}

.summary-row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.summary-field {
  margin-bottom: 0;
}

.summary-field label {
  font-size: 0.78rem;
  color: #7B8794;
}

.summary-field .form-input {
  padding: 8px 10px;
  font-size: 0.95rem;
}

.summary-row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.qty-counter-compact {
  max-width: 180px;
}

.qty-counter-compact button {
  padding: 6px 10px;
  font-size: 1.1rem;
}

.qty-counter-compact input {
  font-size: 1rem;
  padding: 6px 8px;
}

.btn-delete-row {
  width: 38px;
  height: 38px;
  border: none;
  background: #FDE8E8;
  color: #D64545;
  border-radius: 8px;
  font-size: 1.4rem;
  font-weight: bold;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-delete-row:active {
  background: #FBC0C0;
}

/* Report */
.report-summary {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.report-stat {
  flex: 1 1 0;
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  font-size: 0.85rem;
}

.report-stat strong {
  display: block;
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
  margin-bottom: 2px;
}

.report-stat-ok {
  background: #EAF7EE;
  color: #1A6B35;
}

.report-stat-err {
  background: #FDE8E8;
  color: #A62020;
}

.summary-row.report-ok {
  border-left: 5px solid #2E9B4F;
}

.summary-row.report-err {
  border-left: 5px solid #D64545;
}

.summary-row.report-multi {
  border-left: 5px solid #F0B429;
}

.summary-row.report-ok,
.summary-row.report-err,
.summary-row.report-multi {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.report-icon {
  flex-shrink: 0;
  font-size: 1.4rem;
  font-weight: bold;
  width: 30px;
  text-align: center;
}

.report-ok .report-icon { color: #2E9B4F; }
.report-err .report-icon { color: #D64545; }
.report-multi .report-icon { color: #F0B429; }

.report-row-info {
  flex: 1 1 auto;
  min-width: 0;
}

.report-msg {
  font-size: 0.82rem;
  color: #52606D;
  margin-top: 4px;
}

/* Indicatore stato riga fattura */
.stato-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  border-left: 5px solid #D9E2EC;
  background: #F1F4F8;
  font-size: 0.85rem;
  font-weight: 600;
  color: #52606D;
  margin-bottom: 16px;
}

.stato-bar.stato-0 { border-left-color: #D9E2EC; color: #52606D; }
.stato-bar.stato-1 { border-left-color: #F0B429; background: #FFFBEA; color: #7B5E00; }
.stato-bar.stato-2 { border-left-color: #2E9B4F; background: #EAF7EE; color: #1A6B35; }
.stato-bar.stato-3 { border-left-color: #D64545; background: #FDE8E8; color: #A62020; }

/* Riga di info secondaria sotto un campo (es. codice EAN articolo) */
.field-hint {
  font-size: 0.8rem;
  color: #7B8794;
  margin-top: 4px;
  padding-left: 2px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

/* Read-only display field (per dettaglio riga fattura) */
.field-readonly {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #E4E7EB;
  border-radius: 8px;
  background: #F5F7FA;
  color: #1F2933;
  font-size: 1rem;
  min-height: 46px;
  display: flex;
  align-items: center;
  word-break: break-word;
}
