/* =====================================================================
   Responsive / Mobile
   ===================================================================== */

/* ---------- Zoom automatico iOS ---------- */
/* Su iOS Safari, i campi con font < 16px fanno scattare lo zoom al focus.
   Alzando il font dei controlli il problema sparisce senza rinunciare
   allo zoom manuale. */
@media (max-width: 640px) {
  input, select, textarea, button { font-size: 16px; }
}

/* ---------- Area di tocco ---------- */
@media (max-width: 640px) {
  .btn { min-height: 44px; padding: 11px 16px; font-size: 14px; }
  .btn.btn-sm { min-height: 40px; padding: 8px 12px; font-size: 13px; }
  .btn.btn-lg { min-height: 50px; font-size: 15px; }
  .tab { min-height: 44px; }

  .field input, .field select, .form-field input, .form-field select,
  input[type="date"], .scan-input, .cp-qty, .line-qty, .line-giac,
  .dr-bc, .dr-inputs input, .row-item select, .row-item input.qty {
    padding: 12px;
  }
  .cam-btn { width: 48px; height: 48px; flex: 0 0 48px !important; border: 1px solid var(--border); }
  .menu-btn { width: 44px; height: 44px; }
  .line-qty { min-height: 44px; }
}

/* ---------- Layout pagina ---------- */
@media (max-width: 640px) {
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-head .btn { width: 100%; }

  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar .field { width: 100%; margin: 0; }
  .toolbar .small-field { max-width: none; }
  .toolbar .field > button { width: 100%; }

  .form-actions .btn { flex: 1; }
}

/* ---------- Accesso rapido su mobile ---------- */
@media (max-width: 640px) {
  .dash-quick { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .quick-card { padding: 14px 12px; min-height: 108px; }
  .quick-ico { width: 44px; height: 44px; }
}

/* ---------- Sidebar drawer: voci più comode al tocco ---------- */
@media (max-width: 900px) {
  .sidebar nav .nav-item { min-height: 48px; font-size: 15px; }
}

/* ---------- Tabella: le righe diventano card ---------- */
@media (max-width: 640px) {
  .table-wrap { overflow: visible; -webkit-overflow-scrolling: touch; }
  .table-wrap table { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tbody { display: block; }

  .table-wrap tbody tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 4px 0;
    margin-bottom: 10px;
  }
  .table-wrap tbody tr:hover { background: var(--surface); }
  .table-wrap tbody tr:last-child { margin-bottom: 0; }
  /* il border di riga non deve sparire sull'ultima card */
  .table-wrap tbody tr:last-child td { border-bottom: 1px solid var(--border); }

  .table-wrap td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
  }
  .table-wrap td:last-child { border-bottom: 0; }
  .table-wrap td::before {
    content: attr(data-label);
    flex: none;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-2);
  }
  /* prima colonna: titolo della card, senza etichetta */
  .table-wrap td:first-child {
    justify-content: flex-start;
    font-weight: 700;
    padding: 12px 14px 8px;
  }
  .table-wrap td:first-child::before { display: none; }
  /* azioni: senza etichetta, allineate a destra */
  .table-wrap td.cell-actions::before { display: none; }
  .table-wrap td.cell-actions { justify-content: flex-end; }
  /* celle vuote / messaggi */
  .table-wrap td.empty { display: block; text-align: center; border: 0; padding: 18px 14px; font-weight: 400; }
  .table-wrap td.empty::before { display: none; }
  .table-wrap td .muted, .table-wrap td .small { white-space: normal; }
}

/* ---------- Modale: pannello dal basso ---------- */
@media (max-width: 640px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    margin-bottom: 0;
    padding: 20px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .modal.wide { max-width: 100%; }
  .confirm-box { max-width: 100%; }
}

/* ---------- Grafico: scorribile se ci sono molti punti ---------- */
.chart { overflow-x: auto; }

/* ---------- Righe articolo (carico / scarico / ordini) ---------- */
@media (max-width: 640px) {
  .line-row { gap: 8px; }
  .line-qty-wrap { margin-left: 34px; width: calc(100% - 34px); }
  .line-ctl { flex: 1; }
  .line-ctl .line-qty, .line-ctl .line-giac { width: 100%; }

  .cp-addrow { flex-direction: column; align-items: stretch; }
  .cp-addrow .cp-qty { width: 100%; min-height: 48px; }
  .cp-addrow .btn { width: 100%; min-height: 48px; }
}

/* ---------- Login ---------- */
@media (max-width: 640px) {
  .login-wrap { padding: 16px; }
  .login-card { padding: 24px 20px; }
}

/* ---------- Toast ---------- */
.toast-wrap { bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }

/* ---------- Banner installazione PWA ---------- */
.install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 1000;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  padding: 12px;
}
.install-inner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.install-txt {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  line-height: 1.4;
  color: #fff;
}
.install-go {
  margin-top: 10px;
  min-height: 44px;
  background: var(--primary);
  border: none;
  color: #fff;
}
.install-go:hover { background: var(--primary-2); }
.install-x {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
}
