/* ============================================================
   家账簿 HomeLedger — 样式表 v2
   服务端渲染，零前端框架依赖
   设计令牌 → 布局骨架 → 通用组件 → 页面部件 → 响应式
   ============================================================ */

/* hidden 属性的全局防御：组件类若显式声明 display（如 .ai-icon-btn 的 grid），
   会压过 UA 样式对 hidden 的 display:none——按钮该藏没藏还变成死按钮（PR #8 审查抓到） */
[hidden] { display: none !important; }

:root {
  /* 中性色（冷灰调） */
  --bg: #f3f5f9;
  --bg-soft: #eef1f6;
  --card: #ffffff;
  --card-2: #f7f8fb;
  --card-3: #f1f3f8;
  --border: #e6eaf1;
  --border-strong: #d5dbe6;
  --text: #17202e;
  --text-2: #45516a;
  --muted: #7d8aa3;
  --faint: #aab4c6;

  /* 品牌色 */
  --primary: #3d6df5;
  --primary-deep: #2b56d9;
  --primary-soft: #eaf0ff;
  --primary-ring: rgba(61, 109, 245, .16);

  /* 语义色 */
  --income: #12a150;
  --income-soft: #e8f8ef;
  --expense: #e5484d;
  --expense-soft: #feefef;
  --warn: #e8890c;
  --warn-soft: #fdf3e2;
  --info: #2f6fed;
  --info-soft: #eaf1fe;
  --purple: #7c5cf0;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 7px;
  --shadow: 0 2px 6px rgba(18, 28, 45, .05), 0 16px 32px -16px rgba(18, 28, 45, .16);
  --shadow-lg: 0 4px 10px rgba(18, 28, 45, .06), 0 24px 56px -20px rgba(18, 28, 45, .28);
  --shadow-sm: 0 1px 2px rgba(18, 28, 45, .05);
  --topbar-h: 58px;
  --sidebar-w: 232px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0d1118;
  --bg-soft: #11161f;
  --card: #151b26;
  --card-2: #1a212e;
  --card-3: #1f2736;
  --border: #232c3c;
  --border-strong: #303b4f;
  --text: #e7ecf5;
  --text-2: #b6c0d4;
  --muted: #7e8aa2;
  --faint: #5d6980;

  --primary: #5b86ff;
  --primary-deep: #7295ff;
  --primary-soft: #1c2740;
  --primary-ring: rgba(91, 134, 255, .22);

  --income: #3dcc7e;
  --income-soft: #12291c;
  --expense: #f2666a;
  --expense-soft: #2c1619;
  --warn: #f0a03c;
  --warn-soft: #2c2113;
  --info-soft: #18233b;

  --shadow: 0 2px 6px rgba(0, 0, 0, .32), 0 16px 32px -16px rgba(0, 0, 0, .55);
  --shadow-lg: 0 4px 10px rgba(0, 0, 0, .4), 0 24px 56px -20px rgba(0, 0, 0, .7);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background:
    radial-gradient(1000px 460px at 88% -12%, var(--primary-ring) 0%, transparent 58%),
    var(--bg);
  background-attachment: fixed;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; opacity: .88; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
ul, ol { margin: 0; }
svg { vertical-align: middle; }

/* ------------------------------ 图标 ------------------------------ */

.icon {
  width: 18px; height: 18px; flex: 0 0 auto;
  display: inline-block; vertical-align: -3.5px;
}
.icon.sm { width: 15px; height: 15px; vertical-align: -2.5px; }
.icon.lg { width: 22px; height: 22px; vertical-align: -5px; }
.btn .icon, .nav-item .icon, .user-menu-item .icon { vertical-align: middle; }

/* ------------------------------ 布局骨架 ------------------------------ */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 14px;
  font-weight: 700; font-size: 16px; letter-spacing: -.01em;
}
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(140deg, #5b86ff, #3d6df5 55%, #2b56d9);
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 12px -4px rgba(61, 109, 245, .65), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.brand-logo .icon { width: 19px; height: 19px; }

.ledger-switch {
  margin: 0 4px 12px; padding: 8px 10px;
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.ledger-switch label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; font-weight: 550; }
.ledger-switch select {
  width: 100%; border: 0; background: transparent; color: var(--text);
  font-size: 13px; font-weight: 600; font-family: var(--font); cursor: pointer; outline: none;
  padding: 0; box-shadow: none;
}
.ledger-switch .hl-select-trigger { background: transparent; border: 0; padding: 2px 0; font-size: 13px; }

.nav-group { margin-bottom: 4px; }
.nav-title { font-size: 11px; color: var(--faint); padding: 12px 10px 6px; font-weight: 650; letter-spacing: .06em; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px; margin-bottom: 1px;
  transition: background .14s, color .14s;
  position: relative;
}
.nav-item .icon { color: var(--muted); transition: color .14s; }
.nav-item:hover { background: var(--card-2); color: var(--text); }
.nav-item:hover .icon { color: var(--text-2); }
.nav-item.active {
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
}
.nav-item.active .icon { color: var(--primary); }
.nav-item .count {
  margin-left: auto; font-size: 11px; background: var(--expense); color: #fff;
  border-radius: 99px; padding: 0 6px; min-width: 18px; text-align: center; line-height: 17px;
  font-weight: 600;
}

.sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: var(--radius-sm); }
.user-chip:hover { background: var(--card-2); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 600; flex: 0 0 30px;
  overflow: hidden; flex-shrink: 0; position: relative;
}
/* 容器内任何 img（头像上传后 <img class="avatar avatar-img">）都被裁剪填充，不再撑破布局 */
.avatar > img,
.avatar-img {
  width: 100% !important; height: 100% !important;
  max-width: 100% !important; max-height: 100% !important;
  object-fit: cover; border-radius: 50%; display: block;
  min-width: 0; min-height: 0;
}
.user-meta { min-width: 0; }
.user-meta b { display: block; font-size: 13px; font-weight: 600; }
.user-meta span { display: block; font-size: 11px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 22px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; min-width: 0; font-size: 18px; }
.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }

/* ---------------- 顶栏用户菜单 ---------------- */
.user-menu { position: relative; flex: none; }
.user-menu-btn {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--card);
  border-radius: 999px; padding: 4px 12px 4px 4px;
  cursor: pointer; font-family: var(--font); color: var(--text);
  transition: box-shadow .15s, border-color .15s;
}
.user-menu-btn:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.user-menu-btn .caret { color: var(--faint); display: grid; place-items: center; }
.user-menu-name { font-size: 13px; font-weight: 600; max-width: 10em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-drop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 80;
  min-width: 228px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px;
  animation: popIn .16s ease;
}
.user-menu-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.user-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; background: transparent; border-radius: var(--radius-sm);
  color: var(--text); font-size: 13.5px; font-family: var(--font); cursor: pointer; text-align: left;
}
.user-menu-item .icon { color: var(--muted); }
.user-menu-item:hover { background: var(--card-2); }
.user-menu-item.danger { color: var(--expense); }
.user-menu-item.danger .icon { color: var(--expense); }
.user-menu-item.danger:hover { background: var(--expense-soft); }
/* 自传头像：圆形图片，替代首字母色块 */
.avatar-img { width: 100%; height: 100%; max-width: 100%; max-height: 100%; border-radius: 50%; object-fit: cover; display: block; }
/* 可点击换头像的头像：手型 + 悬停光圈提示 */
.avatar-click { cursor: pointer; transition: box-shadow .15s ease; }
.avatar-click:hover { box-shadow: 0 0 0 3px var(--primary-ring); }
/* 窄屏：用户菜单收成纯头像圆标 */
@media (max-width: 860px) {
  .user-menu-name, .user-menu-btn .caret { display: none; }
  .user-menu-btn { padding: 3px; border-radius: 50%; }
}

.content { padding: 20px 22px 96px; max-width: 1240px; width: 100%; }

