:root {
  --bg: #F6F6F4;
  --surface: #FFFFFF;
  --surface-2: #EFF0ED;
  --ink: #1C1C20;
  --ink-2: #8A8A93;
  --ink-3: #BDBDC5;
  --accent: #5B7BDB;
  --income: #3E9B6B;
  --expense: #D9705C;
  --line: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.14);
  --radius: 20px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* 氛围光晕：固定在视口，不随内容滚动 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(1000px 600px at 50% -12%, rgba(91, 123, 219, 0.07), transparent 60%),
    radial-gradient(700px 500px at 100% 12%, rgba(62, 155, 107, 0.05), transparent 55%);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 30px) 24px calc(var(--safe-bottom) + 130px);
}

/* ---------- Hero ---------- */
.hero__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hero__new {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: 22px;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(91, 123, 219, 0.28);
  transition: transform 0.3s var(--ease-spring), box-shadow 0.3s var(--ease-spring);
}
.hero__new:active { transform: scale(0.94); }
.hero__new svg { width: 16px; height: 16px; }

.hero__date {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--ink-2);
}

.hero__title {
  margin: 6px 0 0;
  font-size: 17px;
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: 0.01em;
}

.balance { margin-top: 30px; }

.balance__label {
  display: block;
  font-size: 13px;
  color: var(--ink-2);
  letter-spacing: 0.03em;
}

.balance__value {
  display: block;
  margin-top: 4px;
  font-size: 58px;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.02;
  transition: color 0.4s ease;
}

.balance__value.is-negative { color: var(--expense); }

.balance-row {
  display: flex;
  gap: 40px;
  margin-top: 20px;
}

.sub-balance__label { display: block; font-size: 12px; color: var(--ink-3); }
.sub-balance__value { display: block; margin-top: 3px; font-size: 17px; font-weight: 600; }
.sub-balance__value--debt { color: var(--expense); }

/* ---------- Month card ---------- */
.month-card {
  margin-top: 28px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.month-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
}

.month-card__sub { font-size: 12px; font-weight: 400; color: var(--ink-3); }

.month-card__row { display: flex; gap: 40px; margin-top: 16px; }

.mstat__label { display: block; font-size: 12px; color: var(--ink-3); }
.mstat__value { display: block; margin-top: 2px; font-size: 20px; font-weight: 600; }
.mstat__value--income { color: var(--income); }
.mstat__value--expense { color: var(--expense); }

/* ---------- Entries ---------- */
.entries { margin-top: 32px; }

.day { margin-bottom: 28px; }

.day__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  padding: 0 4px 10px;
}

.day__sum { float: right; font-weight: 400; color: var(--ink-3); }

.entry {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  animation: entry-in 0.45s var(--ease-sheet) both;
}

.entry:active { background: var(--surface-2); }

.entry__icon {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--ink-2);
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.entry__icon svg { width: 20px; height: 20px; }

.entry__body { flex: 1; min-width: 0; }

.entry__cat { font-size: 15px; font-weight: 600; }
.entry__note { font-size: 12px; color: var(--ink-3); margin-top: 1px; }

.entry__amount { font-size: 16px; font-weight: 600; }
.entry__amount--expense { color: var(--ink); }
.entry__amount--income { color: var(--income); }

/* ---------- Empty state ---------- */
.empty { padding: 72px 24px 50px; text-align: center; }

.empty__mark { font-size: 40px; display: block; margin-bottom: 26px; color: var(--ink-3); }

.empty__btn {
  border: none;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 700;
  padding: 15px 34px;
  border-radius: 26px;
  cursor: pointer;
  transition: transform 0.3s var(--ease-spring);
}
.empty__btn:active { transform: scale(0.95); }

/* ---------- Sheet（全屏） ---------- */
.sheet {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: rgba(246, 246, 244, 0.88);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  transform: translateY(100%);
  pointer-events: none;
  transition: transform 0.42s var(--ease-sheet);
  z-index: 50;
}

.sheet.is-open { transform: translateY(0); pointer-events: auto; }

.sheet__top,
.sheet__body,
.sheet__footer {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.sheet__top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 22px) 24px 18px;
}

.sheet__title { font-size: 20px; font-weight: 700; }

.sheet__close {
  border: none;
  background: rgba(0, 0, 0, 0.05);
  padding: 10px 16px;
  border-radius: 22px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.3s var(--ease-spring), background 0.2s ease;
}
.sheet__close:active { transform: scale(0.92); background: rgba(0, 0, 0, 0.1); }

.sheet__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sheet__done {
  border: none;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  padding: 10px 18px;
  border-radius: 22px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(91, 123, 219, 0.28);
  transition: transform 0.3s var(--ease-spring), box-shadow 0.3s var(--ease-spring);
}
.sheet__done:active { transform: scale(0.92); }

.sheet__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 24px 8px;
}

.sheet__footer {
  flex: none;
  padding: 14px 24px calc(var(--safe-bottom) + 20px);
}

/* type switch */
.sheet__type {
  display: flex;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 4px;
  margin: 18px 0 16px;
}

.seg {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.25s ease, color 0.25s ease;
}

.seg.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* amount */
.sheet__amount {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1.5px solid var(--line);
}

.sheet__currency { font-size: 30px; font-weight: 600; color: var(--ink); }

.sheet__amount input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-family: inherit;
  min-width: 0;
}

.sheet__amount input::placeholder { color: var(--ink-3); }

/* categories */
.sheet__cats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 20px 0;
}

.cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 14px 4px;
  border: none;
  background: transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.25s var(--ease-spring), background 0.2s ease;
}

.cat:active { transform: scale(0.9); }

.cat__icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  color: var(--ink-2);
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  transition: color 0.25s ease, background 0.25s ease, transform 0.25s var(--ease-spring);
}

