:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #a5b4fc;
  --primary-bg: #eef2ff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --border: #e8edf3;
  --shadow: 0 1px 3px rgba(15, 23, 42, .05), 0 1px 2px rgba(15, 23, 42, .03);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, .07);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);
  --radius: 16px;
  --radius-sm: 11px;
  --sidebar-w: 232px;
  --topbar-h: 60px;
  --grad-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --grad-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --grad-danger: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: inherit; text-decoration: none; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: all .2s cubic-bezier(.4,0,.2,1);
  background: var(--primary);
  color: #fff;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(99, 102, 241, .25);
}
.btn:hover { opacity: .92; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99, 102, 241, .35); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--grad-primary); box-shadow: 0 2px 10px rgba(102, 126, 234, .3); }
.btn-success { background: var(--grad-success); box-shadow: 0 2px 8px rgba(16, 185, 129, .25); }
.btn-danger { background: var(--grad-danger); box-shadow: 0 2px 8px rgba(239, 68, 68, .25); }
.btn-warning { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 2px 8px rgba(245, 158, 11, .25); }
.btn-outline {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); box-shadow: none; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn-sm { padding: 5px 11px; font-size: 12px; box-shadow: none; }
.btn-icon {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .18s;
}
.btn-icon:hover { background: var(--primary-bg); color: var(--primary); }

