/* =========================================================
   小账本 样式表
   顺序：变量 → 全局 → 顶部 → 卡片/表单 → 列表 → 手机适配
   ========================================================= */

/* ---------- 1. 设计变量：颜色、圆角改这里就能换肤 ---------- */
:root {
  --bg: #0f1115;
  --card: #181b21;
  --card-2: #20242c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f2f4f8;
  --text-dim: #8b93a1;
  --hero-from: #1d2433;
  --hero-to: #14161a;
  --expense: #ff6b6b;
  --income: #3ddc97;
  --accent: #5b8cff;
  --radius: 18px;

  /* 图表配色：同一个分类永远拿到同一个颜色（顺序不能乱改） */
  --c1: #ff6b6b;
  --c2: #ffb84d;
  --c3: #5b8cff;
  --c4: #3ddc97;
  --c5: #b07cff;
  --c6: #4dc9e6;
}

/* 浅色主题：只换颜色变量，结构一行都不用动 */
[data-theme="light"] {
  --bg: #f5f6f9;
  --card: #ffffff;
  --card-2: #f0f2f6;
  --line: rgba(15, 17, 21, 0.08);
  --text: #1a1d24;
  --text-dim: #7a8290;
  --hero-from: #e8eeff;
  --hero-to: #f5f6f9;
  --expense: #e8554f;
  --income: #16a06b;
  --accent: #3f74f0;
  --c1: #f26b6b;
  --c2: #f0a33c;
  --c3: #4d7ff0;
  --c4: #2fbf85;
  --c5: #9a6cf0;
  --c6: #3fb8d4;
}

/* ---------- 2. 全局 ---------- */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0 0 40px;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;
  max-width: 480px;          /* 手机比例，电脑上也不会被拉得太宽 */
  margin-inline: auto;
  min-height: 100vh;
}

button,
input {
  font-family: inherit;
  font-size: 16px;           /* 小于 16px 时 iOS 会自动放大页面 */
  color: inherit;
  border: none;
  outline: none;
}

/* ---------- 3. 顶部结算区 ---------- */
.hero {
  padding: 28px 20px 22px;
  background: linear-gradient(160deg, var(--hero-from) 0%, var(--hero-to) 70%);
  border-bottom: 1px solid var(--line);
  border-radius: 0 0 28px 28px;
}

.hero-top {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 1px;
}

.brand-sub {
  font-size: 13px;
  color: var(--text-dim);
}

.theme-btn {
  margin-left: auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.3s;
}

.theme-btn:active { transform: rotate(45deg); }

.balance {
  margin: 14px 0 20px;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

.hero-stats {
  display: flex;
  gap: 12px;
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 14px;
}

[data-theme="light"] .stat { background: rgba(255, 255, 255, 0.7); }
[data-theme="light"] .theme-btn { background: rgba(0, 0, 0, 0.06); }

.stat-label {
  font-size: 12px;
  color: var(--text-dim);
}

.stat-value {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.income { color: var(--income); }
.expense { color: var(--expense); }

.stat-reset {
  flex: 0 0 72px;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.stat-reset:active { opacity: 0.6; }

/* ---------- 4. 容器与卡片 ---------- */
.container {
  padding: 18px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 支出 / 收入 切换 */
.type-switch {
  display: flex;
  padding: 4px;
  background: var(--card-2);
  border-radius: 12px;
}

.type-btn {
  flex: 1;
  padding: 8px 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.type-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* 表单字段 */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 13px;
  color: var(--text-dim);
}

.amount-input {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--card-2);
  border-radius: 12px;
}

.currency {
  font-size: 22px;
  color: var(--text-dim);
}

#amount-input {
  flex: 1;
  width: 100%;
  background: transparent;
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#amount-input::placeholder { color: #4a505c; }

/* 去掉数字输入框的上下小箭头 */
#amount-input::-webkit-outer-spin-button,
#amount-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#note-input {
  padding: 11px 14px;
  background: var(--card-2);
  border-radius: 12px;
}

/* 分类小按钮 */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  background: var(--card-2);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.18s;
}

.chip.active {
  background: rgba(91, 140, 255, 0.16);
  border-color: var(--accent);
  color: #cfe0ff;
}

/* 提交按钮 */
.submit-btn {
  margin-top: 2px;
  padding: 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #5b8cff, #7a6bff);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.2s;
}

.submit-btn:active { transform: scale(0.98); }

/* ---------- 5. 账单列表 ---------- */
.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.list-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.list-count {
  font-size: 13px;
  color: var(--text-dim);
}

.record-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  animation: slide-in 0.22s ease-out;
}

