/* ============ 设计变量（方便以后做主题 / 暗色模式） ============ */
:root {
  --bg: #f1f4f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6eaf1;
  --text: #1e293b;
  --text-soft: #64748b;
  --text-faint: #94a3b8;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-soft: #eef2ff;
  --income: #10b981;
  --income-soft: #ecfdf5;
  --expense: #ef4444;
  --expense-soft: #fef2f2;
  --amber: #f59e0b;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 232px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--text-faint); }

/* ============ 登录页 ============ */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0%, transparent 50%),
    radial-gradient(1000px 500px at 110% 110%, #dbeafe 0%, transparent 50%),
    var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
}
.login-logo { font-size: 40px; text-align: center; }
.login-card h1 { font-size: 21px; text-align: center; margin: 10px 0 4px; }
.login-card .sub { text-align: center; color: var(--text-faint); margin-bottom: 26px; font-size: 13px; }
.login-card label { display: block; font-size: 13px; color: var(--text-soft); margin: 14px 0 6px; }
.login-card .btn-primary { width: 100%; margin-top: 24px; padding: 12px; font-size: 15px; }
.login-err { background: var(--expense-soft); color: var(--expense); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-top: 16px; display: none; }
.login-tip { text-align: center; color: var(--text-faint); font-size: 12px; margin-top: 18px; }

/* ============ 输入控件 ============ */
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 60px; }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; }