.cat__icon svg { width: 22px; height: 22px; }

.cat.is-selected .cat__icon {
  color: var(--accent);
  background: rgba(91, 123, 219, 0.08);
  border-color: rgba(91, 123, 219, 0.3);
  transform: scale(1.05);
}

.cat__name { font-size: 12px; color: var(--ink); font-weight: 500; }

.cat__back {
  grid-column: 1 / -1;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
}

/* note + save */
.sheet__note { margin: 16px 0 4px; }

.sheet__note input {
  width: 100%;
  border: 1px solid var(--line);
  outline: none;
  background: var(--surface);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.sheet__note input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 123, 219, 0.12);
}

.sheet__save {
  flex: none;
  width: 100%;
  margin-top: 18px;
  border: none;
  border-radius: 15px;
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  color: #FFFFFF;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.3s var(--ease-spring), opacity 0.2s ease;
}

.sheet__save:active { transform: scale(0.97); }
.sheet__save:disabled { opacity: 0.4; }

/* ---------- Pay / Creditor ---------- */
.sheet__pay { margin: 16px 0 4px; }

.pay__toggle {
  display: flex;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}

.sheet__creditor { margin: 16px 0 4px; }

.sheet__creditor input {
  width: 100%;
  border: 1px solid var(--line);
  outline: none;
  background: var(--surface);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
}

.chips { display: flex; gap: 8px; margin-top: 10px; }

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.25s var(--ease-spring), background 0.2s ease, border-color 0.2s ease;
}
.chip:active { transform: scale(0.92); }
.chip.is-active { background: rgba(91, 123, 219, 0.08); border-color: rgba(91, 123, 219, 0.4); color: var(--accent); }

/* ---------- Animations ---------- */
@keyframes entry-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 统计按钮 ---------- */
.hero__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero__stat {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 9px 16px;
  border-radius: 22px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.3s var(--ease-spring), background 0.2s ease;
}
.hero__stat:active { transform: scale(0.94); }

/* ---------- 统计模态 ---------- */
.stat {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translateY(100%);
  pointer-events: none;
  transition: transform 0.42s var(--ease-sheet);
  z-index: 50;
}
.stat.is-open { transform: translateY(0); pointer-events: auto; }

.stat__top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 22px) 24px 18px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.stat__title { font-size: 20px; font-weight: 700; }
.stat__close {
  border: none;
  background: rgba(0, 0, 0, 0.05);
  padding: 10px 16px;
  border-radius: 22px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.3s var(--ease-spring);
}
.stat__close:active { transform: scale(0.92); }

.stat__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 24px calc(var(--safe-bottom) + 40px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.stat__overview {
  display: flex;
  gap: 12px;
}

.stat-kpi {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}
.stat-kpi__label { display: block; font-size: 12px; color: var(--ink-3); }
.stat-kpi__value { display: block; margin-top: 4px; font-size: 20px; font-weight: 700; }
.stat-kpi__value--income { color: var(--income); }
.stat-kpi__value--expense { color: var(--expense); }
.stat-kpi__value.is-negative { color: var(--expense); }

.stat__section { margin-top: 28px; }
.stat__section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 14px;
}

.stat__bars { display: flex; flex-direction: column; gap: 14px; }

.stat-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}
.stat-bar__label {
  flex: none;
  width: 56px;
  font-size: 14px;
  color: var(--ink);
}
.stat-bar__track {
  flex: 1;
  height: 10px;
  background: var(--surface-2);
  border-radius: 5px;
  overflow: hidden;
}
.stat-bar__fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.6s var(--ease-sheet);
}
.stat-bar__fill--accent { background: var(--accent); }
.stat-bar__fill--expense { background: var(--expense); }
.stat-bar__value {
  flex: none;
  min-width: 64px;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.stat__empty {
  font-size: 14px;
  color: var(--ink-3);
  padding: 8px 0;
}

.stat__export {
  display: block;
  width: 100%;
  margin-top: 32px;
  border: none;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  padding: 15px;
  border-radius: 15px;
  border: 1px solid var(--line);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.3s var(--ease-spring), background 0.2s ease;
}
.stat__export:active { transform: scale(0.97); background: var(--surface-2); }

/* ---------- 可点击提示 ---------- */
.stat-kpi {
  cursor: pointer;
  transition: transform 0.2s var(--ease-spring);
}
.stat-kpi:active { transform: scale(0.97); }

.stat-bar { cursor: pointer; }
.stat-bar:active { opacity: 0.7; }

/* ---------- 明细模态 ---------- */
.detail {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translateY(100%);
  pointer-events: none;
  transition: transform 0.42s var(--ease-sheet);
  z-index: 60;
}
.detail.is-open { transform: translateY(0); pointer-events: auto; }

.detail__top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 22px) 24px 18px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.detail__title { font-size: 20px; font-weight: 700; }
.detail__close {
  border: none;
  background: rgba(0, 0, 0, 0.05);
  padding: 10px 16px;
  border-radius: 22px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.3s var(--ease-spring);
}
.detail__close:active { transform: scale(0.92); }

.detail__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 24px calc(var(--safe-bottom) + 40px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.detail-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.detail-row:last-child { border-bottom: none; }

.detail-row__main { flex: 1; min-width: 0; }
.detail-row__label { font-size: 15px; font-weight: 600; }
.detail-row__note { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.detail-row__date { font-size: 12px; color: var(--ink-3); margin-top: 1px; }

.detail-row__amount { font-size: 16px; font-weight: 600; }
.detail-row__amount--income { color: var(--income); }
.detail-row__amount--expense { color: var(--ink); }

.detail__empty {
  font-size: 14px;
  color: var(--ink-3);
  padding: 20px 4px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
