/* ===================== 基础变量 ===================== */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --border: #e6e8ef;
  --border-strong: #d5d8e3;
  --text: #1b1d29;
  --text-2: #5a6072;
  --text-3: #949aab;
  --accent: #6d5efc;
  --accent-soft: #efedff;
  --accent-dark: #574ad6;
  --success: #12a670;
  --success-soft: #e5f7f0;
  --warning: #d98600;
  --warning-soft: #fff4e0;
  --danger: #e0443a;
  --danger-soft: #fdeceb;
  --info: #2b7fd4;
  --info-soft: #e8f2fd;
  --sidebar: #16182499;
  --sidebar-solid: #161824;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 22, 34, .04), 0 6px 20px rgba(20, 22, 34, .06);
  --shadow-lg: 0 12px 40px rgba(20, 22, 34, .18);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

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

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

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

.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--sidebar-solid);
  color: #c8ccdb;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #7d6dff, #a78bfa);
  display: grid;
  place-items: center;
  font-size: 16px;
  flex: 0 0 32px;
}

.brand-text { font-size: 15px; font-weight: 600; color: #fff; letter-spacing: .3px; }
.brand-sub { font-size: 11px; color: #7c8296; margin-top: -2px; }

.nav { padding: 6px 12px; flex: 1; overflow-y: auto; }
.nav-group-title {
  font-size: 11px;
  letter-spacing: .8px;
  color: #6a7085;
  padding: 14px 10px 6px;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: #b6bbcd;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .15s, color .15s;
  user-select: none;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 500; }
.nav-icon { width: 18px; text-align: center; font-size: 14px; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, .07);
  font-size: 12px;
  color: #7c8296;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }
.topbar .sub { font-size: 12.5px; color: var(--text-3); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.content { padding: 22px 26px 60px; flex: 1; }

/* ===================== 卡片 ===================== */
.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: 14.5px; font-weight: 600; }
.card-desc { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.card-body { padding: 18px; }
.card-body.tight { padding: 12px 18px; }

/* ===================== 统计卡 ===================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.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-3); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 26px; font-weight: 650; margin-top: 6px; letter-spacing: -.5px; }
.stat-value small { font-size: 14px; font-weight: 500; color: var(--text-3); margin-left: 2px; }
.stat-foot { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ===================== 按钮 ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-danger { color: var(--danger); border-color: #f3c9c6; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===================== 表单 ===================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }

.label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.label .req { color: var(--danger); margin-left: 2px; }
.hint { font-size: 12px; color: var(--text-3); line-height: 1.5; }

.input, .select, .textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 90px; line-height: 1.65; }
.textarea.mono { font-family: var(--mono); font-size: 12.5px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ===================== 表格 ===================== */
.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.data th {
  text-align: left;
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text-3);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface-2);
}

table.data td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .mono { font-family: var(--mono); font-size: 12.5px; }
.col-actions { text-align: right; white-space: nowrap; }
.col-actions .btn + .btn { margin-left: 6px; }

/* ===================== 徽标 ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-gray { background: #eef0f5; color: var(--text-2); }
.badge-orange { background: var(--warning-soft); color: var(--warning); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-blue { background: var(--info-soft); color: var(--info); }
.badge-violet { background: var(--accent-soft); color: var(--accent-dark); }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
  margin-right: 4px;
}

/* ===================== 工具条 ===================== */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar .spacer { flex: 1; }
.toolbar .input, .toolbar .select { width: auto; min-width: 140px; }

/* ===================== 空状态 / 加载 ===================== */
.empty {
  text-align: center;
  padding: 54px 20px;
  color: var(--text-3);
}
.empty-icon { font-size: 34px; margin-bottom: 10px; opacity: .55; }
.empty-title { font-size: 14px; color: var(--text-2); margin-bottom: 4px; }

.loading { padding: 40px; text-align: center; color: var(--text-3); }
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== 分页 ===================== */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
  gap: 12px;
  flex-wrap: wrap;
}
.pager-btns { display: flex; gap: 6px; align-items: center; }

