:root {
  color-scheme: light;
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #f6f5f3;
  --surface-3: #efede9;
  --border: #e8e6e1;
  --border-strong: #d9d6cf;
  --text: #1c1f26;
  --text-2: #5c6270;
  --muted: #8d929c;
  --accent: #ff692d;
  --accent-soft: #fff0e9;
  --accent-text: #d4501a;
  --income: #1baf7a;
  --expense: #eb6834;
  --line: #2a78d6;
  --line-soft: rgba(42, 120, 214, .12);
  --compare: #c2c0ba;
  --pos: #188a5c;
  --neg: #d23a3a;
  --warn: #b26b00;
  --grid: #efede9;
  --shadow: 0 1px 2px rgba(28, 31, 38, .04), 0 1px 3px rgba(28, 31, 38, .04);
  --shadow-lg: 0 12px 40px rgba(28, 31, 38, .16);
  --radius: 12px;
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100; --c5: #e87ba4; --c6: #008300; --c7: #6250d6; --c8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121212;
    --surface: #1b1b1b;
    --surface-2: #222221;
    --surface-3: #2a2a29;
    --border: #2d2d2b;
    --border-strong: #3a3a37;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #ff7a45;
    --accent-soft: #3a2218;
    --accent-text: #ff9b70;
    --income: #199e70;
    --expense: #d95926;
    --line: #3987e5;
    --line-soft: rgba(57, 135, 229, .16);
    --compare: #55544f;
    --pos: #3fbf86;
    --neg: #ef6b6b;
    --warn: #e0a030;
    --grid: #262624;
    --shadow: none;
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; }
body { min-height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
svg.lucide { width: 18px; height: 18px; stroke-width: 1.8; flex-shrink: 0; }

/* --- Sidebar --- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  /* The visible height: on iPad and iPhone Safari, 100vh includes the space behind the address bar and
     toolbar, which pushed Sync accounts (at the bottom) off screen whenever those bars showed. */
  height: 100dvh;
}
.brand { font-weight: 700; font-size: 18px; padding: 4px 12px 20px; display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 26px; height: 26px; border-radius: 7px; }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tabbar { display: none; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; min-height: 0; }
nav a, .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-2);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 500;
  background: none;
  border: none;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  text-align: left;
}
nav a:hover, .nav-link:hover { background: var(--surface-2); color: var(--text); }
nav a.active, .nav-link.active { background: var(--accent-soft); color: var(--accent-text); }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; border-radius: 10px; padding: 1px 7px; }
.sidebar-foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 10px; }
.sync-status { color: var(--muted); font-size: 11px; padding: 2px 12px; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Page --- */
main { padding: 26px 32px 60px; min-width: 0; max-width: 1360px; width: 100%; margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; min-height: 38px; flex-wrap: wrap; }
h1 { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
h3 { font-size: 13px; font-weight: 600; margin: 0; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.grid { display: grid; gap: 20px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-main-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px 0; }
.card-head a, .card-link { color: var(--accent-text); font-weight: 500; font-size: 13px; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.card-body { padding: 16px 20px 20px; }
.card-body.flush { padding: 8px 0 8px; }
.sticky { position: sticky; top: 20px; }

.big-number { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.mid-number { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.label { color: var(--text-2); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.change { font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 3px; }
.change svg { width: 14px; height: 14px; }

.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }
.chart-box.short { height: 160px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.line { height: 2px; border-radius: 1px; vertical-align: 3px; width: 14px; }
.legend i.dashed { background: repeating-linear-gradient(90deg, var(--compare) 0 4px, transparent 4px 7px) !important; }

/* --- Controls --- */
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 11px;
  min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); padding: 0; }
.input-icon { position: relative; display: flex; align-items: center; }
.input-icon svg { position: absolute; left: 10px; color: var(--muted); width: 16px; height: 16px; pointer-events: none; }
.input-icon input { padding-left: 34px; }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  text-decoration: none;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); filter: none; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-danger { background: transparent; color: var(--neg); border-color: var(--border-strong); }
.btn-icon { padding: 7px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.link { background: none; border: none; color: var(--accent-text); cursor: pointer; padding: 0; font: inherit; font-weight: 500; }
.link.danger { color: var(--neg); }

.segmented { display: inline-flex; background: var(--surface-3); border-radius: 8px; padding: 3px; gap: 2px; }
.segmented button {
  font: inherit; font-size: 12px; font-weight: 600; border: none; background: none; color: var(--text-2);
  padding: 5px 11px; border-radius: 6px; cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.month-picker { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 2px; }
.month-picker span { min-width: 128px; text-align: center; font-weight: 600; font-size: 13px; }
.month-picker button { border: none; background: none; color: var(--text-2); cursor: pointer; padding: 5px 7px; border-radius: 6px; display: flex; }
.month-picker button:hover { background: var(--surface-2); }

/* --- Pills, chips, progress --- */
.cat-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 7px; border-radius: 999px; background: var(--surface-2); font-size: 12.5px; font-weight: 500; color: var(--text); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tag-chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid var(--border-strong); color: var(--text-2); }
.tag-chip i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.badge { font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 6px; }
.badge.accent { color: var(--accent-text); border-color: transparent; background: var(--accent-soft); }
.remaining { font-weight: 600; font-size: 12.5px; padding: 3px 9px; border-radius: 999px; font-variant-numeric: tabular-nums; display: inline-block; }
.remaining.ok { background: rgba(24, 138, 92, .1); color: var(--pos); }
.remaining.over { background: rgba(210, 58, 58, .1); color: var(--neg); }
.remaining.none { color: var(--muted); }

.progress { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.progress.thin { height: 5px; }
.progress > div { height: 100%; background: var(--income); border-radius: 0 4px 4px 0; transition: width .3s; }
.progress.expense > div { background: var(--line); }
.progress.over > div { background: var(--neg); }
.progress.goal > div { background: var(--accent); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 650; font-size: 13px; flex-shrink: 0; color: #fff;
}
.avatar.sq { border-radius: 9px; }
.emoji-box { width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); display: inline-flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0; }

/* --- Lists & tables --- */
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 20px; border-top: 1px solid var(--border); cursor: pointer; }
.list-row:first-child { border-top: none; }
.list-row:hover { background: var(--surface-2); }
.list-row.static { cursor: default; }
.list-row.static:hover { background: none; }
.list-title { font-weight: 500; }
.list-sub { color: var(--muted); font-size: 12px; }
.amount { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; text-align: right; }
.amount.in { color: var(--pos); }

.tx-group-head { display: flex; justify-content: space-between; padding: 10px 20px; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 600; border-top: 1px solid var(--border); }
.tx-group-head:first-child { border-top: none; border-radius: var(--radius) var(--radius) 0 0; }
.tx-row { display: grid; grid-template-columns: 24px minmax(160px, 1.4fr) minmax(130px, 1fr) minmax(120px, .9fr) 110px; gap: 14px; align-items: center; padding: 10px 20px; border-top: 1px solid var(--border); cursor: pointer; }
.tx-row:hover { background: var(--surface-2); }
.compact .tx-row { grid-template-columns: 12px minmax(0, 1fr) auto 96px; }
.compact .tx-account { display: none; }
.tx-row.selected { background: var(--accent-soft); }
.tx-merchant { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tx-merchant .avatar { width: 30px; height: 30px; font-size: 12px; }
.tx-account { color: var(--text-2); font-size: 12.5px; }
.unreviewed-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; flex-shrink: 0; }
.tx-flags { display: inline-flex; gap: 4px; margin-left: 6px; }

table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 20px; border-bottom: 1px solid var(--border); }
.table td { padding: 11px 20px; border-top: 1px solid var(--border); vertical-align: middle; }
.table tr:first-child td { border-top: none; }
.table th.r, .table td.r { text-align: right; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--surface-2); }
.table-scroll { overflow-x: auto; }
.table td.num { white-space: nowrap; }
/* Coins table: when its card is narrow (iPad with the side column), the amount moves under the coin name. */
.coins-wrap { container-type: inline-size; }
.coin-qty-inline { display: none; }
@container (max-width: 620px) {
  .coins-table .coin-qty-col { display: none; }
  .coin-qty-inline { display: inline; }
  .coins-table .list-sub { max-width: 130px !important; }
  .coins-table th, .coins-table td { padding-left: 16px; padding-right: 16px; }
}

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filters select { max-width: 200px; }
.bulk-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--text); color: var(--bg); border-radius: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.bulk-bar select { background: var(--bg); }

/* --- Account groups --- */
.acct-group-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; cursor: pointer; user-select: none; }
.acct-group-head .chev { transition: transform .15s; color: var(--muted); }
.acct-group.collapsed .chev { transform: rotate(-90deg); }
.acct-group.collapsed .acct-group-body { display: none; }
.acct-group + .acct-group { border-top: 1px solid var(--border); }

