*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #1a1d2e;
  --bg3: #222438;
  --bg4: #2a2d45;
  --sidebar: #13152a;
  --text: #e8eaf6;
  --text2: #9899b0;
  --text3: #5a5c78;
  --border: rgba(255,255,255,0.06);
  --border2: rgba(255,255,255,0.12);
  --blue: #4e8ef7;
  --green: #2dd4a0;
  --red: #f7617a;
  --orange: #f7a234;
  --purple: #9b6ef7;
  --cyan: #34d1f7;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ===== 布局 ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ===== 侧边栏 ===== */
.sidebar {
  width: 200px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  border-right: 0.5px solid var(--border);
}

.sidebar-logo {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 0.5px solid var(--border);
}

.sidebar-logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #4e8ef7, #9b6ef7);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.sidebar-logo-text {
  font-size: 15px; font-weight: 600; color: var(--text);
}

.sidebar-logo-sub {
  font-size: 11px; color: var(--text3);
}

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-group-label {
  font-size: 11px; color: var(--text3);
  padding: 10px 20px 4px;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 13px;
}

.nav-item:hover { color: var(--text); background: rgba(255,255,255,0.04); }

.nav-item.active {
  color: var(--blue);
  background: rgba(78,142,247,0.08);
  border-left-color: var(--blue);
}

.nav-item-icon { font-size: 16px; width: 18px; text-align: center; }

.sidebar-user {
  padding: 14px 20px;
  border-top: 0.5px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}

.user-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text3); }

.user-logout { color: var(--text3); font-size: 14px; cursor: pointer; text-decoration: none; }
.user-logout:hover { color: var(--red); }

/* ===== 主内容 ===== */
.main-wrap { margin-left: 200px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  height: 56px;
  background: var(--bg2);
  border-bottom: 0.5px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 12px;
  position: sticky; top: 0; z-index: 50;
}

.topbar-title { font-size: 16px; font-weight: 600; flex: 1; }
.topbar-subtitle { font-size: 12px; color: var(--text3); margin-top: 1px; }

.topbar-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  cursor: pointer; border: none;
  font-family: inherit; transition: all 0.2s;
  white-space: nowrap;
}

.btn-default {
  background: var(--bg3);
  color: var(--text2);
  border: 0.5px solid var(--border2);
}
.btn-default:hover { background: var(--bg4); color: var(--text); }

