:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --in: #dc2626;      /* 中国习惯：涨/收 用红 */
  --out: #16a34a;     /* 跌/支 用绿 */
  --danger: #ef4444;
  --shadow: 0 6px 24px rgba(15, 23, 42, .08);
  --radius: 14px;
}

/* ---------- 深色模式 ---------- */
[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --ink: #e5e7eb;
  --muted: #94a3b8;
  --line: #1f2937;
  --primary: #3b82f6;
  --primary-d: #2563eb;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
}
[data-theme="dark"] .gate { background: linear-gradient(160deg, #020617, #0f172a); }
[data-theme="dark"] .toast { background: #1f2937; color: #e5e7eb; }
[data-theme="dark"] .chip .x { background: #1f2937; }
[data-theme="dark"] .help code { background: #1f2937; }
[data-theme="dark"] .modal { background: rgba(0, 0, 0, .6); }
[data-theme="dark"] .card.hl { background: #0b2545; }
[data-theme="dark"] .inv-bar { background: #1f2937; }

/* 余额正负色（绿正红负） */
.pos { color: #16a34a; }
.neg { color: #dc2626; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.6; }
.center { text-align: center; }
.in { color: var(--in); }
.out { color: var(--out); }
b { font-weight: 700; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: .15s;
}
.btn:hover { border-color: #cbd5e1; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.ghost { background: transparent; }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- 登录遮罩 ---------- */
.gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #0f172a, #1e3a8a);
  padding: 20px; z-index: 50;
}
.gate-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border-radius: 18px; padding: 28px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; font-size: 22px; margin: 0 0 18px; }
.gate-step h2 { font-size: 16px; margin: 0 0 8px; }
.gate-step label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.gate-step input {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; color: var(--ink);
}
.gate-step input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.gate-step .btn { width: 100%; margin-top: 16px; }
.gate-step .row .btn { flex: 1; margin-top: 16px; }
.help { margin-top: 16px; font-size: 13px; color: var(--muted); }
.help summary { cursor: pointer; }
.help ol { padding-left: 18px; line-height: 1.8; }
.help code { background: #f1f5f9; padding: 1px 5px; border-radius: 5px; }
.msg { font-size: 13px; margin: 10px 0 0; min-height: 18px; }
.msg.ok { color: var(--out); }
.msg.err { color: var(--danger); }

/* ---------- 顶栏 ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: #f1f5f9; color: var(--muted);
}
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.err { background: #fee2e2; color: #b91c1c; }

/* ---------- 标签页 ---------- */
.tabs {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 10px 14px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 57px; z-index: 15;
}
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 999px; font-size: 14px;
  white-space: nowrap; cursor: pointer;
  -webkit-user-select: none; user-select: none; touch-action: pan-y;
  transition: transform .1s, opacity .1s;
}
.tab.active { background: var(--primary); color: #fff; }
.tab.dragging {
  opacity: .75;
  transform: scale(1.06);
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 20;
}

/* ---------- 内容 ---------- */
.content { flex: 1; padding: 18px; max-width: 960px; width: 100%; margin: 0 auto; }
.view-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.view-head h2 { margin: 0; font-size: 18px; }
.sub { color: var(--muted); font-size: 13px; }

/* ---------- 汇总卡片 ---------- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.cards.two { grid-template-columns: repeat(2, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.card-value { font-size: 24px; font-weight: 800; }
.card.total .card-value { color: var(--primary); }
.card.in .card-value { color: #16a34a; }   /* 收入：绿 */
.card.out .card-value { color: #dc2626; }  /* 支出：红 */
.mini { display: flex; gap: 14px; font-size: 14px; }

/* ---- 投资：保本模型汇总 ---- */
.inv-cards { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.card.profit .card-value { color: #16a34a; }
.card.risk .card-value { color: #dc2626; }

/* 投资页面内子标签 */
.inv-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.inv-tab {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); padding: 8px 18px; border-radius: 999px; font-size: 14px; cursor: pointer;
}
.inv-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.inv-panel.hidden { display: none; }

/* 项目卡片：回本进度 + 时间进度 双进度条 */
.inv-bars { margin: 8px 0 2px; }
.inv-bar-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.inv-bar { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.inv-bar > i { display: block; height: 100%; border-radius: 999px; }
.inv-bar.ret > i { background: #16a34a; }
.inv-bar.time > i { background: var(--primary); }
.mini .in { color: #16a34a; }   /* 收入：绿 */
.mini .out { color: #dc2626; }  /* 支出：红 */
.mini.net { margin-top: 8px; color: var(--muted); font-size: 13px; }

/* ---------- 流水列表 ---------- */
.txn-list { display: flex; flex-direction: column; gap: 10px; }
.txn {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
  cursor: pointer;
}
.txn .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.txn .meta { flex: 1; min-width: 0; }
.txn .cat { font-weight: 600; font-size: 15px; }
.txn .note { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn .amt { font-weight: 800; font-size: 16px; white-space: nowrap; }
.txn .amt.in { color: #16a34a; }    /* 收入：绿 */
.txn .amt.out { color: #dc2626; }   /* 支出：红 */
.txn .date { color: var(--muted); font-size: 11px; width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* 按日期分组的分隔条 */
.date-sep {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 16px 2px 6px; font-size: 13px; font-weight: 700; color: var(--ink);
}
.date-sep:first-child { margin-top: 0; }
.date-sep .day-sum { font-weight: 500; font-size: 12px; color: var(--muted); }
.date-sep .day-sum .sdate { color: var(--ink); font-weight: 700; margin-right: 4px; }
.date-sep .day-sum .sin { color: #16a34a; }
.date-sep .day-sum .sout { color: #dc2626; }

/* ---------- 投资项目 ---------- */
.inv-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; box-shadow: var(--shadow);
  cursor: pointer; margin-bottom: 12px;
}
.inv-card:last-child { margin-bottom: 0; }
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; gap: 10px; }
.inv-top-left { flex: 1; min-width: 0; }
.inv-name { font-weight: 600; font-size: 15px; }
.inv-actions { display: flex; align-items: center; gap: 6px; }
.inv-actions .btn-text {
  font-size: 12px; padding: 3px 9px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer;
}
.inv-actions .btn-text:hover { border-color: var(--primary); color: var(--primary); }
.inv-status { font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.inv-status.active { color: #15803d; background: #dcfce7; }
.inv-status.done { color: var(--muted); background: #f1f5f9; }
.inv-line { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.inv-line b { color: var(--ink); font-weight: 700; }
.inv-line .profit.in { color: #16a34a; }
.inv-line .profit.out { color: #dc2626; }
.inv-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.inv-bar { height: 6px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.inv-bar > i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

.inv-flow-section { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.inv-flow-section:first-of-type { margin-top: 0; border-top: none; padding-top: 0; }
.inv-flow-head { font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 10px; }
.inv-flow-add { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.inv-flow-add input[type=number] { width: 92px; }
.inv-flow-add input[type=date] { width: 132px; }
.inv-flow-add input[type=text] { flex: 1; min-width: 60px; }
.inv-flow-add select { padding: 8px 9px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: var(--surface); color: var(--ink); }
.flow-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; padding: 8px 0; border-top: 1px solid var(--line);
}
.flow-row .flow-amt { font-weight: 700; min-width: 84px; }
.flow-row .flow-amt.in { color: #16a34a; }
.flow-row .flow-amt.out { color: #dc2626; }
.flow-row .flow-date { color: var(--muted); min-width: 84px; }
.flow-row .flow-account { color: var(--muted); min-width: 60px; }
.flow-row .flow-note { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow-row .flow-del {
  cursor: pointer; border: none; background: #f1f5f9; color: var(--muted);
  width: 22px; height: 22px; border-radius: 50%; font-size: 13px; flex: none;
}
.flow-row .flow-del:hover { background: #fee2e2; color: var(--danger); }
.flow-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* ---------- 基金持仓 ---------- */
.fund-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; box-shadow: var(--shadow);
  cursor: pointer; margin-bottom: 12px;
}
.fund-card:last-child { margin-bottom: 0; }
.fund-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.fund-top-left { flex: 1; min-width: 0; }
.fund-name { font-weight: 600; font-size: 15px; }
.fund-code { font-size: 12px; color: var(--muted); }
.fund-amt { text-align: right; }
.fund-amt .val { font-weight: 800; font-size: 16px; }
.fund-amt .sub { font-size: 12px; color: var(--muted); }
.fund-line { font-size: 13px; color: var(--muted); display: grid; grid-template-columns: 88px 1fr; gap: 8px; align-items: baseline; }
.fund-line span { text-align: left; }
.fund-line b { color: var(--ink); font-weight: 700; text-align: right; }
.fund-line .profit.in { color: #16a34a; }
.fund-line .profit.out { color: #dc2626; }
.fund-nav-date { font-size: 11px; color: var(--muted); margin-top: 6px; }
.fund-tx-btn {
  margin-top: 10px; width: 100%; padding: 7px; border: 1px solid var(--line);
  background: var(--surface); color: var(--primary); border-radius: 9px;
  font-size: 13px; cursor: pointer;
}
.fund-tx-btn:hover { background: var(--bg); }
.fund-chart-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 12px 4px; margin: 12px 0; box-shadow: var(--shadow);
}
.fund-chart-title { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.fund-tx-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.fund-tx-form input, .fund-tx-form select { flex: 1 1 110px; }
.fund-tx-form .btn { flex: 0 0 auto; }
/* 交易记录列表 */
.fund-tx-list .flow-row { flex-wrap: wrap; align-items: center; }
.fund-tx-list .tx-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.fund-tx-list .tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.fund-tx-list .tag-buy { color: #15803d; background: #dcfce7; }
.fund-tx-list .tag-sell { color: #b91c1c; background: #fee2e2; }
.fund-tx-list .tx-amt { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.fund-tx-list .tx-amt .x { cursor: pointer; border: none; background: #f1f5f9; color: var(--muted); width: 22px; height: 22px; border-radius: 50%; font-size: 13px; flex: none; }
.fund-tx-list .tx-amt .x:hover { background: #fee2e2; color: var(--danger); }
.fund-tx-list .tx-sub { flex-basis: 100%; color: var(--muted); font-size: 12px; }

/* ---------- 快速记账 ---------- */
.quick-add { display: flex; gap: 8px; margin-bottom: 8px; }
.quick-add input {
  flex: 1; padding: 12px 14px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 12px; color: var(--ink);
}
.quick-add input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.quick-add .btn { white-space: nowrap; }

/* ---------- 工具栏（导出/导入） ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
.toolbar .btn { font-size: 13px; padding: 8px 14px; }

/* ---------- 流水筛选 ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type=text] {
  flex: 1; min-width: 140px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 10px; font-size: 14px; color: var(--ink);
  background: var(--surface);
}
.filters select {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; color: var(--ink); background: var(--surface);
}

/* ---------- 分类管理 ---------- */
.cat-controls { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.cat-controls select, .cat-controls input[type=text] {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px;
}
.cat-controls input[type=text] { flex: 1; min-width: 140px; }
.cat-controls input[type=color] { width: 42px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; }
.cat-list { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 8px 6px 14px; box-shadow: var(--shadow);
}
.chip .swatch { width: 12px; height: 12px; border-radius: 50%; }
.chip .x { cursor: pointer; border: none; background: #f1f5f9; color: var(--muted); width: 22px; height: 22px; border-radius: 50%; font-size: 13px; }
.chip .x:hover { background: #fee2e2; color: var(--danger); }

/* ---------- 子标签（分类 / 账户） ---------- */
.subtabs { display: flex; gap: 8px; margin-bottom: 16px; }
.subtab {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); padding: 8px 18px; border-radius: 999px; font-size: 14px; cursor: pointer;
}
.subtab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.subpanel { margin-top: 4px; }

/* ---------- 账户区块（汇总页内） ---------- */
.accounts-block { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---------- 账户分组展示 ---------- */
.acc-group { margin-bottom: 16px; }
.acc-group-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.acc-group-name {
  font-size: 13px; font-weight: 700; color: var(--ink);
  padding-left: 8px;
  border-left: 3px solid var(--primary);
}
.grp-sum { font-size: 13px; font-weight: 700; }
.acc-net { font-size: 12px; font-weight: 700; }
.acc-total-wrap { margin-top: 14px; }
.acc-total {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 16px; box-shadow: var(--shadow);
  font-size: 14px; font-weight: 700;
}
.acc-total b { font-size: 18px; }

/* ---------- 图表 ---------- */
.chart-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.chart-box h3 { margin: 0 0 12px; font-size: 15px; }
.chart-box canvas { max-height: 320px; }

/* ---------- 图表时间范围切换 ---------- */
.range-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.range-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  padding: 6px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.range-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.range-custom { display: flex; gap: 6px; align-items: center; }
.range-custom input[type=date] {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
  color: var(--ink); background: var(--surface);
}

/* ---------- 悬浮按钮 ---------- */
.fab {
  position: fixed; right: 18px; bottom: 22px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none;
  font-size: 28px; line-height: 1; box-shadow: 0 8px 24px rgba(37,99,235,.45);
  cursor: pointer; z-index: 30;
}
.fab:hover { background: var(--primary-d); }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(15,23,42,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  width: 100%; max-width: 480px; background: var(--surface);
  border-radius: 18px 18px 0 0; padding: 22px;
  animation: up .2s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-card h3 { margin: 0 0 16px; }
.modal-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.modal-card input, .modal-card select {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; font-size: 15px; color: var(--ink);
}
.modal-card .row .btn { flex: 1; margin-top: 18px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 60; box-shadow: var(--shadow);
}

/* 投资流水行 */
.flow-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
  cursor: pointer;
}
.flow-row .flow-kind { font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.flow-row .flow-kind.in { color: #15803d; background: #dcfce7; }
.flow-row .flow-kind.out { color: #b91c1c; background: #fee2e2; }
.flow-row .flow-meta { flex: 1; min-width: 0; }
.flow-row .flow-name { font-weight: 600; font-size: 15px; }
.flow-row .flow-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow-row .flow-amt { font-weight: 800; font-size: 16px; white-space: nowrap; }
.flow-row .flow-amt.in { color: #16a34a; }
.flow-row .flow-amt.out { color: #dc2626; }
.flow-row .flow-date { color: var(--muted); font-size: 11px; width: 84px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 桌面适配 ---------- */
@media (min-width: 720px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 18px; }
  .content { padding: 26px; }
  .cards { gap: 16px; }
}
