/* ============================================================
   家账簿 HomeLedger — 样式表
   服务端渲染，零前端框架依赖
   ============================================================ */

:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --card-2: #fafbfe;
  --border: #e9edf3;
  --border-strong: #dbe1ea;
  --text: #1f2937;
  --text-2: #475467;
  --muted: #8b95a5;
  --primary: #4f7cff;
  --primary-soft: #eef3ff;
  --primary-deep: #3563e9;
  --income: #16a34a;
  --income-soft: #e9f9ef;
  --expense: #f5222d;
  --expense-soft: #fff1f0;
  --warn: #fa8c16;
  --warn-soft: #fff7e6;
  --info: #1677ff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .12);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --sidebar-w: 224px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0e131f;
  --card: #161d2c;
  --card-2: #1b2333;
  --border: #232c3f;
  --border-strong: #2e3950;
  --text: #e6eaf3;
  --text-2: #b9c2d4;
  --muted: #7f8ba2;
  --primary-soft: #1b2540;
  --income-soft: #12291d;
  --expense-soft: #2c1619;
  --warn-soft: #2c2113;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .6);
  --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;
}

body {
  background:
    radial-gradient(900px 420px at 85% -10%, color-mix(in srgb, var(--primary) 5%, transparent) 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; opacity: .85; }
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 { margin: 0; padding: 0; list-style: none; }
svg { 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: 18px 12px;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 16px;
  font-weight: 700; font-size: 16px;
}
.brand-logo {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #4f7cff, #7b9dff);
  color: #fff; display: grid; place-items: center; font-size: 16px;
  box-shadow: 0 4px 12px -4px rgba(79, 124, 255, .7);
}

.ledger-switch {
  margin: 0 4px 14px; padding: 9px 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: 4px; }
.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;
}

.nav-group { margin-bottom: 6px; }
.nav-title { font-size: 11px; color: var(--muted); padding: 10px 10px 6px; font-weight: 600; letter-spacing: .04em; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px; margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--card-2); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
  position: relative;
}
.nav-item.active::before {
  content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--primary);
}
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }
.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;
}

.sidebar-foot { margin-top: auto; padding-top: 12px; 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;
}
.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;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 22px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; min-width: 0; }
.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 10px 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(--primary); box-shadow: var(--shadow-sm); }
.user-menu-name { font-size: 13px; font-weight: 600; max-width: 10em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-caret { font-size: 10px; color: var(--muted); }
.user-menu-drop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 80;
  min-width: 220px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px;
}
.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:hover { background: var(--card-2); }
/* 自传头像：圆形图片，替代首字母色块 */
.avatar-img { width: 100%; 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 rgba(79, 124, 255, .35); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 35%, transparent); }
/* 窄屏：用户菜单收成纯头像圆标 */
@media (max-width: 860px) {
  .user-menu-name, .user-menu-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: 16px; margin-bottom: 16px;
}
.card.tight { padding: 12px; }
.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: 12px; }
.tiny { font-size: 11px; }
.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; }
.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: 8px 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.4; transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-deep); border-color: var(--primary-deep); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--card-2); color: var(--text); }
.btn-danger { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 35%, var(--border)); }
.btn-danger:hover { background: var(--expense-soft); color: var(--expense); border-color: var(--expense); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { padding: 11px 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-icon { padding: 7px 9px; }

/* 表单 */
.field { margin-bottom: 14px; }
.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: 9px 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 .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
}
textarea { resize: vertical; min-height: 72px; line-height: 1.6; }
select { cursor: pointer; 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: 40px; height: 34px; padding: 2px; border-radius: 8px; 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 40px; letter-spacing: -.02em; }
.amount-input .cur { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 22px; color: var(--muted); font-weight: 600; }

/* 徽标 / 标签 */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 99px; font-size: 11.5px;
  background: var(--card-2); border: 1px solid var(--border); color: var(--text-2);
  white-space: nowrap;
}
.chip.primary { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.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 7px; 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: 14px 16px; box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}
.stat .label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.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: 57px; 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: 36px; height: 36px; border-radius: 11px; flex: 0 0 36px;
  display: grid; place-items: center; font-size: 17px; background: var(--card-2);
}
.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-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 { 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(--muted); font-size: 11px; text-align: center; }
.rank-name { flex: 0 0 100px; }

