/* ========== 全局样式 ========== */
:root {
  --c-primary: #6366F1;
  --c-primary-light: #A5B4FC;
  --c-expense: #EF4444;
  --c-expense-light: #FEE2E2;
  --c-income: #10B981;
  --c-income-light: #D1FAE5;
  --c-bg: #F5F3FF;
  --c-card: #FFFFFF;
  --c-text: #1F2937;
  --c-text-secondary: #6B7280;
  --c-text-light: #9CA3AF;
  --c-border: #E5E7EB;
  --c-divider: #F3F4F6;
  --c-toast-bg: #1F2937;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  position: relative;
}

/* ========== 顶部栏 ========== */
#header {
  background: var(--c-primary);
  color: #fff;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
#headerTitle { font-size: 18px; font-weight: 600; }
.header-sub { font-size: 13px; opacity: 0.85; }

/* ========== 内容区 ========== */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  padding-bottom: 80px;
}

/* ========== 底部导航 ========== */
#tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--c-card);
  border-top: 1px solid var(--c-border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0;
  border: none;
  background: none;
  color: var(--c-text-light);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
}
.tab.active { color: var(--c-primary); }
.tab-icon { font-size: 22px; }

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

/* ========== 记账页 — 快速记录区 ========== */
.record-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}
.quick-add-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 12px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.quick-add-btn:active { transform: scale(0.96); }
.quick-add-btn .quick-add-icon { font-size: 32px; }
.quick-add-btn .quick-add-label { font-size: 14px; }
.quick-add-btn.expense-btn { background: #FFF5F5; color: var(--c-expense); border: 1.5px solid #FECACA; }
.quick-add-btn.income-btn { background: #F0FDF4; color: var(--c-income); border: 1.5px solid #BBF7D0; }

/* 轻量摘要行 */
.record-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 0 14px;
  font-size: 13px;
  color: var(--c-text-secondary);
}
.record-summary .rs-item b { font-weight: 700; }
.record-summary .c-red { color: var(--c-expense); }
.record-summary .c-green { color: var(--c-income); }
.record-summary .rs-divider { color: var(--c-border); }

/* 账单明细标题 + 月份切换 */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
}
.month-picker-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.month-picker-inline button {
  background: none; border: none;
  font-size: 16px; cursor: pointer; color: var(--c-primary);
  padding: 2px 6px;
}
.month-picker-inline span { font-size: 13px; font-weight: 500; color: var(--c-text-secondary); }

