:root {
  --bg: #0f1220;
  --bg-soft: #171a2e;
  --panel: #1b1f38;
  --panel-2: #232848;
  --border: #2c3358;
  --text: #e7eaf6;
  --text-dim: #9aa2c7;
  --text-faint: #6b7299;
  --accent: #6c8cff;
  --accent-2: #8a6cff;
  --green: #3fd08a;
  --red: #ff6b81;
  --amber: #ffc861;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(138, 108, 255, 0.15), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(108, 140, 255, 0.15), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent); }

/* ---------------- 登录页 ---------------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 36px 32px 30px;
}
.login-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  display: grid; place-items: center;
  font-size: 28px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(108, 140, 255, 0.4);
}
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 26px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 7px; }
input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 140, 255, 0.18);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: transform .05s, background .15s, border-color .15s;
  user-select: none;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; color: #fff; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-danger { color: var(--red); border-color: rgba(255,107,129,.4); background: rgba(255,107,129,.08); }
.btn-ghost { background: transparent; }

.error-msg {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
  margin-top: 4px;
}

/* ---------------- 主布局 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 26px;
  background: rgba(15, 18, 32, 0.75);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center; font-size: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(108, 140, 255, 0.4);
}
.brand h1 { font-size: 17px; margin: 0; letter-spacing: .3px; }
.brand .tag { font-size: 11.5px; color: var(--text-faint); }
.spacer { flex: 1; }
.save-status { font-size: 12.5px; color: var(--text-faint); margin-right: 6px; }
.save-status.saving { color: var(--amber); }
.save-status.saved { color: var(--green); }
.save-status.error { color: var(--red); }

.tabs { display: flex; gap: 6px; padding: 16px 26px 0; }
.tab {
  padding: 9px 18px; border-radius: 10px 10px 0 0;
  cursor: pointer; color: var(--text-dim); font-size: 14px;
  border: 1px solid transparent; border-bottom: none;
}
.tab.active { background: var(--panel); color: var(--text); border-color: var(--border); }

.container { max-width: 1240px; margin: 0 auto; padding: 22px 26px 80px; }

/* ---------------- KPI 卡片 ---------------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.kpi {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi .label { font-size: 12.5px; color: var(--text-dim); margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 23px; font-weight: 700; letter-spacing: .3px; font-variant-numeric: tabular-nums; }
.kpi .value.small { font-size: 20px; }
.kpi .unit { font-size: 12px; color: var(--text-faint); font-weight: 400; margin-left: 3px; }
.kpi.negative .value { color: var(--red); }
.kpi.positive .value { color: var(--green); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------------- 面板 / 表格 ---------------- */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-head .group-name { background: transparent; border: 1px solid transparent; color: var(--text); font-size: 15px; font-weight: 600; padding: 4px 8px; border-radius: 8px; width: auto; min-width: 120px; }
.panel-head .group-name:hover { border-color: var(--border); }
.subtotal-chip {
  font-size: 12px; color: var(--text-dim);
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px;
}
.subtotal-chip b { color: var(--text); font-variant-numeric: tabular-nums; }

.table-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 860px; }
table.grid th, table.grid td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid th { color: var(--text-dim); font-weight: 500; font-size: 12.5px; background: rgba(255,255,255,.02); position: sticky; }
table.grid th.left, table.grid td.left { text-align: left; }
table.grid td.num { font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover { background: rgba(108, 140, 255, 0.06); }
table.grid tfoot td { font-weight: 700; color: var(--text); background: rgba(255,255,255,.03); }
.debt-val { color: var(--amber); font-weight: 600; }

td .cell-input {
  width: 108px; text-align: right; padding: 7px 9px; font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
td .name-input { width: 160px; text-align: left; }
td .day-input { width: 92px; text-align: left; }

.inst-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  background: rgba(138, 108, 255, 0.14);
  border: 1px solid rgba(138, 108, 255, 0.35);
  color: #c7bcff; cursor: pointer; font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  transition: filter .12s;
}
.inst-badge:hover { filter: brightness(1.15); }
.inst-badge.zero { background: var(--bg-soft); border-color: var(--border); color: var(--text-faint); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-dim);
  cursor: pointer; font-size: 15px;
}
.icon-btn:hover { color: var(--red); border-color: rgba(255,107,129,.4); }
.icon-btn.up:hover, .icon-btn.down:hover { color: var(--accent); border-color: var(--accent); }

.panel-foot { padding: 12px 18px; display: flex; gap: 10px; flex-wrap: wrap; border-top: 1px solid var(--border); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }

/* 储值 */
.savings-grid td .cell-input { width: 140px; }
.included-toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.included-toggle input { width: auto; }

/* ---------------- 弹窗 ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(6, 8, 18, 0.66);
  backdrop-filter: blur(4px);
  display: none; place-items: center; z-index: 60; padding: 20px;
}
.modal-mask.open { display: grid; }
.modal {
  width: 100%; max-width: 960px; max-height: 88vh; overflow: auto;
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .close { margin-left: auto; }
.modal-body { padding: 18px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; }

.hint { color: var(--text-faint); font-size: 12.5px; margin: 0 0 14px; line-height: 1.6; }
.hint code { background: var(--bg-soft); padding: 1px 6px; border-radius: 5px; color: var(--accent); }

.derived { color: var(--green); font-variant-numeric: tabular-nums; }

/* 趋势 */
.chart-wrap { padding: 18px; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; margin: 8px 18px 0; font-size: 12.5px; color: var(--text-dim); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.empty { text-align: center; color: var(--text-faint); padding: 50px 20px; font-size: 14px; }

/* Toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .2s, transform .2s; z-index: 80; font-size: 13.5px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: rgba(63,208,138,.5); }
.toast.err { border-color: rgba(255,107,129,.5); }

@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr; }
  .container { padding: 16px 12px 70px; }
  .topbar { padding: 12px 14px; }
}