/* 列表里第 n 条晚一点出现，形成错开的下落效果（最多排到第 8 条） */
.record:nth-child(1) { animation-delay: 0ms; }
.record:nth-child(2) { animation-delay: 30ms; }
.record:nth-child(3) { animation-delay: 60ms; }
.record:nth-child(4) { animation-delay: 90ms; }
.record:nth-child(5) { animation-delay: 120ms; }
.record:nth-child(n+6) { animation-delay: 150ms; }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.record-icon {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  font-size: 19px;
  background: var(--card-2);
  border-radius: 11px;
}

.record-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.record-category {
  font-size: 15px;
}

.record-meta {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-amount {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.record-delete {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: transparent;
  color: #5b6270;
  font-size: 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.record-delete:active {
  background: rgba(255, 107, 107, 0.15);
  color: var(--expense);
}

/* 空状态 */
.empty {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 36px 0;
  color: var(--text-dim);
  font-size: 14px;
}

.empty.show { display: flex; }

.empty-icon { font-size: 34px; }

/* ---------- 5.4 预算提醒 ---------- */
.text-btn {
  padding: 4px 10px;
  background: var(--card-2);
  color: var(--accent);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.text-btn:active { opacity: 0.6; }

.budget-main {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.budget-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.budget-spent {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.budget-left {
  font-size: 13px;
  color: var(--text-dim);
  text-align: right;
}

/* 进度条轨道 */
.budget-track {
  position: relative;
  height: 10px;
  background: var(--card-2);
  border-radius: 999px;
  overflow: hidden;
}

.budget-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--income);        /* 默认：安全 */
  transition: width 0.55s cubic-bezier(0.22, 1, 0.36, 1), background 0.3s;
}

/* 三档状态：safe < 60% ≤ warn < 90% ≤ danger */
.is-warn .budget-fill    { background: var(--c2); }
.is-danger .budget-fill  { background: var(--expense); }
.is-danger .budget-spent { color: var(--expense); }

.budget-foot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
}

#budget-pct {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* 超支时抖一下，吸引注意力（只播一次） */
.is-danger.just-over .budget-main {
  animation: shake 0.45s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-5px); }
  50%      { transform: translateX(5px); }
  75%      { transform: translateX(-3px); }
}

/* 分类预算列表 */
.budget-list {
  list-style: none;
  margin: 0;
  padding: 14px 0 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.budget-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.budget-item .bar-head { font-size: 13px; }

.budget-item-track {
  height: 6px;
  background: var(--card-2);
  border-radius: 999px;
  overflow: hidden;
}

.budget-item-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  transition: width 0.55s cubic-bezier(0.22, 1, 0.36, 1), background 0.3s;
}

.budget-item.is-warn .budget-item-fill   { background: var(--c2); }
.budget-item.is-danger .budget-item-fill { background: var(--expense); }
.budget-item.is-danger .bar-amount       { color: var(--expense); }
.budget-item.is-warn .bar-amount         { color: var(--c2); }

.budget-empty {
  padding: 4px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------- 5.42 数据备份 ---------- */
.data-hint {
  margin: -4px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
}

.data-drop {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 18px 14px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  font-size: 13px;
  color: var(--text-dim);
  transition: border-color 0.2s, background 0.2s;
}

/* 拖文件经过时高亮 */
.data-drop.dragover {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.08);
}

.data-drop-icon {
  font-size: 18px;
}

.data-actions {
  display: flex;
  gap: 10px;
}

.data-actions .ghost-btn {
  flex: 1;
  padding: 12px;
  font-size: 14px;
}

.data-note {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}

/* 顶部备份提醒条：安静、可点击、导出后自动消失 */
.backup-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: rgba(240, 163, 60, 0.12);
  border: 1px solid rgba(240, 163, 60, 0.35);
  border-radius: 12px;
  font-size: 12px;
  color: var(--c2);
  text-align: left;
  cursor: pointer;
  animation: hint-in 0.3s ease-out;
}

