:root {
  --paper: #f3f0e7;
  --card: #fffefb;
  --ink: #1d2822;
  --ink-2: #4d5a52;
  --muted: #7d8780;
  --line: #e5e1d6;
  --green: #1d7457;
  --green-soft: #e6f0ea;
  --orange: #b86636;
  --orange-soft: #f7ebe1;
  --red: #a6452d;
  --shadow: 0 10px 30px rgba(35, 44, 37, 0.07);
  --radius: 18px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(900px 500px at 0% 0%, #fbfaf6 0%, transparent 60%),
    radial-gradient(700px 400px at 100% 0%, #e9f0ea 0%, transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
body.sheet-open { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
button:disabled { opacity: .5; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  background: rgba(243, 240, 231, .86);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(229, 225, 214, .65);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 11px;
  background: var(--green); color: #fff;
  display: grid; place-items: center;
  font-size: 16px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(29, 116, 87, .2);
}
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .04em; }
.brand p { margin: 2px 0 0; font-size: 9px; color: var(--muted); letter-spacing: .08em; }

.import-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--green); color: #fff;
  padding: 9px 13px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  box-shadow: 0 6px 16px rgba(29, 116, 87, .18);
}
.import-btn svg { width: 15px; height: 15px; }

#view { max-width: 720px; margin: 0 auto; padding: 16px 16px 28px; }

/* ---------- home ---------- */

.hero {
  background: linear-gradient(160deg, #fffefb 0%, #f8f7f1 100%);
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 24px;
  padding: 20px 18px 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: -60px; top: -80px;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(29,116,87,.1), transparent 70%);
  pointer-events: none;
}
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hero-top > span:first-child { font-size: 12px; color: var(--muted); letter-spacing: .05em; }
.hero-amount {
  font-size: 40px; line-height: 1.08; letter-spacing: -.035em;
  font-weight: 730; font-variant-numeric: tabular-nums;
  margin: 10px 0 0;
}
.hero-amount small { font-size: 20px; font-weight: 600; color: var(--ink-2); margin-right: 2px; letter-spacing: 0; }
.hero-sub { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.hero-sub b { color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.coverage { margin-top: 10px; font-size: 10px; color: #a0a8a2; }

.pill {
  display: inline-flex; align-items: center;
  padding: 5px 9px; border-radius: 999px;
  background: var(--green-soft); color: var(--green);
  font-size: 10px; font-weight: 600; white-space: nowrap;
}
.pill.warn { background: var(--orange-soft); color: var(--orange); }

.mini-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 11px 0; }
.mini {
  background: rgba(255,254,251,.72);
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 14px; padding: 11px 10px;
}
.mini span { display: block; font-size: 10px; color: var(--muted); }
.mini b { display: block; margin-top: 5px; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.warn-text { color: var(--orange) !important; }
.ok-text { color: var(--green) !important; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  box-shadow: 0 6px 20px rgba(36, 44, 38, .035);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 680; letter-spacing: .01em; }
.panel-head > span { font-size: 10px; color: var(--muted); }
.link { color: var(--green); font-size: 11px; padding: 2px; }
.link:hover { text-decoration: underline; }

.mbars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 6px; }
.mbar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 5px; min-width: 0; }
.mbar-track { width: 100%; max-width: 38px; height: 102px; background: #f1efe6; border-radius: 9px; display: flex; align-items: flex-end; overflow: hidden; }
.mbar-track i { width: 100%; background: linear-gradient(180deg, #2c8a69, #1d7457); border-radius: 9px 9px 0 0; min-height: 3px; }
.mbar b { font-size: 9px; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mbar span { font-size: 10px; color: var(--muted); }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 62px 1fr 72px; align-items: center; gap: 8px; font-size: 11px; }
.bar-row > span { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row > b { text-align: right; font-size: 10px; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.bar-track { height: 7px; border-radius: 99px; background: #f0eee5; overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: 99px; background: var(--green); }

.review-list { display: flex; flex-direction: column; }
.review-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left; padding: 10px 0;
  border-bottom: 1px solid #efede5;
}
.review-row:last-child { border-bottom: 0; }
.review-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--orange); flex: 0 0 auto; }
.review-copy { flex: 1; min-width: 0; }
.review-copy b { display: block; font-size: 11.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.review-copy span { display: block; margin-top: 2px; font-size: 10px; color: var(--muted); }
.chev { color: #b3bab4; font-size: 18px; }

.tx-list { display: flex; flex-direction: column; }
.tx-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left; padding: 9px 0;
  border-bottom: 1px solid #f0eee6;
}
.tx-row:last-child { border-bottom: 0; }
.tx-row.compact { padding: 8px 0; }
.tx-logo {
  width: 33px; height: 33px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700; flex: 0 0 auto;
}
.tx-logo.wechat { background: #e6f4ea; color: #1d7457; }
.tx-logo.alipay { background: #e8eff8; color: #2b5c8a; }
.tx-main { flex: 1; min-width: 0; }
.tx-main b { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-main span { display: block; margin-top: 2px; font-size: 9.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amt.out { color: var(--red); }
.tx-amt.in { color: var(--green); }
.tx-amt.pending { color: var(--orange); }
.tx-amt.muted { color: var(--muted); }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--orange); display: inline-block; flex: 0 0 auto; }

.foot { margin: 16px 2px 0; font-size: 9.5px; line-height: 1.7; color: #9ba39d; }

/* ---------- ledger ---------- */

.ledger-head { padding: 6px 2px 12px; }
.ledger-head h1 { margin: 0 0 10px; font-size: 22px; letter-spacing: .01em; }
.ledger-head p { margin: 0; }
.muted { color: var(--muted); font-size: 11px; line-height: 1.65; }
.search-wrap input {
  width: 100%; height: 42px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
  padding: 0 13px; font-size: 13px; outline: none;
}
.search-wrap input:focus { border-color: rgba(29,116,87,.45); box-shadow: 0 0 0 3px rgba(29,116,87,.08); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255,254,251,.7);
  color: var(--ink-2); font-size: 11px;
}
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }
.ledger-count { font-size: 10px; color: var(--muted); min-height: 14px; }
.ledger-list { margin-top: 4px; }
.center { display: flex; justify-content: center; padding: 12px 0; }

/* ---------- review ---------- */

.review-grid { display: flex; flex-direction: column; gap: 9px; }
.review-card {
  width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px;
  box-shadow: 0 5px 16px rgba(36,44,38,.03);
}
.review-top { display: flex; align-items: center; gap: 7px; }
.review-top b { flex: 1; font-size: 12px; font-weight: 600; line-height: 1.4; }
.review-meta { margin: 7px 0 0 13px; font-size: 10px; color: var(--orange); }
.review-samples { margin: 4px 0 0 13px; font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- settings ---------- */

.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid #f0eee6;
}
.settings-row:last-child { border-bottom: 0; }
.settings-row b { display: block; font-size: 12px; font-weight: 600; }
.settings-row span { display: block; margin-top: 2px; font-size: 10px; color: var(--muted); line-height: 1.5; }
.settings-row.danger b { color: var(--red); }
.kv { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 11px; border-bottom: 1px solid #f4f2eb; }
.kv:last-child { border-bottom: 0; }
.kv > span { color: var(--muted); flex: 0 0 auto; }
.kv > b { font-weight: 500; text-align: right; word-break: break-all; }
.checks { margin-top: 10px; }
.checks summary { cursor: pointer; font-size: 11px; color: var(--green); }
.checks pre, .error-box {
  white-space: pre-wrap; word-break: break-word;
  background: #f7f5ee; border: 1px solid #ece9df;
  border-radius: 10px; padding: 10px; margin: 8px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9.5px; line-height: 1.65; color: var(--ink-2);
  max-height: 260px; overflow: auto;
}
.steps { margin: 0; padding-left: 18px; font-size: 11px; line-height: 1.9; color: var(--ink-2); }
.privacy-line { display: flex; gap: 9px; margin: 0; font-size: 10.5px; line-height: 1.7; color: var(--muted); }
.privacy-line svg { width: 16px; height: 16px; flex: 0 0 auto; color: var(--green); margin-top: 1px; }

/* ---------- buttons / empty ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 16px; border-radius: 12px;
  background: var(--green); color: #fff;
  font-size: 12px; font-weight: 600;
  box-shadow: 0 7px 16px rgba(29,116,87,.15);
}
.btn.small { height: 32px; padding: 0 10px; font-size: 10.5px; border-radius: 9px; box-shadow: none; }
.btn.ghost { background: #f5f3eb; color: var(--ink-2); box-shadow: none; border: 1px solid var(--line); }
.btn.danger { background: #f8e9e4; color: var(--red); box-shadow: none; }
.btn svg { width: 16px; height: 16px; }

.empty {
  text-align: center; padding: 48px 22px 30px;
  display: flex; flex-direction: column; align-items: center;
}
.empty.small { padding: 60px 20px; }
.empty-mark {
  width: 58px; height: 58px; border-radius: 18px;
  background: var(--green); color: #fff;
  display: grid; place-items: center;
  font-size: 25px; font-weight: 700;
  box-shadow: 0 12px 28px rgba(29,116,87,.2);
  margin-bottom: 22px;
}
.empty.small .empty-mark { background: var(--green-soft); color: var(--green); box-shadow: none; }
.empty.small .empty-mark svg { width: 28px; height: 28px; }
.empty h1 { margin: 0; font-size: 27px; line-height: 1.35; letter-spacing: -.02em; }
.empty p { margin: 12px 0 22px; font-size: 12px; line-height: 1.8; color: var(--muted); }
.empty .btn { width: 100%; max-width: 240px; height: 46px; }
.empty-hint { margin-top: 12px; font-size: 9.5px; color: #a0a8a2; }
.privacy { display: flex; gap: 7px; align-items: flex-start; margin-top: 26px; max-width: 300px; text-align: left; color: #98a19a; font-size: 9.5px; line-height: 1.7; }
.privacy svg { width: 14px; height: 14px; flex: 0 0 auto; margin-top: 1px; color: var(--green); }
.empty-line { padding: 22px 0; text-align: center; font-size: 11px; color: var(--muted); }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-around;
  max-width: 720px; margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255,254,251,.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid rgba(229,225,214,.8);
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 64px; padding: 4px 0; color: #9aa39c;
  font-size: 9px; letter-spacing: .02em;
}
.tab svg { width: 19px; height: 19px; }
.tab.active { color: var(--green); font-weight: 600; }
.tab-badge {
  position: absolute; top: -2px; right: 2px;
  min-width: 14px; height: 13px; padding: 0 3px;
  border-radius: 999px; background: var(--orange); color: #fff;
  font-size: 7px; line-height: 13px; text-align: center; font-weight: 600;
}

/* ---------- sheet ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20, 27, 22, .34);
  backdrop-filter: blur(2px);
  animation: fade .18s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 720px; margin: 0 auto;
  max-height: 88vh; overflow-y: auto;
  background: var(--paper);
  border-radius: 24px 24px 0 0;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 60px rgba(20, 27, 22, .2);
  animation: slide .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(30px); opacity: .7; } }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 4px 0 0; font-size: 19px; line-height: 1.35; letter-spacing: -.01em; }
.eyebrow { font-size: 9px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: #ece9df; color: var(--ink-2);
  display: grid; place-items: center; flex: 0 0 auto;
}
.icon-btn svg { width: 15px; height: 15px; }
.sheet-amount { margin: 18px 0 4px; font-size: 36px; font-weight: 730; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.sheet-amount.out { color: var(--red); }
.sheet-amount.in { color: var(--green); }
.sheet-amount.pending { color: var(--orange); }
.sheet-amount.muted { color: var(--ink-2); }
.sheet-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.sheet-meta span { background: #e9e6dc; border-radius: 6px; padding: 3px 7px; font-size: 9.5px; color: var(--ink-2); }
.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 12px 0 14px; }
.action-grid .btn { padding: 0 8px; font-size: 10.5px; }
.field { display: block; margin: 12px 0; }
.field span { display: block; font-size: 10px; color: var(--muted); margin-bottom: 5px; }
.field select {
  width: 100%; height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card);
  padding: 0 10px; font-size: 12px; outline: none;
}
.detail-grid { margin-top: 8px; }
.raw { margin-top: 14px; }
.raw summary { cursor: pointer; font-size: 10.5px; color: var(--green); }
.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
.sheet-actions .btn.ghost { flex: 0 0 auto; color: var(--red); }

.review-items { margin-top: 12px; }
.review-item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid #eae7dd; }
.review-item-main { min-width: 0; }
.review-item-main b { display: block; font-size: 11.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.review-item-main span { display: block; margin-top: 3px; font-size: 9.5px; color: var(--muted); }
.review-item-right { text-align: right; flex: 0 0 auto; }
.review-item-right > b { font-size: 11px; font-variant-numeric: tabular-nums; }
.mini-actions { display: flex; gap: 3px; margin-top: 6px; justify-content: flex-end; }
.mini-actions button { font-size: 9px; padding: 4px 6px; border-radius: 6px; background: #efede4; color: var(--ink-2); }
.batch-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.import-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 8px; text-align: center; }
.metric b { display: block; font-size: 22px; font-weight: 720; font-variant-numeric: tabular-nums; }
.metric span { display: block; margin-top: 3px; font-size: 9px; color: var(--muted); }
.metric.warn b { color: var(--orange); }
.spinner { width: 30px; height: 30px; border: 3px solid #e4e0d6; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin: 28px auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 60; max-width: 86vw;
  background: #1e2a23; color: #fff;
  border-radius: 10px; padding: 9px 13px;
  font-size: 11px; line-height: 1.5;
  opacity: 0; pointer-events: none;
  transition: .2s ease;
  box-shadow: 0 10px 30px rgba(20, 27, 22, .2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: var(--orange); }
.toast.error { background: var(--red); }

@media (min-width: 720px) {
  #view { padding-top: 24px; }
  .hero-amount { font-size: 48px; }
  .empty { padding-top: 80px; }
}
