/* ============================================================
   星光内账 SaaS · 三主题毛玻璃体系（手写 CSS，拒绝框架）
   主题：dark 暗色 / light 亮色浅毛玻璃 / aero Vista Aero 动态渐变
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --radius: 14px;
  --radius-sm: 8px;
  --font: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  --income: #34d399;
  --expense: #f87171;
  --transition: all .2s ease;
}

/* ---------- 暗色主题（默认） ---------- */
html[data-theme="dark"] {
  --bg: linear-gradient(135deg, #0f1226 0%, #171a33 50%, #1a1030 100%);
  --bg-attach: fixed;
  --text: #e6e8f2;
  --text-dim: #9aa0b8;
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-bg-strong: rgba(255, 255, 255, 0.10);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --primary: #7c8cf8;
  --primary-text: #fff;
  --hover-bg: rgba(255, 255, 255, 0.08);
  --input-bg: rgba(0, 0, 0, 0.25);
  --table-line: rgba(255, 255, 255, 0.08);
}

/* ---------- 亮色浅毛玻璃 ---------- */
html[data-theme="light"] {
  --bg: linear-gradient(135deg, #eef1f8 0%, #e7ecf7 50%, #eee9f7 100%);
  --bg-attach: fixed;
  --text: #24283b;
  --text-dim: #6b7190;
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-bg-strong: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(255, 255, 255, 0.9);
  --glass-shadow: 0 8px 32px rgba(80, 90, 140, 0.14);
  --primary: #5b6cf0;
  --primary-text: #fff;
  --hover-bg: rgba(90, 100, 200, 0.08);
  --input-bg: rgba(255, 255, 255, 0.8);
  --table-line: rgba(60, 70, 120, 0.10);
}

/* ---------- Vista Aero：淡蓝淡紫动态渐变 ---------- */
html[data-theme="aero"] {
  --bg: linear-gradient(120deg, #a1c4fd, #c2b3f0, #d4e7fb, #b8c6f5);
  --bg-attach: fixed;
  --text: #1d2440;
  --text-dim: #4d5678;
  --glass-bg: rgba(255, 255, 255, 0.30);
  --glass-bg-strong: rgba(255, 255, 255, 0.50);
  --glass-border: rgba(255, 255, 255, 0.65);
  --glass-shadow: 0 8px 32px rgba(70, 100, 180, 0.22), inset 0 1px 0 rgba(255,255,255,.6);
  --primary: #3f6ce0;
  --primary-text: #fff;
  --hover-bg: rgba(255, 255, 255, 0.35);
  --input-bg: rgba(255, 255, 255, 0.55);
  --table-line: rgba(50, 80, 160, 0.15);
}

@keyframes vistaGradient {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  background-attachment: var(--bg-attach);
  min-height: 100vh;
  font-size: 14px;
}
html[data-theme="aero"] body {
  background-size: 400% 400%;
  animation: vistaGradient 20s ease infinite;
}

/* ---------- 毛玻璃基元 ---------- */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
}

/* ---------- 布局骨架 ---------- */
.app-shell { display: flex; min-height: 100vh; gap: 16px; padding: 16px; }
.sidebar {
  width: 230px; flex-shrink: 0; display: flex; flex-direction: column;
  padding: 20px 14px; position: sticky; top: 16px; height: calc(100vh - 32px);
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.content { display: flex; flex-direction: column; gap: 16px; }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-logo {
  font-size: 22px; width: 42px; height: 42px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  color: #fff; border-radius: 12px; flex-shrink: 0;
}
.brand-logo.big { width: 56px; height: 56px; font-size: 28px; margin: 0 auto; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-company {
  font-size: 12px; color: var(--text-dim); max-width: 140px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: var(--radius-sm); color: var(--text-dim); text-decoration: none;
  transition: var(--transition);
}
.nav-item:hover { background: var(--hover-bg); color: var(--text); }
.nav-item.active { background: var(--primary); color: var(--primary-text); }
.nav-icon { width: 20px; text-align: center; }

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--table-line); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, #f59e0b, #ef4444); color: #fff; font-weight: 700; flex-shrink: 0;
}
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: var(--text-dim); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 4px 6px;
}
.page-title { font-size: 22px; font-weight: 700; }

.theme-switch { display: flex; gap: 6px; }
.theme-switch button {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--glass-border);
  background: var(--glass-bg); cursor: pointer; font-size: 15px; transition: var(--transition);
}
.theme-switch button:hover { transform: translateY(-2px); }
.theme-switch button.on { background: var(--primary); }

