:root {
  --bg: #f3f5f9; --panel: #fff; --line: #e3e7ee; --text: #1c2330; --muted: #6b7280;
  --primary: #2563eb; --primary-d: #1d4ed8; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --side: #111827; --side-text: #cbd5e1; --radius: 10px; --shadow: 0 2px 10px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .center { text-align: center; }
.err { color: var(--danger); min-height: 1.2em; font-size: 13px; }
a { color: var(--primary); }

/* ---------- Login ---------- */
.login { height: 100%; display: grid; place-items: center; background: linear-gradient(135deg, #1e293b, #0f172a); }
.login-box { background: var(--panel); padding: 36px 32px; border-radius: 16px; width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.4); text-align: center; }
.login-box h1 { margin: 8px 0 4px; font-size: 22px; }
.login-box label { display: block; text-align: left; margin-top: 14px; font-weight: 600; font-size: 13px; }
.logo { font-size: 36px; color: var(--primary); }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 230px 1fr; height: 100%; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; }
.brand { padding: 20px 18px; font-weight: 700; color: #fff; font-size: 16px; border-bottom: 1px solid #1f2937; }
.brand .logo { font-size: 20px; margin-right: 6px; }
.sidebar nav { flex: 1; padding: 10px; }
.sidebar nav a { display: block; padding: 11px 14px; border-radius: 8px; color: var(--side-text); text-decoration: none; margin-bottom: 3px; }
.sidebar nav a:hover { background: #1f2937; color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.user { padding: 14px 18px; border-top: 1px solid #1f2937; display: flex; justify-content: space-between; align-items: center; color: #fff; }
.user .btn { color: #cbd5e1; border-color: #374151; }
main { overflow: auto; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 18px 28px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h2 { margin: 0; font-size: 20px; }
#view { padding: 24px 28px; }

/* ---------- Componenti ---------- */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 18px; } .grid-4 { grid-template-columns: repeat(4, 1fr); } .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: 2fr 1fr; }
.kpi { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.warn .value { color: var(--warn); } .kpi.ok .value { color: var(--ok); }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; }
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); } .btn.primary:hover { background: var(--primary-d); }
.btn.danger { color: var(--danger); } .btn.danger:hover { background: #fef2f2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; } .btn.wide { width: 100%; margin-top: 18px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=search], .toolbar select { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; min-width: 240px; background: #fff; }
.toolbar .spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .4px; background: #f8fafc; }
tbody tr:hover { background: #f8fafc; } tbody tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { white-space: nowrap; text-align: right; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.badge.bozza { background: #e5e7eb; color: #374151; } .badge.confermato { background: #dbeafe; color: #1d4ed8; }
.badge.spedito { background: #fef3c7; color: #b45309; } .badge.fatturato { background: #dcfce7; color: #15803d; }
.badge.annullato { background: #fee2e2; color: #b91c1c; } .badge.low { background: #fee2e2; color: #b91c1c; } .badge.okk { background: #dcfce7; color: #15803d; }

.pager { display: flex; gap: 6px; justify-content: flex-end; align-items: center; margin-top: 12px; color: var(--muted); }

/* ---------- Form ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
label.f input, label.f select, label.f textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--text); background: #fff; }
label.f input:focus, label.f select:focus, label.f textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
label.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.form-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-box { background: var(--panel); border-radius: 14px; width: min(860px, 100%); max-height: 92vh; overflow: auto; padding: 22px 26px; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 18px; }

/* righe ordine */
.righe table { box-shadow: none; } .righe td, .righe th { padding: 6px 8px; }
.righe input, .righe select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.totali { display: flex; justify-content: flex-end; gap: 30px; margin-top: 12px; font-size: 15px; }
.totali strong { font-size: 18px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; right: 24px; background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.3); z-index: 100; max-width: 380px; }
.toast.error { background: var(--danger); } .toast.ok { background: var(--ok); }

.row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.order-head { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.order-head div span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.order-head div strong { font-size: 15px; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; } .progress i { display: block; height: 100%; background: var(--primary); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; } .sidebar { flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar nav { display: flex; } .brand { border: 0; white-space: nowrap; } .user { border: 0; margin-left: auto; }
  .grid-4, .grid-2, .grid-3, .form-grid, .order-head { grid-template-columns: 1fr; }
  #view { padding: 14px; }
}

/* ---------- Branding Mondo Hi-Tech ---------- */
.login-logo { max-width: 260px; width: 100%; margin: 0 auto 6px; display: block; }
.copy { font-size: 11px; color: var(--muted); margin: 14px 0 0; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 34px; height: 34px; object-fit: contain; }
.brand small { font-weight: 400; color: var(--side-text); font-size: 11px; }
.footer { margin-top: auto; padding: 12px 28px; border-top: 1px solid var(--line); background: var(--panel); font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.footer img { width: 18px; height: 18px; }
