:root {
  color-scheme: light dark;
  --bg: #f4f4f8;
  --surface: #fff;
  --surface-2: #f0f0f5;
  --text: #18181b;
  --muted: #71717a;
  --line: oklch(0 0 0 / 0.06);
  --accent: #6457f9;
  --accent-soft: oklch(0.55 0.22 280 / 0.1);
  --in: #0e9f6e;
  --warn-bg: #fff3dc;
  --warn: #9a5b00;
  --bad-bg: #ffe6e6;
  --bad: #c0262d;
  --hero: linear-gradient(135deg, #5b4cf5 0%, #8b5cf6 55%, #d26bf2 100%);
  --shadow-border:
    0px 0px 0px 1px oklch(0 0 0 / 0.06),
    0px 1px 2px -1px oklch(0 0 0 / 0.06),
    0px 2px 4px 0px oklch(0 0 0 / 0.04);
  --shadow-border-hover:
    0px 0px 0px 1px oklch(0 0 0 / 0.08),
    0px 1px 2px -1px oklch(0 0 0 / 0.08),
    0px 2px 4px 0px oklch(0 0 0 / 0.06);
  --ease: cubic-bezier(0.2, 0, 0, 1);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0f;
    --surface: #17171c;
    --surface-2: #222229;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --line: oklch(1 0 0 / 0.07);
    --accent: #8f86ff;
    --accent-soft: oklch(0.7 0.16 280 / 0.16);
    --in: #34d399;
    --warn-bg: #3a2a10;
    --warn: #ffc56b;
    --bad-bg: #3b1518;
    --bad: #ff8a8a;
    --hero: linear-gradient(135deg, #4337d8 0%, #6d3fd6 55%, #a03fc4 100%);
    --shadow-border: 0 0 0 1px oklch(1 0 0 / 0.08);
    --shadow-border-hover: 0 0 0 1px oklch(1 0 0 / 0.13);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sprite { position: absolute; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
p { margin: 0; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: 0.45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.money { font-variant-numeric: tabular-nums; }
body.masked .money { display: inline-block; filter: blur(7px); user-select: none; }

/* ── 按钮 ── */
.button, .icon-button, .segmented button, .account, .hero-eye {
  transition-property: scale, background-color, box-shadow, color;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
}
.button:active:not(:disabled), .icon-button:active:not(:disabled),
.account:active, .hero-eye:active { scale: 0.96; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
  font-weight: 500;
}
.button:hover:not(:disabled) { box-shadow: var(--shadow-border-hover); }
.button.primary { background: var(--accent); color: #fff; box-shadow: none; font-weight: 600; }
.button.ghost { background: transparent; box-shadow: none; color: var(--accent); }

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
  color: var(--muted);
}
.icon-button:hover:not(:disabled) { color: var(--text); box-shadow: var(--shadow-border-hover); }

select, input[type="date"] {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  min-width: 0;
}

.error { color: var(--bad); min-height: 1.5em; font-size: 0.9rem; }

/* ── 登录 ── */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(60% 45% at 50% 0%, oklch(0.6 0.2 285 / 0.22), transparent 70%),
    var(--bg);
}
.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 32px 24px 20px;
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
  text-align: center;
}
.login-mark {
  justify-self: center;
  width: 64px;
  height: 64px;
  margin-bottom: 4px;
}
.login-hint { color: var(--muted); margin-bottom: 8px; }
.login-card input {
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  text-align: center;
}
.login-card .button { min-height: 48px; }

/* ── 主界面 ── */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(40px, env(safe-area-inset-bottom));
  display: grid;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 8px; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.top-actions { display: flex; gap: 8px; }

/* 总资产 */
.hero {
  position: relative;
  overflow: hidden;
  padding: 20px 20px 22px;
  border-radius: 28px;
  background: var(--hero);
  color: #fff;
}
.hero::after {
  content: "";
  position: absolute;
  inset: auto -30% -70% 30%;
  height: 140%;
  background: radial-gradient(closest-side, oklch(1 0 0 / 0.18), transparent);
  pointer-events: none;
}
.hero-head { display: flex; align-items: center; justify-content: space-between; }
.hero-head p { font-size: 0.9rem; opacity: 0.85; }
.hero-eye {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin: -6px -8px -6px 0;
  border: 0;
  border-radius: 999px;
  background: oklch(1 0 0 / 0.14);
  color: #fff;
  z-index: 1;
}
.hero-eye .icon {
  position: absolute;
  width: 18px;
  height: 18px;
  transition-property: opacity, scale, filter;
  transition-duration: 200ms;
  transition-timing-function: var(--ease);
}
.hero-eye .eye-off, .hero-eye[aria-pressed="true"] .eye-on { opacity: 0; scale: 0.25; filter: blur(4px); }
.hero-eye[aria-pressed="true"] .eye-off { opacity: 1; scale: 1; filter: blur(0); }
.hero-value {
  margin-top: 6px;
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.hero-sub { margin-top: 8px; font-size: 0.85rem; opacity: 0.8; }

/* 卡片 */
.accounts {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 16px;
  margin: -4px -16px 0;
  padding: 4px 16px 4px;
  scrollbar-width: none;
}
.accounts::-webkit-scrollbar { display: none; }
.accounts:empty { display: none; }
.account {
  flex: 0 0 auto;
  min-width: 148px;
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
  text-align: left;
  scroll-snap-align: start;
}
.account:hover { box-shadow: var(--shadow-border-hover); }
.account[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); background: var(--accent-soft); }
.account-name { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.account-balance { font-weight: 650; font-size: 1.05rem; }
.account-date { font-size: 0.75rem; color: var(--muted); }

/* 时间范围 */
.period { display: grid; gap: 10px; }
.segmented {
  display: flex;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented button {
  flex: 1 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-border);
}
.range { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.range input { flex: 1; }

/* 收支 */
.flow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.flow-tile {
  display: grid;
  gap: 2px;
  padding: 14px 16px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
}
.flow-tile span { font-size: 0.85rem; color: var(--muted); }
.flow-tile strong { font-size: 1.3rem; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }
.flow-note { grid-column: 1 / -1; font-size: 0.8rem; color: var(--muted); padding: 0 4px; }
.in { color: var(--in); }

/* 搜索与筛选 */
.toolbar { display: flex; gap: 10px; }
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
  color: var(--muted);
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--text);
}
.search:focus-within { box-shadow: 0 0 0 2px var(--accent); }
.filter-toggle[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
.count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  line-height: 18px;
  font-weight: 600;
}

.panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border-radius: 22px; /* 12 + 10 */
  background: var(--surface);
  box-shadow: var(--shadow-border);
}
.panel .button { grid-column: 1 / -1; min-height: 36px; }

.notice {
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.9rem;
}

/* 账单列表 */
.list { display: grid; gap: 18px; }
.day h2 {
  margin: 0 0 8px;
  padding: 0 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.items {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
  overflow: hidden;
}
.items li + li { border-top: 1px solid var(--line); }

.row summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background-color 150ms ease-out;
}
.row summary::-webkit-details-marker { display: none; }
.row summary:hover, .row[open] summary { background: var(--surface-2); }

.avatar {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 0.95rem;
}
.main, .side { display: grid; gap: 1px; min-width: 0; }
.main { flex: 1; }
.side { text-align: right; flex-shrink: 0; }
.title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta, .balance { color: var(--muted); font-size: 0.8rem; }
.amount { font-weight: 650; font-size: 1rem; }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.7;
  vertical-align: 1px;
}
.badge.partial { background: var(--warn-bg); color: var(--warn); }
.badge.failed { background: var(--bad-bg); color: var(--bad); }

.detail { padding: 2px 16px 16px 68px; }
.raw {
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-all;
}
.detail dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 16px;
  margin: 0;
  font-size: 0.8rem;
}
.detail dt { color: var(--muted); }
.detail dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-all; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 0.9rem; }
.empty-title { color: var(--text); font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.more { justify-self: center; min-width: 160px; }

@media (max-width: 480px) {
  .panel { grid-template-columns: 1fr 1fr; }
  .panel select:last-of-type { grid-column: 1 / -1; }
  .detail { padding-left: 16px; }
  .hero-value { font-size: 2rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; }
}
