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

:root {
  --sidebar-w: 220px;
  --sidebar-bg: #1a2234;
  --accent: #4f6ef7;
  --bg: #f1f5f9;
  --surface: #fff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 20;
}

.sidebar-logo {
  padding: 20px 16px 16px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo small {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: #64748b;
  letter-spacing: .5px;
  text-transform: uppercase;
  margin-top: 3px;
}

.app-build {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: #cbd5e1;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  margin-top: 8px;
  line-height: 1.5;
  letter-spacing: 0.02em;
}
.app-build .v { font-weight: 700; color: #fff; font-size: 12px; }
.app-build .b { color: #94a3b8; font-size: 10px; }

.nav-section { padding: 8px 0; }

.nav-section-label {
  padding: 6px 16px 2px;
  font-size: 10px;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.nav-link {
  display: block;
  padding: 8px 16px;
  color: #94a3b8;
  text-decoration: none;
  cursor: pointer;
  font-size: 13.5px;
  transition: background .1s, color .1s;
  border-left: 3px solid transparent;
}

.nav-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-link.active { background: #2d3d5a; color: #fff; border-left-color: var(--accent); }
.nav-link.disabled { color: #374151; cursor: default; font-size: 13px; }
.nav-link.disabled:hover { background: none; color: #374151; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

.breadcrumb { font-weight: 600; font-size: 15px; }

.topbar-right { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }

.health-dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; display: inline-block; }
.health-dot.online  { background: var(--success); }
.health-dot.offline { background: var(--danger); }

.main-content { flex: 1; padding: 24px; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-title  { font-size: 20px; font-weight: 600; }

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; }

/* ── Module cards ────────────────────────────────────────────────────────── */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: box-shadow .15s, transform .1s;
  text-decoration: none;
  color: inherit;
  display: block;
  box-shadow: var(--shadow);
}

.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); transform: translateY(-1px); }
.card.disabled { opacity: .45; cursor: default; pointer-events: none; }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.card-desc  { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

.card-badge { display: inline-block; margin-top: 10px; padding: 2px 9px; border-radius: 12px; font-size: 11px; font-weight: 500; }
.badge-active  { background: #dcfce7; color: var(--success); }
.badge-soon    { background: #f1f5f9; color: var(--text-muted); }
.badge-warn    { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }

/* ── Filters ─────────────────────────────────────────────────────────────── */
.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }

/* ── Form elements ───────────────────────────────────────────────────────── */
input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,110,247,.1); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: opacity .15s;
}

.btn:hover  { opacity: .88; }
.btn:active { opacity: .75; }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn:disabled  { opacity: .4; cursor: default; pointer-events: none; }

/* ── List page full-height layout ────────────────────────────────────────── */
.main-content.page-list {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  height: calc(100vh - 52px);
}
.list-header {
  flex-shrink: 0;
  padding: 14px 24px 0;
}
.list-header .page-header { margin-bottom: 0; }
.list-header .filters { margin-bottom: 8px; }
.list-table-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 24px 16px;
}
.main-content.page-list .dt-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.main-content.page-list .dt-table thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 2;
}

/* ── Action bar ──────────────────────────────────────────────────────────── */
.action-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  flex-wrap: wrap;
}

