/* ===== 全局重置 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }

:root {
  --bg: #F8F3ED;
  --card: #FFFFFF;
  --text: #3D352C;
  --text-sub: #8B7D6B;
  --expense: #D4756A;
  --income: #7BA678;
  --primary: #C9B8A0;
  --primary-dark: #B5A088;
  --border: #E8E0D5;
  --danger: #E57373;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(61, 53, 44, 0.08);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ===== 布局 ===== */
.layout { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 20px; background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-logo { font-size: 24px; }
.topbar-name { font-weight: 600; font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user { font-size: 14px; color: var(--text-sub); }

.body { display: flex; flex: 1; }
.sidebar {
  width: 200px; padding: 12px 8px; background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 8px; color: var(--text-sub);
  transition: all 0.15s;
}
.menu-item:hover { background: var(--bg); }
.menu-item.active { background: var(--bg); color: var(--text); font-weight: 600; }
.menu-icon { font-size: 18px; width: 24px; text-align: center; }
.menu-text { font-size: 14px; }

.content { flex: 1; padding: 20px; overflow-y: auto; max-width: 900px; }

/* 移动端底部 Tab */
.mobile-tabbar { display: none; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 500;
  transition: all 0.15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; }
.btn-ghost { background: transparent; color: var(--text-sub); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }
.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ===== 表单 ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--text-sub); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--card); font-size: 15px;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-textarea { resize: vertical; min-height: 80px; }

/* ===== 卡片 ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

/* ===== 页面标题 ===== */
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 16px; padding: 4px 0; }

/* ===== 统计摘要 ===== */
.summary-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px;
}
.summary-card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  text-align: center; box-shadow: var(--shadow);
}
.summary-label { font-size: 12px; color: var(--text-sub); margin-bottom: 6px; }
.summary-value { font-size: 20px; font-weight: 700; }
.summary-value.expense { color: var(--expense); }
.summary-value.income { color: var(--income); }

/* ===== 月份选择器 ===== */
.month-selector {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.month-selector .btn { padding: 6px 14px; }
.month-display { font-size: 18px; font-weight: 600; }

/* ===== 搜索框 ===== */
.search-box {
  width: 100%; padding: 10px 16px; border: 1px solid var(--border);
  border-radius: 20px; font-size: 14px; margin-bottom: 16px;
  background: var(--card);
}
.search-box:focus { outline: none; border-color: var(--primary); }

/* ===== 记录列表 ===== */
.record-group { margin-bottom: 16px; }
.record-group-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 4px; font-size: 13px; color: var(--text-sub); font-weight: 600;
}
.record-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; background: var(--card); border-radius: var(--radius);
  margin-bottom: 8px; box-shadow: var(--shadow); transition: transform 0.1s;
}
.record-item:active { transform: scale(0.99); }
.record-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.record-main { flex: 1; min-width: 0; }
.record-title { font-size: 15px; font-weight: 500; }
.record-sub { font-size: 12px; color: var(--text-sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-amount { font-size: 16px; font-weight: 600; flex-shrink: 0; }
.record-amount.expense { color: var(--expense); }
.record-amount.income { color: var(--income); }

/* ===== 列表项通用 ===== */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 15px; font-weight: 500; }
.list-sub { font-size: 12px; color: var(--text-sub); }
.list-amount { font-size: 16px; font-weight: 600; flex-shrink: 0; }
.list-arrow { color: var(--text-sub); font-size: 18px; }

/* ===== Tab 切换 ===== */
.tabs {
  display: flex; gap: 4px; background: var(--bg); border-radius: 10px;
  padding: 3px; margin-bottom: 16px;
}
.tab {
  flex: 1; padding: 8px 0; text-align: center; border-radius: 8px;
  font-size: 14px; color: var(--text-sub); transition: all 0.15s;
}
.tab.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }

/* 类型切换 Tab（支出/收入） */
.type-tabs {
  display: flex; gap: 0; margin-bottom: 20px; border-bottom: 2px solid var(--border);
}
.type-tab {
  padding: 10px 24px; font-size: 15px; color: var(--text-sub);
  border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s;
}
.type-tab.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

/* ===== 分类网格 ===== */
.cat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px;
}
.cat-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 8px; border-radius: var(--radius); transition: all 0.15s;
  border: 2px solid transparent;
}
.cat-item:hover { background: var(--bg); }
.cat-item.selected { background: var(--bg); border-color: var(--primary); }
.cat-emoji { font-size: 28px; }
.cat-name { font-size: 12px; color: var(--text-sub); }

/* ===== 金额输入大字 ===== */
.amount-input-wrap { text-align: center; margin-bottom: 20px; }
.amount-input {
  font-size: 40px; font-weight: 700; text-align: center; border: none;
  background: transparent; width: 100%; color: var(--text);
}
.amount-input:focus { outline: none; }
.amount-currency { font-size: 24px; color: var(--text-sub); vertical-align: top; }