/* --- Budget table --- */
.budget-table { width: 100%; border-collapse: collapse; }
.budget-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; text-align: right; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.budget-table th:first-child { text-align: left; padding-left: 20px; width: 46%; }
.budget-table td { padding: 8px 16px; border-top: 1px solid var(--border); text-align: right; font-variant-numeric: tabular-nums; }
.budget-table td:first-child { text-align: left; padding-left: 20px; }
.budget-table tr.group td { background: var(--surface-2); font-weight: 600; padding-top: 10px; padding-bottom: 10px; }
.budget-table tr.section td { font-weight: 700; font-size: 15px; padding-top: 18px; border-top: none; background: none; }
.budget-table input { width: 104px; text-align: right; padding: 5px 8px; border-color: transparent; background: transparent; }
.budget-table input:hover { border-color: var(--border-strong); }
.budget-table .cat-cell { display: flex; align-items: center; gap: 10px; }
.budget-table .cat-cell .bar { flex: 0 1 110px; }
.budget-table .cat-cell a { min-width: 90px; }
.rollover-btn { opacity: .35; }
.rollover-btn.on { opacity: 1; color: var(--accent-text); }
tr:hover .rollover-btn { opacity: 1; }

/* --- Breakdown bars --- */
.bar-list { display: flex; flex-direction: column; }
.bar-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 20px; border-top: 1px solid var(--border); cursor: pointer; }
.bar-item:first-child { border-top: none; }
.bar-item:hover { background: var(--surface-2); }
.bar-item .progress { grid-column: 1 / -1; height: 6px; }
.bar-item .pct { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* --- Calendar --- */
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); }
.cal-dow { padding: 8px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; text-align: center; }
.cal-day { min-height: 92px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 6px; font-size: 12px; }
.cal-day:nth-child(7n) { border-right: none; }
.cal-day.other { background: var(--surface-2); color: var(--muted); }
.cal-day.today .cal-num { background: var(--accent); color: #fff; border-radius: 50%; }
.cal-num { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; font-weight: 600; }
.cal-item { display: block; font-size: 11px; padding: 2px 6px; border-radius: 5px; background: var(--surface-3); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-item.paid { text-decoration: line-through; color: var(--muted); }
.cal-item.income { background: rgba(27, 175, 122, .14); }

/* --- Goals --- */
.goal-card { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.goal-emoji { font-size: 26px; width: 48px; height: 48px; border-radius: 12px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; }

/* --- Drawer & modal --- */
.drawer-backdrop, .modal-backdrop { position: fixed; inset: 0; background: rgba(15, 17, 21, .32); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 100vw; background: var(--surface);
  box-shadow: var(--shadow-lg); z-index: 50; transform: translateX(105%); transition: transform .2s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 18px; }
.drawer-foot { padding: 14px 20px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: space-between; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field-row { display: flex; gap: 12px; }
.field-row > * { flex: 1; min-width: 0; }  /* let paired fields shrink inside narrow cards */
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-picker label { cursor: pointer; }
.tag-picker input { display: none; }
.tag-picker input:checked + .tag-chip { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }

.modal-backdrop { display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 55; }  /* above drawers: a modal can open from one */
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
.modal-head { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 0 22px 20px; display: flex; justify-content: flex-end; gap: 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 22px; }
.tabs button { background: none; border: none; font: inherit; font-weight: 600; font-size: 13px; color: var(--muted); padding: 10px 6px; margin-right: 12px; border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button.on { color: var(--text); border-color: var(--accent); }

.notice { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; color: var(--text-2); font-size: 13px; }
.notice.accent { background: var(--accent-soft); color: var(--accent-text); }
.review-banner { display: flex; align-items: center; gap: 12px; padding: 14px 20px; }
.error { color: var(--neg); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 36px; height: 36px; margin-bottom: 8px; color: var(--border-strong); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px; max-width: 480px;
  box-shadow: var(--shadow-lg); font-weight: 500;
}

@media (max-width: 1100px) {
  .cols-main-side { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  body { grid-template-columns: 1fr; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .sidebar { display: none; }
  main { padding: calc(14px + env(safe-area-inset-top)) 16px 24px; }
  h1 { font-size: 22px; }
  .page-header { margin-bottom: 14px; gap: 8px; }
  .page-actions { width: 100%; }
  .page-actions .btn { padding: 7px 11px; }
  .grid { gap: 12px; }
  .stack { gap: 12px; }
  .cols-2, .cols-3 { grid-template-columns: 1fr; }
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-head { padding: 14px 16px 0; }
  .card-body { padding: 14px 16px 16px; }
  .list-row, .tx-group-head, .bar-item { padding-left: 16px; padding-right: 16px; }
  .big-number { font-size: 26px; }
  .cols-4 .big-number, .cols-3 .big-number { font-size: 20px !important; }
  .chart-box { height: 200px; }
  .chart-box.tall { height: 230px; }
  .tx-row { grid-template-columns: 10px minmax(0, 1fr) auto; gap: 10px; padding: 10px 16px; }
  .tx-row .tx-cat, .tx-row .tx-account { display: none; }
  .compact .tx-row { grid-template-columns: 10px minmax(0, 1fr) auto; }
  .filters select, .filters .input-icon, .filters .input-icon input { max-width: none; width: 100%; }
  .filters > * { flex: 1 1 140px; }
  .table th, .table td { padding-left: 14px; padding-right: 14px; }
  .budget-table .hide-sm, .table .hide-sm { display: none; }
  .budget-table .cat-cell .bar { display: none; }
  .budget-table input { width: 80px; }
  .budget-table th, .budget-table td { padding-left: 8px; padding-right: 8px; }
  .segmented button { padding: 5px 8px; }
  .month-picker span { min-width: 104px; }
  .drawer { width: 100vw; padding-top: env(safe-area-inset-top); }
  .drawer-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
  .cal-day { min-height: 64px; padding: 3px; }
  .cal-item { font-size: 9.5px; padding: 1px 3px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; font: inherit; font-size: 10.5px; font-weight: 600;
    color: var(--muted); text-decoration: none; background: none; border: none; padding: 4px 0; cursor: pointer;
  }
  .tabbar svg.lucide { width: 22px; height: 22px; }
  .tabbar .active { color: var(--accent-text); }
}

/* --- Heads-up alerts --- */
.alert-row { display: flex; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); align-items: flex-start; }
.alert-row:first-child { border-top: none; }
.alert-icon { width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--line-soft); color: var(--line); }
.alert-row.warning .alert-icon { background: rgba(178, 107, 0, .12); color: var(--warn); }
.alert-icon svg { width: 16px; height: 16px; }
.cal-item.event { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
@media (max-width: 760px) { .alert-row { padding: 12px 16px; } }

/* --- Quick import --- */
.dropzone { display: flex; gap: 14px; align-items: center; padding: 18px; border: 2px dashed var(--border-strong); border-radius: 12px; color: var(--text-2); transition: background .15s, border-color .15s; }
.dropzone > svg { width: 28px; height: 28px; color: var(--muted); flex-shrink: 0; }
.dropzone.ready { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.dropzone.ready > svg { color: var(--accent-text); }
.dropzone.drop-over { border-color: var(--accent); background: var(--accent-soft); }
.qi-list { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; max-height: 46vh; overflow-y: auto; }
.qi-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); cursor: pointer; transition: background .1s; }
.qi-row:first-child { border-top: none; }
.qi-row:hover, .qi-row:focus-visible { background: var(--surface-2); outline: none; }
.qi-row.drop-over { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.qi-row.busy { opacity: .55; pointer-events: none; }
.qi-cta { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--accent-text); white-space: nowrap; }
.qi-cta svg { width: 15px; height: 15px; }
.qi-new .emoji-box svg { width: 16px; height: 16px; }
.qi-result { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); margin-top: 8px; font-size: 13px; }
.qi-result > svg { width: 18px; height: 18px; color: var(--pos); flex-shrink: 0; margin-top: 1px; }
.qi-result.error-row > svg { color: var(--neg); }
.qi-result.undone > svg { color: var(--muted); }
.qi-result .link { margin-left: 10px; }
.drop-overlay { position: fixed; inset: 0; z-index: 70; background: rgba(15, 17, 21, .45); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.drop-overlay > div { background: var(--surface); border: 2px dashed var(--accent); border-radius: 18px; padding: 34px 48px; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: var(--shadow-lg); }
.drop-overlay svg { width: 40px; height: 40px; color: var(--accent); }
.drop-overlay b { font-size: 17px; }
.drop-overlay span { color: var(--muted); font-size: 13px; }
@media (max-width: 760px) { .qi-cta span { display: none; } .dropzone { padding: 14px; } }

/* --- Linked transfers --- */
.link-badge { display: inline-flex; align-items: center; gap: 3px; color: var(--line); border-color: var(--line-soft); background: var(--line-soft); }
.link-badge svg { width: 11px; height: 11px; }
.link-box { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.link-box > svg { width: 18px; height: 18px; color: var(--line); flex-shrink: 0; }
.link-candidates { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.link-candidate { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: none; border-top: 1px solid var(--border); background: var(--surface); font: inherit; color: inherit; text-align: left; cursor: pointer; }
.link-candidate:first-child { border-top: none; }
.link-candidate:hover { background: var(--accent-soft); }

/* --- Categorize inbox --- */
.cat-group { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); transition: opacity .3s, background .3s; }
.cat-group:first-child { border-top: none; }
.cat-group.done { opacity: .3; background: var(--accent-soft); }
.cat-group .cat-pick { width: 200px; }
@media (max-width: 760px) { .cat-group { flex-wrap: wrap; padding: 12px 16px; } .cat-group .cat-pick { width: 100%; } }
.warn-text { color: var(--warn); }
.best-plan { box-shadow: inset 0 0 0 2px var(--accent); }

/* --- Receipts & splits --- */
.receipts { display: flex; flex-wrap: wrap; gap: 8px; }
.receipt { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.receipt img { width: 100%; height: 100%; object-fit: cover; display: block; }
.receipt-file { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 100%; padding: 6px; font-size: 10px; color: var(--text-2); text-align: center; word-break: break-all; text-decoration: none; }
.receipt-file svg { width: 22px; height: 22px; }
.receipt a { color: inherit; text-decoration: none; }
.receipt-del { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: none; background: rgba(0,0,0,.55); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.receipt-del svg { width: 13px; height: 13px; }
.tx-flags .badge svg { width: 11px; height: 11px; vertical-align: -1px; margin-right: 2px; }

/* --- Household view switcher --- */
.view-switch { display: flex; align-items: center; gap: 8px; margin: 0 4px 14px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; color: var(--text-2); }
.view-switch svg { width: 16px; height: 16px; }
.view-switch select { border: none; padding: 2px 0; background: transparent; font-weight: 600; flex: 1; }
@media (max-width: 760px) { #view-switch { display: none; } }

/* Phones: wide tables scroll inside their card instead of widening the page. */
@media (max-width: 760px) {
  .card { overflow-x: auto; }
  .table select { max-width: 104px; padding: 4px 6px; font-size: 12px; }
  .table td, .table th { white-space: nowrap; }
  .table td .list-sub, .table td .ellipsis { white-space: normal; }
}

/* --- Where your money went --- */
.where-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 18px 0 10px; gap: 2px; background: var(--surface); }
.where-bar span { min-width: 3px; }
.where-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 5px 0; font-size: 13px; color: inherit; text-decoration: none; border-radius: 6px; }
a.where-row:hover { background: var(--surface-2); }
.where-row i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }

/* Monthly review */
.rv-cat { display: block; padding: 8px 0; color: inherit; text-decoration: none; border-top: 1px solid var(--border); }
.rv-cat:first-child { border-top: 0; }
.rv-bar { height: 8px; border-radius: 4px; margin-top: 6px; }
.rv-bar span { display: block; height: 100%; border-radius: 4px; background: var(--c1); min-width: 2px; }
.rv-bar.prev { height: 3px; margin-top: 3px; }
.rv-bar.prev span { background: var(--muted, #9ca3af); opacity: .6; }

/* Ask */
.ask-card { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 420px; }
.ask-log { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.ask-empty { margin: auto; text-align: center; max-width: 560px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.ask-empty svg { width: 28px; height: 28px; color: var(--c1); }
.ask-msg { max-width: 760px; padding: 10px 14px; border-radius: 12px; line-height: 1.55; }
.ask-msg p { margin: 0 0 6px; } .ask-msg ul { margin: 4px 0 6px; padding-left: 20px; }
.ask-msg.me { align-self: flex-end; background: var(--c1); color: #fff; }
.ask-msg.bot { align-self: flex-start; background: var(--bg-2, rgba(127,127,127,.08)); border: 1px solid var(--border); }
.ask-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.ask-input input { flex: 1; }
.chip { border: 1px solid var(--border); background: transparent; color: inherit; border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--c1); }
.spin-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c1); animation: askpulse 1s infinite alternate; }
@keyframes askpulse { from { opacity: .3; } to { opacity: 1; } }
@media (max-width: 760px) { .ask-card { height: calc(100vh - 220px); } }

/* On/off switch (Settings → Sidebar) */
input[type="checkbox"].switch { appearance: none; -webkit-appearance: none; width: 36px; height: 20px; border-radius: 999px; padding: 0;
  background: var(--border-strong); border: 0; position: relative; cursor: pointer; transition: background .15s; flex: none; }
input[type="checkbox"].switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
input[type="checkbox"].switch:checked { background: var(--accent); }
input[type="checkbox"].switch:checked::after { transform: translateX(16px); }
input[type="checkbox"].switch:disabled { opacity: .45; cursor: default; }

/* Account icons */
.avatar-img { overflow: hidden; box-shadow: inset 0 0 0 1px var(--border); }
.avatar-img img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.avatar svg { width: 18px; height: 18px; color: #fff; }
.avatar-emoji { font-size: 18px; }
.avatar.big { width: 56px; height: 56px; font-size: 22px; border-radius: 14px; }
.avatar.big svg { width: 28px; height: 28px; }
.avatar.big.avatar-emoji { font-size: 28px; }
.avatar-btn { background: none; border: 0; padding: 0; cursor: pointer; border-radius: 9px; }
.avatar-btn:hover .avatar { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
.icon-choice { height: 40px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.icon-choice:hover { border-color: var(--accent); color: var(--accent); }
.icon-choice svg { width: 18px; height: 18px; }

/* Crypto price chart: coin chips double as the legend */
.cp-chip { display: inline-flex; align-items: center; gap: 6px; opacity: .55; user-select: none; }
.cp-chip.on { opacity: 1; border-color: var(--border-strong); }
.cp-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.cp-chip:not(.on) .cp-dot { background: transparent !important; box-shadow: inset 0 0 0 2px var(--muted); }
.cp-x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 0 0 2px; font-size: 15px; line-height: 1; }
.cp-x:hover { color: var(--text); }
#cp-add svg { width: 13px; height: 13px; vertical-align: -2px; margin-right: 4px; }
.coin-av { position: relative; overflow: hidden; }
.coin-av .coin-logo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #fff; }
.cp-chip .coin-logo { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; }
.logo-av { position: relative; overflow: hidden; }
.logo-av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 2px; opacity: 0; }

/* Cloud copy: "Confirm it's you" dialog (core.js confirmIdentity) */
dialog.reauth { border: none; padding: 0; color: inherit; max-width: min(420px, calc(100vw - 32px)); }
dialog.reauth::backdrop { background: rgba(0, 0, 0, 0.45); }
