:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #9ca3af;
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef2ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ============ 布局 ============ */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 236px;
  flex: 0 0 236px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
}

.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
  letter-spacing: -.5px;
}

.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.2px; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

.nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.nav-label {
  font-size: 11px; color: var(--muted); font-weight: 600;
  letter-spacing: .6px; text-transform: uppercase;
  padding: 14px 8px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--text-2);
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: #f3f4f6; color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item svg { width: 16px; height: 16px; flex: 0 0 16px; stroke-width: 1.8; }

.sidebar-foot { border-top: 1px solid var(--border); padding: 12px; }

.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 8px;
}
.user-chip:hover { background: #f3f4f6; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center;
  font-weight: 650; font-size: 12px; flex: 0 0 28px;
}
.user-meta { min-width: 0; flex: 1; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--muted); }

.main { flex: 1; overflow-y: auto; min-width: 0; }
.page { max-width: 1180px; margin: 0 auto; padding: 26px 30px 60px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
}
.page-title { font-size: 21px; font-weight: 680; letter-spacing: -.4px; }
.page-desc { font-size: 13px; color: var(--text-2); margin-top: 5px; line-height: 1.6; }
.page-actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px; font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: #f9fafb; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ============ 卡片 ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-title { font-size: 14px; font-weight: 650; }
.card-desc { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }

/* ============ 统计卡 ============ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 25px; font-weight: 680; letter-spacing: -.7px; margin-top: 8px; line-height: 1; }
.stat-unit { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat-foot { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-weight: 600; color: var(--text-2);
  font-size: 12px; letter-spacing: .3px;
  padding: 10px 14px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1f2f4;
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: #fafbfc; }
.tbl .num { font-variant-numeric: tabular-nums; }
.tbl .right { text-align: right; }
.tbl .actions { display: flex; gap: 6px; justify-content: flex-end; }

.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ 徽章 ============ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 21px; padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: #f3f4f6; color: var(--text-2);
  white-space: nowrap;
}
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-err { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* ============ 表单 ============ */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--text-2); margin-bottom: 6px;
}
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.5; }

.input, .select, .textarea {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; min-height: 78px; padding: 9px 11px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.input::placeholder { color: var(--muted); }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.switch { display: flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, .42);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99) } to { opacity: 1; transform: none } }

.modal {
  width: 100%; max-width: 480px;
  max-height: 88vh;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: pop .16s ease;
}
.modal.wide { max-width: 620px; }
.modal-head {
  padding: 17px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 15px; font-weight: 650; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.icon-btn {
  width: 28px; height: 28px; border: none; background: transparent;
  border-radius: 6px; cursor: pointer; color: var(--muted);
  display: grid; place-items: center; font-size: 17px; line-height: 1;
}
.icon-btn:hover { background: #f3f4f6; color: var(--text); }

/* ============ 空状态 ============ */
.empty { padding: 46px 20px; text-align: center; }
.empty-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.empty-desc { font-size: 13px; color: var(--muted); margin-bottom: 16px; line-height: 1.6; }

/* ============ Toast ============ */
#toasts {
  position: fixed; top: 18px; right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  min-width: 230px; max-width: 380px;
  padding: 11px 14px;
  background: #111827; color: #fff;
  border-radius: 8px;
  font-size: 13px; line-height: 1.5;
  box-shadow: var(--shadow-lg);
  animation: pop .16s ease;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }

/* ============ 代码块 ============ */
pre.code {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
}
pre.code .c { color: #64748b; }
code.inline {
  background: #f1f5f9; padding: 2px 6px; border-radius: 5px;
  font-family: var(--mono); font-size: 12.5px; color: #334155;
}
.copy-row {
  display: flex; align-items: center; gap: 8px;
  background: #f9fafb; border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px;
}
.copy-row .val { flex: 1; font-family: var(--mono); font-size: 12.5px; overflow-x: auto; white-space: nowrap; }

/* ============ 图表 ============ */
.chart { width: 100%; height: 168px; display: block; }

/* ============ 登录页 ============ */
.auth-wrap { display: flex; min-height: 100vh; }
.auth-side {
  flex: 1;
  background: linear-gradient(150deg, #312e81 0%, #4338ca 42%, #4f46e5 100%);
  color: #fff;
  padding: 54px 56px;
  display: flex; flex-direction: column;
  position: relative;
  overflow: hidden;
}
.auth-side::after {
  content: ""; position: absolute; right: -120px; bottom: -140px;
  width: 420px; height: 420px; border-radius: 50%;
  background: rgba(255,255,255,.06);
}
.auth-side::before {
  content: ""; position: absolute; right: 40px; top: -90px;
  width: 260px; height: 260px; border-radius: 50%;
  background: rgba(255,255,255,.05);
}
.auth-brand { display: flex; align-items: center; gap: 11px; font-size: 16px; font-weight: 650; }
.auth-hero { margin-top: auto; margin-bottom: auto; max-width: 430px; position: relative; z-index: 1; }
.auth-hero h1 { font-size: 33px; line-height: 1.28; letter-spacing: -.9px; font-weight: 680; }
.auth-hero p { margin-top: 16px; font-size: 14.5px; line-height: 1.75; color: rgba(255,255,255,.76); }
.auth-feats { list-style: none; margin-top: 30px; display: grid; gap: 13px; }
.auth-feats li { display: flex; gap: 10px; font-size: 13.5px; color: rgba(255,255,255,.88); line-height: 1.6; }
.auth-feats .tick {
  width: 18px; height: 18px; border-radius: 50%; flex: 0 0 18px;
  background: rgba(255,255,255,.16); display: grid; place-items: center;
  font-size: 11px; margin-top: 1px;
}
.auth-foot { font-size: 12px; color: rgba(255,255,255,.45); position: relative; z-index: 1; }

.auth-main {
  width: 468px; flex: 0 0 468px;
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  background: var(--surface);
}
.auth-card { width: 100%; max-width: 336px; }
.auth-title { font-size: 22px; font-weight: 680; letter-spacing: -.4px; }
.auth-sub { font-size: 13.5px; color: var(--text-2); margin-top: 7px; margin-bottom: 26px; line-height: 1.6; }
.auth-tabs { display: flex; gap: 4px; background: #f3f4f6; padding: 3px; border-radius: 9px; margin-bottom: 20px; }
.auth-tab {
  flex: 1; height: 30px; border: none; background: transparent;
  border-radius: 7px; font-size: 13px; font-weight: 550; color: var(--text-2);
  cursor: pointer;
}
.auth-tab.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.auth-err {
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid #fecaca; border-radius: 8px;
  padding: 9px 12px; font-size: 12.5px; margin-bottom: 14px; line-height: 1.5;
}
.auth-note {
  margin-top: 18px; font-size: 12px; color: var(--muted);
  line-height: 1.7; text-align: center;
}

@media (max-width: 900px) {
  .auth-side { display: none; }
  .auth-main { width: 100%; flex: 1; }
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .page { padding: 20px 16px 50px; }
}
