/* ---------- Tokens (shared look with 拾页) ---------- */
:root {
  --bg: #fafaf9; --surface: #ffffff; --surface-hover: #f5f5f4; --surface-sunk: #f5f5f4;
  --border: #e7e5e4; --border-strong: #d6d3d1;
  --text: #1c1917; --text-muted: #78716c; --text-faint: #a8a29e;
  --shadow: 0 1px 2px rgba(28, 25, 23, .05); --shadow-lift: 0 12px 32px rgba(28, 25, 23, .14);
  --danger: #dc2626; --accent: #2f6fde; --accent-ui: var(--accent);
  --accent-soft: color-mix(in srgb, var(--accent-ui) 12%, transparent);
  --pos: #15803d; --warn-bg: #fef3c7; --warn-text: #92400e;
  --bar: #2f6fde; --bar-track: #f0efed;
  --av-bg-l: 92%; --av-bg-s: 55%; --av-fg-l: 34%; --av-fg-s: 45%;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --num: ui-rounded, -apple-system, "SF Pro Rounded", "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131313; --surface: #1c1c1c; --surface-hover: #252525; --surface-sunk: #171717;
    --border: #2a2a2a; --border-strong: #3a3a3a;
    --text: #ededec; --text-muted: #9a9a98; --text-faint: #6b6b69;
    --shadow: none; --shadow-lift: 0 12px 32px rgba(0, 0, 0, .5);
    --accent-ui: color-mix(in srgb, var(--accent) 70%, white);
    --pos: #4ade80; --warn-bg: #3a2d0c; --warn-text: #fcd34d;
    --bar: #5b8def; --bar-track: #262626;
    --av-bg-l: 24%; --av-bg-s: 28%; --av-fg-l: 78%; --av-fg-s: 55%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131313; --surface: #1c1c1c; --surface-hover: #252525; --surface-sunk: #171717;
  --border: #2a2a2a; --border-strong: #3a3a3a;
  --text: #ededec; --text-muted: #9a9a98; --text-faint: #6b6b69;
  --shadow: none; --shadow-lift: 0 12px 32px rgba(0, 0, 0, .5);
  --accent-ui: color-mix(in srgb, var(--accent) 70%, white);
  --pos: #4ade80; --warn-bg: #3a2d0c; --warn-text: #fcd34d;
  --bar: #5b8def; --bar-track: #262626;
  --av-bg-l: 24%; --av-bg-s: 28%; --av-fg-l: 78%; --av-fg-s: 55%;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-muted); font-weight: 400; }
.small { font-size: 12px; }
.spacer { flex: 1; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; }

