:root {
  --bg: #f6f6f3; --card: #ffffff; --ink: #1d1d1b; --muted: #6b6b66; --line: #e4e3de;
  --accent: #2f5d50; --pos: #23794a; --neg: #1d1d1b; --warn: #b4531a; --bar: #2f5d50; --chip: #eeede8;
  --radius: 10px; color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413; --card: #1d1d1b; --ink: #ecebe6; --muted: #9a9993; --line: #2e2e2b;
    --accent: #7fb9a6; --pos: #6cc28f; --neg: #ecebe6; --warn: #e39462; --bar: #5f9e8a; --chip: #262624;
  }
}
* { box-sizing: border-box; }
body { margin: 0; padding: 20px clamp(12px, 3vw, 32px) 48px; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
h2 { margin: 0 0 2px; font-size: 14px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
button, select, input { font: inherit; color: inherit; }
button.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button.ghost:hover { border-color: var(--muted); }

.balances { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 16px; }
.bal { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; text-align: left; }
.bal:hover, .bal.on { border-color: var(--accent); }
.bal .name { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bal .amt { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.bal .amt.owed { color: var(--warn); }
.bal .asof { color: var(--muted); font-size: 11px; }
.bal.unlinked { opacity: .6; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { flex: 1 1 240px; }
.filters input[type=search], .filters select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.check { display: flex; gap: 6px; align-items: center; color: var(--muted); white-space: nowrap; }

.summary { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-bottom: 12px; color: var(--muted); }
.summary b { color: var(--ink); font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } .grid aside { order: -1; } }
@media (max-width: 640px) {
  .balances { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters select { flex: 1 1 140px; }
  .bars:not(.all) li:nth-child(n+6) { display: none; }
}
.bars-toggle { display: none; margin-top: 10px; }
@media (max-width: 640px) { .bars-toggle { display: inline-block; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.table-card { padding: 0; overflow: hidden; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
th.sortable { cursor: pointer; user-select: none; }
th.sorted::after { content: " ↓"; } th.sorted.asc::after { content: " ↑"; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.date { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
td .m { font-weight: 500; }
td .d { color: var(--muted); font-size: 12px; word-break: break-word; }
td .note { color: var(--accent); font-size: 12px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.num.pos { color: var(--pos); }
td.transfer { opacity: .55; }
.pill { display: inline-block; background: var(--chip); border-radius: 999px; padding: 1px 8px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.pill:hover { outline: 1px solid var(--muted); }
.acct { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.sm-meta { display: none; }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .sm-meta { display: block; margin-top: 3px; }
  td.date { font-size: 12px; }
}
.more { text-align: center; padding: 10px; }
.more:empty { display: none; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.bars { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 9px; }
.bars li { cursor: pointer; }
.bars .row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.bars .row span:last-child { font-variant-numeric: tabular-nums; }
.bars .track { position: relative; height: 6px; background: var(--chip); border-radius: 3px; margin-top: 3px; overflow: hidden; }
.bars .fill { position: absolute; inset: 0 auto 0 0; background: var(--bar); border-radius: 3px; }
.bars .over .fill { background: var(--warn); }
.bars .budget { color: var(--muted); font-size: 11.5px; }
.bars li.on .row span:first-child { font-weight: 600; }
