:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f9fafb; --border: #e3e6eb; --border-strong: #cfd4dc;
  --text: #1c2430; --muted: #667085; --faint: #98a2b3;
  --primary: #1f5eff; --primary-ink: #ffffff; --primary-soft: #e8efff;
  --ok: #12855b; --ok-soft: #e3f5ec; --warn: #b26b00; --warn-soft: #fff3dc;
  --bad: #c4321f; --bad-soft: #fde8e5; --info: #5b4fd6; --info-soft: #eeecfd;
  --b0: #e8f1ff; --b1: #fff3dc; --b2: #ffe4c7; --b3: #ffd2c2; --b4: #fbbcbc; --b5: #f19c9c;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #121a2a; color: #c9d1e0; padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { color: #fff; font-weight: 600; font-size: 15px; padding: 4px 10px 16px; line-height: 1.25; }
.brand small { display: block; color: #8b97ad; font-weight: 400; font-size: 12px; margin-top: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #c9d1e0; padding: 8px 10px; border-radius: 6px; text-decoration: none; }
.nav a:hover { background: #1d2740; }
.nav a.active { background: #26345a; color: #fff; }
.nav .badge { margin-left: auto; background: var(--primary); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; }
.sidebar .me { margin-top: auto; padding: 10px; border-top: 1px solid #26314a; font-size: 12.5px; }
.sidebar .me b { color: #fff; display: block; font-weight: 600; }
.sidebar .me button { margin-top: 8px; }
.main { padding: 20px 24px 40px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.two-col { grid-template-columns: 1.3fr 1fr; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

/* controls */
button, .btn { font: inherit; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
button.primary:hover { filter: brightness(1.07); }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.danger { background: var(--surface); border-color: var(--bad); color: var(--bad); }
button.warn { background: var(--surface); border-color: var(--warn); color: var(--warn); }
button.ghost { border-color: transparent; background: transparent; }
button.sm { padding: 4px 10px; font-size: 12.5px; }
.sidebar button { background: transparent; color: #c9d1e0; border-color: #33415e; }
input, select, textarea { font: inherit; border: 1px solid var(--border-strong); border-radius: 6px; padding: 7px 10px; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.field input, label.field select, label.field textarea { color: var(--text); font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
input.amt { width: 130px; text-align: right; font-variant-numeric: tabular-nums; padding: 5px 8px; }
input.amt.err { border-color: var(--bad); background: var(--bad-soft); }
input.remark { width: 100%; min-width: 90px; padding: 5px 8px; }

/* tables */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: var(--surface-2); font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tbody tr:hover td { background: #fafbff; }
tr.party td { background: #f2f4f8; font-weight: 600; }
tr.party:hover td { background: #eceff5; }
tr.unselected td { color: var(--faint); }
tr.unselected input.amt { opacity: .5; }
tfoot td { font-weight: 600; background: var(--surface-2); position: sticky; bottom: 0; }
.clickable { cursor: pointer; }

/* status & bucket pills */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-DRAFT { background: #eef0f3; color: #475467; }
.s-SUBMITTED { background: var(--info-soft); color: var(--info); }
.s-RETURNED { background: var(--warn-soft); color: var(--warn); }
.s-APPROVED { background: var(--ok-soft); color: var(--ok); }
.s-REJECTED { background: var(--bad-soft); color: var(--bad); }
.s-PAID { background: #dff1fb; color: #0b6a99; }
.s-CANCELLED { background: #eef0f3; color: #98a2b3; text-decoration: line-through; }
.bk { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; color: #4a2b00; white-space: nowrap; }
.bk-0 { background: var(--b0); color: #234; } .bk-1 { background: var(--b1); } .bk-2 { background: var(--b2); }
.bk-3 { background: var(--b3); } .bk-4 { background: var(--b4); } .bk-5 { background: var(--b5); color: #4a0e0e; } .bk-u { background: #eef0f3; color: #475467; }
.pcat { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; background: #e6f4f1; color: #0d6b5c; white-space: nowrap; }
.s-PENDING_FINAL { background: #f3e8ff; color: #7a2fc0; }
tr.mine td { background: #f6f9ff; }
select.catsel { padding: 3px 6px; font-size: 12.5px; max-width: 180px; margin-left: 8px; font-weight: 400; }
.cat { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; background: var(--info-soft); color: var(--info); white-space: nowrap; }
.role { font-size: 11px; padding: 1px 7px; border-radius: 4px; background: #26345a; color: #cfe0ff; }
.role.ADMIN { background: #3b2a55; color: #e7d7ff; }
.role.APPROVER { background: #1d4a3a; color: #c8f1de; }

/* tabs & chips */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: none; background: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 12px; color: var(--muted); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); padding: 4px 10px; border-radius: 999px; font-size: 12.5px; cursor: pointer; user-select: none; }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }

/* ageing bar chart */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 70px 1fr 130px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 18px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; border-radius: 3px; }

/* sticky action bar */
.actionbar { position: sticky; bottom: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 -2px 8px rgba(16,24,40,.06); padding: 12px 16px; margin-top: 14px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; z-index: 5; }
.actionbar .total { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.timeline .when { color: var(--muted); font-size: 12px; }
.timeline .what { font-weight: 600; }
.timeline .cmt { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; margin-top: 4px; font-size: 13px; }
.timeline .chg { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* steps */
.steps { display: flex; gap: 0; margin: 4px 0 4px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 13px; }
.step .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--surface); }
.step.done { color: var(--text); } .step.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.cur { color: var(--text); font-weight: 600; } .step.cur .dot { border-color: var(--primary); color: var(--primary); }
.step.bad .dot { background: var(--bad); border-color: var(--bad); color: #fff; }
.step-line { width: 36px; height: 2px; background: var(--border-strong); margin: 0 8px; align-self: center; }

/* meta list */
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 20px; }
.meta-grid div span { display: block; color: var(--muted); font-size: 12px; }

/* alerts */
.alert { padding: 10px 14px; border-radius: 6px; border: 1px solid; margin-bottom: 12px; font-size: 13.5px; }
.alert.info { background: var(--primary-soft); border-color: #c4d4ff; color: #173a99; }
.alert.warn { background: var(--warn-soft); border-color: #f4d290; color: #6f4400; }
.alert.bad { background: var(--bad-soft); border-color: #f3b5ac; color: #8a1f12; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #121a2a 0%, #1f3266 100%); }
.login { width: 100%; max-width: 380px; }
.login .card { padding: 28px; }
.login h1 { margin-bottom: 4px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 40px rgba(0,0,0,.25); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15px; }
.modal .body { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
#toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: var(--shadow); max-width: 420px; font-size: 13.5px; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

.loading { opacity: .6; pointer-events: none; }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .sidebar .me { margin-top: 0; border-top: none; }
  .main { padding: 16px; }
}
@media print {
  .sidebar, .actionbar, .no-print, button { display: none !important; }
  .shell { display: block; } .main { padding: 0; }
  .card { box-shadow: none; border: none; padding: 0; }
  body { background: #fff; }
}