/* ============ 按钮 ============ */
.btn { padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 14px; transition: all .15s; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--surface-2); border-color: #d4dae5; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--expense); border-color: #f3c9c9; background: var(--expense-soft); }
.btn-danger:hover { background: #fde5e5; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); }

/* ============ 应用骨架 ============ */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: #111827;
  color: #cbd5e1;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; }
.brand .logo { font-size: 24px; }
.brand .name { font-size: 15px; font-weight: 600; color: #fff; line-height: 1.2; }
.brand .name small { display: block; font-size: 11px; color: #64748b; font-weight: 400; }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; color: #94a3b8; font-size: 14px;
  transition: all .14s;
}
.nav a .ico { width: 18px; text-align: center; font-size: 16px; }
.nav a:hover { background: #1f2937; color: #e2e8f0; }
.nav a.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(99,102,241,.4); }
.nav .sep { height: 1px; background: #1f2937; margin: 10px 8px; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; font-size: 11px; color: #475569; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 18px; font-weight: 650; }
.topbar .crumb { color: var(--text-faint); font-size: 13px; margin-top: 1px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 14px; font-weight: 600; }
.user-chip .uinfo { font-size: 13px; line-height: 1.25; }
.user-chip .uinfo b { font-weight: 600; }
.user-chip .uinfo small { color: var(--text-faint); }
.role-badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-dark); margin-left: 6px; }

.content { padding: 26px 28px 40px; max-width: 1240px; width: 100%; }

/* ============ 卡片 / 区块 ============ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title h3 { font-size: 15px; font-weight: 600; }
.section-title .hint { font-size: 12px; color: var(--text-faint); }

/* KPI 卡片 */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi .label { color: var(--text-soft); font-size: 13px; display: flex; align-items: center; gap: 7px; }
.kpi .value { font-size: 27px; font-weight: 700; margin-top: 8px; letter-spacing: -.5px; }
.kpi .value .cny { font-size: 16px; font-weight: 600; color: var(--text-faint); margin-right: 2px; }
.kpi .foot { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.kpi.primary { background: linear-gradient(135deg, #6366f1, #4f46e5); border: none; color: #fff; }
.kpi.primary .label, .kpi.primary .foot { color: rgba(255,255,255,.82); }
.kpi.primary .value .cny { color: rgba(255,255,255,.7); }
.kpi .spark { position: absolute; right: 14px; top: 14px; font-size: 20px; opacity: .25; }
.val-income { color: var(--income); }
.val-expense { color: var(--expense); }

/* 图表布局 */
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; margin-bottom: 22px; }
.grid-2b { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 22px; }
.chart { width: 100%; height: auto; }
.c-grid { stroke: #eef1f6; stroke-width: 1; }
.c-line { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { fill: #fff; stroke: var(--primary); stroke-width: 2; }
.c-dot:hover { r: 5; }
.c-ylabel, .c-xlabel { fill: var(--text-faint); font-size: 11px; }
.c-empty { fill: var(--text-faint); font-size: 14px; }
.c-bar-income { fill: var(--income); }
.c-bar-expense { fill: var(--expense); }
.c-arc { stroke: #fff; stroke-width: 2; transition: opacity .15s; }
.c-arc:hover { opacity: .82; }
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut { width: 200px; flex-shrink: 0; }
.donut-total { font-size: 20px; font-weight: 700; fill: var(--text); }
.donut-total-label { font-size: 11px; fill: var(--text-faint); }
.legend { list-style: none; flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 7px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend .lg-name { flex: 1; color: var(--text-soft); }
.legend .lg-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.legend .lg-pct { color: var(--text-faint); width: 48px; text-align: right; font-variant-numeric: tabular-nums; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; padding: 11px 14px; color: var(--text-soft); font-weight: 600; font-size: 12.5px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
table.data td { padding: 11px 14px; border-bottom: 1px solid #f1f4f9; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.tag.income { background: var(--income-soft); color: #047857; }
.tag.expense { background: var(--expense-soft); color: #b91c1c; }
.tag.cat { background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border); }
.muted { color: var(--text-faint); }
.amt-income { color: var(--income); font-weight: 600; }
.amt-expense { color: var(--expense); font-weight: 600; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-deleted td { opacity: .5; text-decoration: line-through; }

/* 工具栏 / 过滤 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1; min-width: 160px; }
.toolbar input, .toolbar select { width: auto; min-width: 120px; }
.toolbar .search { min-width: 200px; }
.spacer { flex: 1; }

/* 近期活动 */
.activity { list-style: none; display: flex; flex-direction: column; }
.activity li { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid #f1f4f9; align-items: flex-start; }
.activity li:last-child { border-bottom: none; }
.activity .dot-act { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; background: var(--primary); }
.activity .dot-act.create { background: var(--income); }
.activity .dot-act.update { background: var(--amber); }
.activity .dot-act.delete { background: var(--expense); }
.activity .dot-act.login, .activity .dot-act.logout { background: var(--text-faint); }
.activity .a-main { flex: 1; font-size: 13px; }
.activity .a-meta { font-size: 12px; color: var(--text-faint); margin-top: 1px; }

/* 空状态 */
.empty { text-align: center; padding: 50px 20px; color: var(--text-faint); }
.empty .em-ico { font-size: 38px; opacity: .5; }
.empty p { margin-top: 10px; }

/* ============ 模态框 ============ */
.modal-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 100; padding: 20px; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.modal .close-x { background: none; border: none; font-size: 20px; color: var(--text-faint); line-height: 1; }
.modal .err-line { color: var(--expense); font-size: 13px; margin-top: 12px; min-height: 18px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { padding: 9px 18px; border: none; background: var(--surface); color: var(--text-soft); font-size: 14px; }
.seg button.on-income { background: var(--income); color: #fff; }
.seg button.on-expense { background: var(--expense); color: #fff; }

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 11px 20px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: all .25s; z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #b91c1c; }
.toast.ok { background: #047857; }

/* 详情差异 */
.diff-list { list-style: none; font-size: 13px; }
.diff-list li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.diff-list .f { color: var(--text-soft); }
.diff-from { color: var(--expense); text-decoration: line-through; }
.diff-to { color: var(--income); font-weight: 600; }
pre.json { background: var(--surface-2); border-radius: 8px; padding: 12px; font-size: 12px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* 提示条 */
.banner { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 18px; }
.banner.warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.banner .btn { margin-left: auto; }

/* 响应式 */
@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; z-index: 60; transition: left .2s; width: 240px; }
  .sidebar.open { left: 0; }
  .grid-2, .grid-2b { grid-template-columns: 1fr; }
  .menu-btn { display: inline-flex !important; }
}
.menu-btn { display: none; }
