* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
[hidden] { display: none !important; }

/* ================= 登录 ================= */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background:
    radial-gradient(1100px 460px at 50% -10%, #e8eefc 0%, transparent 62%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: var(--sp-6) var(--sp-5);
  box-shadow: var(--sh-2);
}
.auth-brand { text-align: center; margin-bottom: var(--sp-5); }
.brand-mark {
  width: 52px; height: 52px;
  margin: 0 auto var(--sp-3);
  display: grid; place-items: center;
  border-radius: 15px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 18px rgba(59, 111, 224, .32);
}
.brand-mark svg { width: 28px; height: 28px; }
.auth-brand h1 { font-size: var(--fs-xl); letter-spacing: -0.02em; }
.auth-sub { margin: var(--sp-1) 0 0; color: var(--muted); font-size: var(--fs-sm); }

.field { display: block; margin-bottom: var(--sp-4); }
.field-label { display: block; font-size: var(--fs-sm); color: var(--text-2); margin-bottom: 6px; }
.field input {
  width: 100%;
  height: 46px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: var(--fs-base);
  color: var(--text);
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-error {
  margin: 0 0 var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  background: var(--expense-soft);
  color: var(--expense);
  font-size: var(--fs-sm);
}

/* ================= 按钮 ================= */
.btn {
  height: 44px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: var(--fs-base);
  font-weight: 500;
  transition: background .16s var(--ease), border-color .16s var(--ease), transform .12s var(--ease);
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--muted); color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { height: 36px; font-size: var(--fs-sm); padding: 0 var(--sp-3); }

.link-btn {
  background: none; border: 0; padding: 4px 0;
  color: var(--primary-text); font-size: var(--fs-sm);
}
.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; background: transparent;
  border-radius: var(--r-full);
  color: var(--muted);
  transition: background .16s var(--ease), color .16s var(--ease);
}
.icon-btn:hover { background: var(--line); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn-sm {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-full);
  color: var(--text-2);
}
.icon-btn-sm svg { width: 18px; height: 18px; }

/* ================= 布局 ================= */
.app { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); }
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(246, 247, 249, .88);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  height: 56px;
  padding: 0 var(--sp-4);
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-title { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.01em; }

.main {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) var(--sp-6);
  /* keep the last rows clear of the floating action button */
  padding-bottom: calc(var(--nav-h) + 84px + env(safe-area-inset-bottom, 0px));
}

/* ================= 概览 ================= */
.hero {
  background: linear-gradient(155deg, #2f5fc7 0%, #3b6fe0 52%, #4a7ce8 100%);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  color: #fff;
  box-shadow: 0 10px 30px rgba(59, 111, 224, .26);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: -60px; top: -80px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .09);
}
.hero-label { font-size: var(--fs-sm); opacity: .82; }
.hero-value {
  font-family: var(--font-num);
  font-size: var(--fs-3xl);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.hero-meta { display: flex; gap: var(--sp-5); margin-top: var(--sp-4); font-size: var(--fs-sm); }
.hero-meta-item { display: flex; align-items: center; gap: 6px; opacity: .95; }
.hero-meta-item strong { font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-expense { background: #ffd0c8; }
.dot-income { background: #b9f0d2; }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); margin-top: var(--sp-3); }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  box-shadow: var(--sh-1);
}
.stat-label { font-size: var(--fs-xs); color: var(--muted); }
.stat-value {
  font-family: var(--font-num);
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-top: 2px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: var(--sp-5) 0 var(--sp-2);
}
.section-head h2 { font-size: var(--fs-base); }

/* ================= 交易列表 ================= */
.tx-list { display: flex; flex-direction: column; }
.tx-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-2);
  transition: background .16s var(--ease);
}
.tx-icon {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 0; /* icons are svg */
}
.tx-icon svg { width: 20px; height: 20px; }
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-size: var(--fs-base); font-weight: 500; }
.tx-sub {
  font-size: var(--fs-xs);
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tx-amount {
  font-family: var(--font-num);
  font-size: var(--fs-base);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  flex-shrink: 0;
}
.tx-amount.expense { color: var(--expense); }
.tx-amount.income { color: var(--income); }
.tx-amount.transfer { color: var(--text-2); }

.tx-group-label {
  font-size: var(--fs-xs);
  color: var(--muted);
  margin: var(--sp-3) 0 var(--sp-2);
  padding-left: 2px;
}
.tx-day-sum { float: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }

.empty {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  color: var(--muted);
  font-size: var(--fs-sm);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
}
.empty svg { width: 36px; height: 36px; display: block; margin: 0 auto var(--sp-2); opacity: .35; }

/* ================= 流水筛选 ================= */
.filter-bar { display: flex; gap: var(--sp-2); align-items: center; margin-bottom: var(--sp-3); }
.seg {
  display: inline-flex;
  background: var(--line);
  border-radius: var(--r-full);
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}
.seg-btn {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  padding: 6px 14px;
  border-radius: var(--r-full);
  transition: background .16s var(--ease), color .16s var(--ease);
  white-space: nowrap;
}
.seg-btn.is-active { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: var(--sh-1); }
.seg-sm .seg-btn { padding: 4px 10px; font-size: var(--fs-xs); }

.search-input {
  flex: 1; min-width: 0;
  height: 38px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
  font-size: var(--fs-sm);
  color: var(--text);
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.ledger-summary {
  display: flex; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--muted);
}
.ledger-summary strong {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ================= 卡片 / 统计 ================= */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
  box-shadow: var(--sh-1);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-3);
}
.card-head h2 { font-size: var(--fs-base); }
.muted-sm { font-size: var(--fs-xs); color: var(--muted); }

