:root {
  --navy: #1f3864;
  --blue: #2e75b6;
  --green: #0f9d58;
  --red: #d93025;
  --amber: #f29900;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #8a8f98;
  --line: #e8eaed;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; }
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login {
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
  padding: 28px; background: linear-gradient(160deg, #1f3864 0%, #2e5b9e 60%, #3d7ab8 100%);
}
.login h1 { color: #fff; font-size: 30px; margin: 0 0 6px; letter-spacing: 2px; }
.login p { color: rgba(255,255,255,.75); margin: 0 0 32px; font-size: 14px; }
.login .card { background: #fff; border-radius: 18px; padding: 22px; }
.login label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.login input {
  width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: 10px;
  background: #fafbfc; outline: none;
}
.login input:focus { border-color: var(--blue); background: #fff; }
.login .btn-primary { margin-top: 22px; width: 100%; padding: 15px; }
.login .err { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- 框架 ---------- */
.app { max-width: 720px; margin: 0 auto; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: rgba(244,245,247,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; text-align: center; }
.topbar-title .t { font-size: 16px; font-weight: 700; }
.topbar-title .s { font-size: 12px; color: var(--muted); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: #fff; border: 1px solid var(--line); font-size: 18px; color: var(--navy);
}
.icon-btn:active { background: #eef1f5; }

main { padding: 14px 12px 150px; }

/* ---------- 卡片与数字 ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 1px 2px rgba(16,24,40,.05); margin-bottom: 12px;
}
.card-title { font-size: 13px; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 14px 10px; text-align: center;
  box-shadow: 0 1px 2px rgba(16,24,40,.05);
}
.kpi .k { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.kpi .v { font-size: 20px; font-weight: 800; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.kpi .v.income { color: var(--green); }
.kpi .v.expense { color: var(--red); }
.kpi .v.profit { color: var(--navy); }
.kpi.big .v { font-size: 26px; }
.kpi .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.hero {
  background: linear-gradient(135deg, #1f3864, #2e5b9e);
  color: #fff; border-radius: 18px; padding: 20px; margin-bottom: 12px;
  box-shadow: 0 6px 20px rgba(31,56,100,.25);
}
.hero .label { font-size: 13px; opacity: .8; }
.hero .amount { font-size: 38px; font-weight: 800; letter-spacing: -1px; margin: 2px 0 8px; font-variant-numeric: tabular-nums; }
.hero .meta { display: flex; gap: 18px; font-size: 13px; opacity: .9; }
.hero .meta b { font-size: 16px; font-weight: 700; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: 11px; font-size: 15px; font-weight: 600;
  background: #fff; border: 1px solid var(--line); color: var(--text);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-income { background: var(--green); color: #fff; border-color: var(--green); }
.btn-expense { background: var(--red); color: #fff; border-color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--blue); }
.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 7px 10px; font-size: 13px; border-radius: 9px; }
.btn-danger { color: var(--red); border-color: #f5c6c2; background: #fff5f4; }

.quick-add { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.quick-add .btn { padding: 18px; font-size: 17px; border-radius: 14px; box-shadow: 0 3px 10px rgba(0,0,0,.08); }

/* ---------- 列表 ---------- */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
.row {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row:active { background: #f7f8fa; }
.row .ico {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  font-size: 15px; flex-shrink: 0; font-weight: 700;
}
.ico.in { background: #e6f4ea; color: var(--green); }
.ico.out { background: #fce8e6; color: var(--red); }
.row .body { flex: 1; min-width: 0; }
.row .title { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.row .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.row .amt { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.in { color: var(--green); }
.amt.out { color: var(--red); }
.tag {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 6px;
  background: #eef1f5; color: #5f6368; font-weight: 500;
}
.tag.vat { background: #fff3e0; color: #b26a00; }
.tag.auto { background: #e8f0fe; color: #1a73e8; }
.tag.left { background: #f1f3f4; color: #80868b; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; font-size: 14px; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 13px; border: 1px solid var(--line); border-radius: 11px;
  background: #fafbfc; outline: none; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); background: #fff; }
.field textarea { min-height: 84px; resize: vertical; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 13px; border-radius: 11px; border: 1px solid var(--line);
  background: #fafbfc; font-weight: 600; color: var(--muted);
}
.seg button.on.in { background: var(--green); color: #fff; border-color: var(--green); }
.seg button.on.out { background: var(--red); color: #fff; border-color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 13px; border-radius: 10px; border: 1px solid var(--line);
  background: #fafbfc; font-size: 14px;
}
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(255,255,255,.96); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 720px; margin: 0 auto;
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; font-size: 11px; color: var(--muted);
}
.tabbar button .ti { font-size: 19px; line-height: 1; }
.tabbar button.on { color: var(--navy); font-weight: 700; }
.fab {
  position: fixed; right: 18px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 31;
  width: 58px; height: 58px; border-radius: 50%; background: var(--navy); color: #fff;
  font-size: 30px; line-height: 1; display: grid; place-items: center;
  box-shadow: 0 8px 22px rgba(31,56,100,.38);
}
.fab:active { transform: scale(.94); }

/* ---------- 弹层 ---------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.38); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .18s ease;
}
.sheet {
  background: #fff; width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slideUp .22s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 720px) {
  .sheet-mask { align-items: center; }
  .sheet { border-radius: 18px; max-width: 480px; max-height: 88vh; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-head .close { font-size: 24px; color: var(--muted); width: 32px; height: 32px; }
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 提示 ---------- */
#toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%) translateY(20px);
  background: rgba(24,28,35,.92); color: #fff; padding: 11px 18px; border-radius: 11px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 100; max-width: 86vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 统计 ---------- */
.chart-wrap { display: flex; align-items: center; gap: 16px; }
.pie { flex-shrink: 0; }
.legend { flex: 1; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 7px; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-item .n { flex: 1; color: #444; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-item .a { font-variant-numeric: tabular-nums; color: var(--muted); }
.bar-row { margin-bottom: 10px; }
.bar-row .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar { height: 7px; border-radius: 4px; background: #eef1f5; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--blue); }
.trend { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.trend .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.trend .bar2 { width: 100%; max-width: 26px; border-radius: 5px 5px 2px 2px; background: linear-gradient(180deg,#5b8fd6,#2e75b6); }
.trend .lbl { font-size: 10px; color: var(--muted); margin-top: 5px; }

/* ---------- 表格（电脑端） ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); }
table.tx { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tx th { text-align: left; padding: 10px 8px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tx td { padding: 10px 8px; border-bottom: 1px solid #f1f3f4; }
table.tx tr:last-child td { border-bottom: none; }
table.tx td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tx tr:hover td { background: #fafbfc; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.filters .field { margin: 0; }
.filters .full { grid-column: 1 / -1; }

.section-title { font-size: 13px; color: var(--muted); margin: 18px 4px 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.spacer { flex: 1; }
.flex { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.pill { display: inline-block; padding: 3px 9px; border-radius: 20px; background: #eef1f5; font-size: 12px; color: #5f6368; }
.notice {
  background: #fff8e6; border: 1px solid #ffe3a3; color: #7a5200; border-radius: 12px;
  padding: 12px 14px; font-size: 13px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center;
}
.notice .spacer { flex: 1; }
.notice .btn { white-space: nowrap; flex-shrink: 0; }

@media (min-width: 900px) {
  .app { max-width: 1080px; }
  main { padding: 18px 22px 90px; }
  .tabbar { max-width: 1080px; }
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  .desktop-only { display: block; }
}
.desktop-only { display: none; }

.sub.wrap { white-space: normal; line-height: 1.35; }
.btn.sticky-save {
  position: sticky; bottom: -16px; margin-top: 8px;
  box-shadow: 0 -14px 18px rgba(255,255,255,.96);
  background: var(--navy); z-index: 2;
}