/* ========== 统计页 — 大数字 ========== */
.stats-hero { margin-bottom: 14px; }
.stats-hero-row { display: flex; gap: 10px; margin-bottom: 10px; }
.stats-hero-item {
  flex: 1;
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}
.stats-hero-item.expense-bg { background: linear-gradient(135deg, #FEF2F2, #FEE2E2); }
.stats-hero-item.income-bg { background: linear-gradient(135deg, #ECFDF5, #D1FAE5); }
.stats-hero-label { font-size: 12px; color: var(--c-text-secondary); margin-bottom: 6px; }
.stats-hero-item .stats-hero-value {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -1px;
}
.stats-hero-item.expense-bg .stats-hero-value { color: var(--c-expense); }
.stats-hero-item.income-bg .stats-hero-value { color: var(--c-income); }

.stats-hero-balance {
  text-align: center;
  padding: 12px;
  border-radius: 12px;
  font-size: 14px;
  color: var(--c-text-secondary);
}
.stats-hero-balance strong { font-size: 22px; margin-left: 8px; }
.stats-hero-balance.positive { background: #F0FDF4; }
.stats-hero-balance.positive strong { color: var(--c-income); }
.stats-hero-balance.negative { background: #FFF5F5; }
.stats-hero-balance.negative strong { color: var(--c-expense); }

/* ========== 账单列表 ========== */
.tx-date-group { margin-bottom: 12px; }
.tx-date-label {
  font-size: 13px;
  color: var(--c-text-secondary);
  padding: 8px 4px 4px;
  font-weight: 500;
}
.tx-date-summary {
  float: right;
  font-size: 12px;
  font-weight: 600;
}
.tx-date-summary.expense { color: var(--c-expense); }
.tx-date-summary.income { color: var(--c-income); }

.tx-item {
  display: flex;
  align-items: center;
  padding: 12px;
  background: var(--c-card);
  border-radius: 10px;
  margin-bottom: 1px;
  box-shadow: var(--shadow);
  gap: 12px;
}
.tx-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.tx-icon.expense { background: var(--c-expense-light); }
.tx-icon.income { background: var(--c-income-light); }
.tx-info { flex: 1; min-width: 0; }
.tx-info .tx-cat { font-size: 14px; font-weight: 500; }
.tx-info .tx-note { font-size: 12px; color: var(--c-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}
.tx-amount.expense { color: var(--c-expense); }
.tx-amount.income { color: var(--c-income); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--c-text-light);
}
.empty-state .empty-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.empty-state .empty-text { font-size: 14px; }

/* ========== 统计页 ========== */
.stats-summary { display: flex; gap: 10px; margin-bottom: 12px; }
.stat-card {
  flex: 1;
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; color: var(--c-text-secondary); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 18px; font-weight: 700; }
.stat-card .stat-value.red { color: var(--c-expense); }
.stat-card .stat-value.green { color: var(--c-income); }

.chart-container {
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.chart-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--c-text-secondary); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chart-legend-item { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--c-text-secondary); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

canvas { max-width: 100%; }

.month-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}
.month-picker button {
  background: none; border: none;
  font-size: 18px; cursor: pointer; color: var(--c-primary);
  padding: 4px 8px;
}
.month-picker span { font-size: 15px; font-weight: 600; min-width: 80px; text-align: center; }

/* ========== 设置页 ========== */
.setting-group { margin-bottom: 20px; }
.setting-group-title { font-size: 12px; color: var(--c-text-light); padding: 0 4px 6px; }
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  background: var(--c-card);
  border-radius: 10px;
  margin-bottom: 1px;
  box-shadow: var(--shadow);
  cursor: pointer;
  gap: 10px;
  font-size: 14px;
  transition: background 0.15s;
}
.setting-item:active { background: var(--c-divider); }
.setting-item .si-icon { font-size: 18px; }
.setting-item .si-text { flex: 1; }
.setting-item .si-arrow { color: var(--c-text-light); font-size: 14px; }

/* ========== 弹窗 / 底部面板 ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--c-card);
  border-radius: 20px 20px 0 0;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  animation: slideUp 0.25s ease-out;
  max-height: 85dvh;
  overflow-y: auto;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 600;
}

.btn-text { background: none; border: none; color: var(--c-text-secondary); font-size: 15px; cursor: pointer; }
.btn-primary {
  background: var(--c-primary);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.type-toggle {
  display: flex;
  background: var(--c-divider);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 16px;
}
.type-btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--c-text-secondary);
  transition: all 0.2s;
}
.type-btn.active {
  background: #fff;
  color: var(--c-text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.amount-input {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0 16px;
}
.currency {
  font-size: 28px;
  font-weight: 300;
  color: var(--c-text-secondary);
  margin-right: 2px;
}
.amount-input input {
  border: none;
  outline: none;
  font-size: 40px;
  font-weight: 600;
  width: 160px;
  text-align: left;
  background: none;
  color: var(--c-text);
}
.amount-input input::placeholder { color: var(--c-text-light); }
/* 隐藏数字输入框的箭头 */
.amount-input input::-webkit-outer-spin-button,
.amount-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.amount-input input[type=number] { -moz-appearance: textfield; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.cat-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: 1.5px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--c-text-secondary);
  transition: all 0.15s;
  background: var(--c-divider);
}
.cat-option.selected {
  border-color: var(--c-primary);
  background: #EEF2FF;
  color: var(--c-primary);
}
.cat-option .cat-icon { font-size: 22px; }

.form-row {
  display: flex;
  gap: 10px;
}
.input-field {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  color: var(--c-text);
  background: var(--c-divider);
}
.input-field:focus { border-color: var(--c-primary); }

/* ========== Toast ========== */
.toast {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--c-toast-bg);
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.hidden { display: none; }

/* ========== 同步状态 ========== */
.sync-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 6px;
}
.sync-indicator.synced { background: #10B981; }
.sync-indicator.pending { background: #F59E0B; }
.sync-indicator.offline { background: #EF4444; }

/* ========== 确认对话框 ========== */
.confirm-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
}
.confirm-dialog.hidden { display: none; }
.confirm-box {
  background: var(--c-card);
  border-radius: 16px;
  padding: 24px;
  width: 280px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.confirm-box .confirm-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.confirm-box .confirm-msg { font-size: 13px; color: var(--c-text-secondary); margin-bottom: 20px; }
.confirm-box .confirm-actions { display: flex; gap: 10px; }
.confirm-box .confirm-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  cursor: pointer;
}
.confirm-box .btn-cancel { background: var(--c-divider); color: var(--c-text-secondary); }
.confirm-box .btn-danger { background: var(--c-expense); color: #fff; }
