:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #2563eb;
  --border: #e5e9f2;
  --text: #1f2937;
  --text-dim: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #059669;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }

/* ---------- 通用按钮/表单 ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }

.input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border 0.15s, box-shadow 0.15s;
  background: #fff;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }

.tag {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.tag-green { background: #ecfdf5; color: var(--success); }
.tag-red { background: var(--danger-bg); color: var(--danger); }
.tag-blue { background: #eff6ff; color: var(--accent); }
.tag-gray { background: #f1f5f9; color: var(--text-dim); }
.tag-amber { background: #fffbeb; color: var(--warn); }

/* ---------- 登录页 ---------- */
.auth-wrap {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #0ea5e9 100%);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px; background: #fff; border-radius: 16px;
  padding: 36px 32px; box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.auth-logo { text-align: center; margin-bottom: 8px; font-size: 30px; }
.auth-title { text-align: center; font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.auth-sub { text-align: center; color: var(--text-dim); margin: 0 0 24px; font-size: 13px; }
.tabs { display: flex; gap: 6px; margin-bottom: 22px; background: #f1f5f9; padding: 4px; border-radius: 10px; }
.tab { flex: 1; text-align: center; padding: 9px; border-radius: 7px; font-size: 14px; color: var(--text-dim); cursor: pointer; }
.tab.active { background: #fff; color: var(--accent); font-weight: 600; box-shadow: var(--shadow); }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text-dim); }
.field-hint { font-size: 12px; margin: 6px 0 0; color: var(--text-dim); line-height: 1.4; }
.msg { font-size: 13px; margin: 10px 0 0; min-height: 18px; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--success); }
.agree { margin: 4px 0 16px; }
.agree-line { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--text-dim); line-height: 1.6; cursor: pointer; }
.agree-line input { margin-top: 3px; flex-shrink: 0; }
.agree-line a { color: var(--accent); }
.agree-note { font-size: 11.5px; color: var(--warn); margin: 8px 0 0; line-height: 1.5; }

/* ---------- 聊天布局 ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 268px; background: var(--sidebar); color: #e2e8f0; display: flex;
  flex-direction: column; flex-shrink: 0;
}
.sidebar-head { padding: 18px 16px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { font-size: 16px; font-weight: 700; color: #fff; display: flex; align-items: center; gap: 8px; }
.brand small { display: block; font-weight: 400; color: #94a3b8; font-size: 11.5px; margin-top: 2px; }
.new-chat {
  margin: 12px 16px; padding: 10px; border-radius: 9px; background: var(--accent);
  color: #fff; text-align: center; font-size: 14px; border: none;
}
.new-chat:hover { background: var(--accent-hover); }
.conv-list { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px; }
.conv-item {
  padding: 10px 12px; border-radius: 8px; margin-bottom: 3px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; color: #cbd5e1; font-size: 13.5px;
  white-space: nowrap; overflow: hidden;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--sidebar-active); color: #fff; }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.conv-del { opacity: 0; color: #94a3b8; background: none; border: none; padding: 2px 4px; font-size: 15px; }
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: #f87171; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid #1e293b; flex-shrink: 0; }
.user-box { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700;
  flex-shrink: 0;
}
.user-meta { flex: 1; overflow: hidden; }
.user-name { font-size: 13.5px; color: #fff; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: #94a3b8; }
.icon-btn { background: none; border: none; color: #94a3b8; font-size: 16px; padding: 4px; }
.icon-btn:hover { color: #fff; }

/* ---------- 聊天主区 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 28px 0; }
.chat-inner { max-width: 780px; margin: 0 auto; padding: 0 24px; }
.empty-state { text-align: center; color: var(--text-dim); margin-top: 12vh; }
.empty-state h2 { color: var(--text); font-size: 22px; margin: 12px 0 6px; }
.suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 28px; }
.suggest-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
  text-align: left; font-size: 13.5px; color: var(--text); transition: border 0.15s, box-shadow 0.15s;
}
.suggest-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }

.msg-row { display: flex; gap: 10px; margin-bottom: 20px; align-items: flex-start; }
.msg-row.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; display: flex;
  align-items: center; justify-content: center; font-size: 15px; font-weight: 700;
}
.msg-avatar.user { background: #dbeafe; color: var(--accent); }
.msg-avatar.bot { background: #0f172a; color: #fff; }
.msg-body { max-width: 78%; min-width: 0; display: flex; flex-direction: column; }
.msg-row.user .msg-body { align-items: flex-end; }
.msg-row.bot .msg-body { align-items: flex-start; }
.msg-content {
  font-size: 14.5px; word-break: break-word; overflow-wrap: anywhere;
  padding: 10px 14px; border-radius: 14px; text-align: left;
}
.msg-row.bot .msg-content {
  background: #fff; border: 1px solid var(--border); color: var(--text);
  border-top-left-radius: 4px;
}
.msg-row.user .msg-content {
  background: var(--accent); color: #fff; border-top-right-radius: 4px;
}
/* ---------- 消息气泡内 Markdown 渲染 ---------- */
.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }
.msg-content p { margin: 8px 0; }
.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4 {
  margin: 14px 0 6px; line-height: 1.35; font-weight: 700;
}
.msg-content h1 { font-size: 18px; }
.msg-content h2 { font-size: 16.5px; }
.msg-content h3 { font-size: 15px; }
.msg-content h4 { font-size: 14.5px; }
.msg-content strong { font-weight: 700; }
.msg-content em { font-style: italic; }
.msg-content ul, .msg-content ol { margin: 8px 0; padding-left: 22px; }
.msg-content li { margin: 3px 0; }
.msg-content li > p { margin: 2px 0; }
.msg-content a { color: var(--accent); text-decoration: underline; }
.msg-content blockquote {
  margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--border);
  color: var(--text-dim); background: #f8fafc; border-radius: 0 6px 6px 0;
}
.msg-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em; background: #f1f5f9; color: #b91c1c;
  padding: 1.5px 5px; border-radius: 5px; word-break: break-word;
}
.msg-content pre {
  margin: 10px 0; padding: 12px 14px; background: #0f172a; border-radius: 10px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.msg-content pre code {
  display: block; background: none; color: #e2e8f0; padding: 0;
  font-size: 12.8px; line-height: 1.6; white-space: pre; word-break: normal;
}
.msg-content table {
  border-collapse: collapse; margin: 10px 0; font-size: 13.5px;
  display: block; overflow-x: auto; max-width: 100%;
}
.msg-content th, .msg-content td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.msg-content th { background: #f8fafc; font-weight: 600; }
.msg-content img { max-width: 100%; border-radius: 8px; }

/* 用户气泡（蓝底）内的 Markdown 元素配色适配 */
.msg-row.user .msg-content a { color: #fff; }
.msg-row.user .msg-content code { background: rgba(255,255,255,0.22); color: #fff; }
.msg-row.user .msg-content pre { background: rgba(0,0,0,0.28); }
.msg-row.user .msg-content pre code { color: #f1f5f9; }
.msg-row.user .msg-content blockquote { border-left-color: rgba(255,255,255,0.5); color: #e0e7ff; background: rgba(255,255,255,0.12); }
.msg-row.user .msg-content th { background: rgba(255,255,255,0.15); }
.msg-row.user .msg-content th, .msg-row.user .msg-content td { border-color: rgba(255,255,255,0.35); }
.msg-actions { margin-top: 6px; display: flex; gap: 10px; }
.report-btn { background: none; border: none; color: var(--text-dim); font-size: 12.5px; padding: 2px 4px; }
.report-btn:hover { color: var(--danger); }
.report-btn.reported { color: var(--warn); cursor: default; }
.cursor-blink::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 0%,50% { opacity: 1; } 50.01%,100% { opacity: 0; } }

/* ---------- 输入区 ---------- */
.composer { border-top: 1px solid var(--border); background: var(--panel); padding: 16px 0 20px; }
.composer-inner { max-width: 780px; margin: 0 auto; padding: 0 24px; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: 14.5px; font-family: inherit; max-height: 180px; outline: none;
}
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.send-btn { width: 44px; height: 44px; border-radius: 12px; border: none; background: var(--accent); color: #fff; font-size: 18px; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.5; }
.composer-hint { max-width: 780px; margin: 8px auto 0; padding: 0 24px; font-size: 11.5px; color: var(--text-dim); text-align: center; }

/* ---------- 模态框 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 440px; box-shadow: 0 20px 50px rgba(0,0,0,0.3); }
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal p.sub { margin: 0 0 16px; color: var(--text-dim); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.hidden { display: none !important; }

/* ---------- 管理后台 ---------- */
.admin-top {
  background: var(--panel); border-bottom: 1px solid var(--border); padding: 14px 26px;
  display: flex; align-items: center; justify-content: space-between;
}
.admin-top h1 { font-size: 17px; margin: 0; }
.admin-body { max-width: 1120px; margin: 0 auto; padding: 24px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .lbl { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }
.admin-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.admin-tab { padding: 10px 16px; font-size: 14px; color: var(--text-dim); border-bottom: 2px solid transparent; cursor: pointer; }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.panel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; color: var(--text-dim); font-weight: 600; font-size: 12.5px; }
tr:last-child td { border-bottom: none; }
td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--text-dim); }
.report-q { color: var(--text-dim); }
.report-a { max-width: 420px; }
.truncate2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13.5px;
  z-index: 100; opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---------- 个人中心 ---------- */
.pc-body { max-width: 760px; margin: 0 auto; padding: 24px; }
.pc-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px; }
.pc-card h2 { font-size: 15px; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.pc-card .desc { color: var(--text-dim); font-size: 13px; margin: -6px 0 14px; }
.pc-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.pc-row:last-child { border-bottom: none; }
.pc-row .lbl { color: var(--text-dim); }
.key-item { border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.key-item:last-child { margin-bottom: 0; }
.key-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.key-name { font-weight: 600; }
.key-str { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; word-break: break-all; background: #f8fafc; border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; color: var(--text); }
.key-meta { font-size: 12px; color: var(--text-dim); margin-top: 8px; display: flex; gap: 16px; flex-wrap: wrap; }
.code-block { background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 12px 14px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; line-height: 1.7; }

/* ---------- 移动端顶栏 / 侧栏抽屉（默认桌面端隐藏） ---------- */
.mobile-topbar { display: none; }
.hamburger {
  background: none; border: none; color: var(--text); font-size: 22px;
  line-height: 1; padding: 4px 8px; border-radius: 8px;
}
.hamburger:hover { background: #f1f5f9; }
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  z-index: 55; display: none;
}
.sidebar-backdrop.show { display: block; }

/* ---------- 侧栏收起/展开按钮 ---------- */
.sidebar-collapse-btn {
  background: none; border: none; color: #94a3b8; font-size: 20px;
  line-height: 1; padding: 2px 6px; border-radius: 6px; flex-shrink: 0;
}
.sidebar-collapse-btn:hover { color: #fff; background: var(--sidebar-hover); }
.sidebar-open-btn {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 40;
  width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font-size: 18px; box-shadow: var(--shadow);
  align-items: center; justify-content: center;
}
.sidebar-open-btn:hover { background: #f1f5f9; }

/* 桌面端：收起侧栏（宽度归零），显示悬浮展开按钮 */
@media (min-width: 641px) {
  .sidebar { transition: width 0.2s ease; }
  .app.sidebar-hidden .sidebar {
    width: 0; min-width: 0; border-right: none; overflow: hidden;
  }
  .app.sidebar-hidden .sidebar-open-btn { display: flex; }
}

/* ---------- 响应式：平板及以下 ---------- */
@media (max-width: 900px) {
  .admin-body { padding: 18px 16px; }
  .pc-body { padding: 18px 16px; }
  .admin-top { padding: 12px 16px; }
}

/* ---------- 响应式：手机 ---------- */
@media (max-width: 640px) {
  /* 侧栏改为抽屉 */
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%; width: 82%; max-width: 300px;
    z-index: 60; transform: translateX(-100%);
    transition: transform 0.25s ease; box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  }
  .sidebar.open { transform: translateX(0); }

  /* 手机端不使用桌面收起按钮：统一用顶栏汉堡 + 抽屉 */
  .sidebar-collapse-btn { display: none; }
  .sidebar-open-btn { display: none !important; }
  .app.sidebar-hidden .sidebar { width: 82%; }

  /* 顶栏显示 */
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--panel);
    position: sticky; top: 0; z-index: 20;
  }
  .mobile-title { font-size: 15px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* 聊天主区 */
  .chat-scroll { padding: 16px 0; }
  .chat-inner { padding: 0 14px; }
  .composer { padding: 10px 0 14px; }
  .composer-inner { padding: 0 14px; gap: 8px; }
  .composer-hint { padding: 0 14px; }
  .send-btn { width: 42px; height: 42px; }
  .msg-body { max-width: 86%; }
  .msg-content { font-size: 14px; }

  /* 空状态建议卡片单列 */
  .empty-state { margin-top: 8vh; }
  .empty-state h2 { font-size: 19px; }
  .suggest { grid-template-columns: 1fr; gap: 10px; margin-top: 20px; }

  /* 顶部栏（后台/个人中心）允许换行 */
  .admin-top { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .admin-top h1 { font-size: 15px; }
  .admin-body { padding: 14px 12px; }
  .pc-body { padding: 14px 12px; }

  /* 统计卡片 */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card .num { font-size: 22px; }

  /* 后台标签页横向滚动 */
  .admin-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .admin-tab { white-space: nowrap; padding: 10px 12px; }

  /* 宽表格横向滚动 */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 640px; }

  /* 登录卡片 */
  .auth-card { padding: 28px 22px; }

  /* 个人中心卡片内换行 */
  .pc-card { padding: 16px 16px; }
  .key-meta { gap: 10px; }
}