/* 表格 */
.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(74px, 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); }
.cat-item.selected { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.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: 6px; 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: 8px 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;
}
.type-tabs .active { background: var(--card); color: var(--primary); 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;
}
.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: #12693a; border-color: color-mix(in srgb, var(--income) 25%, transparent); }
.flash.error { background: var(--expense-soft); color: #a8071a; border-color: color-mix(in srgb, var(--expense) 25%, transparent); }
.flash.info { background: var(--primary-soft); color: var(--primary-deep); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.flash.warn { background: var(--warn-soft); color: #ad4e00; border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
[data-theme="dark"] .flash.success { color: #56d68c; }
[data-theme="dark"] .flash.error { color: #ff7b7b; }
[data-theme="dark"] .flash.info { color: #8aabff; }
[data-theme="dark"] .flash.warn { color: #ffb74d; }

.notice {
  padding: 11px 13px; border-radius: var(--radius-sm); font-size: 12.5px; line-height: 1.6;
  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; } }

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

/* 分页 */
.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: 8px; border: 1px solid var(--border); font-size: 13px; color: var(--text-2); background: var(--card);
}
.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: 30px 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: 30px; 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); }
.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(0, 0, 0, .6); color: #fff; font-size: 11px; cursor: pointer; line-height: 1;
}
.thumb .tag { position: absolute; left: 0; right: 0; bottom: 0; font-size: 9px; background: rgba(0,0,0,.55); color: #fff; text-align: center; }

/* 草稿卡（AI 识别结果） */
.draft {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 13px;
  background: var(--card); margin-bottom: 10px;
}
.draft-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.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; }
.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(1000px 520px at 12% -8%, #e8efff 0%, transparent 62%),
              radial-gradient(820px 460px at 100% 0%, #e6f7f4 0%, transparent 55%), var(--bg);
}
[data-theme="dark"] .auth-wrap {
  background: radial-gradient(1000px 520px at 12% -8%, #16203a 0%, transparent 62%),
              radial-gradient(820px 460px at 100% 0%, #12261f 0%, transparent 55%), var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 30px 28px; box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.auth-brand .brand-logo { width: 40px; height: 40px; border-radius: 12px; font-size: 20px; }
.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;
}
.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); background: var(--primary-soft); }
.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); }
.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; }

/* 工具类 */
.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: 72px; }

/* 滚动条 */
* { 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; }

/* --------------------------- 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(135deg, var(--primary), #7b9dff); font-size: 24px;
  box-shadow: 0 10px 26px -8px rgba(79, 124, 255, .8);
  display: grid; place-items: center; transition: transform .18s, box-shadow .18s;
}
.ai-fab:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 14px 30px -8px rgba(79, 124, 255, .9); }
.ai-fab:active { transform: scale(.95); }

.ai-panel {
  position: fixed; right: 22px; bottom: 88px; z-index: 70;
  width: 372px; 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); display: flex; flex-direction: column; overflow: hidden;
  animation: aiPop .22s ease;
}
@keyframes aiPop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

.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(135deg, var(--primary), #7b9dff);
  display: grid; place-items: center; font-size: 17px;
}
.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; font-size: 14px;
  color: var(--muted); padding: 5px; border-radius: 7px; line-height: 1;
}
.ai-icon-btn:hover { background: var(--card); color: var(--text); }

.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: var(--primary); 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-meta { font-size: 10.5px; color: var(--muted); margin-top: 7px; display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }

.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(0, 0, 0, .6); 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: var(--primary); color: #fff; font-size: 15px; cursor: pointer;
  transition: background .15s, transform .1s;
}
.ai-send:hover { background: var(--primary-deep); }
.ai-send:active { transform: scale(.94); }
.ai-send:disabled { opacity: .5; cursor: not-allowed; }

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

@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) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .content { padding: 14px 14px 92px; }
  .topbar { padding: 12px 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: 13px; border-radius: 13px; }
  .draft-grid { grid-template-columns: 1fr 1fr; }
  .draft-grid .field:first-child { grid-column: span 2; }
  .txn-day-head { top: 53px; }
  .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);
    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: 1px;
    font-size: 10.5px; color: var(--muted); padding: 5px 0;
  }
  .mobile-nav a .ico { font-size: 18px; line-height: 1.2; }
  .mobile-nav a.active { color: var(--primary); font-weight: 600; }
  .mobile-nav .fab {
    flex: 0 0 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff;
    display: grid; place-items: center; font-size: 24px; margin: 0 6px;
    box-shadow: 0 8px 20px -6px rgba(79, 124, 255, .75); transform: translateY(-12px);
  }
  .mobile-nav .fab .ico { font-size: 26px; }

  /* AI 助手：避开底部导航 */
  .ai-fab { right: 14px; bottom: 84px; width: 48px; height: 48px; font-size: 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 { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

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

.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, transparent); transition: transform .15s ease, border-color .15s ease;
}
.about-feature:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--primary) 40%, transparent); }
.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 color-mix(in srgb, var(--primary) 18%, transparent);
}
