:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --accent: #1f6feb; --accent-ink: #fff; --side: #18202e; --side-ink: #c9d1df;
  --red: #c62828; --red-bg: #fdecec; --amber: #a15c00; --amber-bg: #fff4e0; --green: #1b7a3d; --green-bg: #e6f5ec; --blue-bg: #e8f0fe;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); display: flex; min-height: 100vh; }
.side { width: 220px; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { font-weight: 700; font-size: 18px; padding: 20px 18px; color: #fff; }
.brand span { color: #7fb0ff; }
nav a { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; cursor: pointer; color: var(--side-ink); text-decoration: none; border-left: 3px solid transparent; }
nav a:hover { background: #222c3d; }
nav a.active { background: #26324a; color: #fff; border-left-color: #7fb0ff; }
.badge { background: var(--red); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.side-foot { margin-top: auto; padding: 14px 18px; font-size: 12px; color: #8592a8; }
main { flex: 1; padding: 24px 28px 60px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 12px; border-radius: 7px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: #b9c0cc; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.small, .btn.small { padding: 3px 8px; font-size: 12px; }
button.danger { color: var(--red); }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); min-width: 0; }
textarea { width: 100%; min-height: 60px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.red .v { color: var(--red); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.cols { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .cols { grid-template-columns: 1fr; } }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8faff; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; text-transform: capitalize; }
.pill.paid, .pill.delivered { background: var(--green-bg); color: var(--green); }
.pill.partial, .pill.pending, .pill.soon, .pill.today { background: var(--amber-bg); color: var(--amber); }
.pill.overdue, .pill.unpaid, .pill.cancelled { background: var(--red-bg); color: var(--red); }
.pill.sale, .pill.in { background: var(--blue-bg); color: var(--accent); }
.pill.purchase, .pill.out { background: #f1e8fd; color: #6a3fb5; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.alert { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.alert:last-child { border-bottom: none; }
.alert .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.alert .dot.overdue { background: var(--red); } .alert .dot.today { background: #e08600; } .alert .dot.soon { background: #f2b84b; }
.alert .body { flex: 1; min-width: 0; }
.alert .t { font-weight: 600; }
.alert .d { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding-top: 10px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.bar i { display: block; width: 100%; max-width: 38px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar span { font-size: 11px; color: var(--muted); }
.bar b { font-size: 10px; font-weight: 500; color: var(--muted); }
.modal { position: fixed; inset: 0; background: rgba(20, 26, 38, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 10; }
.modal-box { background: var(--panel); border-radius: 12px; width: 100%; max-width: 760px; padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal-box h2 { margin-top: 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.items td { padding: 5px; } .items input, .items select { width: 100%; }
.totals { text-align: right; margin-top: 10px; line-height: 1.7; font-variant-numeric: tabular-nums; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #18202e; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 20; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.ratecell { width: 90px; text-align: right; }
.note { background: var(--amber-bg); color: #6b4200; padding: 8px 12px; border-radius: 8px; font-size: 12px; margin-top: 6px; }
body.locked .side nav, body.locked .side-foot { visibility: hidden; }
.login { max-width: 380px; margin: 12vh auto 0; }
.side-foot .link { color: #9fb6d8; margin-top: 6px; }
.credit { width: 64px; text-align: right; }
.profit-pos { color: var(--green); } .profit-neg { color: var(--red); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
@media (max-width: 760px) {
  body { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  nav { display: flex; overflow-x: auto; } nav a { border-left: none; white-space: nowrap; }
  .side-foot { display: none; } main { padding: 16px; }
}
