/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn.btn-primary { background: var(--primary); color: #fff; }
.btn.btn-primary:hover { background: var(--primary-2); }
.btn.btn-carico { background: var(--carico); color: #fff; }
.btn.btn-carico:hover { background: #15803d; }
.btn.btn-scarico { background: var(--scarico); color: #fff; }
.btn.btn-scarico:hover { background: #b91c1c; }
.btn.btn-success { background: var(--success); color: #fff; }
.btn.btn-success:hover { background: #15803d; }
.btn.btn-danger { background: var(--danger); color: #fff; }
.btn.btn-ghost { background: transparent; border-color: var(--border); }
.btn.btn-ghost:hover { background: var(--surface-2); }
.btn.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn.btn-danger-ghost:hover { background: var(--danger-050); }
.btn.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn.btn-lg { padding: 13px 18px; font-size: 15px; }
.btn.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

/* ---------- Toolbar / grid / fields ---------- */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 12px;
}
.toolbar .field { margin: 0; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field input, .field select, .form-field input, .form-field select, input[type="date"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .form-field input:focus, .form-field select:focus, input[type="date"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-050);
}
.field input:disabled { background: var(--surface-2); color: var(--muted); }
.field .small-field { max-width: 120px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .15s;
}
.stat:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.stat .stat-ico {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-050);
  color: var(--primary);
  flex: none;
}
.stat .stat-ico svg { width: 22px; height: 22px; }
.stat.alert { border-color: var(--warning); background: var(--warning-050); }
.stat.alert .stat-ico { background: var(--warning-050); color: var(--warning); }
.stat .num { font-size: 22px; font-weight: 800; line-height: 1.1; }
.stat .lbl { font-size: 12px; color: var(--text-2); }
.stat .num.small { font-size: 18px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.cell-actions { white-space: nowrap; text-align: right; }
.cell-actions .btn { margin-left: 4px; }
.cell-actions, th:last-child { text-align: right; }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  vertical-align: middle;
}
.badge.carico { background: var(--success-050); color: var(--success); }
.badge.scarico { background: var(--danger-050); color: var(--danger); }
.badge.admin { background: var(--primary-050); color: var(--primary); }
.badge.operator { background: var(--surface-2); color: var(--text-2); }
.badge.aperta { background: var(--warning-050); color: var(--warning); }
.badge.evasa { background: var(--success-050); color: var(--success); }
.badge.minimo { background: var(--warning-050); color: var(--warning); }
.badge.esaurito { background: var(--danger-050); color: var(--danger); }
.badge.ok { background: var(--success-050); color: var(--success); }
.badge.low { background: var(--warning-050); color: var(--warning); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-2);
  vertical-align: middle;
}
.chip-ok { background: var(--success-050); color: var(--success); border-color: transparent; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--primary); color: #fff; }

/* ---------- Card header ---------- */
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.card-head h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 0; }
.card-head h2 .ico { color: var(--primary); }

/* ---------- Checkbox rows / permessi ---------- */
.check-row { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check-row input { margin-top: 3px; }
.perm-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}
@media (max-width: 640px) { .perm-grid { grid-template-columns: 1fr; } }
.perm-item {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
}
.perm-item:hover { border-color: var(--primary); }
.perm-item input { margin-top: 3px; }
.perm-item strong { display: block; font-size: 12.5px; }

/* ---------- Chart ---------- */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 190px;
  padding: 8px 4px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 2px;
  min-width: 14px;
}
.chart-col .chart-bar {
  width: 55%;
  max-width: 30px;
  border-radius: 4px 4px 0 0;
  transition: height .3s ease;
}
.chart-col .chart-bar.carico { background: var(--carico); }
.chart-col .chart-bar.scarico { background: var(--scarico); }
.chart-col .chart-label {
  font-size: 10px;
  color: var(--text-2);
  white-space: nowrap;
  transform: rotate(-45deg);
  transform-origin: top left;
  margin-top: 6px;
  height: 26px;
}
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px 16px;
  z-index: 200;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 20px;
  animation: modalIn .18s ease;
}
.modal.wide { max-width: 720px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
.row-item {
  display: grid;
  grid-template-columns: 1fr 110px 34px;
  gap: 8px;
  margin-bottom: 8px;
}
.row-item select, .row-item input.qty {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}
.row-item .rm { align-self: center; }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  background: #1e293b;
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn .18s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Confirm dialog ---------- */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 250;
}
.confirm-box {
  background: var(--surface);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.confirm-box h3 { margin-bottom: 8px; }
.confirm-box p { color: var(--text-2); white-space: pre-line; margin-bottom: 6px; }
.confirm-msg { color: var(--text-2); white-space: pre-line; margin-bottom: 6px; }
