:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --ink: #16233a;
  --ink-2: #5c6b85;
  --ink-3: #8d9ab0;
  --line: #e4e9f1;
  --brand: #2f5bd8;
  --brand-soft: #eaf0ff;
  --income: #d23b48;
  --expense: #1c9a6a;
  --warn: #c47a12;
  --danger: #c0392b;
  --radius: 16px;
  --shadow: 0 2px 14px rgba(22, 35, 58, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1422;
    --card: #162034;
    --ink: #eaf0fb;
    --ink-2: #a3b0c7;
    --ink-3: #74839d;
    --line: #26344c;
    --brand: #7ea2ff;
    --brand-soft: #1d2c4c;
    --income: #ff7a86;
    --expense: #5fd4a4;
    --warn: #e3ad58;
    --danger: #ff8a80;
    --shadow: 0 2px 14px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.app { display: flex; flex-direction: column; min-height: 100dvh; max-width: 560px; margin: 0 auto; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: calc(var(--safe-top) + 14px) 18px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 6px;
  background: linear-gradient(140deg, var(--brand), #7f6bf0);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.28);
}
.brand-tag {
  font-size: 11px; font-weight: 600; color: var(--brand);
  background: var(--brand-soft); padding: 2px 7px; border-radius: 20px;
}
.top-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-2);
  padding: 6px 10px; border-radius: 20px; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.dot-online { background: #24b47e; box-shadow: 0 0 0 3px rgba(36,180,126,.15); }
.dot-offline { background: var(--ink-3); }
.dot-pending { background: var(--warn); box-shadow: 0 0 0 3px rgba(196,122,18,.15); }
.dot-error { background: var(--danger); box-shadow: 0 0 0 3px rgba(192,57,43,.15); }

.offline-bar {
  margin: 10px 16px 0; padding: 9px 12px; border-radius: 10px;
  background: rgba(196,122,18,.12); color: var(--warn);
  font-size: 12.5px; text-align: center;
}

.main { flex: 1; padding: 16px 16px calc(84px + var(--safe-bottom)); }
.screen { display: none; animation: fade .18s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 2px 10px; }
.section-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.link-btn { color: var(--brand); font-size: 13px; }
.counter { font-size: 12px; color: var(--ink-3); }

.hero { padding: 20px 18px; background: linear-gradient(150deg, var(--card), var(--brand-soft)); }
.hero-label { font-size: 12px; color: var(--ink-2); }
.hero-value { font-size: 34px; font-weight: 700; letter-spacing: -.5px; margin: 4px 0 16px; font-variant-numeric: tabular-nums; }
.hero-split { display: flex; align-items: center; gap: 18px; }
.hero-split > div { display: flex; flex-direction: column; gap: 2px; }
.hero-divider { width: 1px; height: 28px; background: var(--line); }
.hero-sub-label { font-size: 11px; color: var(--ink-3); }
.hero-sub { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.hero-sub.income { color: var(--income); }
.hero-sub.expense { color: var(--expense); }

.list { padding: 4px 16px; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; display: flex; gap: 8px; align-items: center; }
.row-amount { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-amount.income { color: var(--income); }
.row-amount.expense { color: var(--expense); }
.sync-flag { font-size: 10px; padding: 1px 6px; border-radius: 10px; white-space: nowrap; }
.sync-flag.cloud { color: var(--brand); background: var(--brand-soft); }
.sync-flag.local { color: var(--warn); background: rgba(196,122,18,.12); }
.row-del {
  flex: none; font-size: 11px; color: var(--ink-3);
  padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line);
}
.empty { padding: 30px 8px; text-align: center; color: var(--ink-3); font-size: 13px; }

.hint strong { font-size: 13.5px; }
.hint p { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.6; }

.seg { display: flex; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.seg-btn { flex: 1; padding: 9px 0; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.seg-btn.active { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; outline: none; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--brand); }
.amount-row { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; }
.amount-row:focus-within { border-color: var(--brand); }
.amount-row .cny { color: var(--ink-3); font-size: 18px; }
.amount-row input { border: 0; background: none; padding: 11px 0; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.amount-row input:focus { border: 0; }
.primary-btn, .secondary-btn, .danger-btn {
  width: 100%; padding: 13px; border-radius: 12px; font-weight: 650; font-size: 15px;
}
.primary-btn { background: var(--brand); color: #fff; }
.primary-btn:disabled { opacity: .55; }
.secondary-btn { background: var(--brand-soft); color: var(--brand); border: 1px solid var(--line); }
.danger-btn { background: transparent; color: var(--danger); border: 1px solid var(--line); margin-top: 10px; }
.save-hint { text-align: center; font-size: 12px; color: var(--ink-3); margin: 10px 0 0; }
.field-note { font-size: 11.5px; color: var(--ink-3); line-height: 1.7; margin: 10px 0 0; }
.search-card { padding: 10px 12px; }
.search-card input { width: 100%; border: 0; background: var(--bg); border-radius: 9px; padding: 9px 11px; outline: none; }

.sync-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.sync-title { font-size: 16px; font-weight: 700; }
.sync-sub { font-size: 12px; color: var(--ink-3); }
.stat-row { display: flex; gap: 8px; margin-bottom: 16px; }
.stat {
  flex: 1; min-width: 0; background: var(--bg); border-radius: 11px; padding: 10px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.stat-label { font-size: 10.5px; color: var(--ink-3); }
.stat strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.stat-unit { font-size: 10px; color: var(--ink-3); }
.stat-time { font-size: 12px; }
.sync-msg { font-size: 12px; color: var(--ink-2); margin: 10px 0 0; min-height: 18px; }
.config-card h2, .tools-card h2 { font-size: 14px; margin: 0 0 14px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.kv span { color: var(--ink-3); }
.kv strong { font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.tools-card .secondary-btn { margin-bottom: 2px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  max-width: 560px; margin: 0 auto;
  display: flex; padding: 8px 6px calc(8px + var(--safe-bottom));
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 18px rgba(22,35,58,.05);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; color: var(--ink-3); padding: 3px 0; }
.tab.active { color: var(--brand); font-weight: 650; }
.tab-icon { width: 20px; height: 20px; border-radius: 6px; border: 2px solid currentColor; opacity: .85; position: relative; }
.icon-home { border-radius: 3px; }
.icon-home::after { content: ''; position: absolute; left: 3px; right: 3px; bottom: 3px; height: 5px; border: 2px solid currentColor; border-top: 0; }
.icon-add::before, .icon-add::after { content: ''; position: absolute; background: currentColor; }
.icon-add::before { left: 7px; top: 3px; width: 2px; height: 10px; }
.icon-add::after { left: 3px; top: 7px; width: 10px; height: 2px; }
.icon-list { border-radius: 4px; }
.icon-list::after { content: ''; position: absolute; left: 3px; right: 3px; top: 5px; height: 2px; background: currentColor; box-shadow: 0 4px 0 currentColor; }
.icon-sync { border-radius: 50%; border-top-color: transparent; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translate(-50%, 12px);
  background: rgba(20, 30, 48, .94); color: #fff; padding: 10px 18px; border-radius: 22px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .22s ease; z-index: 50;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
