:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e3e6ec;
  --brand: #0f5c8c; --brand-ink: #fff; --good: #1b7f4b; --good-bg: #e6f4ec; --bad: #b42318; --bad-bg: #fdecea;
  --warn: #9a6200; --warn-bg: #fff4dc; --info-bg: #eaf2fb;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
main { padding: 16px 20px 40px; max-width: 1700px; margin: 0 auto; }
h1 { font-size: 20px; margin: 4px 0 12px; } h2 { font-size: 16px; margin: 0 0 10px; } h3 { margin: 0 0 6px; }
h2.sect { margin: 26px 0 8px; }
.small { font-size: 12px; } .muted { color: var(--muted); } .center { text-align: center; } .nowrap { white-space: nowrap; }
code { background: #eef0f4; padding: 1px 5px; border-radius: 4px; }

header.top { display: flex; align-items: center; gap: 20px; background: var(--brand); color: var(--brand-ink); padding: 8px 20px; flex-wrap: wrap; }
header.top .brand { display: flex; flex-direction: column; line-height: 1.15; }
header.top .brand span { font-size: 12px; opacity: .8; }
header.top nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
header.top nav a, header.top .me a { color: var(--brand-ink); padding: 6px 10px; border-radius: 6px; opacity: .9; }
header.top nav a.on, header.top nav a:hover { background: rgba(255,255,255,.16); text-decoration: none; opacity: 1; }
header.top .me { font-size: 13px; } header.top .me a { padding: 0; }
.role { background: rgba(255,255,255,.2); padding: 1px 7px; border-radius: 10px; font-size: 11px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 14px; }
.card.narrow { max-width: 440px; margin: 40px auto; }
.login h1 { margin-bottom: 0; }
.flash { padding: 9px 12px; border-radius: 8px; margin: 0 0 12px; background: var(--good-bg); color: var(--good); }
.flash.err { background: var(--bad-bg); color: var(--bad); } .flash.warn { background: var(--warn-bg); color: var(--warn); }

.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: flex-end; } .row.wrap { flex-wrap: wrap; }
.row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.inline { display: inline; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid #cfd4dd; border-radius: 6px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3e0; border-color: var(--brand); }
label.chk { flex-direction: row !important; align-items: center; gap: 6px; color: var(--ink) !important; }
.btn { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid #cfd4dd; background: #fff; color: var(--ink); cursor: pointer; display: inline-block; }
.btn:hover { text-decoration: none; background: #f0f2f5; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.primary:hover { background: #0b4a72; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 2px 4px; font: inherit; }
button.link.danger { color: var(--bad); }

.weekbar { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.weekbar h1 { margin: 0; } .wk { color: var(--brand); }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 10px; vertical-align: middle; font-weight: 600; }
.pill.open { background: var(--good-bg); color: var(--good); } .pill.closed { background: #eceef2; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; }
.tile span { font-size: 12px; color: var(--muted); } .tile b { font-size: 20px; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); font-size: 12px; } .tile small i { font-style: normal; color: var(--good); font-weight: 600; }
.tile.bad b { color: var(--bad); } .tile.good b { color: var(--good); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filters input[name=q] { min-width: 220px; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--card); }
table.sheet, table.list { border: 1px solid var(--line); border-radius: 8px; }
th, td { padding: 5px 7px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; z-index: 1; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.old { color: var(--bad); font-weight: 600; }
td.bad { color: var(--bad); }
tr.sel td { background: var(--info-bg); }
table.sheet tbody tr:hover td { background: #fafcff; }
table.sheet tr.st-collected td, table.sheet tr.st-written_off td, table.sheet tr.st-dismissed td { background: #f6faf7; color: var(--muted); }
table.sheet .cust { min-width: 170px; }
table.sheet { font-size: 13px; }
table.sheet th, table.sheet td { padding: 4px 5px; }
table.sheet td.txn { min-width: 128px; max-width: 140px; word-break: break-word; }
table.sheet td.sp { max-width: 100px; }
table.sheet select.cat { width: 100px; padding: 4px; }
table.sheet input.amt { width: 95px; padding: 4px 6px; }
table.sheet input.exp { width: 118px; padding: 3px; font-size: 12px; }
table.sheet textarea.rem { width: 150px; min-height: 30px; padding: 4px 6px; resize: vertical; font-size: 12px; }
td.rem-ro { max-width: 260px; }
td.col { color: var(--good); font-weight: 600; }

.badge { display: inline-block; font-size: 10px; padding: 0 6px; border-radius: 8px; background: #eceef2; color: var(--muted); margin-left: 4px; vertical-align: middle; }
.badge.carry { background: var(--info-bg); color: var(--brand); font-weight: 700; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.done { background: var(--good-bg); color: var(--good); }
.chip { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; white-space: nowrap; }
.chip.r-collected { background: var(--good-bg); color: var(--good); }
.chip.r-partial { background: var(--warn-bg); color: var(--warn); }
.chip.r-pending { background: var(--info-bg); color: var(--brand); }
.chip.r-missed { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.chip.r-deferred { background: #f1ecfb; color: #5b3fa0; }
.saved { margin-left: 4px; font-size: 12px; } .saved.ok { color: var(--good); } .saved.err { color: var(--bad); font-weight: 700; }

.facts { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 12px; }
.facts div { display: flex; flex-direction: column; } .facts span { font-size: 12px; color: var(--muted); }
ul.log { list-style: none; padding: 0; margin: 10px 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
ul.log li { padding: 7px 12px; border-bottom: 1px solid var(--line); }
ul.log .when { color: var(--muted); font-size: 12px; margin-right: 6px; }
ul.log .act { font-size: 11px; background: #eceef2; padding: 0 6px; border-radius: 8px; margin: 0 4px; color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 7px 12px; border-radius: 6px 6px 0 0; color: var(--muted); }
.tabs a.on { background: var(--card); border: 1px solid var(--line); border-bottom-color: var(--card); color: var(--ink); margin-bottom: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
details summary { cursor: pointer; } details table { margin-top: 8px; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(20, 30, 50, .35); }

@media (max-width: 900px) {
  main { padding: 12px; } .grid2 { grid-template-columns: 1fr; }
  header.top { gap: 8px; }
}
