/* ===== 小账本 · 样式 ===== */

:root {
  --bg:            #F6F5F2;
  --surface:       #FFFFFF;
  --ink:           #1A1A18;
  --ink-2:         #6E6A63;
  --ink-3:         #9A958D;
  --line:          #ECE9E2;
  --line-soft:     #F2EFE9;
  --track:         #F0EDE7;
  --expense:       #C94F3D;
  --expense-soft:  #FBEDEA;
  --income:        #4F8A5B;
  --income-soft:   #EDF4EE;
  --radius:        20px;
  --safe-b:        env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "PingFang SC", "MiSans", "HarmonyOS Sans SC",
               "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body.no-scroll { overflow: hidden; }

button, input { font-family: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- 视图 ---------- */
.views { flex: 1; }
.view { display: none; padding: 0 16px calc(96px + var(--safe-b)); }
.view.is-active { display: block; animation: fade .22s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.month-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .2px;
}

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  transition: background .15s;
}
.icon-btn:active { background: var(--line-soft); }

/* ---------- 月度汇总 ---------- */
.summary {
  background: var(--surface);
  border-radius: 24px;
  padding: 20px 20px 16px;
  box-shadow: 0 1px 2px rgba(26,26,24,.04), 0 10px 28px -16px rgba(26,26,24,.16);
}

.summary-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px;
  color: var(--ink-2);
}

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-expense { background: var(--expense); }

.summary-amount {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin: 8px 0 16px;
  font-size: 42px;
  font-weight: 650;
  letter-spacing: -1px;
  line-height: 1.1;
}
.summary-amount .currency {
  font-size: 21px;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0;
}

.summary-footer {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
  color: var(--ink-2);
}
.summary-cell { display: flex; align-items: baseline; gap: 7px; }
.summary-cell b {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.summary-cell b.neg { color: var(--expense); }
.summary-divider { width: 1px; height: 12px; background: var(--line); }

/* ---------- 明细列表 ---------- */
.list { margin-top: 22px; }

.date-group { margin-bottom: 18px; }

.date-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 6px 8px;
  font-size: 12.5px;
  color: var(--ink-3);
  letter-spacing: .3px;
}
.date-head .day-sum { font-variant-numeric: tabular-nums; }

.record-card {
  background: var(--surface);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(26,26,24,.03);
}

.record-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: none;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  text-align: left;
  transition: background .15s;
}
.record-card .record-row:last-child { border-bottom: none; }
.record-row:active { background: var(--line-soft); }

.cat-emoji {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--line-soft);
  font-size: 19px;
}

.record-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.record-cat { font-size: 14.5px; font-weight: 500; }
.record-note {
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-amount {
  font-size: 15.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.record-amount.income { color: var(--income); }

/* ---------- 空状态 ---------- */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-3);
}
.empty-icon { font-size: 36px; opacity: .55; margin-bottom: 12px; }
.empty p { margin: 0 0 6px; font-size: 15px; color: var(--ink-2); }
.empty span { font-size: 12.5px; }
.empty-sm { padding: 36px 20px; }
.empty-sm .empty-icon { font-size: 28px; margin-bottom: 8px; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  height: calc(66px + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  z-index: 30;
}

.tab {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--ink-3);
  font-size: 11.5px;
  transition: color .15s;
}
.tab.is-active { color: var(--ink); font-weight: 600; }

.fab {
  width: 54px; height: 54px;
  margin: 0 26px;
  display: grid; place-items: center;
  border: none;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 8px 20px -6px rgba(26,26,24,.5);
  transform: translateY(-12px);
  transition: transform .15s, background .15s;
}
.fab:active { transform: translateY(-10px) scale(.95); }

/* ---------- 遮罩 ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24,21,18,.38);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
  z-index: 40;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

/* ---------- 记一笔面板 ---------- */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  max-height: 94vh;
  max-height: 94dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px calc(10px + var(--safe-b));
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -10px 44px rgba(0,0,0,.14);
  transform: translateY(102%);
  transition: transform .34s cubic-bezier(.32,.72,0,1);
  z-index: 50;

  --accent: var(--expense);
  --accent-soft: var(--expense-soft);
}
.sheet.open { transform: translateY(0); }
.sheet.type-income { --accent: var(--income); --accent-soft: var(--income-soft); }

.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 58px;
  flex: none;
}
.sheet-spacer { justify-self: end; }

.text-btn {
  justify-self: start;
  border: none;
  background: none;
  padding: 6px 0;
  font-size: 15px;
  color: var(--ink-2);
}

/* 分段切换 */
.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--line-soft);
  border-radius: 999px;
}
.seg-center { display: flex; width: fit-content; margin: 2px auto 0; }
.seg-item {
  border: none;
  background: transparent;
  padding: 6px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  color: var(--ink-2);
  transition: background .2s, color .2s, box-shadow .2s;
}
.seg-item.is-active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(26,26,24,.12);
}

/* 金额 */
.amount-row {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 6px;
  padding: 6px 6px 16px;
}
.amount-cur { font-size: 23px; font-weight: 500; color: var(--ink-3); }
.amount-value {
  font-size: 42px;
  font-weight: 650;
  letter-spacing: -1px;
  line-height: 1.1;
}
.amount-value.is-empty { color: var(--ink-3); }

/* 分类 */
.cat-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-content: start;
  gap: 2px 0;
  overflow-y: auto;
  padding: 2px 0 8px;
  -webkit-overflow-scrolling: touch;
}
.cat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 7px 0;
  border: none;
  background: none;
  border-radius: 14px;
  font-size: 11.5px;
  color: var(--ink-2);
  transition: color .18s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.cat-ico {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: var(--line-soft);
  font-size: 21px;
  transition: background .18s, box-shadow .18s;
}
.cat-item.is-active { color: var(--ink); font-weight: 600; }
.cat-item.is-active .cat-ico {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.cat-item.cat-add { color: var(--ink-3); }
.cat-ico-add {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--line);
  color: var(--ink-3);
}