.backup-hint-action {
  flex: 0 0 auto;
  padding: 4px 10px;
  background: rgba(240, 163, 60, 0.2);
  border-radius: 8px;
  font-weight: 600;
}

@keyframes hint-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- 5.45 弹层 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.modal.open {
  opacity: 1;
  visibility: visible;
}

.modal-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  background: var(--card);
  border-radius: 24px 24px 0 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal.open .modal-sheet { transform: translateY(0); }

.modal-handle {
  width: 38px;
  height: 4px;
  margin: 4px auto 2px;
  background: var(--line);
  border-radius: 999px;
}

.modal-title {
  margin: 0;
  font-size: 18px;
}

.modal-desc {
  margin: -6px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

.amount-input.compact { padding: 6px 12px; }
.amount-input.compact input { font-size: 20px; }

/* 分类预算一行：图标 + 名称 + 输入框 */
.budget-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.budget-form-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.budget-form-row .bar-name { flex: 1; }

.budget-form-row input {
  width: 104px;
  padding: 8px 10px;
  text-align: right;
  background: var(--card-2);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.modal-actions .submit-btn { flex: 1; margin: 0; }

.ghost-btn {
  flex: 0 0 96px;
  padding: 14px;
  background: var(--card-2);
  border-radius: 14px;
  font-size: 16px;
  cursor: pointer;
}

/* ---------- 5.5 支出构成图表 ---------- */
.chart-card { gap: 16px; }

.donut-wrap {
  position: relative;
  width: 168px;
  height: 168px;
  margin: 4px auto 2px;
}

.donut {
  width: 100%;
  height: 100%;
  display: block;
}

/* 圆环每一段：用 stroke 画，鼠标移上去会加粗 */
.donut-seg {
  fill: none;
  stroke-width: 13;
  stroke-linecap: round;
  transform-origin: 50% 50%;
  transition: stroke-width 0.2s, opacity 0.2s;
  cursor: pointer;
}

.donut-seg:hover {
  stroke-width: 16;
}

.donut-track {
  fill: none;
  stroke: var(--card-2);
  stroke-width: 13;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  pointer-events: none;
}

.donut-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.donut-label {
  font-size: 12px;
  color: var(--text-dim);
}

/* 分类排行条 */
.bars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 一行两列：左边“图标 名称”，右边“金额 百分比”，
   进度条单独占满第二行（grid-column: 1 / -1 = 从第一列跨到最后一列） */
.bar {
  display: grid;
  grid-template-columns: 1fr auto;
  row-gap: 6px;
  align-items: baseline;
}

.bar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.bar-icon { font-size: 15px; }

.bar-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-right {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.bar-amount {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.bar-pct {
  min-width: 38px;
  text-align: right;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.bar-track {
  grid-column: 1 / -1;
  height: 7px;
  background: var(--card-2);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.chart-empty {
  padding: 26px 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

/* 轻提示条（由 JS 动态创建） */
.toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translate(-50%, 12px);
  padding: 10px 18px;
  background: rgba(40, 44, 54, 0.96);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 6. 小屏与安全区适配 ---------- */
@media (max-width: 360px) {
  .balance { font-size: 34px; }
  .chip { padding: 7px 10px; font-size: 13px; }
}

@supports (padding: env(safe-area-inset-bottom)) {
  body { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
}
