:root {
  --bg: #f5f0eb;
  --surface: #ffffff;
  --text: #2c2c2c;
  --text-muted: #8a8a8a;
  --primary: #ff6b4a;
  --primary-light: #fff0ec;
  --income: #2ecc71;
  --income-bg: #eafaf1;
  --expense: #e74c3c;
  --expense-bg: #fdecea;
  --balance: #3498db;
  --balance-bg: #ebf5fb;
  --border: #eee8e2;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Noto Sans SC", "Microsoft YaHei UI", sans-serif;
  background: linear-gradient(160deg, #fff5f0 0%, #f5f0eb 40%, #eef4f8 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Header */
.header {
  margin-bottom: 20px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 12px;
}

.greeting {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.title {
  font-size: 26px;
  font-weight: 700;
  background: linear-gradient(135deg, #ff6b4a, #ff9472);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* 年月选择器（胶囊） */
.month-picker {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.mp-arrow {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.mp-arrow:active { background: var(--primary-light); color: var(--primary); }
.mp-arrow:disabled { opacity: 0.3; cursor: default; }

.mp-label {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  padding: 8px 6px;
  min-width: 96px;
  cursor: pointer;
  border-radius: 999px;
  -webkit-tap-highlight-color: transparent;
}

.mp-label::after {
  content: "▾";
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 4px;
}

/* 月份选择弹层 */
.mp-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.25s;
  z-index: 200;
  touch-action: none;
  overscroll-behavior: contain;
}

.mp-mask.show { opacity: 1; }

.mp-sheet {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -46%);
  width: min(400px, calc(100vw - 32px));
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 201;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  outline: none;
}

.mp-sheet.show {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.mp-sheet-handle { display: none; }

.mp-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.mp-sheet-title {
  font-size: 16px;
  font-weight: 600;
}

.mp-today {
  border: none;
  background: var(--primary-light);
  color: var(--primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  min-height: 44px;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mp-year-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.mp-year-arrow {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  background: #fafafa;
  border-radius: 50%;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.mp-year-arrow:active { background: var(--primary-light); color: var(--primary); }
.mp-year-arrow:disabled { opacity: 0.3; cursor: default; }

.mp-year-label {
  font-size: 17px;
  font-weight: 700;
}

.mp-month-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.mp-month {
  padding: 12px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafafa;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.mp-month.now {
  border-color: var(--primary);
  color: var(--primary);
}

.mp-month.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(255, 107, 74, 0.35);
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0; /* 允许网格项收缩，防止长金额把页面撑出横向滚动 */
}

.summary-card .label {
  font-size: 12px;
  color: var(--text-muted);
}

.summary-card .value {
  font-size: 20px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.summary-card.income { background: var(--income-bg); }
.summary-card.income .value { color: var(--income); }
.summary-card.expense { background: var(--expense-bg); }
.summary-card.expense .value { color: var(--expense); }

/* Tabs */
.tabs {
  display: flex;
  background: var(--surface);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 8px;
  z-index: 50;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 10px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(255, 107, 74, 0.35);
}

@media (hover: hover) {
  .tab:hover:not(.active) {
    background: var(--primary-light);
    color: var(--primary);
  }
}

/* Panels */
.panel {
  display: none;
}

.panel.active {
  display: block;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.filter-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 16px; /* ≥16px 防止 iOS 聚焦缩放 */
  min-height: 44px;
  background: var(--surface);
}


/* Record form */
.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.type-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.type-btn[data-type="expense"].active {
  border-color: var(--expense);
  background: var(--expense-bg);
  color: var(--expense);
}

.type-btn[data-type="income"].active {
  border-color: var(--income);
  background: var(--income-bg);
  color: var(--income);
}

.amount-input-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  gap: 4px;
}

.amount-input-wrap .currency {
  font-size: 28px;
  font-weight: 600;
  color: var(--text-muted);
}

.amount-input-wrap input {
  border: none;
  outline: none;
  font-size: 36px;
  font-weight: 700;
  width: 180px;
  text-align: center;
  font-family: inherit;
  color: var(--text);
}

.amount-input-wrap input::placeholder {
  color: #ddd;
}

/* 去掉数字输入框的上下加减箭头 */
.amount-input-wrap input::-webkit-outer-spin-button,
.amount-input-wrap input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.amount-input-wrap input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.cat-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafafa;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  transition: all 0.15s;
}

.cat-btn .icon { font-size: 20px; }

.cat-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

/* 快捷消费项：虚线边框轻微区分于普通分类 */
.cat-btn.preset {
  border-style: dashed;
}

.cat-btn.preset.active {
  border-style: solid;
}

.form-row {
  margin-bottom: 12px;
}


.form-row label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-row input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px; /* ≥16px 防止 iOS 聚焦时自动放大页面 */
  outline: none;
  min-height: 44px;
  background: var(--surface);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s;
}

.form-row input:focus {
  border-color: var(--primary);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #ff6b4a, #ff8566);
  color: white;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(255, 107, 74, 0.35);
}

@media (hover: hover) {
  .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(255, 107, 74, 0.45);
  }
}

.btn-primary:active {
  transform: translateY(0);
}

/* Record list */
.record-list {
  max-height: 480px;
  overflow-y: auto;
}

.record-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.record-item:last-child {
  border-bottom: none;
}

.record-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.record-icon.expense { background: var(--expense-bg); }
.record-icon.income { background: var(--income-bg); }

.record-info {
  flex: 1;
  min-width: 0;
}

.record-info .name {
  font-size: 14px;
  font-weight: 500;
}

.record-info .meta {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-amount {
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
}

.record-amount.expense { color: var(--expense); }
.record-amount.income { color: var(--income); }

/* 账单页操作区：导出/导入/筛选 */
.bill-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 12px;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-ghost:active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.btn-delete {
  border: none;
  background: transparent;
  color: #ccc;
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  min-width: 44px;
  min-height: 44px;
  line-height: 1;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .btn-delete:hover {
    color: var(--expense);
  }
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 0;
  font-size: 14px;
}

/* Charts */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.chart-card .chart-wrap {
  position: relative;
  height: 240px;
}

.chart-card.wide {
  grid-column: 1 / -1;
}

.chart-card.wide .chart-wrap {
  height: 280px;
}

.top-list {
  list-style: none;
}

.top-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.top-list li:last-child {
  border-bottom: none;
}

.top-list .rank {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-right: 10px;
  flex-shrink: 0;
}

.top-list .info {
  flex: 1;
  display: flex;
  align-items: center;
}

.top-list .amount {
  font-weight: 600;
  color: var(--expense);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(44, 44, 44, 0.88);
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Responsive（移动端） */
@media (max-width: 640px) {
  .app {
    padding: 16px 12px calc(32px + env(safe-area-inset-bottom));
  }

  .title { font-size: 22px; }

  /* 标题与年月选择器保持同一行，选择器更紧凑 */
  .header-top {
    align-items: center;
    margin-bottom: 12px;
  }

  /* 箭头保持 44px 触控目标，仅压缩标签留白 */
  .mp-label { min-width: 84px; font-size: 14px; padding: 8px 2px; }

  /* 汇总卡片：三列紧凑排布，一屏可见 */
  .summary-cards { gap: 8px; }

  .summary-card {
    padding: 12px 10px;
    gap: 4px;
    border-radius: 12px;
  }

  .summary-card .label { font-size: 11px; }
  .summary-card .value { font-size: clamp(12px, 4vw, 15px); }

  .card { padding: 16px 14px; }

  .category-grid { grid-template-columns: repeat(4, 1fr); }

  .amount-input-wrap input { font-size: 32px; width: 150px; }

  .chart-grid { grid-template-columns: 1fr; }

  /* 月份弹层改为底部抽屉 */
  .mp-sheet {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    transform: translateY(100%);
    border-radius: 20px 20px 0 0;
    padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .mp-sheet.show { transform: translateY(0); }

  .mp-sheet-handle {
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 0 auto 12px;
  }

  .mp-month { min-height: 48px; }

  .toast {
    bottom: calc(24px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 48px);
    text-align: center;
  }
}