/* ===================== 模态框 ===================== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 34, .45);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 24px;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  animation: rise .18s ease;
}
.modal.wide { max-width: 760px; }
@keyframes rise { from { transform: translateY(10px); opacity: .6; } to { transform: none; opacity: 1; } }

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-close {
  border: none; background: none; cursor: pointer;
  font-size: 20px; color: var(--text-3); line-height: 1; padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

/* ===================== Toast ===================== */
.toast-root {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: #23263a;
  color: #fff;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease;
  max-width: 80vw;
}
.toast.success { background: #0f8f61; }
.toast.error { background: #c93a31; }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===================== 登录页 ===================== */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #191b2a 0%, #2c2450 100%);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 34px 32px 30px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  width: 46px; height: 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, #7d6dff, #a78bfa);
  display: grid; place-items: center;
  font-size: 22px;
  margin-bottom: 16px;
}
.login-title { font-size: 20px; font-weight: 650; margin: 0 0 4px; }
.login-sub { font-size: 13px; color: var(--text-3); margin-bottom: 24px; }
.login-error {
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

/* ===================== 图片上传 ===================== */
.img-field { display: flex; gap: 14px; align-items: flex-start; }
.img-preview {
  width: 96px; height: 96px;
  border-radius: var(--radius);
  border: 1px dashed var(--border-strong);
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: 0 0 96px;
  color: var(--text-3);
  font-size: 12px;
  position: relative;
}
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-preview.tall { height: 150px; width: 112px; flex-basis: 112px; }
.img-actions { display: flex; flex-direction: column; gap: 6px; }

/* ===================== 测试台 ===================== */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 210px);
  min-height: 420px;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { display: flex; gap: 10px; max-width: 82%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-dark);
  display: grid; place-items: center; font-size: 12px; flex: 0 0 30px;
  overflow: hidden;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg.assistant .msg-avatar { background: #e9ecf5; color: var(--text-2); }
.msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
}
.msg.user .msg-bubble { background: var(--accent); color: #fff; border-color: var(--accent); }
.msg-meta { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }
.chat-input-row { display: flex; gap: 10px; margin-top: 14px; align-items: flex-end; }
.chat-input-row .textarea { min-height: 46px; max-height: 140px; }

/* ===================== 代码块 / 激活码输出 ===================== */
.code-block {
  font-family: var(--mono);
  font-size: 13px;
  background: #1c1f2e;
  color: #d6dae8;
  padding: 16px;
  border-radius: var(--radius);
  max-height: 320px;
  overflow-y: auto;
  line-height: 1.85;
  letter-spacing: .4px;
  white-space: pre;
}

.kv { display: grid; grid-template-columns: 116px 1fr; gap: 9px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-all; }

/* ===================== 其它 ===================== */
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.mb-0 { margin-bottom: 0; }
.mt-16 { margin-top: 16px; }
.flex-1 { flex: 1; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }

@media (max-width: 860px) {
  .sidebar { width: 62px; flex-basis: 62px; }
  .brand-text, .brand-sub, .nav-item span:not(.nav-icon), .nav-group-title, .sidebar-footer { display: none; }
  .brand { justify-content: center; padding: 18px 0; }
  .nav-item { justify-content: center; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
}


.model-switch { display:flex; align-items:center; gap:8px; }
.model-switch label { font-size:13px; color:var(--muted,#72798b); white-space:nowrap; }
.model-switch select { border:1px solid var(--border,#e1e5ed); background:var(--surface,#fff); border-radius:8px; padding:7px 10px; color:var(--text,#333b50); font:inherit; font-size:13px; cursor:pointer; }
@media(max-width:800px) { .topbar { flex-wrap:wrap; gap:12px; } .topbar-right { flex-wrap:wrap; } }
