:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --track: #e4e7ec;
  --border: #e4e7ec;
  --text: #0f1729;
  --muted: #667085;
  --accent: #0f766e;
  --accent-soft: #e6f6f3;
  --accent-ink: #ffffff;
  --neg: #d92d20;
  --pos: #067647;
  --shadow: 0 1px 2px rgb(16 24 40 / 5%), 0 1px 3px rgb(16 24 40 / 6%);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e14;
    --surface: #131720;
    --surface-2: #1b202b;
    --track: #262c3a;
    --border: #232938;
    --text: #e8ebf1;
    --muted: #8b95a7;
    --accent: #2dd4bf;
    --accent-soft: rgb(45 212 191 / 10%);
    --accent-ink: #042f2a;
    --neg: #f97066;
    --pos: #4ade80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
h2 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.neg { color: var(--neg) !important; }
.pos { color: var(--pos); }
.cur { font-size: 0.62em; font-weight: 500; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.note { font-size: 13px; color: var(--muted); }
.push { margin-left: auto; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1120px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.logo { width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.logo svg { width: 18px; height: 18px; }
.month-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  box-shadow: var(--shadow);
}
.month-label { border: 0; background: none; padding: 5px 8px; font-weight: 600; min-width: 132px; border-radius: 999px; }
.month-label:not(.is-current) { color: var(--accent); }
.icon-btn { border: 0; background: none; width: 34px; height: 34px; border-radius: 999px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- layout ---------- */
main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 16px calc(100px + env(safe-area-inset-bottom));
  display: grid;
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.section-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; min-height: 32px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; min-width: 0; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent;
  background: var(--surface-2);
  padding: 9px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger-ghost { background: transparent; color: var(--neg); border-color: color-mix(in srgb, var(--neg) 35%, transparent); }
.btn.danger-ghost:hover { background: color-mix(in srgb, var(--neg) 8%, transparent); }
:is(.btn, .row, .box-card, .icon-btn, .chip, .month-label, .fab):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- onboarding ---------- */
.onboard {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.onboard p { margin: 0; flex: 1; }

/* ---------- summary ---------- */
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 2px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.hero { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.stat.hero :is(.stat-label, .stat-sub, .cur) { color: inherit; opacity: 0.8; }
.stat.hero.is-neg { background: var(--neg); color: #fff; }

/* ---------- allocation ---------- */
.alloc-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--track); gap: 2px; }
.alloc-bar span { display: block; height: 100%; min-width: 3px; transition: width 0.3s ease; }
.alloc-bar .unalloc { background: repeating-linear-gradient(-45deg, var(--track) 0 5px, color-mix(in srgb, var(--muted) 25%, var(--track)) 5px 10px); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.legend b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- boxes ---------- */
.boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.box-card {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  min-width: 0;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.box-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--c); }
.box-card:hover { border-color: color-mix(in srgb, var(--c) 50%, var(--border)); }
.box-card:active { transform: scale(0.98); }
.box-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.box-icon { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-size: 18px; flex: none; background: color-mix(in srgb, var(--c) 16%, transparent); }
.box-rule { font-size: 11.5px; color: var(--muted); background: var(--surface-2); padding: 3px 8px; border-radius: 999px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.box-name { font-weight: 600; font-size: 14px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box-amount { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { height: 6px; border-radius: 999px; background: var(--track); overflow: hidden; margin-top: 2px; }
.meter > span { display: block; height: 100%; background: var(--c); border-radius: inherit; transition: width 0.3s ease; }
.meter.over > span { background: var(--neg); }
.box-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.box-foot b { color: var(--text); font-weight: 600; }
.box-card.add { border-style: dashed; box-shadow: none; background: transparent; align-items: center; justify-content: center; color: var(--muted); font-weight: 600; min-height: 150px; }
.box-card.add::before { display: none; }
.box-card.static { cursor: default; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--border); }
.row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  background: none;
  border: 0;
  text-align: left;
  border-radius: 10px;
  min-width: 0;
}
.row:hover { background: var(--surface-2); }
.row-icon { width: 36px; height: 36px; border-radius: 11px; flex: none; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 16%, transparent); font-size: 16px; }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-amt.in { color: var(--pos); }
.fixed-row { display: flex; align-items: center; }
.paid { display: grid; place-items: center; width: 40px; height: 44px; flex: none; cursor: pointer; }
.paid input { width: 19px; height: 19px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.fixed-row.is-paid .row-title { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.list-foot { display: flex; justify-content: space-between; gap: 8px; padding: 10px 6px 0; margin-top: 2px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.list-foot b { color: var(--text); font-variant-numeric: tabular-nums; }
.empty { padding: 20px 6px; color: var(--muted); font-size: 14px; text-align: center; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; margin: -4px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--border); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; white-space: nowrap; font-weight: 500; flex: none; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- floating add button (mobile) ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 20px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 28px rgb(0 0 0 / 22%);
  display: none;
  place-items: center;
  z-index: 15;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(0.95); }

/* ---------- dialog ---------- */
dialog {
  border: 0;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border-radius: 20px;
  width: min(480px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100dvh - 48px);
  box-shadow: 0 24px 64px rgb(0 0 0 / 30%);
  overflow: hidden;
}
dialog::backdrop { background: rgb(8 12 20 / 45%); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
dialog[open] { animation: pop 0.18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
#modalForm { display: flex; flex-direction: column; max-height: inherit; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 4px 20px; }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.title-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 16%, transparent); font-size: 17px; flex: none; }
.modal-body {
  padding: 8px 20px 4px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px 12px;
  align-content: start;
}
.modal-body > * { grid-column: 1 / -1; }
.modal-body > .half { grid-column: span 3; }
.modal-body > .w1 { grid-column: span 1; }
.modal-body > .w5 { grid-column: span 5; }
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  margin-top: 14px;
  flex-wrap: wrap;
}
.spacer { flex: 1; }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input[type="text"], .field input[type="date"], .field select {
  width: 100%;
  height: 46px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 12px;
  padding: 0 12px;
  font-size: 16px;
  outline: none;
  min-width: 0;
}
.field input[type="date"] { -webkit-appearance: none; appearance: none; }
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.field input.icon-input { text-align: center; font-size: 20px; padding: 0 4px; }
.input-wrap { position: relative; }
.input-wrap input { padding-right: 58px !important; }
.input-wrap.big input { height: 58px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.suffix { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; font-weight: 600; pointer-events: none; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.segment { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 3px; border-radius: 12px; gap: 3px; }
.segment label { position: relative; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span { display: block; text-align: center; padding: 9px 4px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segment input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(16 24 40 / 12%), 0 0 0 1px var(--border); }
.segment input:focus-visible + span { outline: 2px solid var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatches label { position: relative; }
.swatches input { position: absolute; opacity: 0; }
.swatches span { display: block; width: 30px; height: 30px; border-radius: 50%; background: var(--c); cursor: pointer; }
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.swatches input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 500; cursor: pointer; }
.check input { width: 19px; height: 19px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.form-error { margin: 0; color: var(--neg); font-size: 13.5px; font-weight: 500; }
.detail-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.detail-stats div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: grid; min-width: 0; }
.detail-stats span { font-size: 12px; color: var(--muted); }
.detail-stats b { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-body h4 { margin: 4px 0 -8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.modal-body .list .row { padding-left: 0; padding-right: 0; }
.settings-block { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.settings-block h4 { margin: 0 !important; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  z-index: 50;
  box-shadow: 0 10px 30px rgb(0 0 0 / 25%);
  max-width: calc(100vw - 32px);
  animation: pop 0.18s ease-out;
}
.toast button { border: 0; background: color-mix(in srgb, var(--bg) 18%, transparent); color: inherit; font-weight: 700; padding: 4px 12px; border-radius: 999px; margin-right: -6px; }

/* ---------- sign in ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 4px 0 -8px; font-size: 24px; letter-spacing: -0.02em; }
.login-card .note { margin: 0 0 4px; }
.logo.big { width: 48px; height: 48px; border-radius: 14px; }
.logo.big svg { width: 26px; height: 26px; }
.btn.block { width: 100%; padding: 12px 16px; font-size: 15px; }
.btn:disabled { opacity: 0.6; cursor: progress; }

/* ---------- view switchers ---------- */
.subbar { max-width: 1120px; margin: 10px auto 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.seg-switch, .tabs, .segment.as-tabs { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 999px; gap: 2px; min-width: 0; }
.seg-switch:empty { display: none; }
.seg-switch button, .tabs button, .segment.as-tabs button {
  border: 0;
  background: none;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.seg-switch button.on, .tabs button.on, .segment.as-tabs button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(16 24 40 / 12%), 0 0 0 1px var(--border); }
.tabs svg { width: 16px; height: 16px; flex: none; }
.segment.as-tabs { display: flex; border-radius: 12px; }
.segment.as-tabs button { flex: 1; border-radius: 9px; padding: 8px; }

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--pos); flex: none; }
.sync[data-s="saving"] i { background: #f59e0b; }
.sync[data-s="offline"] i { background: var(--neg); }
.sync[data-s="offline"] { color: var(--neg); }

/* partner's wallet is read-only */
.ro .edit-only { display: none !important; }
.ro .row:not([data-act="box"]) { cursor: default; }
.ro .row:hover { background: none; }

.view { display: grid; gap: 16px; min-width: 0; }
.empty-card { text-align: center; padding: 32px 20px; }
.empty-card h2 { font-size: 17px; }
.empty-card .note { margin: 6px 0 0; }
.big-emoji { font-size: 36px; margin: 0 0 8px; }
.tag { background: var(--surface-2); border-radius: 999px; padding: 0 6px; font-size: 11.5px; }
.who-tag { font-weight: 600; color: var(--text); }
.row.static { cursor: default; }
.row.static:hover { background: none; }

/* ---------- category picker ---------- */
.cat-pick {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 12px;
  padding: 6px 12px 6px 6px;
  min-height: 50px;
  text-align: left;
}
.cat-pick:focus-visible, .cat-pick[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); outline: none; }
.cat-pick-text { flex: 1; min-width: 0; display: grid; }
.cat-pick-text b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-pick-text small { font-size: 12px; color: var(--muted); }
.caret { color: var(--muted); font-size: 12px; }
.cat-quick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.cat-quick::-webkit-scrollbar { display: none; }
.cat-panel { border: 1px solid var(--border); border-radius: 14px; padding: 10px; display: grid; gap: 10px; background: var(--bg); }
.cat-search {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 16px;
  outline: none;
}
.cat-search:focus { border-color: var(--accent); }
.cat-list { max-height: min(46dvh, 360px); overflow-y: auto; display: grid; gap: 12px; padding-right: 2px; overscroll-behavior: contain; }
.cat-group { display: grid; gap: 6px; }
.cat-group h5 { margin: 0; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-chip {
  border: 1px solid color-mix(in srgb, var(--c) 28%, var(--border));
  background: color-mix(in srgb, var(--c) 9%, var(--surface));
  border-radius: 999px;
  padding: 5px 11px 5px 7px;
  font-size: 13px;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex: none;
}
.cat-chip:hover { border-color: var(--c); }
.cat-chip.on { background: var(--c); border-color: var(--c); color: #fff; }
.cat-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field input[type="password"] {
  width: 100%;
  height: 46px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 12px;
  padding: 0 12px;
  font-size: 16px;
  outline: none;
}
.field input[type="password"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------- icon picker ---------- */
.icon-pick {
  width: 100%;
  height: 46px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 12px;
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
  position: relative;
  transition: border-color 0.15s ease;
}
.icon-pick::after { content: "▾"; position: absolute; right: 4px; bottom: 3px; font-size: 9px; color: var(--muted); }
.icon-pick:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.icon-pick:focus-visible, .icon-pick[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); outline: none; }
.icon-panel { border: 1px solid var(--border); border-radius: 14px; padding: 10px; display: grid; gap: 10px; background: var(--bg); }
.icon-search, .icon-own-input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 16px;
  outline: none;
}
.icon-search:focus, .icon-own-input:focus { border-color: var(--accent); }
.icon-scroll { max-height: min(40dvh, 300px); overflow-y: auto; display: grid; gap: 10px; overscroll-behavior: contain; }
.icon-group { display: grid; gap: 4px; }
.icon-group h5 { margin: 0; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; }
.icon-opt { aspect-ratio: 1; border: 0; background: none; border-radius: 10px; font-size: 22px; line-height: 1; display: grid; place-items: center; padding: 0; }
.icon-opt:hover { background: var(--surface-2); }
.icon-opt.on { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.icon-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.icon-own { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); font-weight: 500; }
.icon-own span { flex: 1; }
.icon-own-input { width: 72px; flex: none; text-align: center; font-size: 20px; padding: 0 6px; }

/* ---------- together ---------- */
.people { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.person { text-align: left; display: grid; gap: 8px; font: inherit; color: inherit; transition: border-color 0.15s ease; }
.person:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.person-head { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.person-left { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.person-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 4px; }
.person-stats span { display: grid; min-width: 0; }
.person-stats small { font-size: 12px; color: var(--muted); }
.person-stats b { font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- balances ---------- */
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.acc-card {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.acc-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--c); }
.acc-card:hover { border-color: color-mix(in srgb, var(--c) 50%, var(--border)); }
.acc-card:active { transform: scale(0.99); }
.acc-balance { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-sub { font-size: 12.5px; color: var(--muted); }
.acc-sub b { font-weight: 650; font-variant-numeric: tabular-nums; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 34px; margin: 2px 0; }
.spark i { flex: 1; background: color-mix(in srgb, var(--c) 40%, var(--track)); border-radius: 3px 3px 1px 1px; min-height: 3px; }
.spark i.is-cur { background: var(--c); }
.spark i.neg-bar { background: var(--neg); }
.acc-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.acc-stats span { display: grid; min-width: 0; }
.acc-stats small { font-size: 11.5px; color: var(--muted); }
.acc-stats b { font-size: 13.5px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-title { display: flex; align-items: center; gap: 10px; font-size: 17px; margin-top: 6px; }
.report-head .note { margin: 4px 0 0; }
.acc-total { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.acc-total span { color: var(--muted); font-size: 13px; font-weight: 600; }
.acc-total b { font-size: 26px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.acc-table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.acc-table th { text-align: right; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.acc-table td { text-align: right; padding: 8px 4px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.acc-table :is(th, td):first-child { text-align: left; }
.acc-table tr.is-cur td { background: var(--accent-soft); }
.acc-table td.pos { color: var(--pos); }

/* ---------- reports ---------- */
.report-head h2 { font-size: 18px; }
.breakdown { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 20px; align-items: start; }
.donut-wrap { position: relative; width: 170px; aspect-ratio: 1; }
.donut { width: 100%; height: 100%; display: block; }
.donut-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.15; }
.donut-label b { font-size: 19px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.donut-label small { font-size: 11.5px; color: var(--muted); }
.glist, .clist { list-style: none; margin: 0; padding: 0; }
.glist > li + li { border-top: 1px solid var(--border); }
.glist summary { list-style: none; display: flex; align-items: center; gap: 12px; padding: 9px 4px; cursor: pointer; border-radius: 10px; }
.glist summary::-webkit-details-marker { display: none; }
.glist summary:hover { background: var(--surface-2); }
.glist summary:focus-visible { outline: 2px solid var(--accent); }
.gbar { display: block; height: 5px; border-radius: 999px; background: var(--track); margin-top: 5px; overflow: hidden; }
.gbar > span { display: block; height: 100%; background: var(--c); border-radius: inherit; }
.row-amt small { display: block; text-align: right; font-size: 11.5px; color: var(--muted); font-weight: 500; }
.clist { padding: 0 4px 10px 52px; display: grid; gap: 4px; font-size: 13.5px; }
.clist li { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.clist b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.trend { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; height: 180px; align-items: end; }
.tcol { display: grid; grid-template-rows: 1fr auto; height: 100%; gap: 6px; min-width: 0; }
.tbars { display: flex; align-items: flex-end; justify-content: center; gap: 3px; height: 100%; border-bottom: 1px solid var(--border); }
.tb { width: min(14px, 28%); border-radius: 4px 4px 0 0; min-height: 2px; transition: height 0.3s ease; }
.tb.inc, .legend i.inc { background: color-mix(in srgb, var(--muted) 45%, var(--track)); }
.tb.aside, .legend i.aside { background: #6366f1; }
.tb.spent, .legend i.spent { background: var(--accent); }
.tlabel { text-align: center; font-size: 12px; color: var(--muted); }
.tcol.is-cur .tlabel { color: var(--text); font-weight: 700; }
.tcol.off { opacity: 0.35; }
.ytd-note { margin-top: 10px; }
.ytd-note b { color: var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .brand-name { display: none; }
  .month-label { min-width: 0; }
  main { gap: 14px; }
  .summary { gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 20px; }
  .boxes { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .box-card { padding: 12px; }
  .box-amount { font-size: 18px; }
  .box-card.add { min-height: 120px; }
  .fab { display: grid; }
  .hide-sm { display: none; }
  .onboard { flex-direction: column; align-items: stretch; }
  dialog {
    width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
  }
  dialog[open] { animation: sheet 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
  @keyframes sheet { from { transform: translateY(100%); } }
  .modal-actions .btn { flex: 1; }
  .modal-actions .spacer { display: none; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }

  /* top: whose wallet; bottom: section tabs with the add button in the middle */
  /* (a backdrop-filter would make the header the containing block of the fixed tab bar) */
  .topbar { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--bg); }
  .sync span { display: none; }
  .seg-switch.who { display: flex; width: 100%; }
  .seg-switch.who button { flex: 1; padding: 7px 8px; }
  .tabs {
    position: fixed;
    z-index: 14;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) 62px; /* three tabs, then room for the + button */
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 6px;
    box-shadow: 0 8px 28px rgb(0 0 0 / 16%);
  }
  .ro .tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tabs button { flex-direction: column; gap: 2px; padding: 6px 2px; border-radius: 16px; font-size: 11.5px; }
  .tabs button.on { box-shadow: none; background: var(--accent-soft); color: var(--accent); }
  .tabs svg { width: 20px; height: 20px; }
  .fab { right: 20px; bottom: calc(15px + env(safe-area-inset-bottom)); width: 52px; height: 52px; border-radius: 17px; z-index: 25; box-shadow: 0 6px 16px rgb(0 0 0 / 20%); }
  .acc-grid { grid-template-columns: minmax(0, 1fr); }
  main { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }

  .breakdown { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .breakdown .glist { width: 100%; }
  .donut-wrap { width: 180px; }
  .people { grid-template-columns: minmax(0, 1fr); }
  .person-left { font-size: 22px; }
  .trend { height: 150px; gap: 4px; }
  .section-head { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