.page { max-width: 760px; margin: 0 auto; padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 9px; cursor: pointer;
  font-size: 14px; color: var(--text); white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { height: 30px; font-size: 13px; padding: 0 10px; }
.btn.wide { width: 100%; height: 40px; }
.btn.danger-text { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; background: transparent;
  border-radius: 8px; color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn.bordered { border: 1px solid var(--border); background: var(--surface); height: 34px; width: 34px; }
.input, .select {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); outline: none; font-size: 14px;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; }
.input:focus, .select:focus { border-color: var(--accent-ui); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.big { height: 48px; font: 600 24px/1 var(--num); font-variant-numeric: tabular-nums; }
.select.small { width: auto; height: 34px; font-size: 13px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); cursor: pointer; user-select: none; white-space: nowrap; }
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; }
.form-error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }
.hint { color: var(--text-muted); font-size: 13px; margin: 12px 2px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.stack { display: grid; gap: 8px; }

/* ---------- Gate ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate-card { width: min(340px, 100%); display: grid; gap: 10px; text-align: center; }
.gate-card h1 { margin: 4px 0 0; font-size: 20px; }
.gate-logo { margin: 0 auto; border-radius: 11px; }
.gate-sub { margin: 0 0 6px; color: var(--text-muted); font-size: 13px; }

/* ---------- Header ---------- */
.header { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.wordmark { font-size: 15px; font-weight: 600; letter-spacing: .08em; color: var(--text-muted); margin-right: 6px; }
.month-nav { display: flex; align-items: center; gap: 2px; }
.month-label { border: 0; background: transparent; font-weight: 600; font-size: 15px; padding: 4px 6px; border-radius: 6px; cursor: pointer; font-variant-numeric: tabular-nums; }
.month-label:hover { background: var(--surface-hover); }

/* ---------- Totals ---------- */
.totals { display: flex; align-items: flex-end; gap: 28px; flex-wrap: wrap; margin: 24px 2px 18px; }
.total { display: grid; gap: 2px; }
.total-label { font-size: 12px; color: var(--text-muted); }
.total-value { font: 600 17px/1.2 var(--num); font-variant-numeric: tabular-nums; }
.total.hero .total-value { font-size: 34px; letter-spacing: -.01em; }
.pending-chip {
  margin-left: auto; align-self: center; border: 0; border-radius: 999px; padding: 5px 12px; cursor: pointer;
  background: var(--warn-bg); color: var(--warn-text); font-size: 13px; font-weight: 500;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab { border: 0; background: transparent; padding: 8px 12px; font-size: 14px; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }

/* ---------- Flow ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search { flex: 1 1 220px; display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text-faint); }
.search:focus-within { border-color: var(--accent-ui); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 14px; min-width: 0; }
.day { margin-bottom: 14px; }
.day-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); padding: 0 4px 6px; }
.day-rows { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.tx { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.tx + .tx { border-top: 1px solid var(--border); }
.tx:hover { background: var(--surface-hover); }
.avatar { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 14px; font-weight: 600;
  background: hsl(var(--h) var(--av-bg-s) var(--av-bg-l)); color: hsl(var(--h) var(--av-fg-s) var(--av-fg-l)); }
.avatar.transfer { --h: 220; background: var(--surface-sunk); color: var(--text-muted); }
.tx-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.tx-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { flex: none; text-align: right; display: grid; gap: 1px; }
.tx-amount .v { font: 600 15px/1.2 var(--num); font-variant-numeric: tabular-nums; }
.tx-amount .v.in { color: var(--pos); }
.tx-amount .v.move { color: var(--text-muted); font-weight: 500; }
.tx-amount .fx { font-size: 11px; color: var(--text-faint); }
.badge { display: inline-block; font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 999px; background: var(--warn-bg); color: var(--warn-text); margin-left: 6px; vertical-align: 1px; }
.clip { color: var(--text-faint); margin-left: 4px; }
.empty { text-align: center; color: var(--text-muted); padding: 48px 16px; font-size: 14px; }
.empty b { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ---------- Cards / stats ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-title { font-size: 13px; font-weight: 600; margin: 0 0 12px; color: var(--text-muted); }
.bars { display: grid; gap: 2px; }
.bar-row { display: grid; grid-template-columns: 5.5em 1fr auto; align-items: center; gap: 10px; padding: 6px 4px; border: 0; background: transparent; width: 100%; text-align: left; border-radius: 8px; cursor: pointer; }
.bar-row:hover { background: var(--surface-hover); }
.bar-row.child { grid-template-columns: 5.5em 1fr auto; padding-left: 18px; cursor: default; }
.bar-row.child:hover { background: transparent; }
.bar-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row.child .bar-name { font-size: 13px; color: var(--text-muted); }
.bar-track { height: 10px; background: var(--bar-track); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row.child .bar-fill { opacity: .55; }
.bar-val { font: 500 13px/1 var(--num); font-variant-numeric: tabular-nums; text-align: right; min-width: 7.5em; }
.bar-val .pct { color: var(--text-faint); margin-left: 6px; font-size: 12px; }
.trend { display: grid; grid-template-columns: repeat(6, 1fr); align-items: end; gap: 10px; height: 170px; padding-top: 18px; }
.trend-col { display: grid; grid-template-rows: 1fr auto; height: 100%; gap: 6px; cursor: default; }
.trend-bar-wrap { display: flex; align-items: flex-end; justify-content: center; position: relative; }
.trend-bar { width: min(34px, 70%); background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .45; }
.trend-col.current .trend-bar { opacity: 1; }
.trend-col:hover .trend-bar { opacity: .8; }
.trend-val { position: absolute; bottom: calc(100% + 2px); font: 500 11px/1 var(--num); color: var(--text-muted); white-space: nowrap; }
.trend-label { text-align: center; font-size: 12px; color: var(--text-muted); }
.trend-col.current .trend-label { color: var(--text); font-weight: 600; }
.plain-list { display: grid; }
.plain-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; font-size: 14px; }
.plain-row + .plain-row { border-top: 1px solid var(--border); }
.plain-row .v { margin-left: auto; font: 500 14px/1 var(--num); font-variant-numeric: tabular-nums; }
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, calc(-100% - 8px)); }

/* ---------- Accounts ---------- */
.networth { display: flex; gap: 28px; flex-wrap: wrap; margin: 4px 2px 16px; }
.acct-list { display: grid; }
.acct { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border: 0; background: transparent; width: 100%; text-align: left; cursor: pointer; border-radius: 8px; }
.acct + .acct { border-top: 1px solid var(--border); }
.acct:hover { background: var(--surface-hover); }
.acct .v { margin-left: auto; font: 600 15px/1 var(--num); font-variant-numeric: tabular-nums; }
.acct.archived { opacity: .5; }

/* ---------- Dialogs ---------- */
.dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lift); width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
.dialog.narrow { width: min(420px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dialog-body { display: grid; gap: 12px; padding: 16px 18px 18px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { font-size: 16px; margin: 0; }
.dialog-foot { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--text-muted); min-width: 0; }
.seg { display: flex; background: var(--surface-sunk); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 6px 4px; border-radius: 7px; font-size: 13px; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.seg.small button { padding: 4px; font-size: 12px; }
.fx summary { font-size: 13px; color: var(--text-muted); cursor: pointer; }
.fx .row { margin-top: 8px; }
.images { display: flex; gap: 8px; flex-wrap: wrap; }
.images:empty { display: none; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-sunk); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.thumb button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; font-size: 13px; line-height: 1; }
.thumb.new::after { content: "待上传"; position: absolute; left: 0; right: 0; bottom: 0; font-size: 10px; text-align: center; background: rgba(0, 0, 0, .5); color: #fff; }
.file-btn { justify-self: start; }
.meta-line { font-size: 12px; color: var(--text-faint); margin: 0; }
.meta-line:empty { display: none; }
.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .85); display: grid; place-items: center; cursor: zoom-out; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* Settings */
.sub-title { font-size: 13px; margin: 14px 0 4px; }
.cat-tree { display: grid; gap: 2px; max-height: 50vh; overflow: auto; margin: 10px 0; }
.cat { display: flex; align-items: center; gap: 6px; padding: 5px 4px; border-radius: 6px; font-size: 14px; }
.cat:hover { background: var(--surface-hover); }
.cat.child { padding-left: 22px; font-size: 13px; color: var(--text-muted); }
.cat .count { font-size: 12px; color: var(--text-faint); }
.cat .acts { margin-left: auto; display: flex; gap: 2px; opacity: 0; }
.cat:hover .acts, .cat:focus-within .acts { opacity: 1; }
.cat .acts button { border: 0; background: transparent; color: var(--text-muted); font-size: 12px; cursor: pointer; padding: 2px 6px; border-radius: 5px; }
.cat .acts button:hover { background: var(--surface); color: var(--text); }
.inline-form { display: flex; gap: 8px; }
[data-pane] { display: grid; gap: 4px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70;
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow-lift); display: flex; gap: 12px; align-items: center; }
.toast button { border: 0; background: transparent; color: var(--accent-ui); font-weight: 600; cursor: pointer; padding: 0; filter: brightness(1.4); }

@media (max-width: 560px) {
  .header .lbl { display: none; }
  .header .btn.primary { width: 34px; padding: 0; }
  .wordmark { display: none; }
  .totals { gap: 18px; margin-top: 18px; }
  .total.hero { flex-basis: 100%; }
  .total.hero .total-value { font-size: 30px; }
  .pending-chip { margin-left: 0; }
  .bar-row, .bar-row.child { grid-template-columns: 4.5em 1fr auto; gap: 8px; }
  .bar-val { min-width: 0; }
  .bar-val .pct { display: none; }
  .cat .acts { opacity: 1; }
}
@media (hover: none) { .cat .acts { opacity: 1; } }