/* 备注 + 日期 */
.meta-row {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0 12px;
}
.note-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: var(--line-soft);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 14px;
  outline: none;
}
.note-input::placeholder { color: var(--ink-3); }
.note-input:focus { box-shadow: inset 0 0 0 1.5px var(--accent); }

.date-btn {
  flex: none;
  border: none;
  background: var(--line-soft);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 13px;
  color: var(--ink-2);
  white-space: nowrap;
}

.hidden-date {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
  border: none;
  padding: 0;
}

/* 键盘 */
.keypad {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 0 0 6px;
}
.keys {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.keys button {
  height: 54px;
  border: none;
  border-radius: 14px;
  background: var(--line-soft);
  font-size: 22px;
  font-weight: 500;
  transition: background .12s;
}
.keys button:active { background: var(--line); }
.keys .del { color: var(--ink-2); display: grid; place-items: center; }

.save-btn {
  flex: none;
  width: 88px;
  border: none;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  transition: opacity .2s, transform .12s;
}
.save-btn:disabled { opacity: .3; }
.save-btn:not(:disabled):active { transform: scale(.97); }

/* ---------- 统计 ---------- */
.stat-hero {
  padding: 24px 6px 10px;
}
.stat-hero .summary-amount { margin-bottom: 0; }

.chart-card {
  background: var(--surface);
  border-radius: 22px;
  padding: 18px 18px 22px;
  margin-top: 10px;
  box-shadow: 0 1px 2px rgba(26,26,24,.04);
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.chart-title { font-size: 15px; font-weight: 600; }
.chart-sub { font-size: 11.5px; color: var(--ink-3); }

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 17px;
  margin-top: 18px;
}

.bar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  font-size: 13.5px;
}
.bar-name { display: flex; align-items: center; gap: 6px; }
.bar-emoji { font-size: 14px; }
.bar-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bar-pct {
  margin-left: 7px;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--ink-3);
}

.bar-track {
  height: 10px;
  background: var(--track);
  border-radius: 0 5px 5px 0;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  min-width: 4px;
  border-radius: 0 5px 5px 0;
  background: var(--expense);
  transition: width .45s cubic-bezier(.32,.72,0,1);
}
.chart-card.type-income .bar-fill { background: var(--income); }

/* ---------- 单笔操作面板 ---------- */
.action-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px calc(16px + var(--safe-b));
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 44px rgba(0,0,0,.14);
  transform: translateY(102%);
  transition: transform .32s cubic-bezier(.32,.72,0,1);
  z-index: 50;
}
.action-sheet.open { transform: translateY(0); }

.act-info {
  padding: 22px 4px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.act-title { font-size: 16px; font-weight: 600; }
.act-sub {
  margin-top: 3px;
  font-size: 14px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.act-note {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--ink-3);
  word-break: break-all;
}

.act-btn {
  width: 100%;
  height: 52px;
  margin-top: 10px;
  border: none;
  border-radius: 14px;
  background: var(--line-soft);
  font-size: 15.5px;
  font-weight: 500;
}
.act-btn:active { background: var(--line); }
.act-danger { color: var(--expense); }
.act-cancel { color: var(--ink-2); }

/* ---------- 新建分类弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 9vh 24px 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal.show { opacity: 1; pointer-events: auto; }

.modal-card {
  width: 100%;
  max-width: 342px;
  padding: 18px;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(20,18,16,.28);
  transform: translateY(10px) scale(.98);
  transition: transform .24s cubic-bezier(.32,.72,0,1);

  --accent: var(--expense);
  --accent-soft: var(--expense-soft);
}
.modal.show .modal-card { transform: none; }
.modal-card.type-income { --accent: var(--income); --accent-soft: var(--income-soft); }

.modal-title { margin: 0; font-size: 17px; font-weight: 650; }
.modal-sub { margin: 3px 0 14px; font-size: 12.5px; color: var(--ink-3); }

.modal-input {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--line-soft);
  font-size: 16px;
  outline: none;
}
.modal-input::placeholder { color: var(--ink-3); }
.modal-input:focus { box-shadow: inset 0 0 0 1.5px var(--accent); }
.modal-input.err { box-shadow: inset 0 0 0 1.5px var(--expense); }

.emoji-label { margin: 16px 0 6px; font-size: 12.5px; color: var(--ink-2); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  max-height: 176px;
  overflow-y: auto;
}
.emoji-item {
  height: 38px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: 21px;
  transition: background .15s, box-shadow .15s;
}
.emoji-item.is-active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.modal-actions { display: flex; gap: 10px; margin-top: 17px; }
.modal-btn {
  flex: 1;
  height: 46px;
  border: none;
  border-radius: 14px;
  background: var(--line-soft);
  font-size: 15px;
  font-weight: 500;
}
.modal-btn:active { background: var(--line); }
.modal-btn-primary {
  flex: 1.4;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.modal-btn-primary:active { opacity: .85; background: var(--accent); }

.modal-hint {
  margin: 12px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-3);
}

/* ---------- 删除分类确认 ---------- */
.confirm-sheet { z-index: 80; }
.confirm-backdrop { z-index: 75; }
.modal-backdrop { z-index: 65; }

/* ---------- 汇总提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(14px + env(safe-area-inset-top, 0px));
  transform: translate(-50%, -12px);
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(26,26,24,.92);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 90;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 360px) {
  .summary-amount { font-size: 36px; }
  .amount-value { font-size: 36px; }
  .cat-ico { width: 42px; height: 42px; font-size: 19px; }
  .keys button { height: 50px; }
}