.month-bar { display: flex; align-items: center; justify-content: center; gap: var(--sp-4); margin-bottom: var(--sp-3); }
.month-label {
  font-family: var(--font-num);
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
  min-width: 110px;
  text-align: center;
}

.donut-wrap { position: relative; display: grid; place-items: center; margin: var(--sp-2) 0 var(--sp-4); }
.donut { width: 168px; height: 168px; border-radius: 50%; position: relative; }
.donut-center { position: absolute; text-align: center; pointer-events: none; }
.donut-total {
  font-family: var(--font-num);
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.donut-cap { font-size: var(--fs-xs); color: var(--muted); }

.cat-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.cat-row { display: flex; align-items: center; gap: var(--sp-3); }
.cat-bullet { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.cat-name { font-size: var(--fs-sm); flex: 0 0 auto; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-bar { flex: 1; height: 6px; background: var(--line); border-radius: var(--r-full); overflow: hidden; min-width: 40px; }
.cat-bar-fill { height: 100%; border-radius: var(--r-full); transition: width .35s var(--ease); }
.cat-amt {
  font-family: var(--font-num);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  min-width: 68px;
  text-align: right;
}
.cat-pct { font-size: var(--fs-xs); color: var(--muted); flex: 0 0 38px; text-align: right; font-variant-numeric: tabular-nums; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 132px;
  padding-top: var(--sp-2);
  overflow: hidden;
}
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; min-width: 0; }
.bar-fill { width: 100%; background: var(--primary); border-radius: 2px 2px 0 0; min-height: 1px; opacity: .85; }
.bar-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

.trend-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.trend-row { display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-sm); }
.trend-month { font-family: var(--font-num); flex: 0 0 58px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.trend-bars { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.trend-bar { height: 5px; border-radius: var(--r-full); min-width: 2px; }
.trend-e { background: var(--expense); }
.trend-i { background: var(--income); }
.trend-vals { font-family: var(--font-num); font-size: var(--fs-xs); color: var(--muted); flex: 0 0 74px; text-align: right; font-variant-numeric: tabular-nums; }

/* ================= 预算 ================= */
.budget-list { display: flex; flex-direction: column; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.budget-item { display: flex; flex-direction: column; gap: 6px; }
.budget-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.budget-name { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); min-width: 0; }
.budget-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.budget-nums { font-family: var(--font-num); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; color: var(--text-2); flex-shrink: 0; }
.budget-nums .over { color: var(--expense); font-weight: 600; }
.budget-track { height: 8px; background: var(--line); border-radius: var(--r-full); overflow: hidden; }
.budget-fill { height: 100%; border-radius: var(--r-full); transition: width .35s var(--ease); }
.budget-hint { font-size: var(--fs-xs); color: var(--muted); }

/* ================= 账户 ================= */
.account-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.account-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) 0;
}
.acc-badge {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  color: #fff;
}
.acc-badge svg { width: 19px; height: 19px; }
.acc-name { flex: 1; font-size: var(--fs-sm); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-bal { font-family: var(--font-num); font-size: var(--fs-sm); font-weight: 600; font-variant-numeric: tabular-nums; }

.action-list { display: flex; flex-direction: column; }
.action-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) 0;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm); color: var(--text); text-decoration: none;
  width: 100%; text-align: left;
}
.action-row:last-child { border-bottom: 0; }
.action-row svg { width: 18px; height: 18px; color: var(--muted); }

