:root {
  --brand: #00275f;
  --brand-2: #1565c0;
  --accent: #2196f3;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1b2430;
  --muted: #5d6b7e;
  --line: #dfe4ea;
  --ok: #1a7f4b;
  --ok-bg: #e3f4ea;
  --warn: #9a6400;
  --warn-bg: #fff3d6;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --info: #1d4e85;
  --info-bg: #e5eef9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand-2); }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #fff; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.logo { display: flex; gap: 10px; align-items: center; font-weight: 700; letter-spacing: .3px; padding: 0 8px 18px; }
.logo .mark, .topbar .mark { flex: none; width: 38px; height: 38px; border-radius: 9px; background: #fff; display: grid; place-items: center; overflow: hidden; }
.topbar .mark { width: 30px; height: 30px; border-radius: 7px; }
.mark img { width: 88%; height: 88%; object-fit: contain; }
.login-logo { display: block; width: 100%; max-width: 300px; height: auto; margin: 0 auto 6px; }
.logo small { display: block; font-weight: 400; opacity: .7; font-size: 12px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #dbe6f3; text-decoration: none; padding: 9px 10px; border-radius: 8px; margin: 2px 0; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav .sep { height: 1px; background: rgba(255,255,255,.14); margin: 10px 6px; }
.side .who { font-size: 12px; opacity: .75; padding: 16px 10px 0; word-break: break-all; }
.side .who button { margin-top: 8px; }
.main { padding: 22px 26px 60px; min-width: 0; }
.topbar { display: none; }

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.span2 { grid-column: span 2; }

/* ---------- cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- forms ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; padding: 8px 10px; border: 1px solid #c9d1db; border-radius: 8px; background: #fff;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ea; border-color: var(--brand-2); }
input:disabled, select:disabled, textarea:disabled { background: #f3f5f8; color: #3e4a5a; }
input[type=checkbox] { width: auto; }
.field { min-width: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

button, .btn {
  font: inherit; font-weight: 600; font-size: 14px; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid #c9d1db; background: #fff; color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { background: #f3f6fa; }
button.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
button.primary:hover { background: var(--brand); }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.danger { color: var(--bad); border-color: #f1b8b2; }
button.danger:hover { background: var(--bad-bg); }
button.link { border: 0; background: none; padding: 4px 6px; color: var(--brand-2); font-weight: 600; }
button.icon { padding: 4px 8px; border: 0; background: none; color: var(--muted); }
button.icon:hover { color: var(--bad); background: var(--bad-bg); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #f8fafc; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f6f9fd; }
td.num, th.num { text-align: right; white-space: nowrap; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

table.lines { min-width: 720px; }
.lines td { padding: 6px 6px; }
.lines input { padding: 6px 8px; }
.lines .c-sku { width: 130px; }
.lines .c-qty { width: 80px; }
.lines .c-price { width: 110px; }
.lines .c-tax { width: 44px; text-align: center; }
.lines .c-amt { width: 110px; }
.lines .c-del { width: 36px; }

.totals { margin-left: auto; width: 100%; max-width: 360px; }
.totals td { border: 0; padding: 5px 4px; }
.totals input { width: 120px; text-align: right; padding: 5px 8px; }
.totals .grand td { font-size: 17px; font-weight: 800; border-top: 2px solid var(--text); padding-top: 8px; }
.totals .bal td { font-weight: 800; color: var(--brand-2); }

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: #eef1f5; color: #3e4a5a; text-transform: capitalize; }
.b-draft { background: #eef1f5; color: #3e4a5a; }
.b-sent, .b-issued { background: var(--info-bg); color: var(--info); }
.b-accepted, .b-paid { background: var(--ok-bg); color: var(--ok); }
.b-partial, .b-converted { background: var(--warn-bg); color: var(--warn); }
.b-declined, .b-void, .b-overdue { background: var(--bad-bg); color: var(--bad); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.filters .field { width: auto; }
.filters input, .filters select { min-width: 150px; }

.notice { padding: 10px 14px; border-radius: 8px; background: var(--info-bg); color: #18406c; font-size: 13.5px; margin-bottom: 14px; }
.notice.warn { background: var(--warn-bg); color: #6b4700; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand) 0%, #0b2340 100%); }
.auth .card { background: #fff; width: 100%; max-width: 380px; border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth h1 { margin: 8px 0 4px; font-size: 20px; }
.auth .stack > * + * { margin-top: 12px; }
.auth button.primary { width: 100%; justify-content: center; padding: 10px; }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,25,40,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(120px); background: #1b2430; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; transition: transform .2s; z-index: 60; max-width: calc(100vw - 32px); }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--bad); }

.report-lines td:first-child { width: 60px; color: var(--muted); font-weight: 700; }
.report-lines tr.total td { font-weight: 800; border-top: 2px solid var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; transform: translateX(-100%); transition: transform .2s; z-index: 40; }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; background: var(--brand); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; padding: 0 6px; }
  .main { padding: 16px 16px 60px; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 560px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .lines .c-sku { width: 90px; }
  .filters .field, .filters input, .filters select { width: 100%; }
}
