:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201d;
  --muted: #6b7672;
  --line: #e6eae8;
  --accent: #107a63;
  --accent-soft: #e2f2ec;
  --travel: #2f6fd6;
  --travel-soft: #e4edfb;
  --income: #0f8a4f;
  --danger: #d23c3c;
  --bar-bg: #e9eeec;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1312;
    --card: #1a201e;
    --text: #e8eeeb;
    --muted: #8d9894;
    --line: #2a3230;
    --accent: #3cbf98;
    --accent-soft: #183229;
    --travel: #6c9ff0;
    --travel-soft: #1b2638;
    --income: #4cc787;
    --danger: #f06a6a;
    --bar-bg: #2a3230;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}
body.locked { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3 { margin: 0; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; }
h3 { font-size: 15px; margin-bottom: 6px; }

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 0 4px; }
.neg { color: var(--danger) !important; }
.pos { color: var(--income); }

.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 4px 0 14px;
}
.page-head small { color: var(--muted); }
.page-head h1 { flex: 1; }
.page-head .icon-btn + h1 { text-align: center; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-size: 24px; color: var(--accent);
}
.text-btn { color: var(--accent); font-size: 15px; padding: 6px 2px; }
.text-btn.strong { font-weight: 600; }

.card {
  display: block;
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card.slim { padding: 11px 16px; font-size: 14px; }
.card.flush { padding: 0; }
.card.link:active { opacity: .7; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row + .row, .bar + .row { margin-top: 6px; }
.big { font-size: 30px; font-weight: 700; letter-spacing: -.5px; margin: 6px 0 10px; font-variant-numeric: tabular-nums; }
.mid { font-size: 20px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
.grid2, .grid3 { display: grid; gap: 12px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid3 .card { padding: 10px 12px; }
.grid3 .mid { font-size: 16px; }

.hero { padding: 16px; }

.bar { height: 8px; border-radius: 4px; background: var(--bar-bg); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.bar.over i { background: var(--danger); }

.notice {
  display: block; padding: 10px 14px; margin-bottom: 12px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); font-size: 14px;
}

.calc { list-style: none; padding: 0; margin: 8px 0; }
.calc li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-variant-numeric: tabular-nums; }
.calc li span:last-child { text-align: right; }
.dots { margin: 0; padding-left: 18px; }
.dots li { margin: 3px 0; }

.sec-head { display: flex; justify-content: space-between; align-items: baseline; margin: 20px 4px 8px; }
.sec-head a { color: var(--accent); font-size: 14px; }
.day-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin: 16px 4px 6px; }
.empty { text-align: center; color: var(--muted); padding: 28px 0; }

.txs { list-style: none; margin: 0 0 12px; }
.tx { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; }
.tx + .tx { border-top: 1px solid var(--line); }
.tx:active { background: var(--bar-bg); }
.tx-icon {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 18px; background: var(--accent-soft);
}
.tx-icon.travel { background: var(--travel-soft); }
.tx-main { flex: 1; min-width: 0; }
.tx-main b { font-weight: 550; display: flex; align-items: center; gap: 6px; }
.tx-main small { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-style: normal; font-size: 11px; font-weight: 500; color: var(--travel); background: var(--travel-soft); padding: 1px 6px; border-radius: 6px; }
.tx-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amt.in { color: var(--income); }

.pill { font-size: 12px; color: var(--muted); background: var(--bar-bg); padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.pill.now { color: var(--accent); background: var(--accent-soft); }

.chips { display: flex; gap: 8px; margin: 2px 0 12px; overflow-x: auto; }
.chip { padding: 6px 14px; border-radius: 16px; background: var(--card); color: var(--muted); font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent); color: #fff; }

.breakdown { margin-top: 8px; }
.bd-row { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 10px; padding: 4px 0; font-size: 14px; }
.bd-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bd-bar { height: 8px; background: var(--bar-bg); border-radius: 4px; overflow: hidden; }
.bd-bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bd-val { font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; }

.wide-btn {
  display: block; width: 100%; text-align: center; padding: 12px; margin: 0 0 12px;
  border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.wide-btn.ghost { background: var(--accent-soft); color: var(--accent); }
.wide-btn.danger { background: transparent; color: var(--danger); margin-top: 16px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.btn-row .wide-btn { margin: 0; }

/* 底部导航 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); padding: 2px 0; }
.tabbar a .ti { font-size: 20px; filter: grayscale(1); opacity: .6; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on .ti { filter: none; opacity: 1; }
.add-btn {
  justify-self: center; width: 52px; height: 52px; border-radius: 50%; margin-top: -18px;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 4px 12px rgba(16, 122, 99, .35);
}

/* 弹出表单 */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto;
  max-width: 560px; margin: 0 auto;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 0 12px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bar-bg); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { padding: 7px 0; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.amount {
  display: flex; align-items: center; gap: 6px; background: var(--card);
  border-radius: 14px; padding: 10px 16px; margin-bottom: 12px;
}
.amount span { font-size: 26px; font-weight: 600; color: var(--muted); }
.amount input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font-family: inherit; font-size: 32px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums;
}
.amount.travel span { color: var(--travel); }
.amount.income span { color: var(--income); }

.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px; border-radius: 12px; background: var(--card); font-size: 12px; color: var(--muted);
  border: 1.5px solid transparent;
}
.cat span { font-size: 22px; }
.cat.on { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }

.field {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border-radius: 12px; padding: 4px 16px; margin-bottom: 8px; min-height: 48px;
}
.field span { flex: none; color: var(--muted); font-size: 14px; }
.field input, .field select {
  flex: 1; min-width: 0; text-align: right; border: 0; outline: 0; background: transparent; color: var(--text);
  font-family: inherit; font-size: 16px; padding: 10px 0; -webkit-appearance: none; appearance: none;
}
.field input[type="date"], .field input[type="month"] { display: flex; justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); z-index: 30;
  transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
  background: rgba(20, 24, 23, .88); color: #fff; padding: 9px 16px; border-radius: 20px; font-size: 14px;
  transition: .2s; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 统计图：类别色按固定顺序（饮食、交通、社交娱乐、日用品、其他） */
:root { --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --grid: #e6eae8; }
@media (prefers-color-scheme: dark) {
  :root { --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --grid: #2a3230; }
}
.more { margin-top: 10px; font-size: 13px; color: var(--accent); }
.chart h3 { margin-bottom: 2px; }
.chart-svg { display: block; width: 100%; height: auto; margin-top: 8px; overflow: visible; }
.chart-svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart-svg .axis { fill: var(--muted); font-size: 10px; }
.chart-svg .val { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart-svg .col { fill: var(--accent); }
.chart-svg .col.over { fill: var(--danger); }
.chart-svg .ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.chart-svg .hit { fill: transparent; cursor: pointer; }
.chart-svg .hit.on { fill: var(--text); fill-opacity: .06; }
.chart-tip { text-align: center; font-size: 13px; color: var(--muted); margin-top: 4px; min-height: 18px; }

.stack { display: flex; gap: 2px; height: 14px; margin: 12px 0 10px; }
.stack i { border-radius: 2px; min-width: 3px; }
.stack i:first-child { border-radius: 4px 2px 2px 4px; }
.stack i:last-child { border-radius: 2px 4px 4px 2px; }
.legend { list-style: none; margin: 0; padding: 0; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto 72px; align-items: center; gap: 10px; padding: 5px 0; font-size: 14px; }
.legend li + li { border-top: 1px solid var(--line); }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend b { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
