/* 云岚记账 · 样式（移动优先；CSP 禁止内联样式，全部写在这里） */

:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --ink: #1d2320;
  --ink-2: #5f6661;
  --ink-3: #979c97;
  --line: #e6e2d9;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3efea;
  --expense: #c2553f;
  --income: #2e8558;
  --danger: #b8402c;
  --shadow: 0 1px 2px rgba(29, 35, 32, .05), 0 6px 20px rgba(29, 35, 32, .05);
  --radius: 16px;
  --tabbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --surface-2: #272b30;
    --ink: #eceeea;
    --ink-2: #a6aba6;
    --ink-3: #6f7570;
    --line: #2e3237;
    --accent: #4fb39a;
    --accent-ink: #0d1a16;
    --accent-soft: #1d332d;
    --expense: #e8806a;
    --income: #62c08c;
    --danger: #e8806a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body.sheet-open { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; text-align: inherit; }
button:disabled { cursor: default; opacity: .45; }
h1, h2, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.expense { color: var(--expense); }
.income { color: var(--income); }
.num, .hero-num, .hero-v, .tx-amount, .tri-v, .legend-amt, .legend-pct, .amount-num, .menu-value { font-variant-numeric: tabular-nums; }

/* ---------- 外壳 ---------- */

.shell {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0 16px;
  background: var(--bg);
}
.topbar-title { flex: 1; font-size: 17px; font-weight: 650; text-align: center; letter-spacing: .01em; }
.topbar-title.left { text-align: left; font-size: 20px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
  color: var(--ink-2);
}
.icon-btn:active:not(:disabled) { background: var(--surface-2); }
.icon-btn.small { width: 36px; height: 36px; font-size: 20px; }
.icon-btn.ghost { visibility: hidden; }

.month-switch { display: flex; align-items: center; }
.month-label { min-width: 92px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

.content { padding: 4px 16px 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 1fr 72px 1fr 1fr;
  width: 100%;
  max-width: 480px;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateX(-50%);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 12px;
  color: var(--ink-3);
}
.tab-dot { width: 18px; height: 3px; border-radius: 2px; background: transparent; }
.tab.active { color: var(--accent); font-weight: 650; }
.tab.active .tab-dot { background: var(--accent); }

.fab-slot { position: relative; }
.fab {
  position: absolute;
  left: 50%;
  top: -22px;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  transform: translateX(-50%);
  border-radius: 50%;
  border: 4px solid var(--bg);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 30px;
  font-weight: 300;
  line-height: 1;
}
.fab:active { transform: translateX(-50%) scale(.95); }

/* ---------- 卡片 ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; font-weight: 650; }
.link { color: var(--accent); font-size: 13px; font-weight: 600; min-height: 32px; }
.link-card { display: flex; align-items: center; justify-content: space-between; width: 100%; color: var(--ink-2); }

.hero { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.hero-label { font-size: 13px; opacity: .8; }
.hero-num { margin: 2px 0 14px; font-size: 34px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; word-break: break-all; }
.hero-split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .22); }
.hero-k { display: block; font-size: 12px; opacity: .8; }
.hero-v { font-size: 16px; font-weight: 600; }
.hero-foot { font-size: 12px; opacity: .8; margin-top: -6px; }

.ai-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px dashed var(--accent);
  background: var(--accent-soft);
}
.ai-bar-text { flex: 1; font-weight: 600; color: var(--accent); }
.ai-bar-eg { font-size: 12px; color: var(--ink-3); }

.budget .bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.budget .bar-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.budget.over .bar-fill { background: var(--expense); }
.budget-text { margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.budget-text strong { color: var(--ink); font-weight: 650; }
.budget.over .budget-text strong { color: var(--expense); }

.quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.quick-item { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; border-radius: 12px; font-size: 12px; color: var(--ink-2); }
.quick-item:active { background: var(--surface-2); }
.quick-icon { font-size: 26px; line-height: 1.2; }

/* ---------- 流水 ---------- */

.tx-list { display: flex; flex-direction: column; margin: -4px 0; }
.tx { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 6px 0; }
.tx + .tx { border-top: 1px solid var(--line); }
.tx-icon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); font-size: 20px; }
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amount { flex: none; font-weight: 650; font-size: 16px; }