/* ===== 进度条 ===== */
.progress-bar {
  height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin: 8px 0;
}
.progress-fill {
  height: 100%; border-radius: 4px; transition: width 0.3s;
  background: var(--income);
}
.progress-fill.warn { background: #E8A856; }
.progress-fill.danger { background: var(--expense); }

/* ===== 空状态 ===== */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-sub);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }
.empty-detail { font-size: 12px; margin-top: 8px; color: var(--danger); }

/* ===== 弹窗 Modal ===== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-content {
  background: var(--card); border-radius: 16px; padding: 20px;
  width: 100%; max-width: 460px; max-height: 85vh; overflow-y: auto;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.modal-title { font-size: 18px; font-weight: 600; }
.modal-close { font-size: 24px; color: var(--text-sub); padding: 4px 8px; }

/* ===== 标签徽章 ===== */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 12px; font-weight: 500;
}
.badge-expense { background: #FAE6E3; color: var(--expense); }
.badge-income { background: #E6F0E5; color: var(--income); }
.badge-neutral { background: var(--bg); color: var(--text-sub); }
.badge-warn { background: #FFF3E0; color: #E8A856; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 10px 24px; border-radius: 24px;
  font-size: 14px; z-index: 300; opacity: 0; transition: all 0.3s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { background: var(--danger); }

/* ===== 图标按钮 ===== */
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; font-size: 16px;
  color: var(--text-sub); transition: background 0.15s;
}
.icon-btn:hover { background: var(--bg); }

/* ===== 头像 ===== */
.avatar {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover;
  background: var(--primary); display: inline-flex; align-items: center; justify-content: center;
  font-size: 28px; color: #fff;
}
.avatar-lg { width: 80px; height: 80px; font-size: 36px; }

/* ===== 表格 ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td {
  padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.data-table th { font-weight: 600; color: var(--text-sub); font-size: 13px; }
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ===== 区块标题 ===== */
.section-title {
  font-size: 14px; font-weight: 600; color: var(--text-sub);
  margin: 16px 0 8px; padding-left: 4px;
}

/* ===== 段间距 ===== */
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sub { color: var(--text-sub); }
.text-danger { color: var(--danger); }
.text-expense { color: var(--expense); }
.text-income { color: var(--income); }
.font-bold { font-weight: 600; }
.font-lg { font-size: 18px; }
.font-sm { font-size: 13px; }

/* ===== Flex 工具 ===== */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-col { display: flex; flex-direction: column; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }

/* ===== 登录页 ===== */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  background: var(--card); border-radius: 20px; padding: 40px 32px;
  width: 100%; max-width: 380px; box-shadow: var(--shadow);
}
.auth-logo { font-size: 56px; text-align: center; margin-bottom: 12px; }
.auth-title { text-align: center; font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { text-align: center; font-size: 14px; color: var(--text-sub); margin-bottom: 24px; }
.auth-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 20px; }
.auth-tab { flex: 1; padding: 8px 0; text-align: center; border-radius: 8px; font-size: 14px; color: var(--text-sub); transition: all 0.15s; }
.auth-tab.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.auth-form { margin-bottom: 16px; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 20px; margin-bottom: 8px; }
.auth-hint { text-align: center; font-size: 12px; color: var(--text-sub); line-height: 1.8; }

/* ===== 响应式：手机端 ===== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { padding: 12px; padding-bottom: 80px; }
  .mobile-tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--card); border-top: 1px solid var(--border);
    z-index: 100; padding: 6px 0; max-height: 64px;
  }
  .tabbar-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; color: var(--text-sub); padding: 4px 0;
  }
  .tabbar-icon { font-size: 22px; }
  .tabbar-add { color: var(--primary); }
  .summary-row { grid-template-columns: 1fr; gap: 8px; }
  .summary-value { font-size: 18px; }
  .cat-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .cat-item { padding: 8px 4px; }
  .cat-emoji { font-size: 24px; }
  .page-title { font-size: 18px; }
  .amount-input { font-size: 32px; }
  .topbar { padding: 0 12px; height: 50px; }
  .topbar-name { display: none; }
  .topbar-user { display: none; }
  .modal-content { border-radius: 12px; padding: 16px; }
}

/* ===== 复选框 ===== */
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--primary); }
.checkbox-row label { font-size: 14px; color: var(--text-sub); }

/* ===== 开关 ===== */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; inset: 0; background: var(--border); border-radius: 12px; transition: 0.3s;
}
.switch-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: 0.3s;
}
.switch input:checked + .switch-slider { background: var(--income); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }

/* ===== 图表容器 ===== */
.chart-wrap { position: relative; height: 300px; margin-bottom: 16px; }
.chart-wrap canvas { max-width: 100%; }
