:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #0b1220;
  --bg-input: #0f172a;
  --bg-hover: #283548;
  --border: rgba(148, 163, 184, 0.14);
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-faint: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #60a5fa;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px;
}
.brand-name { font-size: 16px; font-weight: 500; color: var(--text); }
.menu { padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.menu-item {
  display: flex; align-items: center;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 14px;
  transition: all .15s;
}
.menu-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.menu-item.active { background: rgba(59, 130, 246, 0.14); color: var(--accent); }
.sidebar-foot { padding: 14px 20px; border-top: 1px solid var(--border); color: var(--text-faint); font-size: 12px; }

/* ---------- 主区域 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.8);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 16px; font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-user { color: var(--text-dim); font-size: 13px; }
.content { padding: 26px 28px 40px; max-width: 1240px; width: 100%; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-head h2 { font-size: 15px; font-weight: 500; }

/* ---------- 统计卡片 ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { padding: 18px 20px; margin-bottom: 0; }
.stat-label { color: var(--text-dim); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 500; margin: 6px 0; color: var(--text); letter-spacing: .5px; }
.stat-sub { color: var(--text-faint); font-size: 12px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tbody tr:hover { background: rgba(148, 163, 184, 0.05); }
tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px; }
.empty { text-align: center; color: var(--text-faint); padding: 40px 0; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  line-height: 1.7;
}
.badge-green { background: rgba(34, 197, 94, 0.14); color: var(--green); }
.badge-red { background: rgba(239, 68, 68, 0.14); color: var(--red); }
.badge-amber { background: rgba(245, 158, 11, 0.14); color: var(--amber); }
.badge-blue { background: rgba(59, 130, 246, 0.14); color: var(--accent); }
.badge-gray { background: rgba(148, 163, 184, 0.12); color: var(--text-dim); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  background: transparent;
  color: var(--text);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { border-color: rgba(148,163,184,.4); color: var(--text); }
.btn-danger-ghost { border-color: var(--border); color: var(--red); }
.btn-danger-ghost:hover { border-color: var(--red); }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-item { display: flex; flex-direction: column; gap: 6px; }
.form-item.full { grid-column: 1 / -1; }
.form-item label { font-size: 12px; color: var(--text-dim); }
input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"], select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 64px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, 0.7);
  display: none; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-mask.show { display: flex; }
.modal {
  width: 560px; max-width: calc(100vw - 40px);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}
.modal h3 { font-size: 15px; font-weight: 500; margin-bottom: 18px; }
.modal-key {
  background: var(--bg);
  border: 1px dashed rgba(96, 165, 250, 0.5);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  color: var(--accent);
  word-break: break-all;
  margin-bottom: 12px;
}

/* ---------- 登录页 ---------- */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(59,130,246,.16), transparent 60%),
              radial-gradient(1000px 500px at 90% 110%, rgba(96,165,250,.10), transparent 60%),
              var(--bg);
}
.auth-card {
  width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
}
.auth-logo {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 600;
  margin-bottom: 20px;
}
.auth-card h1 { font-size: 20px; font-weight: 500; margin-bottom: 6px; }
.auth-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 28px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { font-size: 12px; color: var(--text-dim); }
.auth-error { color: var(--red); font-size: 13px; min-height: 20px; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; top: 24px; left: 50%;
  transform: translateX(-50%);
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  transition: opacity .2s;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}
.toast.show { opacity: 1; }
.toast.ok { border-color: rgba(34,197,94,.5); color: var(--green); }
.toast.err { border-color: rgba(239,68,68,.5); color: var(--red); }

/* ---------- 对话调试 ---------- */
.chat-shell { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 420px; }
.chat-bar { display: flex; gap: 12px; margin-bottom: 14px; align-items: center; }
.chat-bar select { width: 200px; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.msg { max-width: 80%; padding: 10px 14px; border-radius: 10px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); }
.chat-input-row { display: flex; gap: 10px; margin-top: 14px; }
.chat-input-row input { flex: 1; }
.cursor-blink::after { content: "▍"; animation: blink 1s step-end infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- 文档页 ---------- */
.docs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .docs-grid { grid-template-columns: 1fr; } }
.docs-grid .card { margin-bottom: 0; }
.doc-block h3 { font-size: 14px; font-weight: 500; margin-bottom: 10px; color: var(--accent); }
.doc-block p, .doc-block li { font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
pre.code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-size: 12px;
  overflow-x: auto;
  color: var(--text);
  font-family: ui-monospace, Consolas, monospace;
  line-height: 1.7;
  margin-top: 10px;
}
kbd { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; font-size: 12px; }

/* ---------- 筛选条 ---------- */
.filter-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { width: auto; min-width: 140px; }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(148,163,184,.25); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* 趋势图 */
.trend-chart { display: flex; align-items: flex-end; gap: 18px; height: 180px; padding-top: 10px; }
.trend-bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.trend-bar .bar { width: 100%; max-width: 46px; background: var(--primary); border-radius: 6px 6px 0 0; min-height: 2px; transition: height .3s; }
.trend-bar .bar:hover { background: var(--accent); }
.trend-bar .val { font-size: 11px; color: var(--text-dim); }
.trend-bar .lbl { font-size: 11px; color: var(--text-faint); }
