:root {
  --bg: #f4f6f9; --card: #fff; --text: #1d2433; --muted: #6b7486; --line: #e3e7ee;
  --side: #17233b; --side-text: #c4cde0; --side-active: #24365a;
  --primary: #1f6feb; --primary-dark: #1757c2; --accent: #f08a24;
  --ok: #1f9d55; --ok-bg: #e5f6ec; --warn: #b7791f; --warn-bg: #fdf3e1; --err: #d64545; --err-bg: #fdeaea;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }

.layout { display: flex; min-height: 100vh; }
.side { width: 232px; background: var(--side); color: var(--side-text); flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 20px 20px 16px; color: #fff; font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand small { display: block; font-weight: 400; color: var(--side-text); font-size: 12px; margin-top: 2px; }
.nav-group { padding: 6px 0; }
.nav-title { padding: 10px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #7d8aa6; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 20px; color: var(--side-text); border-left: 3px solid transparent; }
.nav a:hover { background: var(--side-active); color: #fff; text-decoration: none; }
.nav a.on { background: var(--side-active); color: #fff; border-left-color: var(--accent); }
.nav a.soon { opacity: .55; }
.nav a .tag { margin-left: auto; font-size: 10px; background: #33456b; padding: 1px 6px; border-radius: 8px; }
.side-foot { margin-top: auto; padding: 16px 20px; font-size: 12px; border-top: 1px solid #24365a; }
.side-foot a { color: var(--side-text); }

.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 28px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.content { padding: 24px 28px 48px; max-width: 1280px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f4f8; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #d97614; }
.btn-danger { color: var(--err); border-color: #f3c4c4; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-link { border: 0; background: none; color: var(--primary); padding: 0; cursor: pointer; font: inherit; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card-flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 20px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.two { grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } .side { display: none; } .content, .topbar { padding-left: 16px; padding-right: 16px; } }

table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfd; }
.t td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: #fafcff; }
.t tfoot td { font-weight: 650; background: #fafbfd; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: #eef1f6; color: #4a5468; white-space: nowrap; }
.b-ok, .b-consegnato, .b-accettato { background: var(--ok-bg); color: var(--ok); }
.b-warn, .b-da_inviare, .b-bozza, .b-non_consegnato { background: var(--warn-bg); color: var(--warn); }
.b-err, .b-scartato, .b-rifiutato { background: var(--err-bg); color: var(--err); }
.b-inviato { background: #e6effd; color: var(--primary); }
.b-convertito { background: #efe9fb; color: #6b46c1; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px; border-bottom: 1px solid var(--line); }
.filters .input { width: auto; }

.input { width: 100%; padding: 8px 10px; border: 1px solid #cfd6e1; border-radius: 7px; font: inherit; background: #fff; color: var(--text); }
.input:focus { outline: 2px solid #b9d3fb; border-color: var(--primary); }
textarea.input { resize: vertical; }
.check { width: 16px; height: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px 18px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: #48526a; margin-bottom: 4px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.field .err { font-size: 12px; color: var(--err); margin-top: 3px; }
.field.wide { grid-column: 1 / -1; }
.field.inline { display: flex; align-items: center; gap: 8px; padding-top: 22px; }
.field.inline label { margin: 0; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; background: #e6effd; color: #1d4ea8; }
.messages .success { background: var(--ok-bg); color: #17733f; }
.messages .error { background: var(--err-bg); color: #a12f2f; }
.messages .warning { background: var(--warn-bg); color: #8a5a12; }

/* righe documento */
.righe { width: 100%; border-collapse: collapse; }
.righe th { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 4px; }
.righe td { padding: 4px; vertical-align: top; }
.righe .input { padding: 6px 8px; }
.righe textarea.input { min-height: 34px; }
.righe .c-prod { width: 170px; } .righe .c-cod { width: 90px; } .righe .c-qta { width: 80px; } .righe .c-um { width: 60px; }
.righe .c-prezzo { width: 110px; } .righe .c-sc { width: 70px; } .righe .c-iva { width: 140px; } .righe .c-tot { width: 110px; }
.righe tr.deleted { opacity: .35; }
.totali { margin-left: auto; width: 320px; }
.totali div { display: flex; justify-content: space-between; padding: 6px 0; }
.totali .grand { font-size: 18px; font-weight: 700; border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; }

.chart { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 10px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar span { width: 100%; background: linear-gradient(180deg, #4b8df5, var(--primary)); border-radius: 5px 5px 0 0; min-height: 2px; }
.bar small { color: var(--muted); font-size: 11px; margin-top: 6px; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--side), #2b4a86); }
.login { width: 360px; background: #fff; border-radius: 14px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login h1 { margin-bottom: 4px; }
.login .field { margin-top: 14px; }

.dl { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.inline-form { display: inline; }
.notice { padding: 14px 16px; border-radius: 10px; background: var(--warn-bg); color: #7a4f10; margin-bottom: 20px; }