/* ── DataTable checkbox column ────────────────────────────────────────────── */
.dt-table .col-chk { width: 36px; padding: 0 8px; text-align: center; }
.dt-row.selected   { background: #eff6ff !important; }
input.dt-chk       { cursor: pointer; width: 15px; height: 15px; accent-color: var(--accent); }

/* ── Row nav buttons (↑↓ in detail header) ───────────────────────────────── */
.detail-nav { display: inline-flex; gap: 4px; align-items: center; }
.btn-nav {
  font-size: 16px;
  line-height: 1;
  padding: 2px 7px;
  border-radius: 4px;
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  transition: background .1s, color .1s;
}
.btn-nav:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-nav:disabled { opacity: .3; cursor: default; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  padding: 24px;
  min-width: 320px;
  max-width: 480px;
  width: 90vw;
}
.modal-box.modal-wide { max-width: 860px; }
.modal-header { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.modal-body { color: var(--text-muted); line-height: 1.5; margin-bottom: 16px; }
.modal-body strong { color: var(--text); }
.modal-typing { margin-bottom: 16px; font-size: 13px; }
.modal-typing p { margin-bottom: 6px; }
.modal-type-input { width: 100%; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; }

th {
  background: #f8fafc;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

.table-empty { text-align: center; padding: 40px; color: var(--text-muted); font-style: italic; }

/* ── Stato badge ─────────────────────────────────────────────────────────── */
.stato { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.stato-ricevuto            { background: #eff6ff; color: #2563eb; }
.stato-pagato              { background: #fefce8; color: #ca8a04; }
.stato-merce_in_arrivo     { background: #fff7ed; color: #ea580c; }
.stato-merce_disponibile   { background: #fef3c7; color: #d97706; }
.stato-attesa_spedizione   { background: #f0fdf4; color: #15803d; }
.stato-spedizione_raggruppata,
.stato-spedizione_avviata  { background: #ecfdf5; color: #059669; }
.stato-consegnato          { background: #d1fae5; color: #065f46; }
.stato-attesa_fatturazione { background: #fdf4ff; color: #9333ea; }
.stato-fatturato           { background: #f3e8ff; color: #7c3aed; }
.stato-completato          { background: #f0fdf4; color: #166534; }

/* ── Form card ───────────────────────────────────────────────────────────── */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.form-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px 16px; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea { width: 100%; }
.form-group.full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.form-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 16px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border); grid-column: 1/-1; }
.input-readonly { background: var(--surface-alt, #f1f5f9) !important; color: var(--text-muted); font-family: var(--font-mono, monospace); cursor: default; }
.prezzi-calcolati { background: #f8fafc; border-radius: var(--radius); padding: 10px 12px; border: 1px solid var(--border); }

/* ── Detail panel ────────────────────────────────────────────────────────── */
.detail-panel { background: #f8fafc; border-top: 2px solid var(--border); padding: 16px 20px; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; margin-bottom: 14px; }

.detail-item label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); display: block; margin-bottom: 2px; }
.detail-item span  { font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }

.righe-table { width: 100%; font-size: 12px; border-collapse: collapse; margin-top: 6px; }
.righe-table th { font-size: 10px; padding: 5px 10px; }
.righe-table td { padding: 6px 10px; border-bottom: 1px solid #e2e8f0; }
.righe-table tr:last-child td { border-bottom: none; }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.loading { text-align: center; padding: 60px; color: var(--text-muted); }
.error-msg { background: #fef2f2; border: 1px solid #fecaca; border-radius: var(--radius); padding: 12px 16px; color: var(--danger); margin-bottom: 16px; }
.info-msg  { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius); padding: 12px 16px; color: #1d4ed8; margin-bottom: 16px; }

.two-col { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 20px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; color: #fff;
  z-index: 1000; box-shadow: 0 4px 12px rgba(0,0,0,.15);
  animation: slideUp .2s ease;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--accent); }

@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.price-preview { font-size: 11px; color: var(--text-muted); margin-top: 8px; line-height: 1.8; }

/* ── DataTable ───────────────────────────────────────────────────────────── */
.dt-toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px; position: relative;
}
.dt-cols-btn {
  background: var(--surface); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; font-size: 12px; cursor: pointer; font-weight: 500;
}
.dt-cols-btn:hover { background: #f8fafc; color: var(--accent); border-color: var(--accent); }
.dt-count { font-size: 12px; color: var(--text-muted); }

.dt-picker {
  position: absolute; top: 36px; left: 0; z-index: 100;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  padding: 12px; min-width: 220px; max-height: 340px; overflow-y: auto;
}
.dt-picker-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); margin-bottom: 10px;
}
.dt-picker-list { display: flex; flex-direction: column; gap: 2px; }
.dt-picker-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; cursor: pointer; padding: 4px 6px; border-radius: 4px;
}
.dt-picker-item:hover { background: #f8fafc; }
.dt-picker-item input { margin: 0; cursor: pointer; }

.dt-wrap { overflow-x: auto; }
.dt-table th { position: relative; }
.dt-table th, .dt-table td {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.th-inner { display: flex; align-items: center; gap: 4px; padding-right: 8px; }
.th-label {
  cursor: pointer; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis;
  user-select: none;
}
.th-label:hover { color: var(--accent); }
.sort-icon { font-size: 9px; color: var(--accent); min-width: 10px; }

.col-resizer {
  position: absolute; right: 0; top: 0;
  width: 6px; height: 100%;
  cursor: col-resize; background: transparent;
  z-index: 2;
}
.col-resizer:hover { background: var(--accent); opacity: .4; }

.dt-row { cursor: pointer; }
.dt-row:hover td { background: #f0f7ff; }
.dt-row.expanded td { background: #e6f0ff; }

.cell-null { color: #cbd5e1; }
.cell-yes { color: var(--success); font-weight: 600; }
.cell-no  { color: var(--text-muted); }

/* ── Detail panel (zones) ────────────────────────────────────────────────── */
.det-row > td { padding: 0 !important; background: #f8fafc; }
.det-row .detail-panel { padding: 0; background: #f8fafc; border-top: 2px solid var(--accent); }

.detail-header {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 20px; background: #fff;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.detail-header strong { font-size: 16px; }
.detail-header-meta { color: var(--text-muted); font-size: 12px; }
.detail-header-actions { margin-left: auto; }
.detail-header-actions select { font-size: 12px; padding: 5px 10px; }

.detail-section {
  padding: 14px 20px;
  border-bottom: 1px solid #e2e8f0;
}
.detail-section:last-child { border-bottom: none; }
.detail-section-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--accent); margin-bottom: 10px;
}
.detail-section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px 18px;
}
.detail-section-grid .detail-item { min-width: 0; }
.detail-empty { font-size: 12px; color: var(--text-muted); font-style: italic; }

.order-id-formatted {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
  border-radius: 4px;
  padding: 2px 8px;
  letter-spacing: .5px;
  user-select: all;
}

/* ── Ricerca avanzata ───────────────────────────────────────────────────── */
.adv-bar {
  margin-bottom: 6px;
}
.adv-toggle {
  background: none; border: none; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--accent);
  padding: 4px 6px; border-radius: 4px;
  display: inline-flex; align-items: center; gap: 6px;
}
.adv-toggle:hover { background: #eef2ff; }

.adv-badge {
  display: inline-block;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 10px; line-height: 1.4;
}
.adv-badge-count { font-size: 11px; color: var(--accent); font-weight: 600; }

.adv-panel {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 10px;
  margin-bottom: 10px;
}
.adv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px 12px;
  margin-bottom: 10px;
}
.adv-field { display: flex; flex-direction: column; gap: 3px; }
.adv-field label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .4px; color: var(--text-muted);
}
.adv-field input {
  font-size: 12px; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: 5px;
}
.adv-field input:focus { border-color: var(--accent); }
.adv-actions { display: flex; justify-content: flex-end; }

@media (max-width: 768px) {
  .adv-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Order form (insert / edit) ──────────────────────────────────────────── */
.detail-header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.of-section {
  padding: 14px 20px;
  border-bottom: 1px solid #e2e8f0;
}
.of-section:last-child { border-bottom: none; }
.of-section-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--accent); margin-bottom: 10px;
}

.of-cliente-card {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 14px;
}
.of-cliente-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.of-muted { color: var(--text-muted); font-size: 12px; }

.of-prod-rows { display: flex; flex-direction: column; gap: 8px; }

.of-prod-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 14px;
  display: flex; flex-direction: column; gap: 6px;
}

.of-prod-info { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.of-prod-desc { font-size: 12px; }

.of-prod-controls {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

.of-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .4px; color: var(--text-muted); white-space: nowrap;
}

.of-prod-qty   { width: 64px; }
.of-prod-tipo  { min-width: 140px; }
.of-prod-price { width: 100px; }
.of-prod-price[readonly] { background: #f8fafc; color: var(--text-muted); }

.of-prod-total {
  font-weight: 600; min-width: 80px; flex: 1; text-align: right; font-size: 13px;
}

.of-prod-search { width: 100%; }
.of-prod-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,.12);
  max-height: 240px; overflow-y: auto; z-index: 50;
}
.of-prod-result-item {
  padding: 9px 12px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
}
.of-prod-result-item:last-child { border-bottom: none; }
.of-prod-result-item:hover { background: #f0f7ff; }

.of-totali-grid {
  display: grid; grid-template-columns: 1fr auto;
  gap: 8px 28px; align-items: center; max-width: 440px;
}
.of-val     { font-weight: 600; text-align: right; }
.of-totale  { font-size: 18px; color: var(--accent); }
.of-inp     { width: 110px; text-align: right; padding: 5px 8px; }

/* ── Customer search results (inside modal) ──────────────────────────────── */
.cust-result-item {
  padding: 10px 12px; cursor: pointer; border-radius: 6px;
  display: flex; flex-direction: column; gap: 3px;
  border-bottom: 1px solid var(--border);
}
.cust-result-item:last-child { border-bottom: none; }
.cust-result-item:hover { background: #f0f7ff; }

/* ── Insert placeholder row ──────────────────────────────────────────────── */
.order-insert-hdr {
  background: #eef2ff; color: var(--accent);
  padding: 8px 20px; font-size: 13px;
}

@media (max-width: 640px) {
  /* Product row controls: griglia 2×2 su mobile stretto */
  .of-prod-controls {
    display: grid;
    grid-template-columns: auto 1fr auto 1fr;
    align-items: center;
    gap: 6px 8px;
  }
  .of-prod-qty   { width: 56px; }
  .of-prod-price { width: 80px; }
  .of-prod-tipo  { min-width: 0; width: 100%; grid-column: 1 / -1; }
  .of-prod-total { grid-column: 3 / 5; text-align: right; }

  .of-totali-grid { max-width: 100%; }

  /* Header azioni ordine: a capo, bottoni full-width */
  .detail-header        { flex-wrap: wrap; gap: 6px; }
  .detail-header-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }

  /* Sezioni form: padding ridotto */
  .of-section { padding: 10px 14px; }
  .detail-section { padding: 10px 14px; }
  .detail-header { padding: 10px 14px; }
}

/* ── Hamburger (nascosto su desktop) ────────────────────────────────────── */
.nav-toggle {
  display: none;
  align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px; border-radius: 6px;
  min-width: 36px; min-height: 36px; flex-shrink: 0;
}
.nav-toggle:hover { background: #f1f5f9; }

.topbar-left { display: flex; align-items: center; gap: 8px; }

/* Overlay dietro la sidebar su mobile */
.nav-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 25;
}
.nav-overlay.active { display: block; }

/* ── Responsive mobile (≤ 768px) ────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Hamburger visibile */
  .nav-toggle { display: flex; }

  /* Sidebar: drawer slide-in da sinistra */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 30;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.25); }

  /* Layout: nessun margine sinistro */
  .layout { margin-left: 0; }

  .topbar { padding: 0 12px; }

  .main-content { padding: 12px; }

  /* Page header può wrappare */
  .page-header { flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
  .page-title  { font-size: 17px; }

  /* Filtri: impilati verticalmente */
  .filters { flex-direction: column; gap: 8px; }
  .filter-group { width: 100%; }
  .filter-group input,
  .filter-group select { width: 100% !important; }

  /* Stat cards: 2 colonne */
  .stats-row { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* Cards: 2 colonne */
  .cards-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* Two-col sidebar layout → stacked */
  .two-col { grid-template-columns: 1fr; }

  .form-card { padding: 14px; }

  /* DataTable toolbar */
  .dt-toolbar { flex-wrap: wrap; gap: 6px; }

  /* Detail sections: meno colonne su tablet/telefono grande */
  .detail-section-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .detail-section { padding: 12px 14px; }
  .detail-header { padding: 12px 14px; gap: 8px; }
  .detail-header-actions { width: 100%; margin-left: 0; }

  /* Toast: occupa tutta la larghezza */
  .toast { right: 12px; left: 12px; bottom: 12px; text-align: center; }
}

/* ── Telefoni piccoli (≤ 480px): colonna singola nei dettagli ────────────── */
@media (max-width: 480px) {
  .detail-section-grid { grid-template-columns: 1fr; }
}

/* ── Impostazioni (RQ-INT-006) ──────────────────────────────────────────── */
.main-content.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: start;
}

.settings-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 0;
  position: sticky;
  top: 76px;
  box-shadow: var(--shadow);
}
.settings-nav-title {
  padding: 8px 16px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.settings-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13.5px;
  text-decoration: none;
  color: var(--text);
  border-left: 3px solid transparent;
  transition: background .1s;
}
.settings-nav-item:hover  { background: var(--bg); }
.settings-nav-item.active { background: var(--bg); border-left-color: var(--accent); font-weight: 600; }
.settings-soon {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 8px;
  text-transform: uppercase;
}

.settings-body { min-width: 0; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.settings-card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

dl.kv {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 4px 12px;
  font-size: 13px;
}
dl.kv dt { color: var(--text-muted); }
dl.kv dd { font-weight: 500; word-break: break-word; }
dl.kv dd code {
  font-size: 12px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
}

.settings-table {
  width: 100%;
  font-size: 13px;
  border-collapse: collapse;
}
.settings-table th,
.settings-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.settings-table th { background: #f8fafc; font-weight: 600; }
.settings-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar-fill { height: 100%; background: var(--accent); transition: width .25s; }

/* Settings namespace form */
.settings-ns-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 6px 16px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.settings-ns-row:last-child { border-bottom: none; }
.settings-ns-label label { font-size: 13px; font-weight: 500; display: block; padding-top: 6px; }
.settings-ns-hint { font-size: 11px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.settings-ns-input { padding-top: 2px; }
@media (max-width: 600px) {
  .settings-ns-row { grid-template-columns: 1fr; }
}

.sys-out {
  background: #0f172a;
  color: #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  margin-top: 12px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.sys-out:empty { display: none; }

@media (max-width: 768px) {
  .main-content.settings-layout {
    grid-template-columns: 1fr;
  }
  .settings-nav { position: static; }
}


/* ── Login wall ──────────────────────────────────────────────────────────────*/
.login-wall {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
  box-shadow: 0 8px 40px rgba(0,0,0,.12);
}
.login-logo {
  text-align: center;
  font-size: 28px; font-weight: 700; letter-spacing: -.5px;
  color: var(--accent); margin-bottom: 28px;
}
.login-logo small { display: block; font-size: 12px; font-weight: 400; color: var(--text-muted); letter-spacing: 0; margin-top: 2px; }
.login-error {
  margin-top: 12px; padding: 10px 14px;
  background: #fef2f2; border: 1px solid #fecaca; border-radius: 6px;
  color: #dc2626; font-size: 13px;
}
.login-link {
  display: block; width: 100%; margin-top: 14px;
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: 13px; text-align: center; text-decoration: underline;
}
.login-link:hover { color: var(--accent-dark, #3d5bd9); }

/* User badge topbar */
#userBadge {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted); cursor: pointer;
  padding: 4px 8px; border-radius: 6px;
}
#userBadge:hover { background: var(--bg); }