.btn-primary {
  background: linear-gradient(135deg, #4e8ef7, #6c7ef7);
  color: #fff;
}
.btn-primary:hover { opacity: 0.9; }

.btn-success {
  background: linear-gradient(135deg, #2dd4a0, #34d1f7);
  color: #000;
}

.btn-danger {
  background: rgba(247,97,122,0.15);
  color: var(--red);
  border: 0.5px solid rgba(247,97,122,0.3);
}
.btn-danger:hover { background: rgba(247,97,122,0.25); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 7px; }

.page-content { flex: 1; padding: 20px 24px; }

/* ===== 统计卡片 ===== */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }

.stat-card {
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: -20px; right: -20px;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
}

.stat-card-blue { background: linear-gradient(135deg, #1a3a6e, #1e4080); border: 0.5px solid rgba(78,142,247,0.3); }
.stat-card-green { background: linear-gradient(135deg, #0d3d30, #0f4535); border: 0.5px solid rgba(45,212,160,0.3); }
.stat-card-red { background: linear-gradient(135deg, #4a1a24, #5a1f2c); border: 0.5px solid rgba(247,97,122,0.3); }
.stat-card-orange { background: linear-gradient(135deg, #4a2e0a, #5a380c); border: 0.5px solid rgba(247,162,52,0.3); }
.stat-card-purple { background: linear-gradient(135deg, #2d1a5e, #35206e); border: 0.5px solid rgba(155,110,247,0.3); }
.stat-card-cyan { background: linear-gradient(135deg, #0a3040, #0c3a4d); border: 0.5px solid rgba(52,209,247,0.3); }

.stat-label { font-size: 12px; color: rgba(255,255,255,0.6); margin-bottom: 8px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.stat-value-sm { font-size: 18px; }
.stat-sub { font-size: 11px; color: rgba(255,255,255,0.4); margin-top: 4px; }
.stat-icon { position: absolute; right: 16px; top: 16px; font-size: 24px; opacity: 0.4; }

/* ===== 快捷入口卡片 ===== */
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }

.quick-card {
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
  display: flex; align-items: center; gap: 12px;
}
.quick-card:hover { transform: translateY(-2px); opacity: 0.9; }

.quick-card-1 { background: linear-gradient(135deg, #f7617a, #f7a234); }
.quick-card-2 { background: linear-gradient(135deg, #4e8ef7, #9b6ef7); }
.quick-card-3 { background: linear-gradient(135deg, #2dd4a0, #34d1f7); }

.quick-icon { font-size: 28px; }
.quick-count { font-size: 22px; font-weight: 700; color: #fff; }
.quick-label { font-size: 12px; color: rgba(255,255,255,0.8); }

/* ===== 工具栏 ===== */
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }

.filter-input, .filter-select {
  padding: 7px 12px;
  background: var(--bg2);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px; font-family: inherit;
}

.filter-input:focus, .filter-select:focus { outline: none; border-color: var(--blue); }
.filter-input::placeholder { color: var(--text3); }

/* ===== 表格 ===== */
.table-card {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-card-header {
  display: flex; align-items: center;
  padding: 14px 18px;
  border-bottom: 0.5px solid var(--border);
}

.table-card-title { font-size: 14px; font-weight: 600; flex: 1; }

table { width: 100%; border-collapse: collapse; }

thead th {
  padding: 10px 14px;
  font-size: 11px; font-weight: 600;
  color: var(--text3);
  text-align: left;
  background: var(--bg3);
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
  letter-spacing: 0.04em;
}

tbody td {
  padding: 11px 14px;
  font-size: 13px;
  color: var(--text);
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }

.amount-expense { color: var(--red); font-weight: 600; font-variant-numeric: tabular-nums; }
.amount-income { color: var(--green); font-weight: 600; font-variant-numeric: tabular-nums; }
.text-muted { color: var(--text3); font-size: 12px; }

/* ===== 徽章 ===== */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px; font-weight: 500;
  white-space: nowrap;
}

.badge-paid { background: rgba(45,212,160,0.15); color: var(--green); border: 0.5px solid rgba(45,212,160,0.3); }
.badge-unpaid { background: rgba(247,97,122,0.15); color: var(--red); border: 0.5px solid rgba(247,97,122,0.3); }
.badge-boss { background: rgba(155,110,247,0.15); color: var(--purple); border: 0.5px solid rgba(155,110,247,0.3); }
.badge-personal { background: rgba(52,209,247,0.15); color: var(--cyan); border: 0.5px solid rgba(52,209,247,0.3); }
.badge-orange { background: rgba(247,162,52,0.15); color: var(--orange); border: 0.5px solid rgba(247,162,52,0.3); }
.badge-cat { background: var(--bg3); color: var(--text2); border: 0.5px solid var(--border2); }

/* ===== 操作按钮 ===== */
.row-actions { display: flex; gap: 5px; opacity: 0; transition: opacity 0.2s; }
tbody tr:hover .row-actions { opacity: 1; }

/* ===== 弹窗 ===== */
.modal-mask {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-mask.show { display: flex; }

.modal {
  background: var(--bg2);
  border: 0.5px solid var(--border2);
  border-radius: 16px;
  padding: 0;
  width: 420px; max-width: 92vw;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex; align-items: center;
  padding: 18px 20px 0;
  margin-bottom: 16px;
}

.modal-title { font-size: 16px; font-weight: 600; flex: 1; }

.modal-close {
  width: 28px; height: 28px;
  background: var(--bg3);
  border: none; border-radius: 50%;
  color: var(--text3); font-size: 14px;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 0 20px 20px; }

/* ===== 表单 ===== */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { margin-bottom: 14px; }
.form-group.full { grid-column: 1 / -1; }

.form-label {
  display: block; font-size: 12px;
  color: var(--text3); margin-bottom: 5px;
  font-weight: 500;
}

.form-control {
  width: 100%; padding: 9px 12px;
  background: var(--bg3);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px; font-family: inherit;
  transition: border-color 0.2s;
}
.form-control:focus { outline: none; border-color: var(--blue); background: var(--bg4); }
.form-control::placeholder { color: var(--text3); }

.type-switch {
  display: flex;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 14px;
}

.type-btn {
  flex: 1; padding: 8px;
  border: none; border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text2);
  font-size: 13px; font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: all 0.2s;
}

.type-btn.active-expense { background: linear-gradient(135deg, #f7617a, #f7a234); color: #fff; }
.type-btn.active-income { background: linear-gradient(135deg, #2dd4a0, #34d1f7); color: #000; }

.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 20px;
  border-top: 0.5px solid var(--border);
}

/* ===== 登录页 ===== */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  position: relative; overflow: hidden;
}

.auth-page::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(78,142,247,0.15) 0%, transparent 70%);
  top: -100px; left: -100px;
}

.auth-page::after {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(155,110,247,0.12) 0%, transparent 70%);
  bottom: -100px; right: -100px;
}

.auth-box {
  position: relative; z-index: 1;
  background: var(--bg2);
  border: 0.5px solid var(--border2);
  border-radius: 20px;
  padding: 36px 32px;
  width: 380px; max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.auth-logo {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, #4e8ef7, #9b6ef7);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  margin: 0 auto 16px;
}

.auth-title { font-size: 22px; font-weight: 700; text-align: center; color: var(--text); margin-bottom: 4px; }
.auth-sub { font-size: 13px; color: var(--text3); text-align: center; margin-bottom: 24px; }

.auth-tabs {
  display: flex;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 3px; margin-bottom: 20px;
}

.auth-tab {
  flex: 1; padding: 8px;
  border: none; border-radius: var(--radius-xs);
  background: transparent; color: var(--text2);
  font-size: 13px; font-weight: 500;
  cursor: pointer; font-family: inherit; transition: all 0.2s;
}

.auth-tab.active {
  background: linear-gradient(135deg, #4e8ef7, #6c7ef7);
  color: #fff;
}

.btn-auth {
  width: 100%; padding: 12px;
  background: linear-gradient(135deg, #4e8ef7, #9b6ef7);
  color: #fff; border: none;
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  margin-top: 4px; transition: opacity 0.2s;
}
.btn-auth:hover { opacity: 0.9; }

.err-msg { color: var(--red); font-size: 12px; min-height: 18px; margin-bottom: 8px; }

/* ===== 统计页 ===== */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.chart-full { grid-column: 1 / -1; }

.chart-card {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.chart-card-title { font-size: 13px; font-weight: 600; color: var(--text2); margin-bottom: 14px; letter-spacing: 0.03em; }

.chart-row { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }

.cat-legend { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 8px; }

.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legend-name { flex: 1; color: var(--text2); }
.legend-pct { color: var(--text3); }
.legend-amt { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

.unpaid-alert {
  background: linear-gradient(135deg, rgba(247,162,52,0.1), rgba(247,97,122,0.1));
  border: 0.5px solid rgba(247,162,52,0.3);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 20px;
}

.unpaid-icon { font-size: 32px; }
.unpaid-title { font-size: 13px; color: var(--orange); font-weight: 600; margin-bottom: 4px; }
.unpaid-val { font-size: 22px; font-weight: 700; color: var(--text); }

/* ===== 设置页 ===== */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.settings-card {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.settings-card-title { font-size: 13px; font-weight: 600; color: var(--text2); margin-bottom: 14px; }
.settings-card-full { grid-column: 1 / -1; }

.color-row { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 14px; }
.color-item { display: flex; align-items: center; gap: 10px; }
.color-item label { font-size: 12px; color: var(--text2); }
.color-preview { font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 600; }

.cat-list { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }
.cat-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
}
.cat-icon-badge {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; flex-shrink: 0;
}
.cat-name { flex: 1; font-size: 13px; font-weight: 500; }
.cat-type-tag { font-size: 11px; color: var(--text3); }
.cat-actions { display: flex; gap: 5px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 2rem; left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px; font-weight: 500;
  opacity: 0; transition: opacity 0.3s;
  pointer-events: none; z-index: 300;
  border: 0.5px solid var(--border2);
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; }
.toast.success { border-color: rgba(45,212,160,0.4); }
.toast.error { border-color: rgba(247,97,122,0.4); }

/* ===== 空状态 ===== */
.empty-state {
  text-align: center; padding: 48px;
  color: var(--text3); font-size: 13px;
}
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.4; }

/* ===== 分页 ===== */
.table-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  border-top: 0.5px solid var(--border);
  font-size: 12px; color: var(--text3);
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-wrap { margin-left: 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
.badge-boss { background: rgba(155,110,247,0.15); color: var(--purple); border: 0.5px solid rgba(155,110,247,0.3); }
.badge-personal { background: rgba(52,209,247,0.15); color: var(--cyan); border: 0.5px solid rgba(52,209,247,0.3); }
.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  color: var(--text3);
  text-decoration: none;
  font-size: 13px;
  border-top: 0.5px solid var(--border);
  transition: all 0.2s;
}
.sidebar-logout:hover {
  color: var(--red);
  background: rgba(247,97,122,0.08);
}
/* ===== 手机端适配 ===== */
.mobile-topnav {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--sidebar);
  border-bottom: 0.5px solid var(--border);
  z-index: 150;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.mobile-brand { font-size: 16px; font-weight: 600; color: var(--text); }
.mobile-menu-btn {
  background: var(--bg3);
  border: 0.5px solid var(--border2);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}
.mobile-overlay.show { display: block; }

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  color: var(--text3);
  text-decoration: none;
  font-size: 13px;
  border-top: 0.5px solid var(--border);
  transition: all 0.2s;
  font-weight: 500;
}
.sidebar-logout:hover { color: var(--red); background: rgba(247,97,122,0.08); }

@media (max-width: 768px) {
  .mobile-topnav { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 100;
    width: 240px;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrap { margin-left: 0; padding-top: 52px; }
  .topbar { display: none; }
  .page-content { padding: 10px; }

  /* 卡片两列 */
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
  [style*="grid-template-columns"] { grid-template-columns: repeat(2, 1fr) !important; }

  /* 筛选栏 */
  .toolbar { gap: 6px; flex-wrap: wrap; }
  .filter-input, .filter-select { font-size: 12px; padding: 6px 8px; flex: 1; min-width: 120px; }

  /* 记一笔按钮 — 固定在右下角 */
  .fab-add {
    display: flex;
    position: fixed;
    bottom: 24px;
    right: 20px;
    z-index: 90;
    width: 52px; height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4e8ef7, #6c7ef7);
    color: #fff;
    font-size: 28px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(78,142,247,0.5);
    cursor: pointer;
    border: none;
  }

  /* 表格 */
  table { font-size: 11px; }
  th, td { padding: 6px 4px; }
  .row-actions { opacity: 1; display: flex; }

  /* 弹窗 */
  .modal { width: 95vw; max-height: 85vh; }
  .form-row { grid-template-columns: 1fr; }

  /* 统计图表 */
  .chart-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

/* 桌面端隐藏悬浮按钮 */
.fab-add { display: none; }