.day-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: 12px; color: var(--ink-3); }
.month-sum { display: flex; justify-content: space-between; padding: 0 4px; font-size: 13px; color: var(--ink-2); }
.filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.empty { padding: 28px 0; text-align: center; color: var(--ink-3); }
.empty.small { padding: 16px 0; font-size: 13px; }
.empty-card { display: flex; flex-direction: column; align-items: center; padding-bottom: 28px; }

/* ---------- 统计 ---------- */

.tri { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tri-k { display: block; font-size: 12px; color: var(--ink-3); }
.tri-v { font-weight: 650; font-size: 15px; word-break: break-all; }

.donut { display: block; width: 200px; max-width: 70%; margin: 4px auto 12px; }
.donut-track { stroke: var(--surface-2); }
.donut-k { fill: var(--ink-3); font-size: 12px; }
.donut-v { fill: var(--ink); font-size: 17px; font-weight: 700; }

.legend li { display: flex; align-items: center; gap: 8px; min-height: 34px; font-size: 14px; }
.legend li + li { border-top: 1px solid var(--line); }
.legend-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-amt { font-weight: 600; }
.legend-pct { width: 52px; text-align: right; color: var(--ink-3); font-size: 13px; }
.dot { flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.income-bg { background: var(--income); }
.expense-bg { background: var(--expense); }
.chart-key { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }
.chart-key .dot + .dot, .chart-key .dot:nth-of-type(2) { margin-left: 8px; }

.trend { display: block; width: 100%; height: auto; }
.trend .axis { stroke: var(--line); stroke-width: 1; }
.trend .bar-income { fill: var(--income); }
.trend .bar-expense { fill: var(--expense); }
.trend .bar-label { fill: var(--ink-3); font-size: 9px; }
.trend .axis-label { fill: var(--ink-3); font-size: 11px; }
.trend .axis-label.current { fill: var(--ink); font-weight: 700; }

.insight { white-space: pre-wrap; line-height: 1.7; color: var(--ink); }

/* ---------- 我的 ---------- */

.menu { padding: 4px 16px; }
.menu-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; }
.menu-row + .menu-row { border-top: 1px solid var(--line); }
.menu-row.dim { opacity: .55; }
.menu-icon { flex: none; width: 24px; text-align: center; font-size: 18px; }
.menu-label { flex: 1; min-width: 0; font-weight: 500; }
.menu-value { color: var(--ink-3); font-size: 14px; }
.chev { color: var(--ink-3); font-size: 18px; }
.tag { margin-left: 8px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); font-size: 11px; font-weight: 400; color: var(--ink-2); }
.foot-note { padding: 4px 0 8px; text-align: center; font-size: 12px; color: var(--ink-3); }

.cat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cat { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 60px; padding: 6px 2px; border-radius: 12px; border: 1.5px solid transparent; }
.cat:active { background: var(--surface-2); }
.cat.active { border-color: var(--accent); background: var(--accent-soft); }
.cat.add { color: var(--ink-3); border: 1.5px dashed var(--line); }
.cat-icon { font-size: 24px; line-height: 1.25; }
.cat-name { max-width: 100%; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat.active .cat-name { color: var(--accent); font-weight: 650; }

/* ---------- 表单控件 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 20px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 600;
}
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger-text { border-color: transparent; background: none; color: var(--danger); }
.btn:active:not(:disabled) { filter: brightness(.95); }

.input, .select {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px; /* 小于 16px 时 iOS 聚焦会放大页面 */
}
.select { min-width: 0; padding-right: 4px; font-size: 14px; }
.input:focus, .select:focus { outline: none; border-color: var(--accent); }
textarea.input { padding: 10px 12px; resize: none; line-height: 1.5; }

