/* ==================== 基础 ==================== */
:root {
  --bg: #F2F4F8;
  --card: #FFFFFF;
  --primary: #4F7CF7;
  --primary-deep: #3D63D8;
  --income: #18A058;
  --expense: #E5484D;
  --text: #1B1F27;
  --muted: #8A919F;
  --line: #ECEFF4;
  --shadow: 0 2px 12px rgba(31, 41, 55, .06);
  --tabbar-h: 56px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
}
input, textarea, button { font-family: inherit; font-size: 16px; color: inherit; }
input, textarea { user-select: text; -webkit-user-select: text; }
button { background: none; border: none; cursor: pointer; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
@supports (height: 100dvh) { #app { height: 100dvh; } }

main { flex: 1; min-height: 0; position: relative; overflow: hidden; }

/* ==================== 视图 ==================== */
.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.view.active { display: flex; }

.topbar {
  flex: none;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
.month-nav { display: flex; align-items: center; gap: 2px; margin: auto; }
.month-label { font-size: 17px; font-weight: 700; padding: 6px 10px; border-radius: 10px; }
.month-label:active { background: #E4E8F0; }
.nav-arrow {
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 24px; line-height: 1; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.nav-arrow:active { background: #E4E8F0; }
.page-title { font-size: 26px; font-weight: 800; padding: 4px 2px 2px; letter-spacing: .5px; }

.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 100px;
}

/* ==================== 记账页 ==================== */
.summary-card {
  background: linear-gradient(135deg, #5B8CFF, #4F7CF7);
  border-radius: 20px;
  padding: 18px 12px;
  color: #fff;
  display: flex;
  box-shadow: 0 6px 18px rgba(79, 124, 247, .35);
  margin-top: 4px;
}
.sum-item { flex: 1; text-align: center; position: relative; }
.sum-item + .sum-item::before {
  content: ''; position: absolute; left: 0; top: 22%; bottom: 22%;
  width: 1px; background: rgba(255, 255, 255, .28);
}
.sum-label { font-size: 12px; opacity: .85; }
.sum-val { font-size: 20px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

.day-head {
  display: flex; justify-content: space-between; align-items: center;
  margin: 18px 2px 8px; color: var(--muted); font-size: 12px;
}
.day-sum { font-variant-numeric: tabular-nums; }

.tx-row {
  background: var(--card); border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px; margin-bottom: 8px;
  box-shadow: var(--shadow); transition: transform .08s;
}
.tx-row:active { transform: scale(.985); }
.tx-icon {
  width: 40px; height: 40px; border-radius: 12px; background: #F0F3FA;
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none;
}
.tx-main { flex: 1; min-width: 0; }
.tx-cat { font-weight: 600; font-size: 15px; }
.tx-note { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.tx-amt.expense { color: var(--expense); }
.tx-amt.income { color: var(--income); }

/* ==================== 课时页 ==================== */
.course-card {
  background: var(--card); border-radius: 16px; padding: 16px;
  margin-bottom: 12px; box-shadow: var(--shadow);
}
.course-card:active { transform: scale(.99); }
.course-top { display: flex; align-items: center; gap: 8px; }
.course-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.course-name { font-weight: 700; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-badge { font-size: 11px; color: var(--muted); background: #F0F3FA; border-radius: 8px; padding: 2px 8px; flex: none; }
.course-remain { font-size: 13px; color: var(--muted); margin-top: 10px; }
.course-remain b { font-size: 30px; color: var(--text); font-weight: 800; margin-right: 4px; font-variant-numeric: tabular-nums; }
.course-remain-label { margin-left: 6px; }
.bar { height: 6px; border-radius: 3px; background: #EEF1F7; margin-top: 10px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.course-bottom { display: flex; justify-content: space-between; margin-top: 10px; font-size: 12px; color: var(--muted); gap: 8px; }

/* ==================== 统计页 ==================== */
.stat-cards { display: flex; gap: 10px; margin-top: 4px; }
.stat-card { flex: 1; background: var(--card); border-radius: 16px; padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stat-card .l { font-size: 12px; color: var(--muted); }
.stat-card .v { font-size: 18px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.v.inc { color: var(--income); }
.v.exp { color: var(--expense); }

.panel { background: var(--card); border-radius: 16px; padding: 16px; margin-top: 14px; box-shadow: var(--shadow); }
.panel-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; }

.rank-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.rank-row:last-child { margin-bottom: 0; }
.rank-name { width: 68px; font-size: 12px; color: var(--muted); flex: none; white-space: nowrap; }
.rank-bar { flex: 1; height: 8px; border-radius: 4px; background: #EEF1F7; overflow: hidden; }
.rank-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, #5B8CFF, #4F7CF7); }
.rank-val { width: 96px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }
.rank-pct { margin-left: 6px; color: var(--muted); font-size: 11px; }

.trend { display: flex; align-items: flex-end; gap: 6px; height: 150px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 4px; min-width: 0; }
.trend-bars { display: flex; gap: 2px; align-items: flex-end; height: 96px; width: 100%; justify-content: center; }
.tbar { width: 32%; max-width: 14px; border-radius: 3px 3px 0 0; min-height: 2px; }
.tbar.inc { background: var(--income); }
.tbar.exp { background: var(--expense); }
.trend-label { font-size: 11px; color: var(--muted); }
.trend-net { font-size: 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.trend-net.inc { color: var(--income); }
.trend-net.exp { color: var(--expense); }

.cl-grid { display: flex; gap: 10px; }
.cl-cell { flex: 1; background: #F7F9FC; border-radius: 12px; padding: 10px; text-align: center; }
.cl-cell .l { font-size: 12px; color: var(--muted); }
.cl-cell .v { font-size: 16px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.cl-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 2px; font-size: 14px; border-bottom: 1px dashed var(--line);
}
.cl-row:last-child { border-bottom: none; }
.cl-row .course-dot { width: 8px; height: 8px; }
.cl-row-name { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.cl-row-val { color: var(--muted); font-size: 13px; flex: none; }

/* ==================== 设置页 ==================== */
.settings-card { background: var(--card); border-radius: 16px; margin-top: 14px; box-shadow: var(--shadow); overflow: hidden; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 16px; gap: 12px; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row.col { flex-direction: column; align-items: flex-start; gap: 4px; }
.set-info { flex: 1; min-width: 0; }
.set-row .t { font-weight: 600; }
.set-row .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.about-text { line-height: 1.8; }
.mini-btn {
  height: 38px; padding: 0 16px; border-radius: 10px;
  background: #EDF2FF; color: var(--primary); font-size: 14px; font-weight: 600; flex: none;
}
.mini-btn:active { opacity: .7; }
.mini-btn.danger { background: #FDEDEE; color: var(--expense); }

/* ==================== 底部导航 ==================== */
.tabbar {
  flex: none;
  display: flex;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); transition: color .15s;
}
.tab-btn svg { width: 24px; height: 24px; }
.tab-btn span { font-size: 10px; line-height: 1; }
.tab-btn.active { color: var(--primary); font-weight: 600; }

/* ==================== 浮动按钮 ==================== */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 28px; line-height: 1;
  box-shadow: 0 6px 16px rgba(79, 124, 247, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
  transition: transform .2s;
}
.fab:active { transform: scale(.9); }
.fab.hidden { transform: scale(0); pointer-events: none; }

/* ==================== 底部弹层 ==================== */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 20, 30, .45);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
  z-index: 50;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(105%);
  transition: transform .28s cubic-bezier(.32, .72, .36, 1);
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet.show { transform: translateY(0); }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.sheet-title { flex: 1; font-size: 17px; font-weight: 700; text-align: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; background: #F0F3FA;
  color: var(--muted); font-size: 15px; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { opacity: .7; }

/* ==================== 表单 ==================== */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; height: 46px; border-radius: 12px;
  border: 1.5px solid transparent; background: #F2F4F8;
  padding: 0 14px; outline: none;
  transition: border-color .15s, background .15s;
  -webkit-appearance: none; appearance: none;
}
.field input:focus { border-color: var(--primary); background: #fff; }
.field-value { background: #F2F4F8; border-radius: 12px; padding: 12px 14px; color: var(--muted); }

.seg { display: flex; background: #F2F4F8; border-radius: 12px; padding: 4px; gap: 4px; }
.seg-btn { flex: 1; height: 38px; border-radius: 10px; font-size: 14px; color: var(--muted); font-weight: 600; transition: all .15s; }
.seg-btn.active { background: #fff; color: var(--primary); box-shadow: 0 1px 4px rgba(31, 41, 55, .12); }
.seg.big { margin-bottom: 14px; }
.seg.big .seg-btn { height: 44px; font-size: 16px; }

.amount-box { display: flex; align-items: center; justify-content: center; padding: 6px 0 16px; gap: 6px; }
.amount-symbol { font-size: 26px; font-weight: 700; color: var(--muted); }
.amount-box input {
  width: 70%; font-size: 40px; font-weight: 800; text-align: center;
  background: transparent; border: none; outline: none;
  font-variant-numeric: tabular-nums; -webkit-appearance: none; appearance: none;
}

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.cat-chip {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border-radius: 12px; background: #F2F4F8;
  font-size: 12px; border: 1.5px solid transparent;
}
.cat-chip span { font-size: 22px; }
.cat-chip.active { border-color: var(--primary); background: #EDF2FF; color: var(--primary); font-weight: 600; }

.color-row { display: flex; gap: 14px; flex-wrap: wrap; padding: 4px 0; }
.color-chip { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; transition: transform .12s; }
.color-chip.active { transform: scale(1.15); border-color: var(--text); }

/* ==================== 按钮 ==================== */
.btn {
  display: flex; align-items: center; justify-content: center;
  height: 48px; border-radius: 14px; font-size: 16px; font-weight: 600;
  padding: 0 18px; transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.success { background: var(--income); color: #fff; }
.btn.danger { background: var(--expense); color: #fff; }
.btn.ghost { background: #F0F3FA; color: var(--text); }
.btn.ghost.danger { color: var(--expense); }
.btn.block { width: 100%; }
.row-actions { display: flex; gap: 10px; margin-top: 16px; }
.row-actions .btn { flex: 1; }
.row-actions.ghost { margin-top: 10px; }

.section-title { font-size: 13px; color: var(--muted); margin: 16px 0 8px; font-weight: 600; }
.section-title .muted { font-weight: 400; font-size: 12px; }

/* ==================== 课程详情 ==================== */
.course-hero {
  background: linear-gradient(135deg, #F0F5FF, #E8EEFF);
  border-radius: 16px; padding: 16px; text-align: center; margin-bottom: 4px;
}
.hero-main { font-size: 15px; color: var(--muted); }
.hero-main b { font-size: 34px; color: var(--primary); font-variant-numeric: tabular-nums; margin: 0 2px; }
.hero-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.rec-list { margin-top: 8px; }
.rec-row {
  display: flex; align-items: center; gap: 10px;
  background: #F7F9FC; border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.rec-row:active { background: #EEF1F7; }
.rec-ico {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff; flex: none;
}
.rec-ico.add { background: var(--income); }
.rec-ico.use { background: var(--expense); }
.rec-main { flex: 1; font-size: 14px; min-width: 0; }
.rec-note { font-size: 12px; color: var(--muted); }
.rec-date { font-size: 12px; color: var(--muted); flex: none; }

/* ==================== 账目详情 ==================== */
.detail-amount { text-align: center; font-size: 32px; font-weight: 800; padding: 10px 0 4px; font-variant-numeric: tabular-nums; }
.detail-amount.income { color: var(--income); }
.detail-amount.expense { color: var(--expense); }
.detail-grid { margin: 12px 0 16px; }
.d-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.d-row:last-child { border-bottom: none; }
.d-row span { color: var(--muted); flex: none; }
.d-row b { font-weight: 600; max-width: 65%; text-align: right; word-break: break-all; }

/* ==================== 对话框 ==================== */
.dialog { padding: 10px 4px 0; text-align: center; }
.dialog-msg { font-size: 16px; font-weight: 600; padding: 10px 8px 6px; line-height: 1.6; }

/* ==================== 空状态 / 提示 ==================== */
.empty { padding: 48px 20px; text-align: center; color: var(--muted); font-size: 40px; }
.empty p { font-size: 15px; margin-top: 10px; color: var(--text); font-weight: 600; }
.empty .sub { font-size: 13px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.empty.small { padding: 20px 10px; font-size: 26px; }
.empty.small p { font-size: 14px; margin-top: 6px; }

.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 60px);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(20, 25, 35, .92);
  color: #fff; padding: 9px 18px; border-radius: 20px; font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: all .25s;
  z-index: 99;
  max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
