:root {
  --bg: #f6f5f2; --panel: #fff; --ink: #1d1f23; --muted: #6b7079; --line: #e6e3dd; --grid: #eeece7;
  --accent: #0f6b5b; --pos: #13795b; --neg: #b3362b; --chip: #efede8;
  /* chart roles (validated reference palette) */
  --income: #2a78d6; --spend: #eb6834; --series: #2a78d6; --series-soft: #cde2fb;
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141518; --panel: #1c1e22; --ink: #e9e7e3; --muted: #9a9ea6; --line: #2c2f35; --grid: #26292e;
    --accent: #4fc2a6; --pos: #5cc99a; --neg: #f08a7e; --chip: #262930;
    --income: #3987e5; --spend: #d95926; --series: #3987e5; --series-soft: #1c3c63; }
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
#rule-preview:empty, #edit-preview:empty { display: none; }
[hidden] { display: none !important; }
.top { display: flex; gap: 20px; justify-content: space-between; align-items: center; padding: 10px 28px;
  border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; letter-spacing: -0.01em; font-size: 18px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a { color: var(--muted); text-decoration: none; padding: 7px 12px; border-radius: 8px; font-weight: 550; }
.tabs a:hover { color: var(--ink); background: var(--chip); }
.tabs a.active { color: var(--ink); background: var(--chip); }
.sync { display: flex; gap: 12px; align-items: center; white-space: nowrap; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 28px 64px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 28px 0 12px; font-weight: 600; }
h3 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
h4 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 0 8px; }
.mt { margin-top: 24px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
button, .btn-secondary { font: inherit; border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 7px 14px;
  border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.3; }
button:disabled { opacity: 0.5; cursor: default; }
.btn-secondary, .pager button { background: var(--panel); color: var(--ink); border-color: var(--line); }
button.link { background: none; border: none; color: var(--accent); padding: 4px 6px; }
button.icon { background: none; border: none; color: var(--muted); padding: 2px 8px; font-size: 18px; }
button.icon:hover { color: var(--neg); }
input, select { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-top: 16px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.panel-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .panel { margin-top: 16px; }
.foot { font-size: 12px; margin: 8px 0 0; }

.networth { display: flex; gap: 48px; align-items: baseline; flex-wrap: wrap; }
.networth > div { display: flex; flex-direction: column; }
.label { font-size: 13px; color: var(--muted); }
.big { font-size: 38px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.mid { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.notice { margin-top: 16px; padding: 12px 16px; border-radius: 12px; background: var(--chip); border-left: 4px solid var(--accent); font-size: 14px; }
.notice b { font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tile .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .sub { font-size: 12px; color: var(--muted); }
.empty-note { color: var(--muted); font-size: 14px; padding: 8px 0; }

.accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; cursor: pointer;
  transition: border-color .15s; text-align: left; color: inherit; font: inherit; display: block; width: 100%; }
.card:hover { border-color: var(--accent); }
.card .head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.card img { width: 20px; height: 20px; border-radius: 5px; }
.card .name { font-weight: 600; margin-top: 6px; }
.card .bal { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* meters (budgets) */
.meter { position: relative; height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; min-width: 80px; }
.meter > span { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--series); }
.meter.over > span { background: var(--critical); }
.meter .pace { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: .55; }
.brow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.brow:first-child { border-top: 0; }
.brow .meter { grid-column: 1 / -1; }
.status-over { color: var(--neg); font-weight: 600; }

/* filters + table */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.filters select { max-width: 100%; min-width: 0; }
.filters input[type=search] { flex: 1 1 260px; }
.filters label { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
#csv { margin-left: auto; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips:empty { display: none; }
.fchip { background: var(--chip); border-radius: 999px; padding: 3px 6px 3px 12px; font-size: 13px; display: inline-flex; gap: 4px; align-items: center; }
.fchip button { background: none; border: none; color: var(--muted); padding: 0 6px; font-size: 16px; }
.tx-totals { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 13px; color: var(--muted); margin: 8px 0 10px; }
.tx-totals b { color: var(--ink); font-variant-numeric: tabular-nums; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
.panel .table-wrap { border: 0; border-radius: 0; margin: 0 -20px; }
table.tx { width: 100%; border-collapse: collapse; }
.tx th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); }
.tx td { padding: 9px 14px; border-top: 1px solid var(--line); vertical-align: top; }
.tx tbody tr:first-child td { border-top: 0; }
.tx .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx .date { white-space: nowrap; color: var(--muted); font-size: 13px; }
.desc { display: flex; gap: 10px; align-items: flex-start; }
.desc img, .desc .ph { width: 24px; height: 24px; border-radius: 6px; flex: none; background: var(--chip); }
.desc .main { font-weight: 550; }
.desc .main, .desc .meta { overflow-wrap: anywhere; }
.desc .meta { font-size: 12px; color: var(--muted); }
.cat { min-width: 130px; }
.cat-btn { all: unset; cursor: pointer; display: block; border-radius: 8px; padding: 2px 4px; margin: -2px -4px; }
.cat-btn:hover, .cat-btn:focus-visible { background: var(--chip); outline: none; }
.cat-btn .grp { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
.chip { display: inline-block; font-size: 12px; line-height: 1.35; background: var(--chip); padding: 2px 8px; border-radius: 6px; }
.chip.transfer { background: none; border: 1px dashed var(--line); color: var(--muted); }
.src { font-size: 11px; color: var(--muted); margin-left: 4px; }
tr.is-transfer td.num { color: var(--muted); }
.acct { font-size: 13px; color: var(--muted); white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.acct-inline { display: none; }

/* charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text, .hbars text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.zeroline { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area { fill: var(--series); opacity: .08; }
.dot { fill: var(--series); stroke: var(--panel); stroke-width: 2; }
.bar-income { fill: var(--income); } .bar-spend { fill: var(--spend); }
.bar-hit { fill: transparent; cursor: pointer; }
.bar-hit:hover, .bar-hit.sel { fill: var(--ink); opacity: .05; }
.crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; }
.key.k-income { background: var(--income); } .key.k-spend { background: var(--spend); margin-left: 8px; }
.key.k-avg { width: 2px; height: 12px; border-radius: 0; background: var(--ink); opacity: .55; }
.key.k-budget { width: 2px; height: 12px; border-radius: 0; background: var(--critical); margin-left: 6px; }
.hbars { display: grid; gap: 2px; }
.hbar { all: unset; display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; gap: 10px; align-items: center; padding: 5px 6px;
  border-radius: 6px; cursor: pointer; font-size: 13px; }
.hbar:hover, .hbar:focus-visible { background: var(--chip); }
.hbar .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .nm small { color: var(--muted); display: block; font-size: 11px; }
.hbar .track { position: relative; height: 10px; }
.hbar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--series); min-width: 2px; }
.hbar .avg { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .55; }
.hbar .bud { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--critical); }
.hbar .v { font-variant-numeric: tabular-nums; text-align: right; min-width: 78px; }
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--ink); color: var(--panel); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; line-height: 1.5; box-shadow: 0 4px 16px rgba(0,0,0,.18); max-width: 260px; }
.tip b { font-variant-numeric: tabular-nums; }
.tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* rules / categories / dialog */
.stack { display: grid; gap: 12px; }
.stack label, .row label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.stack label.inline, label.inline { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 auto; }
.row.end { justify-content: flex-end; } .row.end > * { flex: 0 0 auto; }
.cat-list { margin-top: 12px; max-height: 420px; overflow: auto; font-size: 14px; }
.cat-list .g { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 0 4px; }
.cat-list .c { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; }
.kind { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-left: 6px; }
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); width: min(480px, 94vw); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.35); }
.rule-box { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 12px; margin: 0; }
.rule-box legend { padding: 0 4px; }
.rule-box:disabled label:not(.inline) { opacity: .5; }

@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
  .tx th:nth-child(4), .tx td:nth-child(4) { display: none; }
  .budgets th:nth-child(4), .budgets td:nth-child(4) { display: table-cell; }
  .acct-inline { display: inline; }
  .top { flex-wrap: wrap; }
  .tabs { order: 3; flex-basis: 100%; overflow-x: auto; }
}
@media (max-width: 720px) {
  main { padding: 16px; } .top { padding: 10px 16px; gap: 8px; }
  .tx th:nth-child(3), .tx td:nth-child(3) { display: none; }
  .budgets th:nth-child(2), .budgets td:nth-child(2) { display: none; }
  .budgets th:nth-child(3), .budgets td:nth-child(3) { display: table-cell; }
  .tx td, .tx th { padding: 9px 10px; }
  .networth { gap: 24px; } .big { font-size: 30px; }
  .sync #sync-status { display: none; }
  .filters select { flex: 1 1 40%; }
  .filters label { flex: 1 1 40%; } .filters label input { flex: 1; min-width: 0; }
  #csv { margin-left: 0; }
  .tx .date { white-space: normal; width: 64px; font-size: 12px; }
  .desc img, .desc .ph { display: none; }
  .tiles { grid-template-columns: 1fr 1fr 1fr; gap: 8px; } .tile .v { font-size: 17px; }
  .hbar { grid-template-columns: minmax(90px, 40%) 1fr auto; }
}

textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); resize: vertical; }
.why { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.badge { font-size: 11px; border-radius: 4px; padding: 1px 6px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.badge.found { color: var(--pos); } .badge.error { color: var(--neg); }
.lookups td { font-size: 13px; } .lookups select { max-width: 190px; font-size: 13px; padding: 4px 6px; }
.lookups .q { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
#known-list .num { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.panel .lookups-wrap { max-height: 520px; overflow: auto; }

/* ---------- Phase 3: phone ---------- */
.badge-count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--accent);
  color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; }
.bottom-nav { display: none; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 4px; box-shadow: 0 -8px 30px rgba(0,0,0,.15); }
.sheet a { padding: 14px 8px; font-size: 17px; color: var(--ink); border-bottom: 1px solid var(--line); }
.sheet .link { justify-self: center; margin-top: 6px; }

/* gate: pairing / Face ID setup / unlock */
.gate { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(380px, 100%); text-align: center; display: grid; gap: 14px; justify-items: center; }
.gate-card img { border-radius: 16px; }
.gate-card h2 { font-size: 22px; color: var(--ink); text-transform: none; letter-spacing: 0; margin: 4px 0 0; }
.gate-card p { margin: 0; }
.gate-card form, .gate-card button { width: 100%; }
.gate-card input[name=code] { font-size: 22px; text-align: center; letter-spacing: 0.12em; text-transform: uppercase; padding: 10px; }
.gate-card button { padding: 12px 16px; font-size: 16px; }

/* review */
.review-head { display: flex; justify-content: space-between; align-items: baseline; }
.review-head h3 { margin: 0; }
.rcard { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-top: 12px; display: grid; gap: 14px; }
.rcard .rtop { display: flex; gap: 12px; align-items: center; }
.rcard .rtop img, .rcard .rtop .ph { width: 40px; height: 40px; border-radius: 10px; background: var(--chip); flex: none; }
.rcard .who { font-weight: 650; font-size: 17px; overflow-wrap: anywhere; }
.rcard .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.rcard .amt { margin-left: auto; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rcard .guess { font-size: 14px; }
.rcard .guess b { font-weight: 650; }
.cat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.cat-grid button { background: var(--chip); color: var(--ink); border: 1px solid var(--line); padding: 11px 10px; font-size: 14px;
  text-align: left; border-radius: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-grid button:hover { border-color: var(--accent); }
.rcard .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rcard .actions button { padding: 12px; font-size: 15px; }
.rcard .confirm { padding: 13px; font-size: 16px; }
.rcard .more { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rcard .more select { flex: 1; min-width: 0; }
.done { text-align: center; padding: 40px 12px; color: var(--muted); }
.done b { display: block; font-size: 18px; color: var(--ink); margin-bottom: 4px; }

/* settings */
.pair-box { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; margin: 12px 0; padding: 14px; border: 1px dashed var(--line); border-radius: 12px; }
.pair-box .qr svg { display: block; width: 180px; height: 180px; border-radius: 8px; }
.pair-box .code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 24px; letter-spacing: 0.08em; }
.pair-box ol { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.money-in { display: inline-flex; gap: 4px; align-items: center; }

@media (max-width: 720px) {
  .top .tabs { display: none; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .top { padding-top: calc(10px + env(safe-area-inset-top)); }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { display: grid; justify-items: center; gap: 2px; padding: 7px 0 6px; font-size: 11px; color: var(--muted); text-decoration: none; position: relative; }
  .bottom-nav a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .bottom-nav a.active { color: var(--accent); font-weight: 600; }
  .bottom-nav .badge-count { position: absolute; top: 3px; left: calc(50% + 6px); margin: 0; }
  .pair-box { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .cat-grid button { padding: 13px 10px; }
}
@media (display-mode: standalone) {
  .top { position: sticky; }
}
.stack label.inline, label.inline { flex-wrap: nowrap; align-items: flex-start; }
label.inline > input[type=checkbox], label.inline > input[type=radio] { flex: none; margin-top: 2px; }
.list li > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.w-90 { width: 90px; }
.budgets td a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); }
[data-view=settings] .row > button { flex: 0 0 auto; }
#push-here > button { justify-self: start; }
@media (max-width: 720px) { [data-view=settings] .row > button, #push-here > button { flex: 1 1 auto; justify-self: stretch; } }

/* ---- Phase 4: accounts ---- */
.who-chip { color: var(--muted); font-size: 13px; max-width: 14ch; overflow: hidden; text-overflow: ellipsis; }
.who-chip:empty { display: none; }
button.danger { background: var(--panel); color: var(--neg); border-color: var(--neg); }
button.link.neg { color: var(--neg); }
.kind.neg { color: var(--neg); border-color: var(--neg); }
.kind.muted { opacity: .8; }
.block { display: block; margin-top: 4px; }
.nowrap { flex-wrap: nowrap; } .row.nowrap > * { flex: 0 0 auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; width: 100%; }
.confirm-box { border: 1px solid var(--neg); border-radius: 10px; padding: 12px 14px; }
.gate-card #gate-body { width: 100%; }
.gate-card #gate-text .block { color: var(--muted); }
.gate-alt { display: grid; gap: 2px; }
.gate-alt button.link, .gate-card button.link { width: auto; justify-self: center; font-size: 14px; padding: 6px; }
.gate-card label { text-align: left; }
.gate-card label.inline { justify-content: center; }
.gate-foot { color: var(--muted); }
.codes { columns: 2; margin: 0; padding: 12px 12px 12px 34px; background: var(--chip); border-radius: 10px; text-align: left; }
.codes li { padding: 2px 0; }
.codes code { font-size: 15px; letter-spacing: 0.04em; }
.gate-card .row { justify-content: center; }
.gate-card .row > button { width: auto; flex: 1 1 0; }
#setup-form, #invite-form { align-items: end; }
#setup-form > label, #invite-form > label { flex: 1 1 220px; }
#setup-form > button, #invite-form > button { flex: 0 0 auto; }
#invite-box .stack { min-width: 0; }
@media (max-width: 720px) { .who-chip { display: none; } .codes { columns: 1; } }
/* privacy notice */
body.doc { background: var(--bg); }
.doc-main { max-width: 720px; margin: 0 auto; padding: 24px 20px 64px; }
.doc-main h1 { font-size: 28px; margin: 8px 0 4px; }
.doc-main h3 { margin-top: 28px; }
.doc-main li { margin: 6px 0; }
.doc-main .notice { margin: 16px 0; }
.personal-app { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.personal-app summary { cursor: pointer; font-weight: 550; }
.personal-app[open] summary { margin-bottom: 10px; }
.steps { margin: 0; padding-left: 20px; color: var(--muted); }
.steps li { margin: 3px 0; }
a.btn-secondary { display: inline-block; text-decoration: none; text-align: center; border-radius: 8px; }

/* ---------- Phase 5: friendlier everywhere, made for phones ---------- */
html { -webkit-text-size-adjust: 100%; }
button, a, input, select, label, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
select, input, textarea { max-width: 100%; }
.stack > *, .stack label > *, .row > * { min-width: 0; }
.stack label > input:not([type=checkbox]):not([type=radio]), .stack label > select, .stack label > textarea { width: 100%; }
.panel-head { flex-wrap: wrap; }
.page-title { display: none; }

/* Sync: one icon that spins while syncing */
#sync-btn { display: inline-flex; align-items: center; gap: 8px; }
#sync-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
#sync-btn:disabled svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #sync-btn:disabled svg { animation: none; } }

/* Shop avatars: logo, or the first letter on a colour from the name */
.av { width: 32px; height: 32px; border-radius: 9px; flex: none; object-fit: cover; background: var(--chip); }
.av.letter { display: grid; place-items: center; font-weight: 650; font-size: 14px; color: hsl(var(--h) 45% 30%);
  background: hsl(var(--h) 55% 92%); }
.av.lg { width: 44px; height: 44px; border-radius: 12px; font-size: 18px; }
@media (prefers-color-scheme: dark) { .av.letter { color: hsl(var(--h) 60% 80%); background: hsl(var(--h) 25% 22%); } }
.desc { align-items: center; }
tr.day { display: none; }
#filter-toggle { display: none; }
.m-only { display: none; }
.bud-input { width: 110px; text-align: right; }
.pager button { min-width: 96px; }

/* Review card: nothing may push it wider than the screen */
.rcard > *, .rcard .rtop .what { min-width: 0; }
.rcard .rtop { align-items: flex-start; }
.rcard .rtop .what { flex: 1; }
.rcard .more select { min-width: 0; flex: 1 1 160px; }
.rcard label.inline { overflow-wrap: anywhere; }

@media (max-width: 720px) {
  :root { font-size: 16px; }
  /* 16px stops iPhones zooming in when a field is tapped; 44px is a comfortable finger */
  input, select, textarea { font-size: 16px; min-height: 44px; padding: 8px 12px; }
  input[type=checkbox], input[type=radio] { min-height: 0; width: 20px; height: 20px; }
  button, .btn-secondary { min-height: 44px; padding: 10px 16px; font-size: 16px; }
  button.link { min-height: 40px; padding: 8px 10px; }
  .fchip button { min-height: 32px; }
  label.inline { min-height: 40px; }

  /* Header: page name + sync icon */
  .top { padding: calc(8px + env(safe-area-inset-top)) 16px 8px; flex-wrap: nowrap; }
  .brand { display: none; }
  .page-title { display: block; flex: 1; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
  #sync-btn { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 50%;
    background: var(--chip); color: var(--ink); border-color: transparent; }
  #sync-btn .lbl { display: none; }
  main { padding: 12px 16px 24px; }
  h2 { margin-top: 24px; }
  .panel { padding: 16px; border-radius: 14px; }
  .panel .table-wrap { margin: 0 -16px; }

  /* Overview: net worth first, then assets and owing side by side */
  .networth { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
  .networth > div:first-child { grid-column: 1 / -1; }
  .big { font-size: 34px; }
  .mid { font-size: 18px; }
  .accounts { grid-template-columns: 1fr; gap: 8px; }
  .card { padding: 14px 16px; }
  .list li { padding: 10px 0; }

  /* Activity: search + a Filters button; the rest opens below it */
  .filters { gap: 8px; }
  .filters input[type=search] { flex: 1 1 0; min-width: 0; }
  #filter-toggle { display: inline-flex; gap: 6px; align-items: center; flex: none; }
  #filter-toggle .badge-count { margin: 0; }
  .filters:not(.open) > :not(input[type=search]):not(#filter-toggle) { display: none !important; }
  .filters.open > select, .filters.open > label { flex: 1 1 calc(50% - 4px); }
  .filters.open > label { display: grid; gap: 4px; }
  .filters.open > label input { width: 100%; }
  .filters.open > button[type=reset], .filters.open > #csv { flex: 1 1 calc(50% - 4px); text-align: center; }
  .tx-totals { font-size: 14px; gap: 4px 16px; }

  /* Activity list: grouped by day, one tappable row per transaction */
  .table-wrap { border-radius: 14px; }
  table.tx thead { display: none; }
  table.tx tr.day { display: table-row; }
  table.tx tr.day td { padding: 14px 16px 6px; font-size: 13px; font-weight: 650; color: var(--muted); background: var(--bg); border-top: 0; }
  .table-wrap > table.tx tr.day:first-child td { padding-top: 10px; }
  table.tx:not(.budgets) td.date, table.tx:not(.budgets) td.cat, table.tx:not(.budgets) td.acct { display: none; }
  table.tx:not(.budgets) td { padding: 12px 16px; border-top: 1px solid var(--line); }
  table.tx:not(.budgets) tr.day + tr td { border-top: 0; }
  table.tx:not(.budgets) td.num { font-size: 16px; font-weight: 600; padding-left: 4px; }
  .desc { gap: 12px; align-items: flex-start; }
  .desc img, .desc .av { display: grid; width: 36px; height: 36px; }
  .desc .main { font-size: 16px; }
  .desc .meta { font-size: 13px; }
  .desc .cat-btn { margin-top: 4px; }
  .pager { gap: 8px; }

  /* Budgets: one card per category instead of a five-column table */
  table.budgets, table.budgets tbody { display: block; }
  table.budgets tr { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 14px 16px; border-top: 1px solid var(--line); align-items: center; }
  table.budgets tr:first-child { border-top: 0; }
  table.budgets td { display: block; padding: 0; border: 0 !important; }
  table.budgets td.avg { display: none; }
  table.budgets td.spent { grid-column: 2; grid-row: 1; font-size: 17px; font-weight: 650; }
  table.budgets td.spent a { color: var(--ink); text-decoration: none; }
  table.budgets td.prog { grid-column: 1 / -1; min-width: 0 !important; }
  table.budgets td.bud { grid-column: 1 / -1; text-align: left; }
  table.budgets td.bud .money-in { width: 100%; gap: 8px; }
  table.budgets td.bud .m-only { display: inline; flex: 1; }
  .bud-input { width: 120px; }

  /* Edit transaction: a sheet from the bottom of the screen */
  dialog { width: 100%; max-width: 100%; max-height: 92vh; margin: auto 0 0; border-radius: 18px 18px 0 0; border-width: 1px 0 0;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; }
  dialog .row.end { justify-content: stretch; }
  dialog .row.end > * { flex: 1 1 auto; }
  dialog .row.end > button.link { flex-basis: 100%; order: 3; }

  /* Review: big, easy targets */
  .rcard { padding: 16px; }
  .rcard .who { font-size: 18px; }
  .rcard .amt { font-size: 18px; }
  .rcard .more { flex-wrap: wrap; }
  .rcard .more select, .rcard .more button { flex: 1 1 100%; }

  /* Rules and settings: one field per line */
  .row > * { flex: 1 1 100%; }
  .row > button, .row > .btn-secondary, .row.end > * { flex: 1 1 auto; }
  .list li { flex-wrap: wrap; }
  .list li > .row, .list li > button { flex: 0 0 auto; }
  .panel-head .row { flex-wrap: nowrap; }
  .cat-list .c { min-height: 40px; }
  .hbar { padding: 8px 6px; font-size: 14px; }
  .tiles .tile .v { font-size: 17px; }
}
@media (max-width: 380px) {
  .big { font-size: 30px; }
  .tiles { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .desc .main, .desc .meta, .rcard .who, .rcard .meta { overflow-wrap: break-word; word-break: normal; }
  .desc .cat-btn .grp { display: none; }
  .desc .cat-btn { padding: 0; margin: 6px 0 0; }
  .desc .cat-btn .why { display: none; }
  .review-head h3 { display: none; }
  .review-head { justify-content: flex-end; }
  table.budgets td.spent a { display: inline-block; padding: 8px 0; }
}
tr.tx-row { cursor: pointer; }
tr.tx-row:hover td { background: color-mix(in srgb, var(--chip) 45%, transparent); }
@media (hover: none) { tr.tx-row:hover td { background: none; } tr.tx-row:active td { background: var(--chip); } }
@media (max-width: 720px) {
  table.tx:not(.budgets), table.tx:not(.budgets) tbody { display: block; }
  table.tx:not(.budgets) tr.day, table.tx:not(.budgets) tr.day td { display: block; }
  table.tx:not(.budgets) tr.tx-row { display: flex; border-top: 1px solid var(--line); }
  table.tx:not(.budgets) tr.day + tr.tx-row { border-top: 0; }
  table.tx:not(.budgets) tr.tx-row td { border-top: 0; }
  table.tx:not(.budgets) tr.tx-row td:nth-child(2) { flex: 1; min-width: 0; padding-right: 8px; }
  table.tx:not(.budgets) tr.tx-row td.num { flex: none; padding-left: 0; }
  table.tx:not(.budgets) td.empty { display: block; }
}
@media (max-width: 720px) {
  .filters input[type=search] { flex: 1 1 60%; }
  .filters.open > label { align-self: end; }
}
