/* Ledger — Cue 设计系统（与 hermes-remote v5+ 同族） */

:root {
  --bg: #ffffff;
  --canvas: #faf8f2;
  --ink: #34322d;
  --ink2: #858481;
  --ink3: #b3b1ac;
  --line: rgba(0, 0, 0, 0.08);
  --line-soft: rgba(0, 0, 0, 0.05);
  --soft: rgba(0, 0, 0, 0.05);
  --grab: rgba(0, 0, 0, 0.14);
  --card: #ffffff;
  --glass: rgba(255, 255, 255, 0.82);
  --glass-tab: rgba(255, 255, 255, 0.86);
  --mask: rgba(26, 26, 25, 0.32);
  --cta: #1a1a19;
  --cta-fg: #ffffff;
  --accent: #e8943a;
  --accent-soft: rgba(232, 148, 58, 0.14);
  --accent-fg: #9a5d1d;
  --down: #3f9e77;
  --down-soft: rgba(63, 158, 119, 0.12);
  --up: #d9603f;
  --up-soft: rgba(217, 96, 63, 0.12);
  --r-s: 12px;
  --r-m: 16px;
  --r-l: 24px;
  --pill: 999px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.04);
  --hdr-h: 54px;
  --tab-h: 56px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --canvas: #191816;
    --ink: #eceae4;
    --ink2: #98968f;
    --ink3: #6b6963;
    --line: rgba(255, 255, 255, 0.09);
    --line-soft: rgba(255, 255, 255, 0.06);
    --soft: rgba(255, 255, 255, 0.07);
    --grab: rgba(255, 255, 255, 0.18);
    --card: #201f1c;
    --glass: rgba(25, 24, 22, 0.82);
    --glass-tab: rgba(25, 24, 22, 0.86);
    --mask: rgba(0, 0, 0, 0.52);
    --cta: #eceae4;
    --cta-fg: #161513;
    --accent: #f0a04c;
    --accent-soft: rgba(240, 160, 76, 0.18);
    --accent-fg: #f0b878;
    --down: #5cb392;
    --down-soft: rgba(92, 179, 146, 0.18);
    --up: #e8785a;
    --up-soft: rgba(232, 120, 90, 0.18);
    --shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:active { opacity: 0.72; }

.num { font-variant-numeric: tabular-nums; }

/* ---------- 配对屏 ---------- */
.pair {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 60;
  animation: fadeIn 0.4s var(--ease);
}
.pair-card { max-width: 340px; width: 100%; text-align: center; }
.pair-logo { animation: popIn 0.55s var(--ease); }
.pair h1 { margin: 14px 0 6px; font-size: 28px; letter-spacing: -0.02em; }
.pair-sub { color: var(--ink2); font-size: 14px; margin: 0 0 26px; }
.pair textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 12px 14px;
  font-size: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--canvas);
  resize: none;
  color: var(--ink);
  outline: none;
}
.pair textarea:focus { border-color: var(--ink3); }
.btn-cta {
  width: 100%;
  margin-top: 14px;
  background: var(--cta);
  color: var(--cta-fg);
  border-radius: var(--pill);
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.15s var(--ease);
}
.btn-cta:active { transform: scale(0.97); opacity: 1; }
.pair-err { color: var(--up); font-size: 13px; margin: 12px 0 0; white-space: pre-wrap; }
.pair-hint { color: var(--ink3); font-size: 12px; margin: 18px 0 0; }

/* ---------- 顶栏 ---------- */
#app { height: 100dvh; display: flex; flex-direction: column; }
.hdr {
  height: calc(var(--hdr-h) + var(--sat));
  padding: var(--sat) 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 20;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
  backdrop-filter: saturate(1.6) blur(18px);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.hdr-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition: background 0.2s var(--ease);
}
.hdr-btn svg { width: 21px; height: 21px; }
.hdr-btn:active { background: var(--soft); }
.hdr-mid { flex: 1; display: flex; align-items: center; justify-content: center; gap: 2px; min-width: 0; }
.hdr-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.month-nav { display: flex; align-items: center; gap: 2px; }
.month-nav .m-label {
  font-size: 17px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: var(--r-s);
  letter-spacing: -0.01em;
}
.month-nav .m-arrow {
  width: 32px;
  height: 32px;
  border-radius: var(--pill);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: var(--ink);
  transition: opacity 0.2s;
}
.month-nav .m-arrow[disabled] { opacity: 0.22; pointer-events: none; }
.month-nav .m-arrow:active { background: var(--soft); }