.segment { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface-2); }
.segment button { min-height: 34px; padding: 0 14px; border-radius: 8px; font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.segment button.active { background: var(--surface); color: var(--ink); font-weight: 650; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--line); font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 650; }

/* ---------- 登录 ---------- */

.login { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 24px; }
.login-card { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 320px; }
.login-mark { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 20px; background: var(--accent); color: var(--accent-ink); font-size: 32px; font-weight: 700; }
.login-title { font-size: 24px; font-weight: 700; }
.login-sub { margin-bottom: 12px; color: var(--ink-3); }
.form-error { min-height: 20px; font-size: 13px; color: var(--danger); }

/* ---------- 浮层 ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(15, 18, 16, .45);
  animation: fade .16s ease-out;
}
.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 94vh;
  max-height: 94dvh;
  overflow-y: auto;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--bg);
  animation: rise .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; margin: 0 -8px 8px; }
.sheet-head h2 { flex: 1; padding-left: 8px; font-size: 17px; font-weight: 650; }

.form-sheet { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--ink-2); }
.field-hint { font-size: 12px; color: var(--ink-3); }
.field.check { flex-direction: row; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; }
.field.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.manual { display: flex; flex-direction: column; gap: 12px; }
.amount { display: flex; align-items: baseline; justify-content: flex-end; gap: 6px; padding: 4px 4px 8px; border-bottom: 1px solid var(--line); }
.amount-cur { font-size: 20px; font-weight: 600; }
.amount-num { font-size: 40px; font-weight: 700; line-height: 1.15; letter-spacing: -.01em; }
.amount-num.placeholder { color: var(--ink-3); opacity: .6; }
.caret { align-self: center; width: 2px; height: 34px; background: var(--accent); animation: blink 1.1s steps(1) infinite; }

.cat-grid.compact .cat { min-height: 56px; background: var(--surface); }
.cat-grid.compact .cat.active { background: var(--accent-soft); }

.meta { display: flex; align-items: center; gap: 8px; }
.date-pick { flex: none; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.date-label { position: relative; min-width: 64px; padding: 0 2px; text-align: center; font-size: 14px; font-weight: 600; line-height: 44px; white-space: nowrap; }
.date-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.note { flex: 1; min-width: 0; }

.keypad { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 52px; gap: 8px; }
.key { display: grid; place-items: center; border-radius: 12px; background: var(--surface); font-size: 22px; font-weight: 500; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.key:active:not(:disabled) { background: var(--surface-2); }
.key.fn { font-size: 20px; color: var(--ink-2); }
.key.wide { grid-column: span 2; }
.key.save { grid-row: span 3; background: var(--accent); color: var(--accent-ink); font-size: 17px; font-weight: 650; }
.key.save:active:not(:disabled) { background: var(--accent); filter: brightness(.93); }

.ai-pane { display: flex; flex-direction: column; gap: 12px; }
.ai-text { min-height: 92px; }
.drafts { display: flex; flex-direction: column; gap: 8px; }
.draft { padding: 10px 12px; border-radius: 14px; background: var(--surface); }
.draft-top { display: flex; align-items: center; gap: 10px; }
.draft-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.draft-edit .select { min-height: 38px; }

/* ---------- 提示 ---------- */

#toast {
  position: fixed;
  left: 50%;
  top: calc(12px + env(safe-area-inset-top));
  z-index: 40;
  max-width: min(92vw, 440px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity .18s, transform .18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- 桌面：居中成手机形态 ---------- */

@media (min-width: 768px) {
  body { background: var(--surface-2); }
  .shell { margin: 24px auto; min-height: calc(100dvh - 48px); background: var(--bg); border-radius: 28px; box-shadow: 0 12px 48px rgba(0, 0, 0, .12); overflow: clip; }
  .topbar { border-radius: 28px 28px 0 0; }
  .tabbar { bottom: 24px; border-radius: 0 0 28px 28px; }
  .backdrop { align-items: center; }
  .sheet { border-radius: 20px; max-height: 88dvh; }
}

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