:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --primary: #4361ee;
  --primary-d: #324bd1;
  --primary-soft: #eaefff;
  --text: #1c2433;
  --muted: #6b7488;
  --line: #e7ebf2;
  --expense: #e5484d;
  --income: #16a34a;
  --warn: #d97706;
  --shadow: 0 6px 22px rgba(28, 36, 51, .07);
  --radius: 18px;
  --radius-sm: 12px;
  --nav-h: 62px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 10px);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
.link { font-size: 13px; color: var(--primary); cursor: pointer; font-weight: 600; }

/* ---------- 顶部 ---------- */
.topbar {
  background: linear-gradient(120deg, #4361ee 0%, #6d5efc 100%);
  color: #fff;
  padding: 18px 18px 16px;
  position: sticky; top: 0; z-index: 30;
  box-shadow: 0 4px 16px rgba(67, 97, 238, .22);
}
.topbar-inner { max-width: 820px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.brand { font-size: 19px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.brand-ic { font-size: 22px; }
.brand-sub { font-size: 13px; opacity: .9; margin-left: auto; font-weight: 600; }

/* ---------- 底部导航（移动端优先，桌面也用） ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding: 0 6px env(safe-area-inset-bottom, 0px);
  background: rgba(255,255,255,.96);
  backdrop-filter: saturate(180%) blur(10px);
  border-top: 1px solid var(--line);
  display: flex; align-items: stretch;
}
.tab {
  flex: 1 1 0; border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600; padding: 6px 2px;
  transition: color .15s;
}
.tab span { font-size: 21px; line-height: 1; filter: grayscale(.4); opacity: .8; transition: all .15s; }
.tab.active { color: var(--primary); }
.tab.active span { filter: none; opacity: 1; transform: translateY(-1px); }

main { max-width: 820px; margin: 16px auto; padding: 0 14px; }
section { display: none; }
section.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card-head h2 { margin: 0; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.help { font-size: 13px; color: var(--muted); margin: 6px 0 0; line-height: 1.6; }
.hint { background: var(--primary-soft); border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 10px; color: var(--primary-d); }

/* ---------- Hero（概览） ---------- */
.hero {
  background: linear-gradient(135deg, #4361ee 0%, #6d5efc 60%, #8b5cf6 100%);
  color: #fff; border-radius: 22px; padding: 22px 22px 18px; margin-bottom: 16px;
  box-shadow: 0 12px 30px rgba(67, 97, 238, .28); position: relative; overflow: hidden;
}
.hero-label { font-size: 13px; opacity: .9; }
.hero-amount { font-size: 38px; font-weight: 800; letter-spacing: .5px; margin: 2px 0 8px; line-height: 1.1; }
.hero-sub { display: flex; gap: 16px; font-size: 13px; opacity: .95; flex-wrap: wrap; }
.hero-sub b { font-weight: 700; }
.hero-donut { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); width: 92px; height: 92px; }
.hero-donut canvas { width: 92px !important; height: 92px !important; }
.hero-donut-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; opacity: .85; text-align: center; padding: 6px; }

.pending-banner {
  background: #fff7e6; border: 1px solid #ffe2a8; color: #8a5a00;
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; font-size: 14px;
}
.pending-banner a { color: #b07400; font-weight: 700; cursor: pointer; }

/* ---------- 表单 ---------- */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; flex: 1; min-width: 0; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 13px;
  font-size: 15px; background: #fff; color: var(--text); width: 100%; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
button {
  border: none; border-radius: 12px; padding: 11px 20px; font-size: 15px;
  cursor: pointer; background: var(--primary); color: #fff; font-weight: 700; transition: background .15s, transform .05s;
}
button:active { transform: scale(.98); }
button:hover { background: var(--primary-d); }
button.ghost { background: #fff; color: var(--text); border: 1.5px solid var(--line); }
button.ghost:hover { background: #f3f5f9; }
button.danger { background: #fff; color: var(--expense); border: 1.5px solid #f6c9cb; }
button.danger:hover { background: #fdecec; }

/* ---------- 麦克风 ---------- */
.mic-wrap { text-align: center; padding: 14px 0 4px; }
#micBtn {
  width: 88px; height: 88px; border-radius: 50%; font-size: 34px;
  background: linear-gradient(135deg, #4361ee, #6d5efc); color: #fff;
  box-shadow: 0 10px 26px rgba(67, 97, 238, .38); display: inline-flex; align-items: center; justify-content: center;
  border: none;
}
#micBtn:active { transform: scale(.96); }
#micBtn.recording { background: linear-gradient(135deg, #ff7a7a, #e5484d); animation: pulse 1.2s infinite; box-shadow: 0 10px 26px rgba(229, 72, 77, .4); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(229, 72, 77, .5); }
  70% { box-shadow: 0 0 0 16px rgba(229, 72, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0); }
}
.live { margin-top: 12px; min-height: 22px; color: var(--muted); font-size: 14px; text-align: center; }
.live b { color: var(--text); }
.audio-preview {
  display: flex; align-items: center; gap: 10px; margin-top: 12px;
  background: var(--primary-soft); border-radius: 12px; padding: 10px 12px;
}
.audio-preview .ap-ic { font-size: 18px; }
.audio-preview .ap-tx { font-size: 13px; color: var(--primary-d); font-weight: 600; white-space: nowrap; }
.audio-preview audio { flex: 1; min-width: 0; height: 38px; }

/* ---------- 识别原文块 ---------- */
.recog-block { margin-top: 12px; border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; background: #fbfcfe; }
.recog-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.recog-head label { font-size: 13px; font-weight: 700; color: var(--text); }
.recog-text { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 14px; font-family: inherit; color: var(--text); background: #fff; }
.recog-text:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.recog-tip { font-size: 12px; color: var(--muted); margin-top: 6px; }
.badge.src-baidu { background: #e6f6ee; color: #16a34a; border: 1px solid #bfe6cf; }
.badge.src-browser { background: #eaf0ff; color: #4361ee; border: 1px solid #c9d6ff; }
.badge.src-none { background: #fff3da; color: #d97706; border: 1px solid #ffd9a8; }

/* ---------- 汇总卡 ---------- */
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.sum-card { background: #f8fafc; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.sum-card .v { font-size: 20px; font-weight: 800; margin-top: 4px; }
.sum-card .k { font-size: 12px; color: var(--muted); }
.sum-card .v.expense { color: var(--expense); }
.sum-card .v.income { color: var(--income); }

/* ---------- 流水列表 ---------- */
.tx-list { display: flex; flex-direction: column; gap: 10px; }
.tx-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 14px; background: #fff; flex-wrap: wrap;
}
.tx-item.is-unrec { border-color: #ffe2a8; background: #fffdf6; }
.tx-icon { font-size: 22px; width: 42px; height: 42px; display: flex; align-items: center; justify-content: center; background: #f1f4fb; border-radius: 12px; flex-shrink: 0; }
.tx-main { flex: 1; min-width: 0; }
.tx-main .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-main .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-size: 17px; font-weight: 800; white-space: nowrap; }
.amount-expense { color: var(--expense); }
.amount-income { color: var(--income); }
.tx-actions { display: flex; gap: 6px; flex-shrink: 0; }
.tx-actions button { padding: 6px 12px; font-size: 13px; }
.tx-item audio { width: 130px; height: 34px; flex-shrink: 0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; background: #eef1f8; color: var(--muted); font-weight: 600; }
.badge.warn { background: #fff3da; color: var(--warn); }

/* ---------- 图表 ---------- */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-box { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.chart-box h3 { margin: 0 0 10px; font-size: 14px; }
.canvas-wrap { position: relative; height: 260px; }

/* ---------- 分类管理 ---------- */
.cat-manage { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.cat-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.cat-item .ic { font-size: 22px; flex-shrink: 0; }
.cat-item .nm { flex: 1; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item button { padding: 6px 12px; font-size: 13px; border-radius: 9px; flex-shrink: 0; }
.cat-manage-form { display: grid; grid-template-columns: 1fr 80px 120px 1fr; gap: 10px; align-items: end; }

.empty { color: var(--muted); text-align: center; padding: 24px; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px); transform: translateX(-50%);
  background: #1c2433; color: #fff; padding: 11px 20px; border-radius: 12px;
  font-size: 14px; opacity: 0; transition: opacity .25s; z-index: 60; pointer-events: none; max-width: 92vw;
  text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.show { opacity: 1; }

/* ---------- 桌面端微调 ---------- */
@media (min-width: 768px) {
  .tabs { max-width: 820px; margin: 0 auto; left: 50%; right: auto; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
}
@media (max-width: 560px) {
  .charts { grid-template-columns: 1fr; }
  .tx-item audio { width: 100%; order: 5; }
  .tx-amount { order: 4; }
  .tx-actions { order: 3; }
  .row { gap: 0; }
  .row .field { margin-bottom: 12px; }
  .cat-manage { grid-template-columns: 1fr; }
  .cat-item { flex-wrap: wrap; gap: 8px; }
  .cat-item .nm { flex: 1 1 60%; }
  .cat-item button { flex: 1; }
  .cat-manage-form { grid-template-columns: 1fr; }
  .hero-amount { font-size: 32px; }
}