.mobile-nav { display: none; }

/* ------------------------------ 通用组件 ------------------------------ */

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 18px; margin-bottom: 16px;
}
.card.tight { padding: 13px; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  margin: -4px 0 12px;
}
.card-head h2 { flex: 1; min-width: 0; }
.card-head .hint { font-size: 12px; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }

.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.bold { font-weight: 650; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }
.mt0 { margin-top: 0; } .mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
.mb0 { margin-bottom: 0; } .mb8 { margin-bottom: 8px; } .mb12 { margin-bottom: 12px; } .mb16 { margin-bottom: 16px; }

.amount { font-variant-numeric: tabular-nums; font-weight: 650; letter-spacing: -.01em; }
.amount.income { color: var(--income); }
.amount.expense { color: var(--expense); }
.amount.neutral { color: var(--text-2); }
.amount.big { font-size: 26px; letter-spacing: -.02em; }
.amount.xl { font-size: 30px; letter-spacing: -.025em; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--card); color: var(--text); font-size: 13.5px; font-family: var(--font);
  font-weight: 550; cursor: pointer; line-height: 1.45; transition: all .14s ease; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  user-select: none; -webkit-user-select: none;
}
.btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn:active { transform: scale(.97); box-shadow: none; }
.btn .icon { color: var(--muted); transition: color .14s; }
.btn:hover .icon { color: var(--primary); }
.btn-primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--primary) 92%, #fff), var(--primary));
  border-color: var(--primary); color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 1px 2px rgba(18, 28, 45, .12);
}
.btn-primary .icon, .btn-primary:hover .icon { color: #fff; }
.btn-primary:hover { background: linear-gradient(180deg, var(--primary), var(--primary-deep)); border-color: var(--primary-deep); color: #fff; box-shadow: 0 4px 14px -4px var(--primary-ring), inset 0 1px 0 rgba(255,255,255,.15); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); box-shadow: none; }
.btn-ghost:hover { background: var(--card-2); border-color: transparent; color: var(--text); }
.btn-ghost .icon, .btn-ghost:hover .icon { color: inherit; }
.btn-danger { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 38%, var(--border)); box-shadow: none; }
.btn-danger .icon, .btn-danger:hover .icon { color: var(--expense); }
.btn-danger:hover { background: var(--expense-soft); color: var(--expense); border-color: var(--expense); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; border-radius: var(--radius-xs); }
.btn-lg { padding: 10px 20px; font-size: 15px; border-radius: 11px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn[disabled]:hover { border-color: var(--border-strong); color: var(--text); background: var(--card); }
.btn[disabled].btn-primary:hover { background: linear-gradient(180deg, color-mix(in srgb, var(--primary) 92%, #fff), var(--primary)); color: #fff; }
.btn-icon { padding: 7px; }
.btn.btn-plain { box-shadow: none; }

/* 表单 */
.field { margin-bottom: 14px; min-width: 0; }
.field > label { display: block; font-size: 12.5px; color: var(--text-2); font-weight: 550; margin-bottom: 6px; }
.field .help { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.5; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="email"], input[type="month"], input[type="time"], input[type="search"],
select, textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--card); color: var(--text);
  font-size: 14px; font-family: var(--font); outline: none;
  transition: border-color .14s, box-shadow .14s, background .14s;
  min-height: 36px;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border-strong)); }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3.5px var(--primary-ring);
}
textarea { resize: vertical; min-height: 72px; line-height: 1.6; }
select {
  cursor: pointer; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat; padding-right: 30px;
}
input[type="color"] { width: 44px; height: 36px; padding: 3px; border-radius: var(--radius-xs); cursor: pointer; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; vertical-align: -2px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }

.inline-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }

.amount-input { position: relative; }
.amount-input input { font-size: 30px; font-weight: 700; padding: 12px 14px 12px 42px; letter-spacing: -.02em; min-height: 0; }
.amount-input .cur { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); font-size: 22px; color: var(--faint); font-weight: 600; }

/* ------------------------- 自定义下拉框（JS 增强） ------------------------- */
/* 结构：<span class="hl-select"><button class="hl-select-trigger">…</button><div class="hl-select-menu">…</div></span>
   原生 select 仍留在 DOM（隐藏），值与 change 事件同步；触屏设备自动回退原生选择器。 */
.hl-select { position: relative; display: block; width: 100%; }
.hl-select.hl-disabled { opacity: .6; }
.hl-select.hl-disabled .hl-select-trigger { cursor: default; box-shadow: none; }
.hl-select-trigger {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 30px 8px 12px; min-height: 36px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text);
  font-size: 14px; font-family: var(--font); line-height: 1.45;
  cursor: pointer; text-align: left; transition: border-color .14s, box-shadow .14s;
}
.hl-select-trigger:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border-strong)); }
.hl-select.open .hl-select-trigger, .hl-select-trigger:focus-visible {
  border-color: var(--primary); box-shadow: 0 0 0 3.5px var(--primary-ring);
}
.hl-select-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hl-select-label .ph { color: var(--faint); }
.hl-select-caret { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); display: grid; place-items: center; transition: transform .16s; pointer-events: none; }
.hl-select.open .hl-select-caret { transform: translateY(-50%) rotate(180deg); }
.hl-select-menu {
  /* 默认隐藏：菜单懒创建后常驻 DOM，必须靠 .open 才显示（否则关闭后悬浮在内容上） */
  display: none;
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 90;
  min-width: max(100%, 210px); max-width: min(320px, calc(100vw - 32px));
  max-height: 302px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 11px; box-shadow: var(--shadow-lg); padding: 5px;
  animation: popIn .14s ease;
}
.hl-select.open .hl-select-menu { display: block; }
.hl-select-menu.up { top: auto; bottom: calc(100% + 6px); }
.hl-select-opt {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: var(--radius-xs);
  background: transparent; color: var(--text); font-size: 13.5px; font-family: var(--font);
  cursor: pointer; text-align: left; line-height: 1.45;
  transition: background .12s;
}
.hl-select-opt:hover { background: var(--card-2); }
.hl-select-opt:active { background: var(--primary-soft); }
.hl-select-opt.selected { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.hl-select-opt .opt-ico { flex: 0 0 auto; width: 22px; text-align: center; font-size: 15px; line-height: 1.2; }
.hl-select-opt .opt-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hl-select-opt .opt-sub {
  flex: 0 0 auto; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: 11.5px; font-weight: 450;
  font-variant-numeric: tabular-nums;
}
.hl-select-opt.selected .opt-sub { color: color-mix(in srgb, var(--primary) 70%, var(--muted)); }
.hl-select-opt .checkmark { flex: 0 0 auto; margin-left: 0; visibility: hidden; color: var(--primary); }
.hl-select-opt.selected .checkmark { visibility: visible; }
.hl-select-opt .sub { color: var(--muted); font-size: 11.5px; margin-left: auto; }
.hl-select-group {
  position: sticky; top: -5px; z-index: 1;
  padding: 7px 10px 3px; margin: 0 -5px; padding-left: 10px; padding-right: 10px;
  background: var(--card);
  font-size: 11px; color: var(--faint); font-weight: 650; letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
.hl-select-empty { padding: 14px; text-align: center; color: var(--muted); font-size: 12.5px; }

/* ------------------------------ 徽标 / 标签 ------------------------------ */

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2.5px 9px; border-radius: 99px; font-size: 11.5px; line-height: 1.6;
  background: var(--card-2); border: 1px solid var(--border); color: var(--text-2);
  white-space: nowrap; font-weight: 500;
  transition: border-color .14s, background .14s, color .14s, box-shadow .14s;
}
a.chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.chip.primary { background: var(--primary-soft); border-color: transparent; color: var(--primary); font-weight: 600; }
.chip.income { background: var(--income-soft); border-color: transparent; color: var(--income); }
.chip.expense { background: var(--expense-soft); border-color: transparent; color: var(--expense); }
.chip.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.chip.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.tag-pill {
  display: inline-block; padding: 1px 8px; border-radius: 99px;
  font-size: 11px; background: var(--card-2); border: 1px solid var(--border); color: var(--text-2);
}

/* 统计卡 */
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  position: relative; overflow: hidden;
}
.stat::after {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), transparent 70%);
  opacity: 0; transition: opacity .18s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }
