/* 家庭账本 · 设计系统 */
:root {
  --bg: #f3f4f7;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #7c8798;
  --line: #eceef2;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --pos: #0e9f6e;
  --pos-soft: #e7f7f1;
  --neg: #e11d48;
  --neg-soft: #fee9ee;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 14px 32px -22px rgba(16, 24, 40, 0.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { overscroll-behavior-y: none; }

h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; border: none; background: none; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }

.app {
  max-width: 540px;
  margin: 0 auto;
  padding: 16px 16px calc(104px + var(--safe-b));
  min-height: 100vh;
}

/* ---------- 通用 ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }

.section { margin-top: 20px; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 2px;
}
.section-title { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.section-sub { font-size: 12px; color: var(--muted); }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 14px;
}
.page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.eyebrow { font-size: 12px; color: var(--muted); font-weight: 500; }

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 650;
  box-shadow: 0 6px 16px -8px rgba(79, 70, 229, 0.8);
}

.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.mono { font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  background: #f1f2f6;
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
  transition: transform 0.12s ease, opacity 0.12s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  color: #fff;
  box-shadow: 0 10px 24px -14px rgba(79, 70, 229, 0.9);
}
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 11px; }
.btn:disabled { opacity: 0.55; }
.btn-danger { background: var(--neg-soft); color: var(--neg); }

/* ---------- 表单 ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: #fafbfc;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.input:focus { border-color: #c7c9f5; background: #fff; box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.08); }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237c8798' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

/* ---------- 顶部英雄卡 ---------- */
.hero {
  position: relative;
  border-radius: 22px;
  padding: 18px 18px 16px;
  color: #fff;
  background: radial-gradient(120% 140% at 100% 0%, #3b3fa8 0%, #1b1c3a 45%, #12131f 100%);
  box-shadow: 0 20px 40px -28px rgba(18, 19, 31, 0.9);
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  inset: auto -40px -70px auto;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.55), transparent 70%);
  filter: blur(8px);
  pointer-events: none;
}
.hero-top { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: rgba(255,255,255,0.7); }
.hero-badge {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  font-size: 11px;
  color: rgba(255,255,255,0.85);
}
.hero-amount {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}
.hero-amount small { font-size: 16px; font-weight: 600; opacity: 0.75; margin-right: 2px; }
.hero-sub { font-size: 12px; color: rgba(255,255,255,0.55); }
.hero-bar {
  height: 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  margin: 14px 0 14px;
  overflow: hidden;
}
.hero-bar i {
  display: block; height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #818cf8, #c7d2fe);
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.hero-bar.warn i { background: linear-gradient(90deg, #fb7185, #fda4af); }
.hero-foot { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hero-foot div { display: flex; flex-direction: column; gap: 2px; }
.hero-foot b { font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }
.hero-foot span { font-size: 11px; color: rgba(255,255,255,0.5); }

/* ---------- 本月额度 ---------- */
.quota { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.quota-main { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.quota-label { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }
.progress { height: 8px; border-radius: 999px; background: #eef0f4; overflow: hidden; margin: 12px 0 8px; }
.progress i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #6366f1, #4f46e5); transition: width 0.45s ease; }
.progress.warn i { background: linear-gradient(90deg, #fb7185, #e11d48); }
.quota-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat {
  background: var(--card);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat span { font-size: 11.5px; color: var(--muted); }

/* ---------- 分类图例 ---------- */
.donut-wrap { display: flex; align-items: center; gap: 14px; }
.donut-box { position: relative; width: 132px; height: 132px; flex: none; }
.donut-center {
  position: absolute; inset: 0;
  display: grid; place-content: center;
  text-align: center;
}
.donut-center b { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.donut-center span { font-size: 10.5px; color: var(--muted); }
.legend { flex: 1; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.legend-row { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.legend-dot { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.legend-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 600; }
.legend-pct { font-size: 11px; color: var(--muted); width: 34px; text-align: right; }

/* ---------- 记录列表 ---------- */
.rec-group { margin-bottom: 6px; }
.rec-date {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--muted);
  padding: 10px 4px 6px;
}
.rec-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 12px;
  background: var(--card);
  border-radius: 14px;
  margin-bottom: 7px;
  box-shadow: 0 1px 2px rgba(16,24,40,0.03);
  transition: transform 0.1s;
}
.rec-item:active { transform: scale(0.995); background: #fafbfd; }
.rec-icon {
  width: 38px; height: 38px; flex: none;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 18px;
  background: #f4f5f9;
}
.rec-body { flex: 1; min-width: 0; }
.rec-title { font-size: 14.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-meta { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; margin-top: 1px; }
.tag-sys {
  font-size: 10px; padding: 1px 5px; border-radius: 5px;
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
}
.rec-amt { font-size: 15.5px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- Chip / 分段 ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  height: 34px; padding: 0 13px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 12.5px; font-weight: 550;
  color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 5px;
  transition: all 0.15s;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.tint { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.chip.dashed { border-style: dashed; color: var(--muted); }
select.input { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, #9aa4b2 50%), linear-gradient(135deg, #9aa4b2 50%, transparent 50%); background-position: right 18px center, right 13px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

.seg { display: flex; background: #eef0f4; border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; height: 34px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(16,24,40,0.1); }

.month-nav {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-radius: 14px; padding: 8px 10px; box-shadow: var(--shadow);
}
.month-nav b { font-size: 14.5px; font-weight: 650; }
.month-nav button {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  color: var(--ink-2); background: #f6f7fa; font-size: 15px;
}
.month-nav button:disabled { opacity: 0.35; }

/* ---------- 空状态 ---------- */
.empty { text-align: center; padding: 28px 12px; color: var(--muted); font-size: 13px; }
.empty .em { font-size: 30px; display: block; margin-bottom: 8px; opacity: 0.85; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 8px 12px calc(8px + var(--safe-b));
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(18px) saturate(1.4);
  border-top: 1px solid rgba(236,238,242,0.9);
  z-index: 40;
}
.tabbar-inner { max-width: 540px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 0; color: #9aa3b2; font-size: 10.5px; font-weight: 550; }
.tab.active { color: var(--ink); }
.tab svg { width: 21px; height: 21px; }
.tab-fab {
  width: 50px; height: 50px; margin: -20px auto 0;
  border-radius: 17px;
  background: linear-gradient(135deg, #4f46e5, #3730a3);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 12px 26px -12px rgba(55, 48, 163, 0.95);
  font-size: 26px; font-weight: 300; line-height: 1;
}
.tab-fab:active { transform: scale(0.94); }

/* ---------- 底部弹层 ---------- */
.sheet-mask {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-end;
  animation: fade 0.18s ease;
}
.sheet {
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  background: #fff;
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(16px + var(--safe-b));
  max-height: 92vh;
  overflow-y: auto;
  animation: up 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
.sheet-handle { width: 38px; height: 4px; border-radius: 999px; background: #e5e7ef; margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { font-size: 17px; font-weight: 680; letter-spacing: -0.02em; }
.sheet-close { width: 30px; height: 30px; border-radius: 50%; background: #f2f3f7; display: grid; place-items: center; color: var(--muted); font-size: 15px; }
@keyframes up { from { transform: translateY(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.amount-display {
  display: flex; align-items: baseline; justify-content: center; gap: 6px;
  padding: 6px 0 14px;
}
.amount-display span { font-size: 24px; font-weight: 600; color: var(--muted); }
.amount-display input {
  border: none; outline: none; background: none;
  font-size: 42px; font-weight: 700; letter-spacing: -0.03em;
  width: 2ch; min-width: 2ch; max-width: 82%;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  padding: 0;
}
.amount-display input::placeholder { color: #d7dbe3; }

.icon-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.icon-btn {
  aspect-ratio: 1;
  border-radius: 11px;
  background: #f6f7fa;
  display: grid; place-items: center;
  font-size: 18px;
  border: 1.5px solid transparent;
}
.icon-btn.active { border-color: var(--primary); background: var(--primary-soft); }

/* ---------- 两级分类选择 ---------- */
.lab-hint { float: right; font-style: normal; font-weight: 500; font-size: 11.5px; color: var(--muted); }
.cat-tops { padding-bottom: 6px; }
.cat-subs {
  display: flex; flex-wrap: wrap; gap: 7px;
  margin-top: 8px;
}
.cat-subs .chip { height: 32px; font-size: 12px; }
.dot-custom {
  width: 5px; height: 5px; border-radius: 50%; background: var(--primary);
  display: inline-block; vertical-align: middle; font-style: normal;
}
.picker-ro { opacity: 0.62; pointer-events: none; }

/* ---------- 大类占比条 ---------- */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; }
.bar-head b { font-variant-numeric: tabular-nums; }
.bar-track { height: 7px; border-radius: 999px; background: #f1f3f7; overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: 999px; min-width: 3px; }
.bar-sub { margin-top: 5px; font-size: 11px; color: var(--muted); line-height: 1.5; }

/* ---------- 分类一览 ---------- */
.cat-all { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.cat-all summary { font-size: 12.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.cat-all-row { margin-top: 9px; font-size: 12px; line-height: 1.6; }
.cat-all-row b { display: block; color: var(--ink); font-size: 12.5px; }
.cat-all-row span { color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(108px + var(--safe-b));
  transform: translate(-50%, 12px);
  background: rgba(15, 23, 42, 0.94);
  color: #fff;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 90;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 登录 / 引导 ---------- */
.auth-wrap { padding: 8vh 4px 0; }
.brand { text-align: center; margin-bottom: 26px; }
.brand-mark {
  width: 58px; height: 58px; margin: 0 auto 12px;
  border-radius: 18px;
  background: linear-gradient(135deg, #4f46e5, #1e1b4b);
  color: #fff; display: grid; place-items: center;
  font-size: 26px; font-weight: 700;
  box-shadow: 0 16px 32px -18px rgba(30, 27, 75, 0.9);
}
.brand h1 { font-size: 22px; font-weight: 720; letter-spacing: -0.02em; }
.brand p { font-size: 13px; color: var(--muted); margin-top: 4px; }

.auth-card { padding: 20px 18px; }
.auth-switch { text-align: center; font-size: 13px; color: var(--muted); margin-top: 16px; }
.auth-switch a { font-weight: 600; }

.hint { font-size: 11.5px; color: var(--muted); margin-top: -6px; margin-bottom: 12px; }

.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 26px; font-weight: 700; letter-spacing: 0.22em;
  text-align: center;
  padding: 14px; border-radius: 14px;
  background: #f6f7fa; color: var(--ink);
  user-select: all;
}

.member-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.member-row + .member-row { border-top: 1px solid var(--line); }
.member-av {
  width: 34px; height: 34px; border-radius: 50%;
  background: #eef0f8; color: #4b5563;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 650;
}
.member-info { flex: 1; min-width: 0; }
.member-info b { font-size: 14px; font-weight: 600; }
.member-info span { display: block; font-size: 11.5px; color: var(--muted); }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.divider { height: 1px; background: var(--line); margin: 12px 0; }

.budget-row { display: flex; gap: 8px; }
.budget-row .input { flex: 1; }

canvas { display: block; width: 100% !important; }
.chart-box { position: relative; height: 168px; }
.chart-box.tall { height: 190px; }

.rule-card { display: flex; align-items: center; gap: 11px; padding: 12px; }
.rule-card.paused { opacity: 0.55; }
.freq-badge {
  font-size: 10.5px; font-weight: 600;
  padding: 2px 7px; border-radius: 6px;
  background: #f1f2f7; color: var(--ink-2);
}
.freq-badge.on { background: var(--pos-soft); color: var(--pos); }

.split-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: #eef0f4; }
.split-bar i { display: block; height: 100%; }

.mini-legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.mini-legend span { display: inline-flex; align-items: center; gap: 5px; }
.mini-legend i { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }

.loading-screen { display: grid; place-items: center; min-height: 70vh; color: var(--muted); font-size: 13px; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid #e3e6ee; border-top-color: var(--primary);
  animation: spin 0.7s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