/* ===== 表单 ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: all .18s;
  background: #f8fafc;
  color: var(--text);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .12);
}
.amount-input { font-size: 18px; font-weight: 600; }

/* ===== 标签 ===== */
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
}
.tag-income { background: #d1fae5; color: #047857; }
.tag-expense { background: #fee2e2; color: #b91c1c; }
.tag-ongoing { background: #dbeafe; color: #1e40af; }
.tag-done { background: #e0e7ff; color: #3730a3; }
.tag-pending { background: #fef3c7; color: #92400e; }

/* ===== 登录页 ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 22px;
  padding: 38px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon {
  width: 68px; height: 68px;
  background: var(--grad-primary);
  border-radius: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 34px; margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(102, 126, 234, .35);
}
.login-logo h1 { font-size: 21px; color: var(--text); font-weight: 700; }
.login-logo p { color: var(--text-2); font-size: 13px; margin-top: 4px; }

/* ===== 主布局 ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
  box-shadow: 2px 0 12px rgba(15, 23, 42, .03);
}
.sidebar-header {
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 11px;
}
.sidebar-header .logo-icon {
  width: 38px; height: 38px;
  background: var(--grad-primary);
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(102, 126, 234, .3);
}
.sidebar-header h2 { font-size: 16px; font-weight: 700; line-height: 1.2; }
.sidebar-header small { font-size: 11px; color: var(--text-2); }

.nav { flex: 1; padding: 10px 10px; overflow-y: auto; }
.nav-section {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  padding: 12px 12px 6px;
  letter-spacing: .6px;
  font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  margin-bottom: 3px;
  transition: all .18s;
  font-size: 14px;
  font-weight: 500;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active {
  background: var(--grad-primary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(102, 126, 234, .35);
}
.nav-item .ico { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.share-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 10px 12px; margin-bottom: 10px;
  border: none; border-radius: var(--radius-sm);
  background: var(--grad-primary);
  color: #fff; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all .2s;
  box-shadow: 0 4px 12px rgba(102, 126, 234, .3);
}
.share-btn:hover { opacity: .92; transform: translateY(-1px); box-shadow: 0 6px 16px rgba(102, 126, 234, .4); }
.share-btn:active { transform: scale(.98); }
.user-info {
  display: flex; align-items: center; gap: 10px;
  padding: 9px; border-radius: var(--radius-sm); background: var(--bg);
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--grad-primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0; font-size: 14px;
}
.user-info .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info .role { font-size: 11px; color: var(--text-2); }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 3px rgba(15,23,42,.03);
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.menu-toggle {
  display: none;
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  align-items: center; justify-content: center;
  font-size: 20px; color: var(--text);
  flex-shrink: 0;
}
.content { padding: 24px; flex: 1; }

/* 遮罩 */
.overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 99;
  display: none;
  backdrop-filter: blur(2px);
}
.overlay.show { display: block; }

/* ===== 统计卡片 ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
  border: 1px solid var(--border);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card .label { font-size: 13px; color: var(--text-2); margin-bottom: 8px; font-weight: 500; }
.stat-card .value { font-size: 28px; font-weight: 700; letter-spacing: -.5px; }
.stat-card .sub { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.stat-card.income .value { color: var(--success); }
.stat-card.expense .value { color: var(--danger); }
.stat-card.balance .value { color: var(--primary); }
.stat-card.income { background: linear-gradient(135deg, #fff 60%, #ecfdf5); }
.stat-card.expense { background: linear-gradient(135deg, #fff 60%, #fef2f2); }
.stat-card.balance { background: linear-gradient(135deg, #fff 60%, #eef2ff); }
.stat-card .bg-icon {
  position: absolute; right: -8px; top: -8px;
  font-size: 72px; opacity: .08;
}

/* ===== 卡片 ===== */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h3 { font-size: 16px; font-weight: 600; }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  white-space: nowrap;
}
th { background: #f8fafc; color: var(--text-2); font-weight: 600; position: sticky; top: 0; font-size: 12.5px; }
tbody tr { transition: background .15s; }
tbody tr:hover td { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
.amount-in { color: #10b981; font-weight: 600; }
.amount-out { color: #ef4444; font-weight: 600; }

/* ===== 项目卡片 ===== */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.project-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all .2s cubic-bezier(.4,0,.2,1);
  border: 1px solid var(--border);
}
.project-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
}
.project-card h4 { font-size: 16px; margin-bottom: 8px; font-weight: 600; }
.project-card .meta { font-size: 12.5px; color: var(--text-2); margin-bottom: 14px; line-height: 1.8; }
.project-card .fin {
  display: flex; justify-content: space-between;
  padding-top: 14px; border-top: 1px solid var(--border);
  gap: 8px;
}
.project-card .fin div { text-align: center; flex: 1; min-width: 0; }
.project-card .fin .label { font-size: 11px; color: var(--text-2); }
.project-card .fin .val { font-size: 15px; font-weight: 700; margin-top: 2px; }

/* 项目详情头部 */
.project-header {
  background: var(--grad-primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(102, 126, 234, .25);
  position: relative;
  overflow: hidden;
}
.project-header::after {
  content: '';
  position: absolute; right: -40px; top: -40px;
  width: 160px; height: 160px;
  background: rgba(255,255,255,.08);
  border-radius: 50%;
}
.project-header h2 { font-size: 22px; margin-bottom: 10px; font-weight: 700; position: relative; }
.project-header .info { display: flex; gap: 20px; flex-wrap: wrap; font-size: 13px; opacity: .92; position: relative; }
.project-header .info span { display: inline-flex; align-items: center; gap: 4px; }

/* 筛选栏 */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px; align-items: center;
}
.filter-bar select, .filter-bar input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff; outline: none;
  font-size: 13px;
  transition: border-color .18s;
}
.filter-bar select:focus, .filter-bar input:focus { border-color: var(--primary); }

/* ===== 模态框 ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: fadeIn .2s;
  backdrop-filter: blur(3px);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff;
  border-radius: 18px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .25s cubic-bezier(.4, 0, .2, 1);
  box-shadow: var(--shadow-lg);
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: #fff; z-index: 1;
  border-radius: 18px 18px 0 0;
}
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  position: sticky; bottom: 0; background: #fff;
  border-radius: 0 0 18px 18px;
}

/* ===== Toast ===== */
#toast {
  position: fixed;
  top: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
  max-width: 90vw;
}
.toast-item {
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideDown .3s;
  text-align: center;
}
.toast-item.success { background: var(--success); }
.toast-item.error { background: var(--danger); }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== 图表 ===== */
.chart-box { position: relative; height: 300px; }

/* 横向条形图 */
.bar-chart { padding: 6px 2px; max-height: 300px; overflow-y: auto; }
.bar-section-title {
  font-size: 12px; font-weight: 600; color: var(--text-2);
  margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid #f0f4f8;
  display: flex; align-items: center;
}
.bar-section-title .amount-out { color: #f87171; font-weight: 700; margin-left: 6px; font-size: 13px; }
.bar-section-title .amount-in { color: #34d399; font-weight: 700; margin-left: 6px; font-size: 13px; }
.bar-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 4px; font-size: 13px;
  transition: background .15s;
  border-radius: 8px;
}
.bar-row:hover { background: #f8fafc; }
.bar-label {
  flex: 0 0 auto; min-width: 56px; max-width: 88px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: #475569; font-size: 12.5px; font-weight: 500;
}
.bar-track {
  flex: 1 1 auto; height: 18px; background: #f1f5f9;
  border-radius: 9px; overflow: hidden; position: relative;
}
.bar-fill {
  height: 100%; border-radius: 9px; min-width: 3px;
  transition: width .5s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.bar-amount {
  flex: 0 0 auto; font-weight: 600; font-size: 12.5px;
  color: #334155; min-width: 76px; text-align: right;
}

/* ===== 空状态 ===== */
.empty {
  text-align: center; padding: 60px 20px; color: var(--text-2);
}
.empty .ico { font-size: 48px; margin-bottom: 12px; opacity: .5; }

/* 分类标签 */
.cat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-chip {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.cat-chip:hover { border-color: var(--primary); }
.cat-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== 权限矩阵 ===== */
.perm-matrix {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.perm-row {
  display: grid;
  grid-template-columns: 1.5fr repeat(4, 1fr);
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.perm-row:last-child { border-bottom: none; }
.perm-row.perm-head {
  background: #f8fafc;
  font-weight: 600; color: var(--text-2); font-size: 12px;
}
.perm-mod { padding: 11px 12px; font-size: 13px; font-weight: 500; }
.perm-act {
  padding: 11px 8px; text-align: center;
  border-left: 1px solid var(--border); font-size: 12px;
}
.perm-act input[type="checkbox"] {
  width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary);
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  :root { --sidebar-w: 240px; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; height: 56px; }
  .topbar h1 { font-size: 17px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-card .value { font-size: 22px; }
  .stat-card .bg-icon { font-size: 56px; }
  .project-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  th, td { padding: 10px 10px; font-size: 12.5px; }
  .login-card { padding: 30px 22px; }
  .login-logo h1 { font-size: 20px; }
  .project-header { padding: 18px; }
  .project-header h2 { font-size: 19px; }
  .project-header .info { gap: 12px; font-size: 12px; }
  .perm-row { grid-template-columns: 1.3fr repeat(4, 1fr); }
  .perm-mod { font-size: 12px; padding: 10px 8px; }
  .perm-act { font-size: 11px; padding: 10px 4px; }
  .topbar-actions .btn { padding: 8px 13px; font-size: 13px; }
  .modal { max-height: 92vh; border-radius: 16px; }
  .modal-body { padding: 18px; }
  .modal-header, .modal-footer { padding-left: 18px; padding-right: 18px; }
  .chart-box { height: 240px; }
  .charts-row { grid-template-columns: 1fr !important; }
  .bar-chart { max-height: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 20px; }
  .stat-card .label { font-size: 12px; }
  .stat-card .bg-icon { display: none; }
  .topbar h1 { font-size: 16px; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding: 7px 10px; font-size: 12.5px; }
  .project-card { padding: 16px; }
  .project-card .fin { flex-wrap: wrap; gap: 10px; }
  .project-card .fin div { flex: 1; min-width: 70px; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar select, .filter-bar input { width: 100%; }
  .card { padding: 14px; }
  .card-header h3 { font-size: 15px; }
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; max-height: 100vh; height: 100vh; max-width: 100%; }
  .modal-header { padding: 16px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 14px 16px; }
  .btn { padding: 10px 14px; }
  table { min-width: 500px; }
  th, td { padding: 10px 8px; font-size: 12px; }
}

/* 暗色模式 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --card: #1e293b; --text: #e2e8f0; --text-2: #94a3b8;
    --text-3: #64748b; --border: #334155;
  }
  body { background: #0f172a; }
  .card, .sidebar, .topbar, .login-card, .stat-card, .project-card { background: #1e293b; }
  .nav-item:hover, tr:hover td, th { background: #334155; }
  .form-group input, .form-group select, .form-group textarea, .filter-bar select, .filter-bar input {
    background: #334155; color: #e2e8f0; border-color: #475569;
  }
  .btn-outline { background: #1e293b; color: #e2e8f0; border-color: #475569; }
  .perm-row.perm-head, .user-info { background: #334155; }
  .btn-icon { background: #334155; }
}
