:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2733;
  --muted: #7a8699;
  --line: #e5eaf1;
  --primary: #2f6fed;
  --primary-dk: #245bd0;
  --red: #e54d42;     /* 涨/收入 */
  --green: #2ba471;   /* 跌/支出 */
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
  min-height: 100vh;
}
button { font-family: inherit; }
a { color: var(--primary); }

/* ---- 登录 ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: linear-gradient(135deg, #eaf1ff 0%, #f4f6f9 60%); }
.login-card { background: var(--card); border-radius: 16px; box-shadow: 0 8px 30px rgba(31,39,51,.08);
  padding: 36px 32px; width: 100%; max-width: 380px; }
.login-logo { font-size: 40px; text-align: center; }
.login-card h1 { font-size: 20px; text-align: center; margin: 8px 0 4px; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: 13px; }
.login-foot { margin-top: 18px; text-align: center; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.login-hint { color: #b3bcc9; font-size: 12px; }

/* ---- 顶栏 ---- */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; height: 56px; }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav button { border: 0; background: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 14px; }
.topnav button.active { background: #eaf1ff; color: var(--primary); font-weight: 600; }
.user-box { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
#user-name { color: var(--muted); }

/* ---- 布局 ---- */
main { max-width: 1080px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 16px; margin-bottom: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.page-head h2 { font-size: 17px; }
.muted { color: var(--muted); }

/* ---- 汇总卡 ---- */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 16px; }
.sum-card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 14px 16px; }
.sum-card .label { color: var(--muted); font-size: 12px; }
.sum-card .val { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.sum-card.income .val { color: var(--red); }
.sum-card.expense .val { color: var(--green); }

/* ---- 表单 ---- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-size: 16px; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 60px; }
.form-row { display: flex; gap: 10px; }
.form-row .field { flex: 1; min-width: 0; }

/* ---- 按钮 ---- */
.btn { border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; font-size: 14px; background: #eef1f6; color: var(--text); }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dk); }
.btn.danger { color: var(--red); background: #fdeeed; }
.btn.ghost { background: none; border: 1px solid var(--line); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- 筛选条 ---- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 13px; background: #fff; color: var(--text); }
.filters input[type="date"] { width: 0; min-width: 0; flex: 0 1 135px; }
.filters input[type="text"] { flex: 1 1 120px; min-width: 0; }

/* ---- 表格 ---- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tr:hover td { background: #f8fafc; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* 统计页「账户出账统计」矩阵：月份列紧凑排列 */
table.tbl.acc-stats th, table.tbl.acc-stats td { padding: 8px; font-size: 12px; white-space: nowrap; }
table.tbl.acc-stats th { color: var(--muted); }
/* 表尾操作列与表头右对齐一致 */
table.tbl th:last-child { text-align: right; }
table.tbl td.cell-main { font-weight: 500; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; }
.tag.income { color: var(--red); background: #fdeeed; }
.tag.expense { color: var(--green); background: #e9f6f0; }
.tag.off { color: var(--muted); background: #eef1f6; }
.td-acts { white-space: nowrap; text-align: right; }
.td-acts button { margin-left: 6px; }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--muted); }

/* ---- 弹窗 ---- */
.modal-mask { position: fixed; inset: 0; background: rgba(31,39,51,.45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; padding: 20px; }
.modal h3 { margin-bottom: 16px; font-size: 16px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* ---- 报销截图 ---- */
.img-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.img-preview:empty { display: none; }
.img-thumb { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border, #e2e6ee); }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.img-del { position: absolute; top: 2px; right: 2px; width: 16px; height: 16px; line-height: 14px; text-align: center; font-style: normal; font-size: 11px; border-radius: 50%; background: rgba(31,39,51,.7); color: #fff; cursor: pointer; }
.btn-link { background: none; border: none; padding: 0; color: var(--primary, #2f6fed); cursor: pointer; font-size: inherit; }
.img-badge { font-size: 12px; margin-left: 4px; }
.lightbox { background: rgba(15,19,26,.88); cursor: zoom-out; }
.lightbox .lb-body { max-width: 92vw; max-height: 92vh; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.lightbox .lb-body img { max-width: 92vw; max-height: 86vh; object-fit: contain; border-radius: 6px; }
.lightbox .lb-bar { color: #dfe5ef; font-size: 13px; }
.lightbox .lb-hint { color: #98a2b3; margin-left: 6px; }
.lb-nav { position: fixed; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border: none; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; font-size: 26px; cursor: pointer; }
.lb-prev { left: 18px; } .lb-next { right: 18px; }
.lb-nav:hover { background: rgba(255,255,255,.28); }

/* ---- Toast ---- */
#toast-root { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #333c4d; color: #fff; padding: 9px 18px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.2); animation: fadein .18s; max-width: 86vw; }
.toast.err { background: #c0392b; }
.toast.ok { background: var(--green); }
@keyframes fadein { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; } }

/* ---- 图表 ---- */
.chart-box svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.cat-list { margin-top: 12px; }
.cat-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.cat-row:last-child { border-bottom: 0; }
.cat-row .bar-bg { flex: 1; height: 8px; background: #eef1f6; border-radius: 4px; overflow: hidden; min-width: 0; }
.cat-row .bar { height: 100%; border-radius: 4px; }
.cat-row .nm { width: 84px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-row .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.seg { display: inline-flex; background: #eef1f6; border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* ---- 移动端 ---- */
@media (max-width: 768px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .sum-card .val { font-size: 16px; }
  .topbar-inner { padding: 0 10px; gap: 8px; }
  .topnav button { padding: 7px 10px; }
  main { padding: 10px; }
  .card { padding: 12px; }
  table.tbl thead { display: none; }
  table.tbl tbody tr { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.tbl tbody tr:last-child { border-bottom: 0; }
  table.tbl td { display: flex; justify-content: space-between; border-bottom: 0; padding: 4px 8px; }
  table.tbl td::before { content: attr(data-label); color: var(--muted); font-size: 12px; }
  table.tbl td.cell-main { order: -1; }
  table.tbl td.cell-main::before { display: none; }
  table.tbl td.td-acts { border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 8px; justify-content: flex-end; }
  table.tbl td.td-acts::before { display: none; }
  .modal { max-width: none; border-radius: 0; align-self: stretch; max-height: 100dvh; height: 100dvh; }
  .modal-mask { padding: 0; }
}
