:root {
  --bg0: #e8f0ea;
  --bg1: #d4e5d8;
  --ink: #14241c;
  --muted: #5a6f62;
  --line: #b8cfc0;
  --surface: rgba(255, 252, 247, 0.92);
  --surface-solid: #fffcf7;
  --accent: #1a6b4a;
  --accent-soft: #c8e6d4;
  --expense: #9f1239;
  --income: #0f766e;
  --balance: #1e3a5f;
  --radius: 16px;
  --shadow: 0 8px 28px rgba(20, 36, 28, 0.08);
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --navbar-h: 52px;
  --bottom-h: 64px;
}

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

html, body { min-height: 100%; margin: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 10% -10%, #f4faf5 0%, transparent 55%),
    radial-gradient(90% 70% at 100% 0%, #cfe8d8 0%, transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

.app-shell {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: calc(var(--navbar-h) + var(--safe-top) + 12px) 16px calc(24px + var(--safe-bottom));
}
.app-shell.has-bottom {
  padding-bottom: calc(var(--bottom-h) + var(--safe-bottom) + 20px);
}

/* —— NavBar —— */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding: var(--safe-top) 12px 0;
  background: rgba(255, 252, 247, 0.92);
  border-bottom: 1px solid rgba(184, 207, 192, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.navbar-inner {
  width: min(720px, 100%);
  margin: 0 auto;
  min-height: var(--navbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.navbar-left {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.navbar-title {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.navbar-back {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  margin-left: -6px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.navbar-back:active { background: rgba(200, 230, 212, 0.45); }
.navbar-user {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 42%;
  min-height: 36px;
  height: 36px;
  padding: 0 12px;
  border: none;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
}
.navbar-user:active { opacity: 0.85; }

/* —— 底部记一笔 —— */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 8px 16px calc(8px + var(--safe-bottom));
  background: rgba(255, 252, 247, 0.94);
  border-top: 1px solid rgba(184, 207, 192, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.bottom-bar-inner {
  width: min(720px, 100%);
  margin: 0 auto;
}
.btn-record {
  width: 100%;
  min-height: 48px;
  font-size: 1.05rem;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #1a6b4a, #0f4f38);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(26, 107, 74, 0.28);
  cursor: pointer;
}
.btn-record:active { transform: scale(0.99); }

.page-title {
  font-family: var(--display);
  font-size: clamp(1.4rem, 5vw, 1.8rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

.muted { color: var(--muted); font-size: 0.92rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-block { width: 100%; }
.btn-danger-text {
  background: transparent;
  color: var(--expense);
  border: none;
  font-weight: 600;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field input, .field textarea {
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-solid);
  outline: none;
}
.field textarea { min-height: 88px; resize: vertical; }

.card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 16px;
  border: 1px solid rgba(184, 207, 192, 0.7);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  margin-bottom: 12px;
}
.card.current {
  border-color: var(--accent);
  background: linear-gradient(160deg, rgba(200, 230, 212, 0.55), var(--surface));
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.card-title {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
}
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 8px;
  border-radius: 999px;
}

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric-label { font-size: 0.72rem; color: var(--muted); margin-bottom: 4px; }
.metric-value {
  font-size: clamp(0.95rem, 3.6vw, 1.1rem);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric-value.balance { color: var(--balance); }
.metric-value.income { color: var(--income); }
.metric-value.expense { color: var(--expense); }

/* 设置列表 */
.settings-list {
  border-radius: var(--radius);
  background: var(--surface-solid);
  border: 1px solid rgba(184, 207, 192, 0.7);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.settings-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 0 16px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  font-weight: 600;
  cursor: pointer;
}
.settings-item:last-child { border-bottom: none; }
.settings-item:active { background: rgba(200, 230, 212, 0.35); }
.settings-item .chevron { color: var(--muted); font-weight: 400; }
.settings-item.is-danger { color: var(--expense); }
.settings-panel {
  margin-top: 14px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid rgba(184, 207, 192, 0.7);
}
.settings-panel h2 {
  font-family: var(--display);
  font-size: 1.1rem;
  margin: 0 0 6px;
}
.settings-panel .desc {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 14px;
}

.chart-panel {
  padding: 14px 12px 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid rgba(184, 207, 192, 0.7);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.balance { background: #1e3a5f; }
.dot.income { background: #0f766e; }
.dot.expense { background: #9f1239; }
.chart-canvas { width: 100%; height: 180px; display: block; }

.login-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px calc(32px + var(--safe-bottom));
  width: min(420px, 100%);
  margin: 0 auto;
}
.login-brand {
  font-family: var(--display);
  font-size: clamp(2rem, 8vw, 2.6rem);
  font-weight: 600;
  margin: 0 0 8px;
}
.error { color: var(--expense); font-size: 0.9rem; margin: 0 0 12px; }
.loading, .empty { text-align: center; color: var(--muted); padding: 36px 12px; }

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 36, 28, 0.45);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.28s ease;
  pointer-events: none;
}
.sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: min(92dvh, 920px);
  display: flex; flex-direction: column;
  background: var(--surface-solid);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(20, 36, 28, 0.18);
  transform: translateY(110%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}
.sheet.is-open {
  transform: translateY(0);
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sheet-body {
  flex: 1; overflow: auto;
  padding: 12px 16px 16px;
  -webkit-overflow-scrolling: touch;
}
.sheet-footer {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--surface-solid);
}

/* iOS：日期/时间纵向排列，避免挤在一行重叠 */
.time-highlight {
  padding: 14px 12px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #1a6b4a, #245f4a);
  color: #fff;
}
.time-highlight .label {
  font-size: 0.8rem;
  opacity: 0.9;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.time-highlight .label-hint {
  font-size: 0.72rem;
  font-weight: 500;
  opacity: 0.85;
}
.time-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.time-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  min-width: 0;
}
.time-highlight input[type="date"],
.time-highlight input[type="time"] {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  font-size: 16px; /* 避免 iOS 自动缩放 */
  -webkit-appearance: none;
  appearance: none;
}
.time-row input[type="time"] { flex: 1; }
.time-highlight .btn-now {
  flex-shrink: 0;
  min-height: 48px;
  min-width: 64px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.section-title {
  font-size: 0.85rem; font-weight: 700; color: var(--muted);
  margin: 16px 0 8px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.row-item {
  display: grid; grid-template-columns: 1fr 110px; gap: 8px;
  margin-bottom: 8px; align-items: center;
}
.row-item input, .income-row input {
  min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 16px;
  min-width: 0;
}
.income-row {
  display: grid; grid-template-columns: 1fr 88px 44px; gap: 8px; margin-bottom: 8px;
}
.icon-btn {
  min-height: 46px; min-width: 44px;
  border: 1px solid var(--line); border-radius: 10px;
  background: transparent; cursor: pointer; font-size: 1.2rem;
}
.preview-box {
  margin-top: 12px; padding: 12px; border-radius: 12px;
  background: var(--accent-soft); font-weight: 600;
}
.detail-block {
  padding: 14px; border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid rgba(184, 207, 192, 0.7);
  margin-bottom: 12px;
}
.detail-block h3 { margin: 0 0 10px; font-size: 0.95rem; }
.kv {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 0.95rem;
}
.kv:last-child { border-bottom: none; }

.detail-summary {
  margin-bottom: 14px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(184, 207, 192, 0.7);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.detail-summary .muted { margin: 10px 0 0; }
.history-section { margin-top: 8px; }
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.history-card {
  position: relative;
  padding: 16px 44px 16px 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(184, 207, 192, 0.7);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.history-card-time {
  font-weight: 700;
  font-size: 0.98rem;
  margin-bottom: 10px;
}
.history-edit {
  position: absolute;
  top: 12px;
  right: 10px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.history-actions {
  position: absolute;
  top: 8px;
  right: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.history-actions .history-edit {
  position: static;
}
.history-card-actions {
  padding-right: 48px;
}
.history-delete:active {
  color: var(--expense);
}
.history-edit:active {
  background: rgba(200, 230, 212, 0.45);
  color: var(--accent);
}
.history-note {
  margin: 8px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}
.history-details {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.history-subhead {
  margin: 10px 0 4px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.history-subhead:first-child { margin-top: 0; }
.history-kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 5px 0;
  font-size: 0.92rem;
}
.history-empty {
  margin: 0;
  padding: 2px 0 4px;
  font-size: 0.85rem;
}

.account-list {
  border-top: 1px solid var(--line);
}
.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.account-row.is-archived { opacity: 0.7; }
.account-main {
  flex: 1;
  min-width: 0;
}
.account-view {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.account-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-edit-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.account-edit-btn:active {
  background: rgba(200, 230, 212, 0.45);
  color: var(--accent);
}
.account-edit-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.account-rename-input {
  flex: 1;
  min-width: 120px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-solid);
  outline: none;
}
.account-bal {
  font-weight: 700;
  color: var(--balance);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.badge-soft {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(184, 207, 192, 0.55);
  color: var(--muted);
}

.btn-danger {
  background: transparent;
  color: var(--expense);
  border: 1px solid rgba(159, 18, 57, 0.35);
}

@media (min-width: 860px) {
  .app-shell { width: min(720px, 100%); }
  .navbar-inner, .bottom-bar-inner { width: min(720px, 100%); }
}
