/* 记账本 —— 极简风：暖白底、细线、黑色主按钮、大号数字 */
:root {
  --ink: #1b1d21;
  --sub: #8b909a;
  --faint: #b9bdc5;
  --bg: #f7f7f5;
  --card: #ffffff;
  --line: #ecebe8;
  --chip: #f2f2ef;
  --expense: #e5484d;
  --income: #30a46c;
  --radius: 18px;
  --tabbar-h: 56px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 18px 4px;
}
.month-nav { display: flex; align-items: center; gap: 2px; }
.month-label { font-size: 16px; font-weight: 600; min-width: 108px; text-align: center; letter-spacing: .02em; }
.nav-btn {
  border: none; background: none; color: var(--sub);
  width: 32px; height: 32px; border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.nav-btn:active { background: var(--chip); color: var(--ink); }
.top-right { display: flex; align-items: center; gap: 10px; }
.today-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--sub);
  font-size: 12px; padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.today-btn:active { color: var(--ink); border-color: var(--faint); }
.sync-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--sub); cursor: default;
}
.sync-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); display: inline-block; }
.sync-chip b { font-weight: 500; }
.sync-chip.ok i { background: var(--income); }
.sync-chip.busy i { background: #f0b429; animation: blink 1s infinite; }
.sync-chip.warn i { background: #f0b429; }
.sync-chip.err i { background: var(--expense); }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- 结余卡 ---------- */
.hero {
  margin: 12px 18px 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 16px;
}
.hero-k { font-size: 12px; color: var(--sub); letter-spacing: .05em; }
.hero-v {
  font-size: 34px; font-weight: 700; margin-top: 6px;
  font-variant-numeric: tabular-nums; letter-spacing: -.01em;
}
.hero-v.neg { color: var(--expense); }
.hero-row { display: flex; gap: 28px; margin-top: 14px; }
.hero-cell { display: flex; flex-direction: column; gap: 2px; }
.hero-cell .k { font-size: 11.5px; color: var(--sub); }
.hero-cell .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.v.expense { color: var(--expense); }
.v.income { color: var(--income); }

/* ---------- 主视图 ---------- */
main { flex: 1; padding: 12px 18px calc(var(--tabbar-h) + 22px + env(safe-area-inset-bottom)); }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.empty { text-align: center; color: var(--faint); padding: 44px 10px; font-size: 14px; }
.empty .big { font-size: 30px; display: block; margin-bottom: 10px; opacity: .6; }

/* ---------- 安装引导条 ---------- */
.install-banner {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 18px 0; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
}
.ib-ico { font-size: 20px; flex: none; }
.ib-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ib-txt b { font-size: 13px; }
.ib-txt em { font-style: normal; font-size: 11px; color: var(--sub); }
.ib-btn {
  border: none; background: var(--ink); color: #fff; font-size: 13px;
  padding: 7px 18px; border-radius: 9px; cursor: pointer; font-weight: 600; flex: none;
}
.ib-x { border: none; background: none; color: var(--faint); font-size: 14px; cursor: pointer; padding: 4px; flex: none; }
.ib-help {
  display: none; flex-basis: 100%; font-size: 12px; color: var(--sub);
  line-height: 1.8; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 2px;
}
.install-banner { flex-wrap: wrap; }
.install-banner .ib-help[hidden] { display: none; }
.install-banner .ib-help:not([hidden]) { display: block; }

/* ---------- 账本切换 ---------- */
.ledger-row {
  display: flex; gap: 8px; padding: 8px 18px 0;
  overflow-x: auto; scrollbar-width: none;
}
.ledger-row::-webkit-scrollbar { display: none; }
.lchip {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--sub);
  font-size: 12.5px; padding: 6px 13px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  transition: all .15s ease;
}
.lchip.on { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
.lchip-add { border-style: dashed; color: var(--faint); background: transparent; }
.lchip-add:active { border-color: var(--ink); color: var(--ink); }

/* ---------- 账本管理行 ---------- */
.mrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mrow:last-child { border-bottom: none; }
.mico {
  width: 32px; height: 32px; border-radius: 50%; background: var(--chip);
  display: flex; align-items: center; justify-content: center; font-size: 15px; flex: none;
}
.mname { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }
.mname em { display: block; font-style: normal; font-size: 11.5px; color: var(--faint); font-weight: 400; margin-top: 1px; }
.mini {
  border: 1px solid var(--line); background: var(--card); color: var(--sub);
  font-size: 12px; padding: 5px 11px; border-radius: 8px; cursor: pointer; flex: none;
}
.mini:active { border-color: var(--faint); color: var(--ink); }
.mini.danger { color: var(--expense); border-color: #f3c5bd; }

/* ---------- 日历总览 ---------- */
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head span { text-align: center; font-size: 10.5px; color: var(--faint); padding-bottom: 4px; }
.cal-cell {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  min-height: 46px; padding: 5px 0 3px; border-radius: 10px;
}
.cal-cell.pad { min-height: 0; padding: 0; }
.cal-cell .cd { font-size: 12.5px; font-weight: 600; color: var(--sub); line-height: 1.25; }
.cal-cell .ce, .cal-cell .ci { font-size: 8.5px; line-height: 1.35; font-variant-numeric: tabular-nums; visibility: hidden; }
.cal-cell.has { background: var(--chip); cursor: pointer; }
.cal-cell.has .cd { color: var(--ink); }
.cal-cell.has .ce { color: var(--expense); visibility: visible; }
.cal-cell.has .ci { color: var(--income); visibility: visible; }
.cal-cell.has:active { transform: scale(.94); }
.cal-cell.today { background: var(--ink); }
.cal-cell.today .cd { color: #fff; }
.cal-cell.today.has .ce { color: #ff9d97; }
.cal-cell.today.has .ci { color: #7ddcae; }
.day-filter {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 14px; margin-bottom: 10px; font-size: 13px; font-weight: 600;
}
.day-filter button {
  border: none; background: var(--chip); color: var(--sub);
  font-size: 12px; padding: 5px 11px; border-radius: 8px; cursor: pointer; font-weight: 400;
}

/* ---------- 记一笔 ---------- */
.seg {
  display: flex; background: var(--chip); border-radius: 12px; padding: 3px; margin-bottom: 18px;
}
.seg button {
  flex: 1; padding: 8px; border: none; border-radius: 9px; background: transparent;
  font-size: 14px; color: var(--sub); cursor: pointer; font-weight: 500;
  transition: all .15s ease;
}
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.05); }

.amount-row { display: flex; align-items: baseline; gap: 8px; border-bottom: 1.5px solid var(--line); padding-bottom: 12px; margin-bottom: 18px; }
.amount-row:focus-within { border-color: var(--ink); }
.amount-row .yen { font-size: 24px; color: var(--faint); font-weight: 600; }
#amount {
  border: none; outline: none; font-size: 34px; font-weight: 700; width: 100%;
  background: transparent; color: var(--ink); font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
#amount::placeholder { color: #d8dade; font-weight: 600; }

.cat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px 4px; margin-bottom: 20px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  border: none; background: none; cursor: pointer; padding: 0;
}
.cat .cico {
  width: 46px; height: 46px; border-radius: 50%; background: var(--chip);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; transition: all .15s ease; border: 1.5px solid transparent;
}
.cat .cname { font-size: 11px; color: var(--sub); max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cat.sel .cico { border-color: var(--ink); background: #fff; }
.cat.sel .cname { color: var(--ink); font-weight: 600; }
.cat.add-cat .cico { border: 1.5px dashed var(--faint); background: transparent; color: var(--faint); font-size: 18px; }

.frow { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.frow:last-of-type { border-bottom: none; }
.frow .fk { width: 40px; color: var(--sub); font-size: 13.5px; flex: none; }
.frow input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 14.5px; color: var(--ink); min-width: 0;
}
.frow select {
  flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px;
  font-size: 14px; background: var(--card); color: var(--ink); outline: none; min-width: 0;
}

.btn-primary {
  width: 100%; padding: 14px; border: none; border-radius: 13px; margin-top: 16px;
  background: var(--ink); color: #fff; font-size: 15.5px; font-weight: 600; cursor: pointer;
  transition: opacity .15s ease;
}
.btn-primary:active { opacity: .8; }
.btn-ghost {
  padding: 14px 18px; border: 1px solid var(--line); border-radius: 13px;
  background: var(--card); color: var(--sub); font-size: 14.5px; cursor: pointer;
}
.btn-ghost:active { border-color: var(--faint); color: var(--ink); }
.btn-danger { color: var(--expense); }
.edit-actions { display: flex; gap: 10px; margin-top: 16px; }
.edit-actions .btn-primary { flex: 1; margin-top: 0; }

/* ---------- 明细 ---------- */
.list-card { padding: 4px 16px 8px; }
.day-group { margin-top: 10px; }
.day-head {
  display: flex; justify-content: space-between; font-size: 12px;
  color: var(--sub); padding: 4px 0 8px;
}
.day-head .day-total { font-variant-numeric: tabular-nums; }
.rrow {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.rrow:active { opacity: .6; }
.rico {
  width: 36px; height: 36px; border-radius: 50%; background: var(--chip);
  display: flex; align-items: center; justify-content: center; font-size: 17px; flex: none;
}
.rmid { flex: 1; min-width: 0; }
.rname { font-size: 14px; font-weight: 500; }
.rnote { font-size: 11.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.ramt { font-size: 14.5px; font-weight: 600; font-variant-numeric: tabular-nums; flex: none; }
.ramt.expense { color: var(--ink); }
.ramt.income { color: var(--income); }

/* ---------- 统计 ---------- */
.chart-title { font-size: 12.5px; color: var(--sub); margin: 0 0 14px; font-weight: 600; letter-spacing: .03em; }
canvas { width: 100%; display: block; }
.pie-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.pie-wrap canvas { flex: 0 0 140px; width: 140px; height: 140px; }
.legend { flex: 1; min-width: 180px; }
.legend-item { padding: 5px 0; }
.legend-line { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.legend-line .l-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.legend-line .l-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.legend-line .l-pct { color: var(--sub); width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.lbar { height: 4px; border-radius: 2px; background: var(--chip); margin-top: 5px; overflow: hidden; }
.lbar i { display: block; height: 100%; border-radius: 2px; }

/* ---------- 设置 ---------- */
.set-row { padding: 10px 0; }
.set-k { font-size: 12.5px; color: var(--sub); margin-bottom: 8px; }
.set-row input {
  width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 11px 13px;
  font-size: 14px; background: var(--card); color: var(--ink); outline: none;
}
.set-row input:focus { border-color: var(--ink); }
.set-actions { display: flex; gap: 10px; margin-top: 12px; }
.set-actions .btn-primary { flex: 1; margin-top: 0; }
.set-status { font-size: 13px; color: var(--sub); line-height: 2; margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.set-status b { color: var(--ink); font-weight: 600; }
.set-status .err-txt { color: var(--expense); }
.set-help { font-size: 12px; color: var(--faint); line-height: 1.9; margin-top: 10px; }
.set-help a { color: var(--sub); }

/* ---------- 底栏 ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  max-width: 520px; margin: 0 auto;
  display: flex; background: rgba(255,255,255,0.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; border: none; background: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  font-size: 10.5px; color: var(--faint); cursor: pointer; transition: color .15s ease;
}
.tab.on { color: var(--ink); font-weight: 600; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 50;
  background: rgba(27, 29, 33, 0.92); color: #fff; font-size: 13px;
  padding: 9px 18px; border-radius: 999px; max-width: 82vw; text-align: center;
  animation: pop 0.18s ease-out;
}
.toast.err { background: rgba(190, 60, 45, 0.95); }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(6px); } }

@media (min-width: 560px) {
  body { background: #efefec; }
  #app { background: var(--bg); }
}