/* ---------- 主区 ---------- */
.main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--canvas);
  position: relative;
}
.view { padding: 14px 16px 28px; max-width: 560px; margin: 0 auto; }
.view-in { animation: viewIn 0.34s var(--ease) both; }

/* 下拉刷新 */
.ptr {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: transform 0.2s var(--ease), opacity 0.2s var(--ease);
}
#ptr.spin { opacity: 1 !important; }
#ptr-dot {
  width: 26px;
  height: 26px;
  border-radius: var(--pill);
  background: var(--cta);
  position: relative;
  box-shadow: var(--shadow);
}
#ptr-dot::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: var(--pill);
  border: 2px solid var(--cta-fg);
  border-top-color: transparent;
}
#ptr.spin #ptr-dot { animation: spin 0.7s linear infinite; }

/* ---------- 卡片与通用 ---------- */
.card {
  background: var(--card);
  border-radius: var(--r-l);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.sec-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink2);
  margin: 2px 2px 10px;
  letter-spacing: 0.02em;
}

/* 本月 hero */
.hero { text-align: center; padding: 22px 18px 18px; }
.hero-label { font-size: 13px; color: var(--ink2); }
.hero-total { font-size: 42px; font-weight: 800; letter-spacing: -0.03em; margin: 2px 0 10px; }
.hero-badges { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.badge {
  background: var(--accent-soft);
  color: var(--accent-fg);
  border-radius: var(--pill);
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 600;
}
.badge.plain { background: var(--soft); color: var(--ink2); }
.badge.up { background: var(--up-soft); color: var(--up); }
.badge.down { background: var(--down-soft); color: var(--down); }

/* 环形图 */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut-fig { position: relative; width: 148px; height: 148px; flex: none; animation: donutIn 0.7s var(--ease) both; }
@keyframes donutIn {
  0% { opacity: 0; transform: scale(0.82) rotate(-24deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
.donut-fig svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-seg { fill: none; transition: stroke-dashoffset 0.9s var(--ease), stroke-width 0.2s var(--ease); cursor: pointer; }
.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.donut-center b { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.donut-center span { font-size: 11px; color: var(--ink2); }
.cat-legend { flex: 1; min-width: 0; }
.cat-row { border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-main {
  width: 100%;
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 2px;
  text-align: left;
}
.cat-dot { width: 12px; height: 12px; border-radius: 4px; }
.cat-name { font-size: 14.5px; font-weight: 600; }
.cat-name small { color: var(--ink3); font-weight: 500; margin-left: 6px; }
.cat-amt { text-align: right; font-size: 14.5px; font-weight: 700; }
.cat-amt small { display: block; color: var(--ink3); font-weight: 500; font-size: 11.5px; }
.cat-bar { height: 4px; border-radius: 2px; background: var(--soft); overflow: hidden; margin: -2px 0 4px 22px; }
.cat-bar i { display: block; height: 100%; border-radius: 2px; width: 0; transition: width 0.8s var(--ease); }
.cat-subs { overflow: hidden; max-height: 0; transition: max-height 0.34s var(--ease); }
.cat-subs.open { max-height: 300px; }
.cat-sub-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 2px 7px 22px;
  font-size: 13px;
  color: var(--ink2);
  border-top: 1px dashed var(--line-soft);
  animation: fadeIn 0.3s var(--ease) both;
}
.cat-sub-row b { color: var(--ink); font-weight: 600; }
.cat-row.open .cat-chevron { transform: rotate(90deg); }
.cat-chevron {
  display: inline-block;
  font-size: 10px;
  color: var(--ink3);
  margin-left: 6px;
  transition: transform 0.3s var(--ease);
}

/* 每日条形 */
.daily-bars { display: flex; align-items: flex-end; gap: 2px; height: 76px; }
.day-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; }
.day-bar {
  width: 100%;
  max-width: 18px;
  border-radius: 4px 4px 2px 2px;
  background: var(--ink);
  opacity: 0.82;
  min-height: 2px;
  transform-origin: bottom;
  animation: growUp 0.6s var(--ease) both;
}
.day-bar.today { background: var(--accent); opacity: 1; }
.day-num { font-size: 9px; color: var(--ink3); }
.day-num.today { color: var(--accent); font-weight: 700; }
.daily-note { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink3); margin-top: 6px; }

/* 渠道 chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  border-radius: var(--pill);
  padding: 7px 14px;
  font-size: 13px;
  background: var(--card);
  display: flex;
  align-items: center;
  gap: 6px;
}
.chip b { font-weight: 700; }
.chip i { width: 8px; height: 8px; border-radius: var(--pill); display: inline-block; }

/* 明细列表 */
.entry-day { margin-bottom: 4px; }
.day-head {
  position: sticky;
  top: 0;
  z-index: 4;
  background: linear-gradient(var(--canvas) 74%, transparent);
  padding: 12px 2px 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink2);
  display: flex;
  justify-content: space-between;
}
.day-head .num { font-weight: 700; color: var(--ink); }
.entries { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: var(--shadow); overflow: hidden; }
.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  animation: slideIn 0.34s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 26ms);
}
.entry:last-child { border-bottom: 0; }
.entry-cat { width: 34px; height: 34px; border-radius: 11px; flex: none; display: flex; align-items: center; justify-content: center; }
.entry-cat svg { width: 17px; height: 17px; }
.entry-body { flex: 1; min-width: 0; }
.entry-merchant { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-note { font-size: 12px; color: var(--ink3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-note:empty { display: none; }
.entry-amt { font-size: 15.5px; font-weight: 700; letter-spacing: -0.01em; }
.entry-amt small { display: block; font-size: 10.5px; color: var(--ink3); font-weight: 500; text-align: right; }

/* 趋势 */
.t-bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding: 0 2px; }
.t-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.t-col-btn { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.t-bar-wrap { width: 100%; flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.t-bar {
  width: 62%;
  max-width: 34px;
  border-radius: 8px 8px 3px 3px;
  background: var(--ink);
  transform-origin: bottom;
  animation: growUp 0.7s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 60ms);
}
.t-col.cur .t-bar { background: var(--accent); }
.t-val { font-size: 10.5px; color: var(--ink2); font-weight: 600; }
.t-lab { font-size: 11px; color: var(--ink3); }
.t-col.cur .t-lab { color: var(--ink); font-weight: 700; }
.t-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.t-stat { text-align: center; padding: 12px 4px; }
.t-stat b { display: block; font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.t-stat span { font-size: 11.5px; color: var(--ink2); }
.comp-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.comp-lab { width: 34px; font-size: 11.5px; color: var(--ink2); font-weight: 600; flex: none; }
.comp-bar { flex: 1; height: 22px; border-radius: 6px; overflow: hidden; display: flex; }
.comp-bar i { height: 100%; animation: growWide 0.8s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms); }
.comp-amt { width: 72px; text-align: right; font-size: 12px; font-weight: 600; flex: none; }
.mer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}
.mer-row:last-child { border-bottom: 0; }
.mer-rank {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: var(--canvas);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.mer-rank.top { background: var(--cta); color: var(--cta-fg); border-color: var(--cta); }
.mer-name { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mer-name small { display: block; font-size: 11.5px; color: var(--ink3); font-weight: 500; }
.mer-amt { font-size: 14.5px; font-weight: 700; }

/* 搜索 */
.s-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--pill);
  padding: 10px 16px;
  box-shadow: var(--shadow);
}
.s-input-wrap svg { width: 16px; height: 16px; color: var(--ink3); flex: none; }
#s-input {
  flex: 1;
  border: 0;
  outline: 0;
  font-size: 16px;
  background: none;
  color: var(--ink);
  min-width: 0;
}
.s-input-wrap .s-clear { color: var(--ink3); font-size: 15px; width: 24px; height: 24px; border-radius: var(--pill); }
.s-filter-chips { display: flex; gap: 7px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.s-filter-chips::-webkit-scrollbar { display: none; }
.fchip {
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  padding: 6px 13px;
  font-size: 12.5px;
  background: var(--card);
  color: var(--ink2);
  font-weight: 600;
  transition: all 0.2s var(--ease);
}
.fchip.on { background: var(--cta); color: var(--cta-fg); border-color: var(--cta); }
.s-cat-bar { display: flex; gap: 7px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.s-cat-bar::-webkit-scrollbar { display: none; }
.s-cat {
  flex: none;
  font-size: 12px;
  padding: 5px 11px;
  border-radius: var(--pill);
  background: var(--soft);
  color: var(--ink2);
}
.s-cat.on { background: var(--accent-soft); color: var(--accent-fg); font-weight: 700; }
.s-sum { font-size: 12.5px; color: var(--ink2); padding: 10px 2px 6px; }
.s-empty { text-align: center; color: var(--ink3); font-size: 13.5px; padding: 36px 0; }

/* ---------- tabbar ---------- */
.tabbar {
  flex: none;
  height: calc(var(--tab-h) + var(--sab));
  padding-bottom: var(--sab);
  display: flex;
  background: var(--glass-tab);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
  backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink3);
  font-size: 10.5px;
  font-weight: 600;
  transition: color 0.2s var(--ease);
}
.tab svg { width: 23px; height: 23px; }
.tab.on { color: var(--cta); }
.tab.on span { transform: scale(1.06); }
.tab span { transition: transform 0.2s var(--ease); }

/* ---------- sheet ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
}
.sheet-mask {
  position: absolute;
  inset: 0;
  background: var(--mask);
  animation: fadeIn 0.25s var(--ease);
}
.sheet-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--card);
  border-radius: var(--r-l) var(--r-l) 0 0;
  padding: 8px 18px calc(22px + var(--sab));
  max-height: 78dvh;
  overflow-y: auto;
  animation: sheetUp 0.34s var(--ease);
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.1);
}
.sheet-grab { width: 38px; height: 5px; border-radius: 3px; background: var(--grab); margin: 6px auto 12px; }
.sheet-title { font-size: 17px; margin: 0 0 12px; letter-spacing: -0.01em; }
.sheet-list { padding-bottom: 8px; }
.m-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  animation: slideIn 0.3s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 30ms);
}
.m-row:last-child { border-bottom: 0; }
.m-row .m-name { font-size: 15.5px; font-weight: 600; }
.m-row .m-name small { color: var(--ink3); font-weight: 500; margin-left: 8px; }
.m-row .m-meta { font-size: 13px; color: var(--ink2); display: flex; align-items: center; gap: 10px; }
.m-row .m-check { color: var(--accent); font-weight: 800; }

.set-group {
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  margin-bottom: 14px;
  overflow: hidden;
}
.set-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.set-row:last-child { border-bottom: 0; }
.set-row span { color: var(--ink2); }
.set-row b { font-weight: 600; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-btn {
  width: 100%;
  padding: 14px;
  font-size: 14.5px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.set-btn:last-child { border-bottom: 0; }
.set-btn.danger { color: var(--up); }
.set-foot { text-align: center; color: var(--ink3); font-size: 11.5px; margin: 4px 0 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--sab) + 18px);
  transform: translateX(-50%);
  background: var(--cta);
  color: var(--cta-fg);
  border-radius: var(--pill);
  padding: 10px 20px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  z-index: 70;
  animation: toastIn 0.3s var(--ease);
  max-width: 82vw;
  text-align: center;
}

/* ---------- 动画 ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  0% { opacity: 0; transform: scale(0.86); }
  60% { opacity: 1; transform: scale(1.04); }
  100% { transform: scale(1); }
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes growUp {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}
@keyframes growWide {
  from { width: 0 !important; }
}
@keyframes sheetUp {
  from { transform: translateY(60%); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