/* ---------- 统计卡片 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.stat-card { padding: 18px 20px; transition: var(--transition); }
.stat-card:hover { transform: translateY(-3px); }
.stat-label { color: var(--text-dim); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; margin: 8px 0 4px; font-variant-numeric: tabular-nums; }
.stat-foot { font-size: 12px; color: var(--text-dim); }
.income { color: var(--income); }
.expense { color: var(--expense); }

/* ---------- 面板 / 表格 ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } .sidebar { display: none; } }

.panel { padding: 18px 20px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.panel-head h2 { font-size: 16px; }
.link { color: var(--primary); text-decoration: none; font-size: 13px; }
.link:hover { text-decoration: underline; }

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; color: var(--text-dim); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--table-line); white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid var(--table-line); vertical-align: middle; }
.table tbody tr { transition: var(--transition); }
.table tbody tr:hover { background: var(--hover-bg); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .ops { text-align: right; white-space: nowrap; }
.table .desc { max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table .empty { text-align: center; color: var(--text-dim); padding: 32px 0; }

.table-summary { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }
.table-summary b { color: var(--text); }

.tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px;
  background: var(--hover-bg); border: 1px solid var(--glass-border);
}
.tag-income { color: var(--income); border-color: color-mix(in srgb, var(--income) 40%, transparent); }
.tag-expense { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 40%, transparent); }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; }
.page-info { color: var(--text-dim); font-size: 13px; }

/* ---------- 按钮 ---------- */
.btn {
  padding: 9px 18px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; font-size: 14px; font-family: var(--font); transition: var(--transition);
  background: var(--glass-bg-strong); color: var(--text);
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  color: var(--primary-text); border: none; box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 40%, transparent);
}
.btn-ghost { background: transparent; border-color: var(--glass-border); }
.btn-danger { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 40%, transparent); background: transparent; }
.btn-mini { padding: 4px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field span { color: var(--text-dim); }
input, select {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--glass-border);
  background: var(--input-bg); color: var(--text); font-family: var(--font); font-size: 14px;
  outline: none; transition: var(--transition);
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
select option { background: #fff; color: #222; }
html[data-theme="dark"] select option { background: #1c2039; color: #e6e8f2; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .form-grid-4 { grid-template-columns: 1fr 1fr; } }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { justify-content: flex-end; flex-direction: row; align-items: end; grid-column: 1 / -1; display: flex; }

.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-bar .sep { color: var(--text-dim); }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input[type="text"] { flex: 1; min-width: 120px; }

.alert { padding: 10px 14px; border-radius: 10px; font-size: 13px; margin: 10px 0; }
.alert-error {
  color: var(--expense); background: color-mix(in srgb, var(--expense) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--expense) 35%, transparent);
}
.alert-ok {
  color: var(--income); background: color-mix(in srgb, var(--income) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--income) 35%, transparent);
}

/* ---------- 弹窗 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(10, 12, 30, 0.45); backdrop-filter: blur(4px);
  animation: fadeIn .18s ease;
}
.modal { width: min(560px, calc(100vw - 32px)); padding: 22px 24px; animation: popIn .2s ease; max-height: calc(100vh - 48px); overflow-y: auto; }
.modal-wide { width: min(680px, calc(100vw - 32px)); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 17px; }
.modal-close {
  width: 30px; height: 30px; border-radius: 8px; border: none; cursor: pointer;
  background: var(--hover-bg); color: var(--text); font-size: 17px;
}
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* 角色权限矩阵 */
.perm-group { margin-bottom: 12px; }
.perm-group-title { font-weight: 600; font-size: 13px; opacity: .75; margin-bottom: 6px; }
.perm-group-items { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.perm-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.perm-check input { accent-color: var(--accent, #6c8cff); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Toast ---------- */
#toast-root { position: fixed; top: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  padding: 12px 18px; border-radius: 12px; font-size: 14px; color: var(--text);
  background: var(--glass-bg-strong); backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

/* ---------- 图表 ---------- */
.chart-box { position: relative; height: 260px; margin-top: 8px; }
.chart-box.tall { height: 300px; }

/* ---------- 登录页 ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card { width: min(400px, 100%); padding: 36px 32px; position: relative; }
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-brand h1 { font-size: 20px; margin-top: 14px; }
.auth-sub { color: var(--text-dim); font-size: 12px; margin-top: 6px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 13px; }
.auth-footer a { color: var(--text-dim); text-decoration: none; }
.auth-footer a:hover { color: var(--primary); }
.auth-theme { position: absolute; top: 14px; right: 14px; }
