:root {
  --bg:        #FFF7EF;
  --bg-2:      #EAFBF4;
  --card:      #FFFFFF;
  --ink:       #4A3F35;
  --ink-2:     #96887B;
  --ink-3:     #B9AB9D;
  --line:      #F2E6D8;
  --line-2:    #EADCCB;

  --tiger:     #FF8A5B;
  --tiger-soft:#FFEDE3;
  --cow:       #F0A92E;
  --cow-soft:  #FFF3DC;

  --mint:      #2FB89A;
  --mint-soft: #E2F7F1;
  --sky:       #5BA8F5;
  --sky-soft:  #E7F2FE;

  --expense:   #FF6B6B;
  --income:    #2FBF71;
  --warn:      #F5A623;

  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 11px;
  --shadow: 0 6px 20px rgba(122, 96, 68, .08);
  --shadow-lg: 0 12px 34px rgba(122, 96, 68, .16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 12% -8%, #FFE9D6 0%, transparent 60%),
    radial-gradient(900px 480px at 100% 0%, #E4F8F1 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
.hidden { display: none !important; }

/* ============ 登录页 ============ */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
#welcome-view {
  position: fixed; inset: 0; z-index: 70; overflow-y: auto;
  background:
    radial-gradient(1200px 500px at 12% -8%, #FFE9D6 0%, transparent 60%),
    radial-gradient(900px 480px at 100% 0%, #E4F8F1 0%, transparent 55%),
    var(--bg);
}
#lock-view {
  position: fixed; inset: 0; z-index: 85; overflow-y: auto;
  background:
    radial-gradient(1200px 500px at 12% -8%, #FFE9D6 0%, transparent 60%),
    radial-gradient(900px 480px at 100% 0%, #E4F8F1 0%, transparent 55%),
    var(--bg);
}
.chk { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; padding: 2px; }
.chk input { width: 16px; height: 16px; accent-color: var(--tiger); }
.auth-card {
  width: 100%; max-width: 400px; background: var(--card);
  border-radius: 26px; padding: 30px 24px 24px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--line);
}
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-logo { font-size: 44px; letter-spacing: 4px; }
.auth-logo .bounce { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.auth-logo .bounce2 { display: inline-block; animation: bob 2.4s ease-in-out .5s infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-7px) } }
.auth-head h1 { margin: 6px 0 2px; font-size: 23px; letter-spacing: 1px; }
.auth-sub { margin: 0; color: var(--ink-2); font-size: 13px; }

.seg { display: flex; gap: 4px; background: #FBF3EA; padding: 4px; border-radius: 14px; margin-bottom: 18px; }
.seg-btn {
  flex: 1; padding: 8px 4px; border-radius: 11px; font-size: 12.5px; color: var(--ink-2);
  transition: .18s; white-space: nowrap;
}
.seg-btn.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 2px 8px rgba(122,96,68,.12); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12px; color: var(--ink-2); padding-left: 3px; }
.field input, .row-inline input, .row-inline select, .inp {
  width: 100%; padding: 12px 14px; border-radius: var(--r-sm);
  border: 1.5px solid var(--line-2); background: #FFFDFB; outline: none; transition: .15s;
}
.field input:focus, .row-inline input:focus, .inp:focus { border-color: var(--tiger); background: #fff; }
.row-inline { display: flex; gap: 8px; }
.row-inline input { flex: 1; min-width: 0; }

.btn-primary {
  padding: 13px; border-radius: 14px; color: #fff; font-weight: 600; font-size: 15px;
  background: linear-gradient(135deg, #FFA26E, #FF7E4D); box-shadow: 0 5px 14px rgba(255,126,77,.32);
  transition: .15s;
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .55; box-shadow: none; }
.btn-ghost {
  padding: 12px 15px; border-radius: var(--r-sm); background: #FFF1E5; color: var(--tiger);
  font-weight: 600; font-size: 13px; white-space: nowrap; transition: .15s;
}
.btn-ghost:disabled { opacity: .5; }
.btn-text { color: var(--ink-2); font-size: 12.5px; padding: 4px; text-decoration: underline; }
.auth-tip { margin: 14px 0 0; font-size: 12.5px; min-height: 18px; text-align: center; color: var(--ink-2); }
.auth-tip.err { color: var(--expense); }
.auth-tip.ok { color: var(--income); }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px calc(10px);
  background: rgba(255,247,239,.88); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; white-space: nowrap; }
.month-nav { display: flex; align-items: center; gap: 2px; margin-left: auto; background: #fff; border-radius: 20px; padding: 3px; box-shadow: var(--shadow); }
.mbtn { width: 30px; height: 30px; border-radius: 50%; font-size: 18px; color: var(--ink-2); }
.mbtn:active { background: #FBF3EA; }
.mmonth { padding: 0 10px; font-weight: 700; font-size: 14px; min-width: 82px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-chip {
  font-size: 11.5px; color: var(--ink-2); background: #fff; padding: 5px 10px; border-radius: 20px;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; box-shadow: var(--shadow);
}
.link-btn { font-size: 12px; color: var(--ink-3); }

/* ============ 页面 ============ */
.hero {
  text-align: center; padding: 20px 14px 18px; margin-bottom: 14px;
  background: var(--card); border-radius: var(--r-lg); border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background-image: linear-gradient(180deg, #FFF3E8 0%, #FFFFFF 62%);
}
.hero-emoji { font-size: 40px; letter-spacing: 8px; }
.hero-emoji .bounce { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.hero-emoji .bounce2 { display: inline-block; animation: bob 2.4s ease-in-out .5s infinite; }
.hero-title { font-size: 21px; font-weight: 800; letter-spacing: 2px; margin-top: 6px; }
.hero-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }

.page { padding: 16px 16px 110px; max-width: 880px; margin: 0 auto; }
.card {
  background: var(--card); border-radius: var(--r-lg); padding: 16px;
  box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 14px;
}
.card-title { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 14.5px; margin: 0 0 12px; }
.card-title .sub { font-weight: 400; font-size: 12px; color: var(--ink-3); margin-left: auto; }

/* 顶部三卡 */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--card); border-radius: var(--r-md); padding: 13px 12px; text-align: center;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.stat .k { font-size: 11.5px; color: var(--ink-2); }
.stat .v { font-size: 19px; font-weight: 800; margin-top: 3px; letter-spacing: -.3px; }
.stat .v.exp { color: var(--expense); }
.stat .v.inc { color: var(--income); }
.stat .v.bal { color: var(--ink); }

/* 角色对比 */
.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-card { border-radius: var(--r-md); padding: 13px; border: 1.5px solid transparent; }
.role-card.tiger { background: var(--tiger-soft); border-color: #FFD9C4; }
.role-card.cow { background: var(--cow-soft); border-color: #FAE3B4; }
.role-head { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13.5px; }
.role-amt { font-size: 20px; font-weight: 800; margin: 6px 0 2px; }
.role-meta { font-size: 11.5px; color: var(--ink-2); }
.role-meta b { font-weight: 700; }
.share-bar { display: flex; height: 9px; border-radius: 6px; overflow: hidden; margin-top: 10px; background: #fff; }
.share-bar i { display: block; transition: width .4s ease; }

/* 环形图 */
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.donut-legend { flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: 6px; }
.lg-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; }
.lg-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.lg-name { flex: 1; }
.lg-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.lg-pct { color: var(--ink-3); width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

/* 归属条 */
.scope-bar { display: flex; height: 30px; border-radius: 12px; overflow: hidden; font-size: 12px; font-weight: 600; color: #fff; }
.scope-bar div { display: flex; align-items: center; justify-content: center; transition: width .4s; white-space: nowrap; overflow: hidden; }

/* 趋势图 */
.trend { display: flex; align-items: flex-end; gap: 8px; height: 130px; padding-top: 6px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.trend-bars { display: flex; align-items: flex-end; gap: 3px; height: 100%; width: 100%; justify-content: center; }
.trend-bars i { width: 9px; border-radius: 4px 4px 0 0; display: block; min-height: 2px; transition: height .4s; }
.trend-lab { font-size: 10.5px; color: var(--ink-3); }
.trend-val { font-size: 10px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* 明细 */
.filters { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 3px; margin-bottom: 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  padding: 7px 13px; border-radius: 20px; background: #fff; border: 1.5px solid var(--line-2);
  font-size: 12.5px; color: var(--ink-2); white-space: nowrap; transition: .15s; flex: none;
}
.chip.active { background: var(--tiger); color: #fff; border-color: var(--tiger); font-weight: 600; }
.chip.cow.active { background: var(--cow); border-color: var(--cow); }
.chip.mint.active { background: var(--mint); border-color: var(--mint); }
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input { flex: 1; }

.day-group { margin-bottom: 12px; }
.day-head {
  display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-2);
  padding: 4px 6px 6px; font-variant-numeric: tabular-nums;
}
.txn {
  display: flex; align-items: center; gap: 11px; padding: 11px 12px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 7px; transition: .15s;
}
.txn:active { background: #FFFCF8; }
.txn-emoji {
  width: 40px; height: 40px; border-radius: 13px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex: none; background: #FBF3EA;
}
.txn-main { flex: 1; min-width: 0; }
.txn-t { display: flex; align-items: center; gap: 5px; font-weight: 600; font-size: 14px; }
.txn-t .cat { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-s { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; }
.txn-amt { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.txn-amt.exp { color: var(--expense); }
.txn-amt.inc { color: var(--income); }
.txn-amt.tr { color: var(--sky); }
.badge {
  font-size: 10px; padding: 1px 6px; border-radius: 8px; background: #F4EEE7; color: var(--ink-2); font-weight: 600;
}
.badge.tiger { background: var(--tiger-soft); color: #D2601F; }
.badge.cow { background: var(--cow-soft); color: #B87D0E; }
.badge.home { background: var(--mint-soft); color: #1B8B72; }
.badge.link { background: var(--sky-soft); color: #2C7CC7; }

/* 关联子项 */
.linked {
  margin: -3px 0 7px 30px; padding: 7px 11px; background: var(--sky-soft);
  border-radius: 0 0 12px 12px; border: 1px solid #D6E9FB; border-top: none;
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: #2C7CC7;
}
.linked .lk-amt { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.net-line {
  margin: -3px 0 10px 30px; font-size: 11.5px; color: var(--ink-2); padding: 0 4px 4px;
}

/* 账户 */
.acc-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 13px; margin-bottom: 9px; display: flex; align-items: center; gap: 11px; transition: .15s;
}
.acc-card:active { background: #FFFCF8; }
.acc-emoji { width: 42px; height: 42px; border-radius: 14px; background: #FBF3EA; display: flex; align-items: center; justify-content: center; font-size: 21px; flex: none; }
.acc-main { flex: 1; min-width: 0; }
.acc-name { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.acc-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.acc-bal { text-align: right; }
.acc-bal .b { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }
.acc-bal .b.neg { color: var(--expense); }
.acc-bal .l { font-size: 11px; color: var(--ink-3); }
.section-head { display: flex; align-items: center; gap: 8px; margin: 16px 0 10px; font-weight: 700; font-size: 14px; }
.section-head:first-child { margin-top: 0; }

/* 应收应付 */
.debt-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 13px; margin-bottom: 9px;
}
.debt-top { display: flex; align-items: center; gap: 9px; }
.debt-emoji { font-size: 22px; }
.debt-name { font-weight: 700; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.debt-amt { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.debt-prog { height: 7px; border-radius: 5px; background: #F4EEE7; margin-top: 9px; overflow: hidden; }
.debt-prog i { display: block; height: 100%; border-radius: 5px; transition: width .4s; }
.debt-meta { display: flex; gap: 8px; margin-top: 8px; font-size: 11.5px; color: var(--ink-3); flex-wrap: wrap; }

/* ============ 底部导航 ============ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-around;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.94); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--ink-3); padding: 3px 0; }
.tab i { font-size: 20px; font-style: normal; filter: grayscale(1) opacity(.45); transition: .18s; }
.tab span { font-size: 10.5px; }
.tab.active { color: var(--tiger); }
.tab.active i { filter: none; transform: translateY(-1px) scale(1.08); }
.fab {
  width: 52px; height: 52px; border-radius: 50%; font-size: 30px; line-height: 1; color: #fff;
  background: linear-gradient(135deg, #FFA26E, #FF7E4D); box-shadow: 0 6px 16px rgba(255,126,77,.42);
  margin-top: -22px; display: flex; align-items: center; justify-content: center; transition: .15s;
}
.fab:active { transform: scale(.94); }

/* ============ 弹窗 ============ */
.mask {
  position: fixed; inset: 0; background: rgba(74,63,53,.42); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.sheet {
  width: 100%; max-width: 520px; background: var(--bg); border-radius: 26px 26px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto; animation: up .24s cubic-bezier(.2,.9,.3,1);
}
@keyframes up { from { transform: translateY(28px); opacity: .6 } to { transform: translateY(0); opacity: 1 } }
.sheet-bar { width: 40px; height: 4px; border-radius: 3px; background: var(--line-2); margin: 6px auto 12px; }
.sheet-title { font-size: 16px; font-weight: 800; text-align: center; margin-bottom: 14px; }
.sheet-body { background: #fff; border-radius: var(--r-md); padding: 14px; border: 1px solid var(--line); margin-bottom: 12px; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn-primary { flex: 1; }
.btn-danger { flex: 1; padding: 13px; border-radius: 14px; background: #FFECEC; color: var(--expense); font-weight: 600; }

.amt-input { display: flex; align-items: center; gap: 6px; border-bottom: 2px solid var(--line-2); padding: 6px 0 10px; margin-bottom: 14px; }
.amt-input .cur { font-size: 24px; font-weight: 700; color: var(--ink-3); }
.amt-input input { flex: 1; border: none; outline: none; background: transparent; font-size: 32px; font-weight: 800; padding: 0; min-width: 0; }
.amt-input input::placeholder { color: #E3D8CC; }

.grid-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.opt {
  padding: 9px 4px; border-radius: 13px; background: #FBF6F0; border: 1.5px solid transparent;
  text-align: center; font-size: 11.5px; color: var(--ink-2); transition: .15s; line-height: 1.3;
}
.opt .e { display: block; font-size: 19px; margin-bottom: 2px; }
.opt.active { background: var(--tiger-soft); border-color: var(--tiger); color: #C9571A; font-weight: 700; }
.opt.cow.active { background: var(--cow-soft); border-color: var(--cow); color: #A97208; }
.opt.mint.active { background: var(--mint-soft); border-color: var(--mint); color: #17876E; }
.opt.sky.active { background: var(--sky-soft); border-color: var(--sky); color: #2C7CC7; }

.form-row { margin-bottom: 12px; }
.form-row:last-child { margin-bottom: 0; }
.form-row > label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 5px; padding-left: 3px; }
.form-row select, .form-row input { width: 100%; padding: 11px 13px; border-radius: var(--r-sm); border: 1.5px solid var(--line-2); background: #FFFDFB; outline: none; }
.form-row select:focus, .form-row input:focus { border-color: var(--tiger); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 11.5px; color: var(--ink-3); margin-top: 5px; line-height: 1.5; }

/* 分类占比排行 */
.rank-head { font-size: 12px; color: var(--ink-2); margin: 12px 0 8px; padding-left: 3px; }
.catrow {
  padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer;
  transition: background .15s;
}
.catrow:hover, .catrow:active { background: #FFF6EE; }
.cr-head { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.cr-name { font-weight: 600; color: var(--ink-1); }
.cr-num { margin-left: auto; color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.cr-num b { color: var(--tiger); font-size: 13px; }
.cr-track {
  margin-top: 6px; height: 10px; border-radius: 6px; background: #F6EFE7; overflow: hidden;
}
.cr-bar { height: 100%; display: flex; border-radius: 6px; overflow: hidden; min-width: 6px; }
.cr-bar i { height: 100%; display: block; }
.cr-sub {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 5px;
  font-size: 11px; color: var(--ink-3);
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(14px);
  background: rgba(74,63,53,.94); color: #fff; padding: 10px 18px; border-radius: 22px;
  font-size: 13px; z-index: 200; opacity: 0; pointer-events: none; transition: .22s;
  max-width: 84vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--expense); }
.toast.ok { background: var(--income); }

.loading {
  position: fixed; inset: 0; background: rgba(255,247,239,.72); z-index: 150;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: var(--ink-2); font-size: 13px;
}
.spinner { font-size: 34px; animation: bob 1s ease-in-out infinite; }

.empty { text-align: center; padding: 34px 16px; color: var(--ink-3); font-size: 13px; }
.empty .e { font-size: 40px; display: block; margin-bottom: 8px; opacity: .8; }

@media (max-width: 420px) {
  .brand { font-size: 14.5px; }
  .user-chip { display: none; }
  .stat .v { font-size: 17px; }
}
@media (min-width: 720px) {
  .tabbar { justify-content: center; gap: 26px; }
  .tab { flex: none; width: 74px; }
  .fab { margin-top: -22px; }
  .page { padding-bottom: 130px; }
}