.stat:hover::after { opacity: .8; }
.stat .label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; font-weight: 500; }
.stat .value { margin-top: 5px; font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 11.5px; margin-top: 3px; color: var(--muted); }
.stat .delta.up { color: var(--expense); }
.stat .delta.down { color: var(--income); }

/* 交易列表 */
.txn-day { border-bottom: 1px solid var(--border); }
.txn-day:last-child { border-bottom: 0; }
.txn-day-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 2px 7px; font-size: 12px; color: var(--muted);
  background: var(--card); position: sticky; top: calc(var(--topbar-h) - 1px); z-index: 5;
}
.txn-day-head .day-sum { margin-left: auto; display: flex; gap: 12px; font-variant-numeric: tabular-nums; }

.txn {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 6px; border-radius: var(--radius-sm);
  transition: background .12s;
}
.txn + .txn { border-top: 1px solid var(--border); border-radius: 0; }
.txn:hover { background: var(--card-2); }
.txn + .txn:hover { border-radius: var(--radius-sm); }
.txn-ico {
  width: 38px; height: 38px; border-radius: 12px; flex: 0 0 38px;
  display: grid; place-items: center; font-size: 18px; background: var(--card-2);
  border: 1px solid var(--border);
}
.txn-main { flex: 1; min-width: 0; }
.txn-title { font-size: 14px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.txn-title .note { color: var(--muted); font-weight: 400; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 商家名与备注并列直显：商家稍重、备注灰 */
.txn-merchant { color: var(--text-2); font-weight: 500; font-size: 12.5px; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0; }
/* 行可点击看详情 */
.txn { cursor: pointer; }
.txn-sub { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-top: 2px; flex-wrap: wrap; }
.txn-amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; font-size: 15px; white-space: nowrap; }
.txn-act { opacity: 0; transition: opacity .15s; display: flex; gap: 4px; }
.txn:hover .txn-act, .txn:focus-within .txn-act { opacity: 1; }
.txn.pending { opacity: .7; }

.list-empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.list-empty .big { font-size: 34px; display: block; margin-bottom: 8px; }

/* 进度条 */
.progress { background: var(--card-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.progress i { display: block; height: 100%; border-radius: 99px; transition: width .4s; }

/* 图例 / 排行 */
.legend-row, .rank-row {
  display: flex; align-items: center; gap: 9px; padding: 5px 0; font-size: 13px;
}
.legend-dot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 9px; }
.legend-name, .rank-name { flex: 0 0 auto; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-bar, .rank-track { flex: 1; height: 7px; background: var(--card-2); border-radius: 99px; overflow: hidden; min-width: 30px; border: 1px solid var(--border); }
.legend-bar i, .rank-track i { display: block; height: 100%; border-radius: 99px; }
.legend-pct { flex: 0 0 46px; text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.legend-val, .rank-val { flex: 0 0 84px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; font-size: 12.5px; }
.rank-idx { flex: 0 0 16px; color: var(--faint); font-size: 11px; text-align: center; }
.rank-name { flex: 0 0 100px; }
/* 可下钻的排行名：默认同正文色，悬停提示可点 */
a.rank-name { color: inherit; }
a.rank-name:hover { color: var(--primary); opacity: 1; }

/* 表格 */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--card-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* 分类选择栅格 */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.cat-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--card); cursor: pointer; font-size: 11.5px; color: var(--text-2);
  text-align: center; transition: all .13s;
}
.cat-item:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.cat-item.selected { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; box-shadow: 0 0 0 1px var(--primary) inset; }
.cat-item .ci { font-size: 19px; }
.cat-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* 类型切换 */
.type-tabs { display: flex; gap: 5px; background: var(--card-2); padding: 4px; border-radius: 11px; border: 1px solid var(--border); flex-wrap: wrap; }
.type-tabs a, .type-tabs button {
  flex: 1; min-width: 62px; text-align: center; padding: 7px 6px; border-radius: 8px;
  font-size: 13px; color: var(--text-2); border: 0; background: transparent; cursor: pointer;
  font-family: var(--font); font-weight: 550; white-space: nowrap;
  transition: background .14s, color .14s, box-shadow .14s;
}
.type-tabs a:hover, .type-tabs button:hover { color: var(--text); }
.type-tabs .active { background: var(--card); color: var(--primary); font-weight: 600; box-shadow: var(--shadow-sm); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs a {
  padding: 9px 13px; font-size: 13.5px; color: var(--text-2); border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap; transition: color .14s, border-color .14s;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }

/* 提示条 */
.flash {
  display: flex; align-items: center; gap: 9px; padding: 11px 14px; border-radius: var(--radius-sm);
  margin-bottom: 16px; font-size: 13.5px; border: 1px solid transparent; animation: slideIn .28s ease;
}
.flash.success { background: var(--income-soft); color: #0e7a3d; border-color: color-mix(in srgb, var(--income) 28%, transparent); }
.flash.error { background: var(--expense-soft); color: #b3252a; border-color: color-mix(in srgb, var(--expense) 28%, transparent); }
.flash.info { background: var(--primary-soft); color: var(--primary-deep); border-color: color-mix(in srgb, var(--primary) 28%, transparent); }
.flash.warn { background: var(--warn-soft); color: #a35a00; border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
[data-theme="dark"] .flash.success { color: #4fd68b; }
[data-theme="dark"] .flash.error { color: #ff8085; }
[data-theme="dark"] .flash.info { color: #8fb0ff; }
[data-theme="dark"] .flash.warn { color: #ffb45e; }

.notice {
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 12.5px; line-height: 1.65;
  background: var(--card-2); border: 1px dashed var(--border-strong); color: var(--text-2);
}
.notice.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.notice.info { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }

@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* 空状态 */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .big { font-size: 36px; display: block; margin-bottom: 10px; opacity: .85; }

/* 分页 */
.pager { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 16px 0 4px; flex-wrap: wrap; }
.pager a, .pager span {
  min-width: 32px; height: 32px; display: grid; place-items: center; padding: 0 8px;
  border-radius: var(--radius-xs); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); background: var(--card);
  transition: border-color .14s, color .14s;
}
.pager a:hover { border-color: var(--primary); color: var(--primary); }
.pager .cur { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pager .gap { border: 0; background: transparent; }

/* 上传区 */
.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 32px 18px; text-align: center; cursor: pointer;
  background: var(--card-2); transition: all .18s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .big { font-size: 32px; display: block; margin-bottom: 8px; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.thumb { position: relative; width: 78px; height: 78px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: 3px; right: 3px; width: 19px; height: 19px; border-radius: 50%;
  border: 0; background: rgba(15, 23, 42, .65); color: #fff; font-size: 11px; cursor: pointer; line-height: 1;
  display: grid; place-items: center;
}
.thumb .tag { position: absolute; left: 0; right: 0; bottom: 0; font-size: 9px; background: rgba(15,23,42,.6); color: #fff; text-align: center; }

/* 草稿卡（AI 识别结果） */
.draft {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 13px;
  background: var(--card); margin-bottom: 10px; box-shadow: var(--shadow-sm);
}
.draft-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.draft-grid { display: grid; grid-template-columns: 118px 1fr 1fr; gap: 9px; }
.draft-grid .field { margin-bottom: 0; }
.confidence { font-size: 10.5px; padding: 1px 6px; border-radius: 99px; font-weight: 600; }
.confidence.high { background: var(--income-soft); color: var(--income); }
.confidence.mid { background: var(--warn-soft); color: var(--warn); }
.confidence.low { background: var(--expense-soft); color: var(--expense); }

/* 图表容器 */
.chart-box { width: 100%; overflow: hidden; }
.chart-legend-inline { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }

/* 登录页 */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 480px at 10% -10%, var(--primary-ring) 0%, transparent 60%),
    radial-gradient(760px 420px at 100% 0%, color-mix(in srgb, var(--income) 9%, transparent) 0%, transparent 55%),
    var(--bg);
}
[data-theme="dark"] .auth-wrap {
  background:
    radial-gradient(900px 480px at 10% -10%, var(--primary-ring) 0%, transparent 60%),
    radial-gradient(760px 420px at 100% 0%, color-mix(in srgb, var(--income) 7%, transparent) 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px 30px; box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 24px; }
.auth-brand .brand-logo { width: 42px; height: 42px; border-radius: 13px; }
.auth-brand .brand-logo .icon { width: 23px; height: 23px; }
.auth-brand b { font-size: 17px; display: block; }
.auth-brand span { font-size: 12px; color: var(--muted); }
.auth-foot { text-align: center; font-size: 12.5px; color: var(--muted); margin-top: 18px; }

/* 详情行 */
.kv { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.kv .k { flex: 0 0 88px; color: var(--muted); }
.kv .v { flex: 1; word-break: break-all; }

/* 日历 */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { text-align: center; font-size: 11.5px; color: var(--muted); padding: 6px 0; font-weight: 600; }
.cal-cell {
  min-height: 62px; border-radius: 10px; border: 1px solid var(--border); padding: 6px 7px;
  background: var(--card); display: flex; flex-direction: column; gap: 2px; position: relative;
  transition: border-color .14s, box-shadow .14s;
}
.cal-cell.empty { background: transparent; border-color: transparent; }
.cal-cell.today { border-color: var(--primary); border-width: 1.6px; }
.cal-cell.active { cursor: pointer; }
.cal-cell.active:hover { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.cal-cell .d { font-size: 12px; font-weight: 600; color: var(--text-2); }
.cal-cell.today .d { color: var(--primary); }
.cal-cell .e { font-size: 10.5px; color: var(--expense); font-weight: 600; }
.cal-cell .i { font-size: 10.5px; color: var(--income); font-weight: 600; }

/* 图库 */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; border: 1px solid var(--border); border-radius: 11px; overflow: hidden; background: var(--card); box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s; }
.gallery figure:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.gallery img { width: 100%; height: 132px; object-fit: cover; display: block; cursor: zoom-in; background: var(--card-2); }
.gallery figcaption { padding: 7px 9px; font-size: 11.5px; color: var(--muted); }
.gallery figcaption b { display: block; color: var(--text-2); font-size: 12.5px; }

/* 确认弹窗 */
.modal-mask {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(10, 15, 26, .45);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 380px; background: var(--card);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 20px; animation: popIn .18s ease;
}
.modal-title { font-size: 15.5px; font-weight: 650; display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.modal-title .icon { color: var(--warn); }

/* 交易详情弹窗：沿用确认弹窗骨架（同遮罩/动画/移动端底部弹层），略宽放 kv 与附件 */
.modal.txn-detail { max-width: 440px; }
.txn-detail-amt { font-size: 24px; font-weight: 700; margin: 2px 0 10px; font-variant-numeric: tabular-nums; }
.txn-detail .kv:last-of-type { border-bottom: 0; }
.txn-detail-att { margin: 12px 0 8px; }
.txn-detail-gallery { gap: 8px; }
.txn-detail-gallery figure { border-radius: 9px; }
.txn-detail-gallery img { height: 92px; cursor: zoom-in; }
.modal.danger .modal-title .icon { color: var(--expense); }
.modal-body { font-size: 13.5px; color: var(--text-2); line-height: 1.65; word-break: break-word; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* 工具类 */
.scroll-x { overflow-x: auto; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.sticky-side { position: sticky; top: calc(var(--topbar-h) + 14px); }

/* 滚动条 */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }

/* Toast */
#toast-box { pointer-events: none; }
#toast-box .flash { pointer-events: auto; box-shadow: var(--shadow-lg); min-width: 220px; max-width: 90vw; margin: 0; }

/* --------------------------- AI 记账助手 --------------------------- */

.ai-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 70;
  width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(140deg, #5b86ff, #3d6df5 55%, #2b56d9); color: #fff;
  box-shadow: 0 10px 26px -8px rgba(61, 109, 245, .8), inset 0 1px 0 rgba(255, 255, 255, .25);
  display: grid; place-items: center; transition: transform .18s, box-shadow .18s;
}
.ai-fab .icon { width: 24px; height: 24px; }
.ai-fab:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 14px 30px -8px rgba(61, 109, 245, .9); }
.ai-fab:active { transform: scale(.95); }

.ai-panel {
  position: fixed; right: 22px; bottom: 88px; z-index: 70;
  width: 376px; max-width: calc(100vw - 32px); height: 520px; max-height: calc(100vh - 120px);
  background: var(--card); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
  animation: popIn .2s ease;
}

.ai-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-bottom: 1px solid var(--border); background: var(--card-2);
}
.ai-head-avatar {
  width: 34px; height: 34px; border-radius: 11px; flex: 0 0 34px;
  background: linear-gradient(140deg, #5b86ff, #3d6df5 60%, #2b56d9); color: #fff;
  display: grid; place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22);
}
.ai-head-avatar .icon { width: 18px; height: 18px; }
.ai-head-meta { flex: 1; min-width: 0; }
.ai-head-meta b { display: block; font-size: 13.5px; }
.ai-head-meta span { display: block; font-size: 11px; color: var(--muted); }
.ai-icon-btn {
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); padding: 6px; border-radius: var(--radius-xs); line-height: 1;
  display: grid; place-items: center; transition: background .14s, color .14s;
}
.ai-icon-btn:hover { background: var(--card-3); color: var(--text); }
.ai-icon-btn .icon { width: 16px; height: 16px; }

.ai-msgs { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.ai-bubble {
  max-width: 88%; padding: 9px 12px; border-radius: 14px;
  font-size: 13px; line-height: 1.55; word-break: break-word;
}
.ai-bubble.bot { align-self: flex-start; background: var(--card-2); border: 1px solid var(--border); border-top-left-radius: 4px; }
.ai-bubble.user { align-self: flex-end; background: linear-gradient(180deg, var(--primary), var(--primary-deep)); color: #fff; border-bottom-right-radius: 4px; }
.ai-bubble em { font-style: normal; color: var(--primary); font-weight: 600; }
.ai-bubble.user em { color: #fff; }
.ai-bubble img { max-width: 150px; border-radius: 9px; display: block; margin-top: 6px; border: 1px solid var(--border); }
.ai-bubble.error { background: var(--expense-soft); color: var(--expense); border-color: transparent; }
.ai-bubble.error a { color: inherit; text-decoration: underline; }

.ai-record { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 12.5px; }
.ai-record:last-child { border-bottom: 0; }
.ai-record .ico { font-size: 16px; flex: 0 0 auto; }
.ai-record .m { flex: 1; min-width: 0; }
.ai-record .m b { display: block; font-weight: 600; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-record .m span { display: block; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-record .amt { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ai-record .amt.income { color: var(--income); }
.ai-record .amt.expense { color: var(--expense); }
.ai-warn { font-size: 11px; color: var(--warn); margin-top: 7px; line-height: 1.5; }
.ai-answer { font-size: 12.5px; line-height: 1.65; word-break: break-word; }
/* 语音输入（P3）：录音中红色呼吸提示；不支持的浏览器按钮由脚本保持隐藏 */
.ai-icon-btn.listening { color: #f5222d; animation: aiMicPulse 1.2s ease-in-out infinite; }
@keyframes aiMicPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.ai-meta { font-size: 10.5px; color: var(--muted); margin-top: 7px; display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.ai-undo { border: 1px solid var(--border-strong); background: transparent; color: var(--muted); border-radius: 8px; padding: 2px 10px; font-size: 11px; cursor: pointer; transition: color .15s ease-in-out, border-color .15s ease-in-out; }
.ai-undo:hover { color: #f5222d; border-color: #f5222d; }
.ai-undo.done { pointer-events: none; color: var(--muted); border-color: var(--border); }
.ai-hint { font-size: 10px; color: var(--muted); font-weight: 400; }

.ai-typing { display: inline-flex; gap: 4px; padding: 3px 2px; }
.ai-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: aiBlink 1.2s infinite; }
.ai-typing i:nth-child(2) { animation-delay: .2s; }
.ai-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes aiBlink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

.ai-thumbs { display: flex; gap: 6px; padding: 8px 12px 0; flex-wrap: wrap; }
.ai-thumbs .t { position: relative; width: 44px; height: 44px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.ai-thumbs .t img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-thumbs .t button {
  position: absolute; top: 0; right: 0; width: 16px; height: 16px; border: 0;
  border-radius: 0 0 0 8px; background: rgba(15, 23, 42, .65); color: #fff; font-size: 9px; cursor: pointer; line-height: 1;
}

.ai-inputbar { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--card-2); }
.ai-inputbar textarea {
  flex: 1; resize: none; min-height: 38px; max-height: 110px;
  padding: 8px 11px; border-radius: 12px; font-size: 13px; line-height: 1.5;
}
.ai-send {
  width: 38px; height: 38px; flex: 0 0 38px; border: 0; border-radius: 12px;
  background: linear-gradient(180deg, var(--primary), var(--primary-deep)); color: #fff; cursor: pointer;
  display: grid; place-items: center;
  transition: filter .15s, transform .1s;
}
.ai-send .icon { width: 17px; height: 17px; }
.ai-send:hover { filter: brightness(1.08); }
.ai-send:active { transform: scale(.94); }
.ai-send:disabled { opacity: .5; cursor: not-allowed; }

/* 桌面端：AI 助手入口在顶栏（悬浮球会遮挡右下内容，仅移动端保留）。
   触屏设备（横屏手机/平板）即使视口 ≥821px 也走移动形态：保留悬浮球 */
@media (min-width: 821px) and (pointer: fine) {
  .ai-fab { display: none; }
  .ai-panel {
    top: calc(var(--topbar-h) + 8px); bottom: auto;
    height: min(520px, calc(100vh - var(--topbar-h) - 24px));
    animation: aiPopTop .2s ease;
  }
}
@keyframes aiPopTop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ------------------------------ 响应式 ------------------------------ */

@media (max-width: 1100px) {
  .grid-main { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 820px), (pointer: coarse) and (max-width: 1024px) {
  :root { --sidebar-w: 0px; --topbar-h: 54px; }
  .sidebar { display: none; }
  .content { padding: 14px 14px 92px; }
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 17px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 14px; border-radius: 13px; }
  .draft-grid { grid-template-columns: 1fr 1fr; }
  .draft-grid .field:first-child { grid-column: span 2; }
  .stat .value { font-size: 19px; }
  .amount.big { font-size: 23px; }
  .cal-cell { min-height: 52px; padding: 4px; }
  .cal-cell .e, .cal-cell .i { font-size: 9.5px; }
  .table.responsive th:nth-child(n+5), .table.responsive td:nth-child(n+5) { display: none; }

  /* 移动端底部导航 */
  .mobile-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: color-mix(in srgb, var(--card) 94%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom));
    justify-content: space-around; align-items: flex-end;
  }
  .mobile-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 10.5px; color: var(--muted); padding: 5px 0;
  }
  .mobile-nav a .icon { width: 19px; height: 19px; }
  .mobile-nav a.active { color: var(--primary); font-weight: 600; }
  .mobile-nav .fab {
    flex: 0 0 52px; height: 52px; border-radius: 50%;
    background: linear-gradient(180deg, var(--primary), var(--primary-deep)); color: #fff;
    display: grid; place-items: center; margin: 0 6px;
    box-shadow: 0 8px 20px -6px rgba(61, 109, 245, .75); transform: translateY(-12px);
  }
  .mobile-nav .fab .icon { width: 26px; height: 26px; }

  /* AI 助手：避开底部导航 */
  .ai-fab { right: 14px; bottom: 84px; width: 48px; height: 48px; }
  .ai-fab .icon { width: 21px; height: 21px; }
  .ai-panel { right: 12px; bottom: 140px; height: min(480px, calc(100vh - 170px)); }
}

@media (max-width: 520px) {
  .grid-4, .grid-5 { grid-template-columns: 1fr 1fr; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .legend-val, .rank-val { flex: 0 0 70px; }
  .rank-name { flex: 0 0 74px; }
}

@media print {
  .sidebar, .topbar, .mobile-nav, .btn, .ai-fab, .ai-panel { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  /* iteration-count 一并压到 1：否则 mSpin/aiMicPulse 等 infinite 动画在 .01ms 时长下
     每帧落随机相位，图标呈随机角度抖动而非静止（评审建议，一次覆盖所有 infinite 动画） */
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ------------------------------ 关于页 ------------------------------ */

.about-hero { display: flex; flex-direction: column; gap: 18px; padding: 22px; }
.about-hero-main { display: flex; gap: 16px; align-items: flex-start; }

.about-features { gap: 12px; }
.about-feature {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--card-2); transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.about-feature:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--primary) 40%, transparent); box-shadow: var(--shadow-sm); }
.about-feature .ico {
  flex: 0 0 38px; height: 38px; border-radius: 10px; font-size: 19px;
  display: grid; place-items: center; background: var(--primary-soft);
}

.about-feedback { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }
@media (min-width: 821px) {
  .about-feedback { flex-direction: row; align-items: center; justify-content: space-between; }
  .about-fb-text { flex: 1; min-width: 0; padding-right: 18px; }
}

.about-timeline { position: relative; padding-left: 18px; }
.about-timeline::before {
  content: ''; position: absolute; left: 4px; top: 6px; bottom: 6px;
  width: 2px; border-radius: 1px; background: var(--border);
}
.tl-item { position: relative; padding: 0 0 18px 14px; }
.tl-item:last-child { padding-bottom: 2px; }
.tl-dot {
  position: absolute; left: -18px; top: 7px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

/* ============================================================
   移动端适配与桌面打磨（v1.4.0）
   ============================================================ */

/* ------------------------------ 桌面细节打磨 ------------------------------ */

::selection { background: var(--primary-ring); }

.content { animation: contentIn .22s ease; }
@keyframes contentIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.nav-item.active { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 22%, transparent); }
.brand-logo, .ai-fab, .ai-head-avatar, .mobile-nav .fab { transition: transform .18s, box-shadow .18s, filter .18s; }

/* 汉堡按钮 / 抽屉遮罩 / 抽屉关闭钮：桌面隐藏 */
.nav-burger, .nav-drawer-close { display: none; }
.drawer-mask { display: block; }

.btn-label { display: inline; }

/* ------------------------------ 移动端（≤820px） ------------------------------ */

@media (max-width: 820px), (pointer: coarse) and (max-width: 1024px) {
  /* 侧栏 → 抽屉：默认移出屏幕，body.nav-open 滑入 */
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    height: 100dvh;
    width: min(84vw, 300px);
    transform: translateX(-105%);
    transition: transform .22s ease;
    z-index: 110;
    box-shadow: var(--shadow-lg);
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  body.nav-open .sidebar { transform: none; }
  .nav-drawer-close {
    display: grid; place-items: center;
    margin-left: auto; width: 34px; height: 34px;
    border: 0; border-radius: var(--radius-sm);
    background: transparent; color: var(--muted); cursor: pointer;
  }
  .nav-drawer-close:hover { background: var(--card-2); color: var(--text); }

  .drawer-mask {
    position: fixed; inset: 0; z-index: 105;
    background: rgba(10, 15, 26, .45);
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  body.nav-open .drawer-mask { opacity: 1; pointer-events: auto; }

  .nav-burger {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex: 0 0 36px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--card); color: var(--text-2); cursor: pointer;
    transition: border-color .14s, color .14s;
  }
  .nav-burger:active { color: var(--primary); border-color: var(--primary); }

  /* 顶栏紧凑 */
  .topbar { padding: 8px 10px; gap: 7px; min-height: 52px; }
  .topbar h1 { font-size: 16px; }
  .topbar .sub { font-size: 11px; }
  .content { padding: 12px 12px calc(88px + env(safe-area-inset-bottom)); }

  /* 触控优先的表单行：纵向堆叠、控件全宽 */
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form .field { width: auto !important; min-width: 0 !important; flex: none !important; }
  .inline-form .field .btn, .inline-form .field button { width: 100%; }

  /* 筛选 chip 行：横向滚动（配 .chip-row） */
  .chip-row {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .chip-row::-webkit-scrollbar { display: none; }
  .chip-row > * { flex: 0 0 auto; }

  /* 类型页签：横向滚动（记一笔 7 个页签放不下） */
  .type-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .type-tabs::-webkit-scrollbar { display: none; }
  .type-tabs a, .type-tabs button { flex: 0 0 auto; min-width: 64px; }

  /* 弹窗 → 底部弹层（Bottom Sheet） */
  .modal-mask { place-items: end center; padding: 0; }
  .modal {
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
    animation: sheetIn .22s ease;
  }
  .modal-actions .btn { flex: 1; padding: 11px 14px; }

  /* AI 面板：近全宽，置于底部导航之上 */
  .ai-panel {
    left: 10px; right: 10px; width: auto;
    bottom: calc(78px + env(safe-area-inset-bottom));
    height: min(66vh, 520px);
  }

  .user-menu-drop { min-width: 200px; }
  .stat .value { font-size: 18px; }
  .amount-input input { font-size: 26px; }
  .card { padding: 14px; }

  /* 底部导航 + 安全区 */
  .mobile-nav {
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--card) 92%, transparent);
  }
  .mobile-nav a { padding: 6px 0 4px; }
}

/* ------------------------------ 小屏手机（≤480px） ------------------------------ */

@media (max-width: 480px) {
  .topbar h1 { font-size: 15.5px; }
  .btn-label { display: none; }   /* 「记一笔」收成纯图标 */
  /* grid-2/grid-3 是内容大卡（如报表排行），小屏保持单列；
     只有 stat 卡（grid-4/5）才 2 列。此前把 grid-2 也拆两列，
     导致报表排行卡只有 ~170px 宽、数值要横向滚动才能看到 */
  .grid-4, .grid-5 { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 17px; }
  .stat .delta { font-size: 10.5px; }
  .txn-act { opacity: 1; }        /* 触屏无 hover：操作按钮常显 */
  .table.responsive th:nth-child(n+4), .table.responsive td:nth-child(n+4) { display: none; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery img { height: 110px; }
  .cal-cell { min-height: 46px; padding: 3px 4px; border-radius: 8px; }
  .cal-cell .e, .cal-cell .i { font-size: 9px; }
  .auth-card { padding: 26px 20px; border-radius: 16px; }
  .kv .k { flex-basis: 76px; }
  .pager a, .pager span { min-width: 36px; height: 36px; }
  .hl-select-menu { max-width: calc(100vw - 24px); }
}

/* ------------------------------ 触屏设备 ------------------------------ */

@media (pointer: coarse) {
  .btn:not(.btn-sm):not(.btn-icon) { min-height: 42px; }
  .btn-sm { min-height: 34px; }
  input[type="text"], input[type="password"], input[type="number"], input[type="date"],
  input[type="email"], input[type="month"], input[type="time"], input[type="search"],
  select, textarea, .hl-select-trigger {
    min-height: 42px;
  }
  .amount-input input { min-height: 0; }
  .ledger-switch select { min-height: 0; }
  .pager a, .pager span { min-width: 40px; height: 40px; }
  .cat-item { padding: 12px 4px; }
  .chip { padding: 5px 11px; font-size: 12px; }
  .nav-item { padding: 11px 12px; }
  .tabs a { padding: 12px 14px; }
  .mobile-nav a { min-height: 48px; }
}

@keyframes sheetIn { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 手机端自适应补强：行内内容智能换行重排（而非溢出） */
@media (max-width: 820px), (pointer: coarse) and (max-width: 1024px) {
  .row { flex-wrap: wrap; row-gap: 6px; }
  .row > * { min-width: 0; }
  .type-tabs { min-width: 0; }
  .card, .card-head { min-width: 0; }
  .card-head { flex-wrap: wrap; }
  .card { overflow-wrap: break-word; }
  .mono { overflow-wrap: anywhere; }
  .txn-title, .txn-sub { min-width: 0; }
  .about-hero-main { flex-direction: column; }
}

/* grid/flex 子项允许收缩（1fr 轨道 min-width:auto 是横向溢出的常见根源） */
@media (max-width: 820px), (pointer: coarse) and (max-width: 1024px) {
  .grid > *, .grid-main > *, .content .card, .content form { min-width: 0; }
}

/* 抽屉修复：原响应式块把 .sidebar 设为 display:none，抽屉模式必须改回 flex */
@media (max-width: 820px), (pointer: coarse) and (max-width: 1024px) {
  body.nav-ready .sidebar { display: flex; }
}

/* 手机端交易行：防标题逐字竖排，操作按钮紧凑 */
@media (max-width: 820px), (pointer: coarse) and (max-width: 1024px) {
  .txn { gap: 8px; }
  .txn-ico { width: 32px; height: 32px; flex-basis: 32px; border-radius: 10px; font-size: 16px; }
  .txn-title > span:not(.note) { flex-shrink: 0; white-space: nowrap; }
  .txn-title .note { flex: 1 1 auto; min-width: 40px; }
  .txn-amt { font-size: 13.5px; }
  .txn-act { opacity: .9; }
  .txn-act .btn { padding: 4px 7px; }
}

/* 手机端记一笔：卡片重排为 主表单 → 分类 → 保存 → AA/提示（display:contents 让卡片直接成为栅格项） */
@media (max-width: 820px), (pointer: coarse) and (max-width: 1024px) {
  #txn-form .grid-main > div { display: contents; }
  #txn-form .grid-main > div:first-child > .card:first-child { order: 0; }
  #txn-form .grid-main > div:first-child > .card:last-child { order: 3; }
  #txn-form .grid-main > div:last-child > #f-cat-wrap { order: 1; }
  #txn-form .grid-main > div:last-child > .card:nth-child(2) { order: 2; }
  #txn-form .grid-main > div:last-child > .notice { order: 4; }
}

/* 上一条 :last-child 修正（右列末尾还有提示条） */

/* v1.4.1 补强：超长分类名不挤爆交易行；贴近视口右缘的下拉改右对齐 */
@media (max-width: 820px), (pointer: coarse) and (max-width: 1024px) {
  .txn-title > span:not(.note) { max-width: 60%; overflow: hidden; text-overflow: ellipsis; }
}
.hl-select-menu.right { left: auto; right: 0; }

/* 交易分类名可点击筛选（纯交互：既有数据变导航入口） */
a.txn-cat { color: inherit; transition: color .12s; }
a.txn-cat:hover { color: var(--primary); }

/* ============================================================
   v1.5.0 UI/交互打磨（基于 Bootstrap / Tabler / shadcn 令牌研究）
   只动视觉与交互，不加功能
   ============================================================ */

:root { --ease: cubic-bezier(.4, 0, .2, 1); }  /* Material 标准曲线 */

/* 统一过渡：颜色类 .15s ease-in-out（Bootstrap 组件基准） */
.btn, .chip, .nav-item, .tabs a, .pager a, .pager span,
.type-tabs a, .type-tabs button, .hl-select-trigger, .user-menu-btn,
.nav-burger, .ai-icon-btn, .ai-send, .thumb button, .ai-thumbs .t button {
  transition: color .15s ease-in-out, background-color .15s ease-in-out,
    border-color .15s ease-in-out, box-shadow .15s ease-in-out, transform .1s var(--ease);
}

/* 行悬停背景过渡（明细行 / 表格行 / 下拉选项） */
.txn, .table td, .cat-item, .gallery figure { transition: background-color .12s ease-in-out, border-color .12s ease-in-out, box-shadow .12s ease-in-out; }

/* 主题切换平滑：主要容器背景/边框颜色过渡，避免切换闪变 */
body, .card, .sidebar, .topbar, .mobile-nav, .stat, .notice, .flash {
  transition: background-color .2s ease-in-out, border-color .2s ease-in-out;
}

/* 按压反馈统一（按钮已有 scale，补齐 chips/分页/页签/摘要行） */
.chip:active, .pager a:active, .type-tabs a:active, .type-tabs button:active,
.user-menu-item:active, .user-menu-btn:active { transform: scale(.96); }
.chip, .user-menu-item, .palette-item, .hl-select-opt, .cat-parent { transition: transform .1s var(--ease), background-color .12s ease-in-out, color .12s ease-in-out, border-color .12s ease-in-out; }

/* 平滑滚动（受全局 reduced-motion 约束） */
html { scroll-behavior: smooth; }

/* 悬停设备：侧栏图标轻微位移，主次分明 */
@media (hover: hover) {
  .nav-item .icon { transition: transform .15s var(--ease); }
  .nav-item:hover .icon { transform: translateX(1.5px); }
}

/* 正文链接悬停下划线偏移（可访问性基线） */
.content a { text-underline-offset: 3px; }

/* 抽屉滑入用标准曲线 */
.sidebar { transition: transform .22s var(--ease), box-shadow .22s var(--ease); }

/* 键盘焦点环统一为 3.5px 主色（与输入框一致，覆盖默认 2px outline） */
.chip:focus-visible, .pager a:focus-visible, .nav-item:focus-visible,
.hl-select-opt:focus-visible, .user-menu-item:focus-visible, .palette-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3.5px var(--primary-ring);
}

/* ============================================================
   v1.5.1：自定义日期选择器（桌面端；触屏保留原生）
   ============================================================ */

.hl-date { position: relative; display: block; width: 100%; }
.hl-date-trigger {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 12px; min-height: 36px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text);
  font-size: 14px; font-family: var(--font); line-height: 1.45;
  cursor: pointer; text-align: left;
  transition: color .15s ease-in-out, background-color .15s ease-in-out,
    border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.hl-date-trigger .icon { color: var(--muted); }
.hl-date-trigger:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border-strong)); }
.hl-date.open .hl-date-trigger, .hl-date-trigger:focus-visible {
  border-color: var(--primary); box-shadow: 0 0 0 3.5px var(--primary-ring);
}
.hl-date-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hl-date-label.ph { color: var(--faint); }

.hl-date-menu {
  display: none;
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 95;
  width: 282px; max-width: calc(100vw - 24px);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 13px; box-shadow: var(--shadow-lg);
  padding: 10px;
  animation: popIn .14s ease;
}
.hl-date.open .hl-date-menu { display: block; }
.hl-date-menu.up { top: auto; bottom: calc(100% + 6px); }
.hl-date-menu.right { left: auto; right: 0; }

.hl-date-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.hl-date-title { flex: 1; display: flex; align-items: center; justify-content: center; gap: 2px; text-align: center; font-weight: 650; font-size: 13.5px; }
/* 标题里的年/月直达按钮：视觉与原纯文本标题一致，仅加悬停提示可点 */
.hl-date-tb {
  border: 0; background: none; padding: 4px 7px; border-radius: 8px;
  font: inherit; font-size: 13.5px; font-weight: 650; color: var(--text);
  cursor: pointer; transition: background-color .12s ease-in-out, color .12s ease-in-out;
}
.hl-date-tb:hover { background: var(--card-2); color: var(--primary); }
.hl-date-nav {
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 0; border-radius: var(--radius-xs); background: transparent; color: var(--muted);
  cursor: pointer;
  transition: background-color .12s ease-in-out, color .12s ease-in-out;
}
.hl-date-nav:hover { background: var(--card-2); color: var(--text); }

.hl-date-week {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 2px;
}
.hl-date-week span {
  text-align: center; font-size: 11px; color: var(--faint); font-weight: 600; padding: 3px 0;
}
.hl-date-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.hl-date-cell {
  display: grid; place-items: center; height: 32px;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--text); font-size: 13px; font-family: var(--font);
  cursor: pointer; font-variant-numeric: tabular-nums;
  transition: background-color .1s ease-in-out, color .1s ease-in-out;
}
.hl-date-cell:hover { background: var(--card-2); }
.hl-date-cell.blank { pointer-events: none; }
.hl-date-cell.today { color: var(--primary); font-weight: 650; }
.hl-date-cell.selected {
  background: var(--primary); color: #fff; font-weight: 650;
  box-shadow: 0 2px 8px -2px var(--primary-ring);
}
.hl-date-cell.selected:hover { background: var(--primary-deep); }

.hl-date-foot { display: flex; align-items: center; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.hl-date-act {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: var(--radius-xs);
  background: var(--card); color: var(--text-2); font-size: 12.5px; font-family: var(--font);
  cursor: pointer;
  transition: background-color .12s ease-in-out, color .12s ease-in-out, border-color .12s ease-in-out;
}
.hl-date-act:hover { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

/* 无 JS 回退：触屏/未增强时原生 input 已有全局样式，无需额外处理 */

/* ============================================================
   v1.6.3：日历页 UI 对齐设计体系
   ============================================================ */

.cal-grid { gap: 5px; }
.cal-head { font-size: 11px; color: var(--faint); font-weight: 600; padding: 4px 0; text-transform: uppercase; letter-spacing: .04em; }
.cal-cell {
  border-radius: 10px;
  transition: background-color .12s ease-in-out, border-color .12s ease-in-out, box-shadow .12s ease-in-out;
}
.cal-cell.active:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.cal-cell.today {
  border-color: var(--primary);
  border-width: 1.5px;
}
.cal-cell .d { font-size: 12px; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }
.cal-cell.today .d { color: var(--primary); }
.cal-cell .e { font-size: 10px; color: var(--expense); font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-cell .i { font-size: 10px; color: var(--income); font-weight: 600; font-variant-numeric: tabular-nums; }

/* 月导航按钮组 */
.cal-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cal-nav .cal-title { font-size: 16px; font-weight: 700; letter-spacing: -.01em; min-width: 110px; text-align: center; }
.cal-nav .btn { min-width: 0; }

@media (max-width: 820px), (pointer: coarse) and (max-width: 1024px) {
  .cal-grid { gap: 3px; }
  .cal-cell { min-height: 44px; padding: 3px 4px; border-radius: 8px; }
  .cal-cell .d { font-size: 11px; }
  .cal-cell .e, .cal-cell .i { font-size: 9px; }
  /* 手机端导航行允许换行：月份统计换到第二行（nowrap 会把「结余」挤出屏幕） */
  .cal-nav { flex-direction: row; flex-wrap: wrap; row-gap: 8px; }
  .cal-nav .spacer { display: none; }
  .cal-nav .cal-title { flex: 1; }
}

/* 日历热力图空格暗色适配 */
.hm-empty { fill: var(--card-2); }

/* 月份选择器格子（3×4） */
.hl-date-mon-grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
.hl-date-cell.hl-date-mon {
  height: 38px; font-size: 13px; border-radius: 8px;
  display: grid; place-items: center;
}

/* 年份直达格子（4×3，规格与月份格一致） */
.hl-date-yr-grid { grid-template-columns: repeat(4, 1fr); gap: 4px; }
.hl-date-cell.hl-date-yr {
  height: 38px; font-size: 13px; border-radius: 8px;
  display: grid; place-items: center;
}

/* 文件上传按钮美化（隐藏原生 input，用自定义按钮触发） */
.file-pick-btn { position: relative; overflow: hidden; }


/* ============================================================
   手机极简模式（P10 阶段 1）：三 Tab 布局 + 捕获区 + 草稿卡片
   ============================================================ */
.m-body { background: var(--bg); }
.m-head { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--border); }
.m-head-brand { display: flex; align-items: center; gap: 6px; font-weight: 650; font-size: 14px; color: var(--primary); }
.m-head-brand .icon { width: 18px; height: 18px; }
.m-ledger-switch { flex: 1; min-width: 0; }
.m-ledger-switch select { width: 100%; max-width: 180px; margin: 0 auto; display: block; font-size: 12.5px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--card-2); color: var(--text); }
.m-head-link { position: relative; color: var(--muted); padding: 4px; }
.m-badge { position: absolute; top: -2px; right: -4px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; background: var(--expense); color: #fff; font-size: 9.5px; line-height: 15px; text-align: center; }
.m-main { padding: 12px 14px calc(76px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; }
.m-tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
/* 软键盘打开时藏底栏（m.js 用 VisualViewport 判键盘）：键盘会把固定底栏顶上来
   盖住捕获区的输入框/识别按钮，逼用户先收键盘才能点（维护者反馈） */
body.kb-open .m-tabbar { display: none; }
.m-tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 10.5px; color: var(--muted); text-decoration: none; }
.m-tab .icon { width: 21px; height: 21px; }
.m-tab.active { color: var(--primary); font-weight: 650; }

.m-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.m-card-head, .m-more-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.m-hero-month { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.m-hero-nums { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.m-hero-num .k { display: block; font-size: 11px; color: var(--muted); }
.m-hero-num .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.m-hero-num.expense .v { color: var(--expense); }
.m-hero-num.income .v { color: var(--income); }
.m-budget { margin-top: 12px; }
.m-budget-row { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px; }
.m-budget .bar { height: 6px; border-radius: 4px; background: var(--card-2); overflow: hidden; }
.m-budget .bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }
.m-budget .bar.warn .bar-fill { background: var(--warn); }
.m-budget .bar.over .bar-fill { background: var(--expense); }

.m-capture-input { display: flex; flex-direction: column; gap: 8px; }
.m-capture-input textarea { width: 100%; resize: none; border: 1px solid var(--border); border-radius: 11px; padding: 9px 11px; font-size: 14px; background: var(--card-2); color: var(--text); line-height: 1.45; min-height: 0; /* 覆盖全局 textarea 72px 下限，高度完全由 rows 掌控（审查 P3） */ }
.m-capture-input textarea:focus { outline: none; border-color: var(--primary); }
/* 操作行：输入框独占一行后，按钮带文字标签（长辈可发现性）、更大的点击目标；
   次操作（语音/拍单）靠左，主操作（识别）推到右端 */
.m-capture-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.m-capture-btn { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px; height: 36px; padding: 0 13px; border-radius: 18px; border: 1px solid var(--border); background: var(--card-2); color: var(--muted); font-size: 13px; }
.m-capture-btn .icon { width: 16px; height: 16px; }
.m-capture-btn span { white-space: nowrap; }
.m-capture-actions .m-capture-btn.primary { margin-left: auto; padding: 0 16px; }
.m-capture-btn.primary { background: var(--primary); border-color: transparent; color: #fff; }
.m-capture-btn.listening { color: #f5222d; animation: aiMicPulse 1.2s ease-in-out infinite; }
/* 识别进行中：图标旋转 + 文案「识别中…」（m.js busy 态），AI 返回前不让用户误认为卡死 */
.m-capture-btn.busy .icon { animation: mSpin 0.9s linear infinite; }
@keyframes mSpin { to { transform: rotate(360deg); } }
.m-thumbs { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.m-thumbs .t { position: relative; }
.m-thumbs img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.m-thumbs .t button { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; border: 0; background: var(--expense); color: #fff; font-size: 10px; line-height: 18px; padding: 0; }
.m-capture-msg { margin-top: 8px; font-size: 12px; line-height: 1.5; }
.m-capture-msg.warn { color: var(--warn); }

.m-draft { border: 1px solid var(--border); border-radius: 11px; padding: 10px 11px; margin-top: 10px; background: var(--card-2); }
.m-draft.done { border-color: var(--income); }
.m-draft-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.m-draft-count { font-size: 10px; color: var(--primary); border: 1px solid currentColor; border-radius: 8px; padding: 0 5px; white-space: nowrap; }
.m-draft-head .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.m-draft-head .amt.income { color: var(--income); }
.m-draft-head .amt.expense { color: var(--expense); }
.m-draft-sub { font-size: 11px; color: var(--muted); margin-top: 3px; }
.m-draft-ops { display: flex; gap: 8px; margin-top: 9px; }
.m-draft-done { font-size: 12.5px; color: var(--income); font-weight: 600; }

/* 问账回答卡（P10 阶段 2）：捕获区里问句的输出，与草稿卡同容器 */
.m-answer { position: relative; border: 1px solid var(--border); border-radius: 11px; padding: 10px 11px; margin-top: 10px; background: var(--card-2); }
.m-answer-tag { font-size: 11px; color: var(--muted); margin-bottom: 4px; padding-right: 20px; }
.m-answer-body { font-size: 13px; line-height: 1.65; white-space: pre-line; word-break: break-word; }
.m-answer-warn { margin-top: 6px; font-size: 12px; color: var(--warn); line-height: 1.5; }
.m-answer-meta { margin-top: 7px; font-size: 11px; }
.m-answer-x { position: absolute; top: 5px; right: 7px; border: 0; background: none; color: var(--muted); font-size: 12px; line-height: 1; padding: 4px; cursor: pointer; }

.m-recent { margin: -2px 0; }
.m-txn { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); text-decoration: none; color: var(--text); }
.m-txn:last-child { border-bottom: 0; }
.m-txn .ico { font-size: 17px; flex: 0 0 auto; }
.m-txn .m { flex: 1; min-width: 0; }
.m-txn .m b { display: block; font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-txn .m .tiny { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-txn .amt { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 13.5px; }
.m-txn .amt.income { color: var(--income); }
.m-txn .amt.expense { color: var(--expense); }
.m-empty { text-align: center; color: var(--muted); font-size: 12.5px; padding: 14px 0; }

.m-more-group { margin-bottom: 6px; }
.m-more-title { font-size: 11px; color: var(--muted); margin: 10px 2px 4px; }
.m-more-item { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px dashed var(--border); text-decoration: none; color: var(--text); font-size: 14px; }
.m-more-item:last-child { border-bottom: 0; }
.m-more-item .icon { width: 17px; height: 17px; color: var(--muted); }
.m-draft-acc-row { display: flex; align-items: center; gap: 7px; margin-top: 8px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.m-draft-acc { flex: 1; min-width: 0; font-size: 13px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--card); color: var(--text); }
.m-draft-hint { font-size: 10.5px; color: var(--primary); white-space: nowrap; }
button.m-more-item { width: 100%; background: none; border: 0; border-bottom: 1px dashed var(--border); cursor: pointer; font: inherit; text-align: left; }
button.m-more-item.danger { color: var(--expense); }
