/* ============================================================
   记账本 · 设计系统
   色板:bg #F2F4F6 / card #FFF / ink #20262D / sub #8B94A1
        支出红 #E5484D / 收入绿 #2FA36B(红绿只用于金额语义)
   签名:票根式金额条 —— 等宽数字 + 虚线分隔
   ============================================================ */
:root {
  --bg: #f2f4f6;
  --card: #ffffff;
  --ink: #20262d;
  --ink-2: #4a525c;
  --sub: #8b94a1;
  --line: #eceff2;
  --red: #e5484d;
  --red-soft: #fdecec;
  --green: #2fa36b;
  --green-soft: #e6f5ee;
  --shadow: 0 1px 2px rgba(32, 38, 45, 0.04), 0 6px 20px rgba(32, 38, 45, 0.05);
  --radius: 16px;
  --tabbar-h: 58px;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
    "MiSans", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-num: "DIN Alternate", "Bahnschrift", "SF Mono", ui-monospace, "Consolas",
    monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button { font-family: inherit; border: none; background: none; color: inherit; cursor: pointer; }
input, textarea { font-family: inherit; color: inherit; }

.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: 0.3px; }
.hidden { display: none !important; }

/* ---------- 主视图容器 ---------- */
#views { max-width: 520px; margin: 0 auto; min-height: 100dvh; }
.page { display: none; min-height: 100dvh; padding: 0 14px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
.page.active { display: block; animation: pageIn 0.22s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 顶部导航(页内) ---------- */
.nav {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 -14px; padding: 12px 14px 10px;
  background: linear-gradient(var(--bg) 82%, transparent);
}
.nav-title { font-size: 21px; font-weight: 700; letter-spacing: 0.5px; }

/* 月份切换 pill */
.month-switch { display: flex; align-items: center; gap: 2px; background: var(--card); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.month-switch button { width: 30px; height: 30px; border-radius: 999px; font-size: 16px; color: var(--ink-2); }
.month-switch button:active { background: var(--bg); }
.month-cur { min-width: 86px; text-align: center; font-weight: 600; font-size: 14px; font-family: var(--font-num); }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-top: 12px; }
.card-title { font-size: 13px; color: var(--sub); margin-bottom: 10px; font-weight: 500; }

/* ---------- 首屏汇总(票根式) ---------- */
.summary { display: flex; margin-top: 12px; padding: 18px 6px 14px; }
.summary .col { flex: 1; text-align: center; position: relative; }
.summary .col + .col::before { content: ""; position: absolute; left: 0; top: 12%; height: 76%; border-left: 1.5px dashed var(--line); }
.summary .label { font-size: 12px; color: var(--sub); }
.summary .value { font-size: 21px; font-weight: 700; margin-top: 2px; }
.summary .value.expense { color: var(--red); }
.summary .value.income { color: var(--green); }
.summary .value.balance { color: var(--ink); }

/* ---------- 明细列表 ---------- */
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 16px 4px 8px; color: var(--sub); font-size: 12.5px;
}
.day-head .d { font-weight: 600; color: var(--ink-2); }
.day-head .sums { font-family: var(--font-num); }
.day-head .sums .in { color: var(--green); margin-left: 8px; }
.day-head .sums .out { color: var(--red); margin-left: 8px; }

.record-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.record { display: flex; align-items: center; gap: 12px; padding: 13px 16px; }
.record + .record { border-top: 1px solid var(--line); }
.record:active { background: #f7f9fa; }
.record .ico { width: 40px; height: 40px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; font-size: 20px; flex: none; }
.record .mid { flex: 1; min-width: 0; }
.record .name { font-weight: 600; font-size: 15px; }
.record .note { font-size: 12.5px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record .amt { font-size: 16.5px; font-weight: 700; }
.record .amt.expense { color: var(--red); }
.record .amt.income { color: var(--green); }

.load-more { width: 100%; padding: 14px; text-align: center; color: var(--sub); font-size: 13px; }
.load-more:active { color: var(--ink-2); }

/* 空状态 */
.empty { text-align: center; padding: 64px 0 40px; color: var(--sub); }
.empty .big { font-size: 44px; }
.empty p { margin-top: 10px; font-size: 13.5px; }
.empty button { margin-top: 16px; background: var(--ink); color: #fff; border-radius: 999px; padding: 9px 22px; font-size: 13.5px; }

/* ---------- 分段控件 ---------- */
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; padding: 7px 0; border-radius: 8px; font-size: 13.5px; color: var(--ink-2); font-weight: 500; }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(32, 38, 45, 0.08); }
.seg.seg-money button.on[data-v="expense"] { color: var(--red); }
.seg.seg-money button.on[data-v="income"] { color: var(--green); }

/* ---------- 统计 ---------- */
.chart-box { width: 100%; height: 240px; }
.chart-box.tall { height: 220px; }
.rank { margin-top: 6px; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.rank-row .ico { width: 34px; height: 34px; border-radius: 10px; background: var(--bg); display: grid; place-items: center; font-size: 17px; flex: none; }
.rank-row .rname { width: 58px; font-size: 13.5px; font-weight: 600; flex: none; }
.rank-row .bar-wrap { flex: 1; height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.rank-row .bar { height: 100%; border-radius: 99px; background: var(--red); }
.rank-row.bar-income .bar { background: var(--green); }
.rank-row .rval { width: 92px; text-align: right; flex: none; }
.rank-row .rval .v { font-size: 13.5px; font-weight: 700; }
.rank-row .rval .p { font-size: 11px; color: var(--sub); font-family: var(--font-num); }

/* ---------- 预算 ---------- */
.budget-hero { display: flex; align-items: center; gap: 20px; }
.ring { width: 108px; height: 108px; flex: none; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-txt { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring .ring-txt .pct { font-size: 20px; font-weight: 700; font-family: var(--font-num); }
.ring .ring-txt .lbl { font-size: 10.5px; color: var(--sub); }
.budget-hero .mid { flex: 1; }
.budget-hero .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--sub); padding: 3px 0; }
.budget-hero .row b { color: var(--ink); font-weight: 700; }
.budget-hero .row b.warn { color: var(--red); }

.bcat { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.bcat + .bcat { border-top: 1px solid var(--line); }
.bcat .ico { width: 34px; height: 34px; border-radius: 10px; background: var(--bg); display: grid; place-items: center; font-size: 17px; flex: none; }
.bcat .bmid { flex: 1; min-width: 0; }
.bcat .bline1 { display: flex; justify-content: space-between; font-size: 13.5px; }
.bcat .bline1 .b { font-weight: 600; }
.bcat .bline1 .v { color: var(--sub); font-size: 12.5px; }
.bcat .bline1 .v.over { color: var(--red); font-weight: 700; }
.bcat .bar-wrap { margin-top: 6px; height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bcat .bar { height: 100%; border-radius: 99px; background: var(--green); }
.bcat .bar.over { background: var(--red); }

/* ---------- 我的 ---------- */
.mine-hero { display: flex; align-items: center; gap: 16px; margin-top: 12px; }
.mine-hero .avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 26px; font-weight: 700; }
.mine-hero .t1 { font-size: 17px; font-weight: 700; }
.mine-hero .t2 { font-size: 12.5px; color: var(--sub); margin-top: 2px; }
.mine-nums { display: flex; margin-top: 14px; }
.mine-nums .col { flex: 1; text-align: center; }
.mine-nums .col + .col { border-left: 1.5px dashed var(--line); }
.mine-nums .v { font-size: 16px; font-weight: 700; font-family: var(--font-num); }
.mine-nums .l { font-size: 11.5px; color: var(--sub); margin-top: 1px; }

.menu { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-top: 14px; }
.menu-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 15px 16px; font-size: 14.5px; text-align: left; }
.menu-item + .menu-item { border-top: 1px solid var(--line); }
.menu-item:active { background: #f7f9fa; }
.menu-item .mico { font-size: 18px; width: 24px; text-align: center; flex: none; }
.menu-item .grow { flex: 1; }
.menu-item .hint { color: var(--sub); font-size: 12.5px; }
.menu-item .arrow { color: #c3c9d1; font-size: 14px; }
.menu-item.danger { color: var(--red); }

/* ---------- 底部 TabBar ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  max-width: 520px; margin: 0 auto;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: stretch;
}
#tabbar .tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 10.5px; color: var(--sub); }
#tabbar .tab .tab-ico { font-size: 20px; filter: grayscale(1) opacity(0.62); transition: filter 0.15s, transform 0.15s; }
#tabbar .tab.on { color: var(--ink); font-weight: 600; }
#tabbar .tab.on .tab-ico { filter: none; transform: translateY(-1px); }
#tabbar .tab-add { position: relative; }
#tabbar .tab-add span {
  position: absolute; left: 50%; top: -18px; transform: translateX(-50%);
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--ink); color: #fff;
  font-size: 28px; font-weight: 300; line-height: 50px;
  box-shadow: 0 8px 20px rgba(32, 38, 45, 0.35), 0 0 0 5px var(--bg);
}
#tabbar .tab-add:active span { transform: translateX(-50%) scale(0.94); }

/* ---------- 上滑覆盖页(记一笔 / 分类管理) ---------- */
.overlay-page {
  position: fixed; inset: 0; z-index: 60;
  max-width: 520px; margin: 0 auto;
  background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0.3, 1);
}
.overlay-page.show { transform: translateY(0); }

.op-nav { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; flex: none; }
.op-nav .op-title { font-size: 16.5px; font-weight: 700; }
.op-nav button { font-size: 15px; color: var(--ink-2); padding: 6px 10px; border-radius: 10px; }
.op-nav button:active { background: rgba(32, 38, 45, 0.06); }
.op-nav button.primary { color: var(--green); font-weight: 700; }
.op-body { flex: 1; overflow-y: auto; padding: 0 14px 10px; }

/* ---------- 记一笔 ---------- */
.add-page { background: var(--card); }
.add-page .op-body { padding: 0 14px; display: flex; flex-direction: column; }

.add-seg { margin: 4px auto 14px; width: 200px; display: flex; background: var(--bg); padding: 3px; border-radius: 12px; }
.add-seg button { flex: 1; padding: 9px 0; border-radius: 10px; font-size: 15px; font-weight: 600; color: var(--sub); }
.add-seg button.on { background: #fff; box-shadow: 0 1px 4px rgba(32, 38, 45, 0.12); color: var(--ink); }
.add-seg button.on[data-v="expense"] { color: var(--red); }
.add-seg button.on[data-v="income"] { color: var(--green); }

.cat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px 0; padding-bottom: 6px; }
.cat-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; }
.cat-cell .ci { width: 46px; height: 46px; border-radius: 16px; display: grid; place-items: center; font-size: 24px; background: var(--bg); transition: transform 0.12s, background 0.12s, box-shadow 0.12s; }
.cat-cell .cn { font-size: 11px; color: var(--ink-2); }
.cat-cell.on .ci { background: var(--ink); box-shadow: 0 6px 14px rgba(32, 38, 45, 0.28); transform: translateY(-2px); }
.cat-cell.on .cn { color: var(--ink); font-weight: 700; }
.cat-cell:active .ci { transform: scale(0.94); }

/* 票根式金额区(签名元素) */
.ticket-zone {
  margin: 10px 0; padding: 16px 18px 14px;
  border-top: 1.5px dashed var(--line);
  border-bottom: 1.5px dashed var(--line);
  background-image: repeating-linear-gradient(90deg, transparent 0 27px, rgba(32, 38, 45, 0.045) 27px 28px);
}
.ticket-zone .tz-label { font-size: 12px; color: var(--sub); display: flex; justify-content: space-between; }
.ticket-zone .tz-label .cur { font-family: var(--font-num); }
.ticket-amount { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 44px; font-weight: 700; letter-spacing: 1px; text-align: right; padding-top: 4px; }
.ticket-amount .yuan { font-size: 22px; font-weight: 600; color: var(--sub); margin-right: 2px; }
.ticket-amount.placeholder { color: #c9cfD6; }
.ticket-amount.expense-color { color: var(--red); }
.ticket-amount.income-color { color: var(--green); }

.add-meta { padding: 4px 2px; }
.add-meta .meta-row { display: flex; align-items: center; gap: 10px; padding: 11px 2px; }
.add-meta .meta-row + .meta-row { border-top: 1px solid var(--line); }
.add-meta .mlabel { font-size: 13.5px; color: var(--sub); flex: none; }
.add-meta input[type="text"] { flex: 1; border: none; outline: none; background: none; font-size: 14.5px; }
.add-meta input[type="date"] { flex: 1; border: none; outline: none; background: none; font-size: 14.5px; font-family: var(--font-num); color: var(--ink); text-align: right; }

/* 键盘 */
.keypad { flex: none; background: #fbfcfd; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); user-select: none; }
.keypad-grid {
  display: grid;
  grid-template-areas:
    "n7 n8 n9 del"
    "n4 n5 n6 dot"
    "n1 n2 n3 ok"
    "d00 n0 again ok";
  gap: 1px; padding: 1px;
}
.keypad-grid button { height: 52px; font-size: 20px; font-family: var(--font-num); background: #fff; }
.keypad-grid button:active { background: #eef1f4; }
.k-del { grid-area: del; background: #eef1f4 !important; font-size: 17px !important; color: var(--ink-2); }
.k-dot { grid-area: dot; }
.k-d00 { grid-area: d00; color: var(--ink-2); }
.k-again { grid-area: again; font-family: var(--font-body) !important; font-size: 15px !important; background: #eef1f4 !important; color: var(--ink-2); font-weight: 600; }
.k-ok { grid-area: ok; background: var(--ink) !important; color: #fff; font-family: var(--font-body) !important; font-size: 16.5px !important; font-weight: 700; }
.k-ok:active { background: #333a43 !important; }
.k-ok:disabled { background: #c9cfD6 !important; color: #fff; }

/* ---------- 分类管理 ---------- */
.cat-manage-add { margin-top: 12px; width: 100%; padding: 13px; border-radius: var(--radius); border: 1.5px dashed #c9cfD6; color: var(--sub); font-size: 14px; background: none; }
.cat-manage-add:active { background: #eef1f4; }
.cat-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.cat-row + .cat-row { border-top: 1px solid var(--line); }
.cat-row .ico { width: 38px; height: 38px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; font-size: 19px; }
.cat-row .nm { flex: 1; font-weight: 600; font-size: 14.5px; }
.cat-row .tag { font-size: 10.5px; color: var(--sub); background: var(--bg); border-radius: 99px; padding: 2px 8px; }
.cat-row .arrow { color: #c3c9d1; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 34px 26px 28px; text-align: center; }
.login-logo { width: 64px; height: 64px; margin: 0 auto 14px; }
.login-card h1 { font-size: 19px; letter-spacing: 1px; }
.login-card .sub { color: var(--sub); font-size: 12.5px; margin: 6px 0 22px; }
.login-card input { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 15px; outline: none; text-align: center; letter-spacing: 2px; }
.login-card input:focus { border-color: var(--ink); }
.login-card .err { color: var(--red); font-size: 12.5px; min-height: 18px; margin-top: 8px; }
.login-card .go { width: 100%; margin-top: 12px; background: var(--ink); color: #fff; border-radius: 12px; padding: 13px; font-size: 15.5px; font-weight: 700; }
.login-card .go:active { background: #333a43; }
.login-tip { margin-top: 16px; font-size: 11px; color: #b6bdc7; }

/* ---------- 底部弹层 sheet ---------- */
.sheet-mask { position: fixed; inset: 0; z-index: 80; background: rgba(20, 24, 30, 0.45); animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 81;
  max-width: 520px; margin: 0 auto;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(0); animation: slideUp 0.24s cubic-bezier(0.32, 0.72, 0.3, 1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet .sh-title { text-align: center; font-size: 15px; font-weight: 700; padding-bottom: 6px; }
.sheet .sh-sub { text-align: center; color: var(--sub); font-size: 12px; padding-bottom: 8px; }
.sh-actions button { width: 100%; padding: 14px; font-size: 15px; text-align: center; border-radius: 12px; }
.sh-actions button + button { margin-top: 8px; }
.sh-actions button.danger { color: var(--red); background: var(--red-soft); font-weight: 600; }
.sh-actions button.normal { background: var(--bg); font-weight: 600; }
.sh-actions button.cancel { background: var(--bg); color: var(--sub); }

/* 表单 sheet */
.sh-form .f-row { margin-top: 12px; }
.sh-form label { display: block; font-size: 12.5px; color: var(--sub); margin-bottom: 6px; }
.sh-form input { width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 15px; outline: none; }
.sh-form input:focus { border-color: var(--ink); }
.sh-form .f-submit { width: 100%; margin-top: 18px; background: var(--ink); color: #fff; border-radius: 12px; padding: 13px; font-size: 15.5px; font-weight: 700; }
.sh-form .f-err { color: var(--red); font-size: 12.5px; min-height: 17px; margin-top: 6px; }

/* emoji 选择 */
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-top: 6px; max-height: 150px; overflow-y: auto; }
.emoji-grid button { font-size: 21px; padding: 6px 0; border-radius: 9px; }
.emoji-grid button.on { background: var(--ink); }

/* ---------- Toast ---------- */
#toast-root { position: fixed; inset: 0; z-index: 99; pointer-events: none; display: grid; place-items: center; padding-bottom: 20dvh; }
.toast { background: rgba(32, 38, 45, 0.92); color: #fff; padding: 11px 20px; border-radius: 12px; font-size: 13.5px; animation: toastIn 0.2s ease; max-width: 78vw; text-align: center; }
@keyframes toastIn { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: none; } }

/* ---------- 关于弹窗 ---------- */
.about-list { font-size: 13px; color: var(--ink-2); line-height: 2; padding: 4px 6px; }
.about-list b { color: var(--ink); }

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

/* ---------- 桌面宽屏微调 ---------- */
@media (min-width: 521px) {
  body { background: #e8eaee; }
  #app { position: relative; }
  #tabbar { border: 1px solid var(--line); border-bottom: none; border-radius: 20px 20px 0 0; }
  .overlay-page { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .sheet { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
