:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --ink-2: #5b6472;
  --ink-3: #8a93a3;
  --line: #e5e8ee;
  --brand: #3b6ef5;
  --brand-soft: #eaf0fe;
  --green: #129a5b;
  --green-soft: #e3f6ec;
  --red: #d64545;
  --red-soft: #fdeaea;
  --amber: #b97e0c;
  --amber-soft: #fbf1dc;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
a { color: var(--brand); text-decoration: none; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 20px;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--ink-2); font-size: 14px;
}
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.spacer { flex: 1; }

.container { max-width: 1080px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---- cards & layout ---- */
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; color: var(--ink-2); font-weight: 600; }
.stat .label { font-size: 13px; color: var(--ink-3); }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* ---- badges / pills ---- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; line-height: 1.6; white-space: nowrap;
}
.badge.gray  { background: var(--bg); color: var(--ink-2); }
.badge.blue  { background: var(--brand-soft); color: var(--brand); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red   { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.muted { color: var(--ink-3); }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---- buttons & forms ---- */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 8px; padding: 7px 14px; font-size: 14px; cursor: pointer;
}
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { opacity: .9; color: #fff; }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
.btn.ghost { border: none; background: transparent; }
.btn.sm { padding: 3px 10px; font-size: 13px; }

input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  font: inherit; color: var(--ink); background: #fff; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label { font-size: 13px; color: var(--ink-2); display: block; margin-bottom: 4px; }
.field { display: flex; flex-direction: column; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }

/* ---- tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* ---- transactions ---- */
.tx-row { display: flex; align-items: center; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.tx-row:last-child { border-bottom: none; }
.tx-icon {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.tx-main { flex: 1; min-width: 0; }
.tx-main .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-main .t2 { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.tx-del { border: none; background: none; color: var(--ink-3); cursor: pointer; padding: 4px; }
.tx-del:hover { color: var(--red); }

/* ---- month switcher ---- */
.ym-switch { display: flex; align-items: center; gap: 10px; justify-content: center; }
.ym-switch .ym { font-weight: 700; font-size: 16px; min-width: 110px; text-align: center; }

/* ---- progress bars ---- */
.bar { background: var(--bg); border-radius: 6px; height: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.cat-row { display: grid; grid-template-columns: 90px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; margin: 7px 0; }
.cat-row .bar > i { background: linear-gradient(90deg, var(--brand), #7ea1f8); }

/* ---- card (credit) panel ---- */
.cardpanel { border-top: 3px solid var(--brand); }
.cardpanel .bankline { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.usage { margin: 10px 0 4px; }

/* ---- todos ---- */
.todo-row { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.todo-row:last-child { border-bottom: none; }
.todo-row.done .title { text-decoration: line-through; color: var(--ink-3); }
.todo-row .title { flex: 1; }
.pri { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.pri.p2 { background: var(--red); } .pri.p1 { background: var(--amber); } .pri.p0 { background: var(--line); }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { border: none; background: none; padding: 5px 12px; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-size: 14px; }
.tabs button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ---- dialog ---- */
.dlg { border: none; border-radius: 14px; box-shadow: 0 10px 40px rgba(16,24,40,.18); padding: 0; width: min(430px, 92vw); }
.dlg::backdrop { background: rgba(20,26,36,.4); }
.dlg .dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 0; font-weight: 700; font-size: 16px; }
.dlg .dlg-head button { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--ink-3); }
.dlg form { padding: 12px 18px 18px; display: grid; gap: 10px; }
.dlg .actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---- misc ---- */
.section { margin-top: 26px; }
.section > h2 { font-size: 16px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.section > h2 .btn { margin-left: auto; }
.empty { text-align: center; color: var(--ink-3); padding: 30px 10px; font-size: 14px; }
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #1c2430; color: #fff; padding: 9px 18px; border-radius: 999px;
  font-size: 14px; opacity: 0; transition: all .25s; z-index: 99; pointer-events: none;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }
.hint { font-size: 12px; color: var(--ink-3); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