.foot-note { text-align: center; font-size: var(--fs-xs); color: var(--muted); margin: var(--sp-4) 0 0; }

/* ================= 悬浮按钮 / 标签栏 ================= */
.fab {
  position: fixed;
  right: max(18px, calc(50% - 360px + 18px));
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px;
  border-radius: var(--r-full);
  border: 0;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 8px 22px rgba(59, 111, 224, .38);
  z-index: 40;
  transition: transform .16s var(--ease), background .16s var(--ease);
}
.fab:hover { background: var(--primary-hover); }
.fab:active { transform: scale(.94); }
.fab svg { width: 26px; height: 26px; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 35;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  transition: color .16s var(--ease);
}
.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--primary); }
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -4px; }

/* ================= 记账抽屉 ================= */
.sheet-mask, .modal-mask {
  position: fixed; inset: 0;
  background: rgba(16, 18, 22, .42);
  z-index: 50;
  animation: fadeIn .18s var(--ease);
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes sheetUp { from { transform: translateY(100%) } to { transform: translateY(0) } }

.sheet {
  position: fixed;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  z-index: 51;
  display: flex; flex-direction: column;
  box-shadow: 0 -8px 40px rgba(16, 18, 22, .16);
  animation: sheetUp .26s var(--ease);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sheet-cancel, .sheet-save {
  border: 0; background: none; font-size: var(--fs-base); padding: 6px 4px;
  min-width: 48px;
}
.sheet-cancel { color: var(--muted); }
.sheet-save { color: var(--primary); font-weight: 600; text-align: right; }
.seg-kind { background: var(--bg); }

.amount-row {
  display: flex; align-items: baseline; gap: 6px;
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.amount-cur { font-size: var(--fs-xl); color: var(--text-2); font-family: var(--font-num); }
.amount-input {
  flex: 1; min-width: 0;
  border: 0; outline: none;
  font-family: var(--font-num);
  font-size: var(--fs-3xl);
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text);
  background: transparent;
  font-variant-numeric: tabular-nums;
}
.amount-input::placeholder { color: #c8ccd4; }

.sheet-body { overflow-y: auto; padding: var(--sp-4); -webkit-overflow-scrolling: touch; }
.pick-block { margin-bottom: var(--sp-4); }
.pick-label { font-size: var(--fs-xs); color: var(--muted); margin-bottom: var(--sp-2); }

.chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: var(--sp-2); }
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: var(--sp-2) 4px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-md);
  font-size: var(--fs-xs);
  color: var(--text-2);
  transition: border-color .14s var(--ease), background .14s var(--ease);
  min-height: 64px;
}
.chip svg { width: 21px; height: 21px; }
.chip.is-active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-text); font-weight: 500; }
.chip .chip-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chip-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.chip-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  color: var(--text-2);
  min-height: 40px;
}
.chip-pill.is-active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-text); font-weight: 500; }

.input {
  width: 100%; height: 44px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: var(--fs-base);
  color: var(--text);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ================= 弹窗 ================= */
.modal {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 40px);
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  z-index: 51;
  box-shadow: var(--sh-3);
  animation: fadeIn .18s var(--ease);
}
.modal h3 { font-size: var(--fs-lg); margin-bottom: var(--sp-4); }
.modal-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-5); }
.modal .field { margin-bottom: var(--sp-3); }

/* ================= Toast ================= */
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--nav-h) + 84px);
  transform: translateX(-50%);
  background: rgba(22, 24, 29, .92);
  color: #fff;
  font-size: var(--fs-sm);
  padding: 10px 18px;
  border-radius: var(--r-full);
  z-index: 60;
  max-width: calc(100% - 40px);
  text-align: center;
  animation: fadeIn .18s var(--ease);
}

/* ================= 响应式 ================= */
@media (min-width: 768px) {
  .main { padding: var(--sp-5) var(--sp-5) var(--sp-7); }
  .hero { padding: var(--sp-6); }
  .hero-value { font-size: 42px; }
  .stat-row { gap: var(--sp-4); }
  .fab { right: calc(50% - 360px + 24px); }
}

@media (max-width: 360px) {
  .hero-value { font-size: var(--fs-2xl); }
  .chip-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .filter-bar { flex-wrap: wrap; }
  .search-input { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
