:root {
  --brand: #3b6ef6;
  --brand-2: #6f5bff;
  --brand-soft: #eef3ff;
  --expense: #f4516c;
  --expense-soft: #fff0f2;
  --income: #14b08a;
  --income-soft: #ebfaf5;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1b2030;
  --text-2: #4b5468;
  --muted: #8b93a7;
  --line: #eef1f7;
  --shadow: 0 10px 30px rgba(27, 32, 48, 0.06);
  --radius: 18px;
  --tab-h: 62px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: #e9edf6;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; border: none; background: none; }

[hidden] { display: none !important; }

.hidden { display: none !important; }

/* ---------- 通用组件 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.2s ease;
  user-select: none;
}
.btn:active { transform: scale(0.985); opacity: 0.92; }
.btn--primary {
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 10px 22px rgba(59, 110, 246, 0.28);
}
.btn--ghost {
  color: var(--text-2);
  background: #f1f4fa;
}
.btn--danger { color: var(--expense); background: var(--expense-soft); }
.btn--lg { width: 100%; height: 52px; font-size: 16px; border-radius: 16px; }
.btn--sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 6px 2px;
}
.field__input {
  width: 100%;
  height: 48px;
  border: 1.5px solid var(--line);
  background: #fafbfe;
  border-radius: 14px;
  padding: 0 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.field__input:focus {
  border-color: var(--brand);
  background: #fff;
}

/* ---------- 登录页 ---------- */
.auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  background:
    radial-gradient(120% 80% at 15% 0%, #4f7cff 0%, rgba(79, 124, 255, 0) 55%),
    radial-gradient(90% 70% at 100% 10%, #8b6bff 0%, rgba(139, 107, 255, 0) 55%),
    linear-gradient(180deg, #eef2ff 0%, #f7f9ff 42%, #f4f6fb 100%);
}
.auth__inner {
  width: 100%;
  max-width: 440px;
  padding: calc(56px + env(safe-area-inset-top, 0px)) 24px 40px;
}
.auth__brand { text-align: center; margin-bottom: 28px; }
.auth__logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  font-size: 30px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 16px 32px rgba(59, 110, 246, 0.32);
}
.auth__title { margin: 0 0 6px; font-size: 26px; letter-spacing: 1px; }
.auth__subtitle { margin: 0; color: var(--muted); font-size: 14px; }

.auth__tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.9);
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 18px;
  backdrop-filter: blur(8px);
}
.auth__tab {
  height: 40px;
  border-radius: 11px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
.auth__tab.is-active {
  background: #fff;
  color: var(--brand);
  box-shadow: 0 4px 12px rgba(27, 32, 48, 0.08);
}
.auth__form {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  padding: 22px 20px 20px;
  box-shadow: 0 18px 50px rgba(27, 32, 48, 0.1);
  backdrop-filter: blur(12px);
}
.auth__hint {
  margin: 14px 2px 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  min-height: 18px;
}

/* ---------- 应用外壳 ---------- */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 60px rgba(27, 32, 48, 0.08);
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 8px);
}
.view { padding: 0 16px 16px; animation: viewIn 0.22s ease; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 顶部 ---------- */
.page-head {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -16px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: rgba(244, 246, 251, 0.9);
  backdrop-filter: blur(14px);
}
.page-head__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-title { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: 0.3px; }
.page-sub { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

.month-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 4px 14px rgba(27, 32, 48, 0.06);
}
.month-switch button {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: var(--text-2);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.month-switch button:active { background: #f1f4fa; }
.month-switch__label {
  min-width: 86px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* ---------- 记一笔 ---------- */
.hero {
  margin-top: 10px;
  border-radius: 24px;
  padding: 20px;
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(255, 255, 255, 0.26) 0%, rgba(255, 255, 255, 0) 55%),
    linear-gradient(135deg, #3b6ef6 0%, #6f5bff 100%);
  color: #fff;
  box-shadow: 0 18px 36px rgba(59, 110, 246, 0.28);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "¥";
  position: absolute;
  right: -10px;
  bottom: -46px;
  font-size: 170px;
  font-weight: 700;
  opacity: 0.08;
  pointer-events: none;
}
.hero__top { display: flex; align-items: center; justify-content: space-between; }
.hero__label { font-size: 12px; opacity: 0.82; letter-spacing: 0.5px; }
.seg {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  padding: 3px;
}
.seg button {
  padding: 6px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  transition: background 0.18s ease, color 0.18s ease;
}
.seg button.is-active { background: #fff; color: var(--brand); }

.hero__amount {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 14px;
  position: relative;
  z-index: 1;
}
.hero__currency { font-size: 24px; font-weight: 600; opacity: 0.9; }
.hero__input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 42px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  padding: 2px 0;
}
.hero__input::placeholder { color: rgba(255, 255, 255, 0.5); }
.hero__month {
  margin-top: 10px;
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  gap: 14px;
  position: relative;
  z-index: 1;
}

.section { margin-top: 20px; }
.section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 2px 10px;
}
.section__title { font-size: 14px; font-weight: 600; color: var(--text-2); margin: 0; }
.section__hint { font-size: 12px; color: var(--muted); }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 8px 10px;
  box-shadow: var(--shadow);
}
.cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px 2px;
  border-radius: 12px;
  transition: background 0.15s ease;
}
.cat__icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: #f4f6fb;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cat__name {
  font-size: 11px;
  color: var(--text-2);
  max-width: 56px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cat.is-active .cat__icon { transform: translateY(-1px) scale(1.04); box-shadow: 0 6px 14px rgba(27, 32, 48, 0.12); }
.cat.is-active .cat__name { color: var(--brand); font-weight: 600; }

.form-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.form-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.form-row:last-child { border-bottom: none; }
.form-row__label { font-size: 14px; color: var(--text-2); min-width: 48px; }
.form-row__input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  padding: 13px 0;
  color: var(--text);
}
.form-row__input::placeholder { color: #b6bccb; }
.form-row input[type="date"] { text-align: right; color: var(--text); }
.form-row__chevron { color: #c3c9d6; font-size: 16px; }

.save-wrap { margin-top: 18px; }

/* ---------- 明细 ---------- */
.summary-card {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--card);
  border-radius: 20px;
  padding: 16px 8px;
  box-shadow: var(--shadow);
}
.summary-card__item { text-align: center; position: relative; }
.summary-card__item + .summary-card__item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--line);
}
.summary-card__label { font-size: 12px; color: var(--muted); }
.summary-card__value {
  margin-top: 4px;
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.value-expense { color: var(--expense); }
.value-income { color: var(--income); }

.filters {
  display: flex;
  gap: 8px;
  margin: 16px 0 4px;
}
.chip {
  padding: 7px 16px;
  border-radius: 999px;
  background: #fff;
  color: var(--text-2);
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(27, 32, 48, 0.04);
}
.chip.is-active { background: var(--text); color: #fff; }

.day-group { margin-top: 16px; }
.day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 8px;
  font-size: 12px;
  color: var(--muted);
}
.day-head__date { font-weight: 600; color: var(--text-2); }
.tx-list {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.tx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.tx-row:last-child { border-bottom: none; }
.tx-row:active { background: #fafbfe; }
.tx-row__icon {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  flex: none;
  background: #f4f6fb;
}
.tx-row__main { flex: 1; min-width: 0; }
.tx-row__title {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tx-row__note {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}
.tx-row__amount {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.tx-row__amount.is-income { color: var(--income); }
.tx-row__amount.is-expense { color: var(--text); }

.load-more {
  margin: 18px auto 4px;
  display: block;
  color: var(--muted);
  font-size: 13px;
  padding: 10px 18px;
}

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty__icon { font-size: 40px; margin-bottom: 10px; opacity: 0.8; }
.empty__text { font-size: 14px; }

/* ---------- 统计 ---------- */
.stats-card {
  margin-top: 12px;
  background: var(--card);
  border-radius: 20px;
  padding: 20px 18px;
  box-shadow: var(--shadow);
}
.stats-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.stats-card__title { font-size: 15px; font-weight: 600; margin: 0; }
.seg--light {
  background: #f1f4fa;
  border-radius: 11px;
  padding: 3px;
  display: inline-flex;
}
.seg--light button {
  padding: 5px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.seg--light button.is-active { background: #fff; color: var(--brand); box-shadow: 0 2px 8px rgba(27, 32, 48, 0.08); }

.donut-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 0 4px;
}
.donut { position: relative; width: 176px; height: 176px; flex: none; }
.donut svg { transform: rotate(-90deg); }
.donut__center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.donut__label { font-size: 12px; color: var(--muted); }
.donut__value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }

.rank { margin-top: 10px; }
.rank__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.rank__item:last-child { border-bottom: none; }
.rank__icon {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: #f4f6fb;
  flex: none;
}
.rank__main { flex: 1; min-width: 0; }
.rank__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.rank__name { font-size: 14px; font-weight: 500; }
.rank__amount { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rank__bar {
  height: 5px;
  background: #f1f4fa;
  border-radius: 999px;
  margin-top: 6px;
  overflow: hidden;
}
.rank__bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}
.rank__pct { font-size: 11px; color: var(--muted); min-width: 40px; text-align: right; }

.trend {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  height: 150px;
  padding-top: 12px;
}
.trend__col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.trend__bars { display: flex; align-items: flex-end; gap: 3px; height: 100%; width: 100%; justify-content: center; }
.trend__bar {
  width: 8px;
  border-radius: 4px 4px 2px 2px;
  min-height: 3px;
  transition: height 0.4s ease;
}
.trend__bar--expense { background: linear-gradient(180deg, #ff8fa3, var(--expense)); }
.trend__bar--income { background: linear-gradient(180deg, #6ee0c1, var(--income)); }
.trend__label { font-size: 10px; color: var(--muted); white-space: nowrap; }
.trend__legend { display: flex; gap: 14px; justify-content: center; margin-top: 10px; font-size: 11px; color: var(--muted); }
.trend__legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

/* ---------- 我的 ---------- */
.profile {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
  border-radius: 22px;
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(255, 255, 255, 0.22) 0%, rgba(255, 255, 255, 0) 55%),
    linear-gradient(135deg, #3b6ef6, #6f5bff);
  color: #fff;
  box-shadow: 0 16px 32px rgba(59, 110, 246, 0.26);
}
.profile__avatar {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  flex: none;
}
.profile__name { font-size: 18px; font-weight: 700; }
.profile__meta { font-size: 12px; opacity: 0.85; margin-top: 3px; }

.menu {
  margin-top: 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.menu__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 15px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.menu__item:last-child { border-bottom: none; }
.menu__item:active { background: #fafbfe; }
.menu__icon {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex: none;
}
.menu__text { flex: 1; }
.menu__extra { font-size: 12px; color: var(--muted); }
.menu__item--danger .menu__icon { background: var(--expense-soft); color: var(--expense); }

.app-footer {
  text-align: center;
  font-size: 11px;
  color: #b6bccb;
  padding: 22px 0 8px;
  line-height: 1.8;
}

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  max-width: 480px;
  margin: 0 auto;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding: 0 8px var(--safe-bottom);
  display: flex;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  border-top: 1px solid rgba(27, 32, 48, 0.06);
}
.tabbar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #a3aab9;
  font-size: 10px;
  transition: color 0.18s ease;
}
.tabbar__item svg { width: 23px; height: 23px; fill: currentColor; }
.tabbar__item.is-active { color: var(--brand); font-weight: 600; }

/* ---------- 弹层 ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18, 22, 34, 0.42);
  z-index: 60;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  max-width: 480px;
  margin: 0 auto;
  background: #fff;
  border-radius: 24px 24px 0 0;
  padding: 8px 18px calc(20px + var(--safe-bottom));
  max-height: 86vh;
  overflow-y: auto;
  animation: sheetUp 0.28s cubic-bezier(0.22, 0.9, 0.3, 1);
  box-shadow: 0 -12px 40px rgba(27, 32, 48, 0.16);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet__grab {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: #e3e7f0;
  margin: 4px auto 12px;
}
.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.sheet__title { font-size: 17px; font-weight: 700; margin: 0; }
.sheet__close { color: var(--muted); font-size: 22px; line-height: 1; padding: 2px 6px; }
.sheet__actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet__actions .btn { flex: 1; }

.cat-manage { display: flex; flex-direction: column; gap: 8px; }
.cat-manage__list { max-height: 40vh; overflow-y: auto; }
.cat-manage__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
}
.cat-manage__row:last-child { border-bottom: none; }
.cat-manage__icon {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: #f4f6fb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}
.cat-manage__name { flex: 1; font-size: 14px; }
.cat-manage__del { color: var(--muted); font-size: 20px; padding: 0 6px; }
.cat-manage__form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.cat-manage__form .field__input { height: 44px; }

.emoji-row { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0; }
.emoji-row button {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  background: #f4f6fb;
  font-size: 18px;
}
.emoji-row button.is-active { background: var(--brand-soft); box-shadow: inset 0 0 0 2px var(--brand); }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 26px);
  transform: translate(-50%, 12px);
  z-index: 90;
  background: rgba(24, 29, 44, 0.92);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  max-width: 80vw;
  text-align: center;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

.loading {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 40px 0;
}

@media (min-width: 481px) {
  body { padding: 0; }
  .app { min-height: 100dvh; }
}
