/* ==========================================================================
   408 RAG 智能备考系统 —— 全局样式
   刻意不引入任何 CDN / UI 框架：答辩现场断网也能完整渲染。
   ========================================================================== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-lg: 0 2px 4px rgba(15, 23, 42, .04), 0 24px 48px -24px rgba(15, 23, 42, .18);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

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

/* ------------------------------------------------------------------ 布局 */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 20px;
  height: 60px; padding: 0 24px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; white-space: nowrap; }

.brand .logo {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff; font-size: 13px; font-weight: 800; letter-spacing: -.5px;
}

.nav { display: flex; gap: 4px; margin-left: 8px; }

.nav a {
  padding: 7px 14px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 14px; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); }

.topbar .spacer { flex: 1; }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 5px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
}
.user-chip .avatar {
  display: grid; place-items: center; width: 24px; height: 24px;
  border-radius: 50%; background: var(--primary); color: #fff;
  font-size: 12px; font-weight: 700;
}

.container { max-width: 1180px; margin: 0 auto; padding: 24px; }
.container-narrow { max-width: 860px; margin: 0 auto; padding: 24px; }

/* ------------------------------------------------------------------ 卡片 */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-title { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; font-size: 16px; font-weight: 650; }
.card-sub { margin: 0 0 16px; color: var(--text-muted); font-size: 13px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } }

.stat { padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stat .label { font-size: 12px; color: var(--text-soft); letter-spacing: .3px; }
.stat .value { margin-top: 6px; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .unit { font-size: 13px; font-weight: 500; color: var(--text-soft); margin-left: 2px; }

/* ------------------------------------------------------------------ 表单 */
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field .hint { margin-top: 6px; font-size: 12px; color: var(--text-soft); }

input[type="text"], input[type="password"], input[type="number"], input[type="tel"], select, textarea {
  width: 100%; padding: 10px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { resize: vertical; min-height: 88px; line-height: 1.6; }
select { cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: background .15s, transform .05s, opacity .15s;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface); color: var(--text-muted); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-muted); cursor: pointer; user-select: none; }
.switch input { width: auto; accent-color: var(--primary); cursor: pointer; }

/* ------------------------------------------------------------------ 标签 */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.tag-blue { background: var(--primary-soft); color: var(--primary-dark); border-color: #dbeafe; }
.tag-green { background: var(--success-soft); color: var(--success); border-color: #d1fae5; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: #fef3c7; }
.tag-red { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.tag-purple { background: #f5f3ff; color: #6d28d9; border-color: #ede9fe; }

/* ------------------------------------------------------------------ 表格 */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 12px; font-weight: 600; color: var(--text-soft); letter-spacing: .3px; background: var(--surface-2); }
tbody tr:hover { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 13px; }

/* ------------------------------------------------------------------ 登录页 */
.auth-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr;
}
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } .auth-hero { display: none !important; } }

.auth-hero {
  display: flex; flex-direction: column; justify-content: center; gap: 22px;
  padding: 56px; color: #fff;
  background: radial-gradient(1000px 500px at 10% 0%, #3b82f6 0%, transparent 60%),
              linear-gradient(140deg, #1e3a8a, #4c1d95 60%, #1e1b4b);
}
.auth-hero h1 { margin: 0; font-size: 32px; line-height: 1.3; font-weight: 750; }
.auth-hero p { margin: 0; color: #c7d2fe; font-size: 15px; max-width: 460px; }
.auth-hero .feature-list { display: grid; gap: 12px; margin-top: 8px; }
.auth-hero .feature { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: #dbeafe; }
.auth-hero .feature b { color: #fff; display: block; font-size: 14px; }
.auth-hero .dot {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255, 255, 255, .16); display: grid; place-items: center;
  font-size: 11px; font-weight: 700; margin-top: 1px;
}

.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h2 { margin: 0 0 4px; font-size: 22px; }
.auth-box .sub { margin: 0 0 24px; color: var(--text-muted); font-size: 14px; }
.auth-switch { margin-top: 16px; text-align: center; font-size: 14px; color: var(--text-muted); }
.auth-switch button {
  background: none; border: none; color: var(--primary); font-weight: 600;
  font-size: 14px; cursor: pointer; font-family: inherit; padding: 0;
}

/* 验证码输入框 + 「获取验证码」按钮 */
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; }
.code-row .btn { flex: none; white-space: nowrap; }

/* 验证码提示条：演示模式下直接把验证码显示在这里 */
.hint.demo {
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--warn-soft); border: 1px solid #fef3c7; color: var(--warn);
  font-size: 13px;
}

/* 登录表单下方的次要入口（忘记密码？） */
.auth-links { margin-top: 12px; text-align: right; }
.auth-links button {
  background: none; border: none; color: var(--primary); font-weight: 600;
  font-size: 13.5px; cursor: pointer; font-family: inherit; padding: 0;
}

/* ------------------------------------------------------------------ 聊天页 */
.chat-layout { display: grid; grid-template-columns: 260px 1fr; height: calc(100vh - 60px); }
@media (max-width: 900px) { .chat-layout { grid-template-columns: 1fr; } .sidebar { display: none; } }

.sidebar {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar h3 { margin: 0; font-size: 12px; color: var(--text-soft); letter-spacing: .5px; text-transform: uppercase; }
.session-item {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 9px 11px; border-radius: var(--radius-sm);
  font-size: 13.5px; color: var(--text-muted); cursor: pointer;
  border: 1px solid transparent;
}
.session-item:hover { background: var(--surface-2); }
.session-item.active { background: var(--primary-soft); color: var(--primary-dark); border-color: #dbeafe; font-weight: 600; }
.session-item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .del { opacity: 0; color: var(--text-soft); font-size: 15px; line-height: 1; }
.session-item:hover .del { opacity: 1; }
.session-item .del:hover { color: var(--danger); }

.chat-main { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.messages { flex: 1; overflow-y: auto; padding: 24px; scroll-behavior: smooth; }
.messages-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

.msg { display: flex; gap: 12px; }
.msg .who {
  flex: none; display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 9px;
  font-size: 12px; font-weight: 700; color: #fff;
}
.msg.user .who { background: #0f172a; }
.msg.assistant .who { background: linear-gradient(135deg, #2563eb, #7c3aed); }
.msg .bubble { flex: 1; min-width: 0; }
.msg .content {
  padding: 12px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  font-size: 14.5px; line-height: 1.75; white-space: pre-wrap; word-break: break-word;
}
.msg.user .content { background: var(--primary-soft); border-color: #dbeafe; }
.msg .content p { margin: 0 0 10px; }
.msg .content p:last-child { margin-bottom: 0; }
.msg .content code {
  padding: 1.5px 5px; border-radius: 4px; background: #f1f5f9;
  font-family: var(--mono); font-size: 13px; color: #b91c1c;
}
.msg .content pre {
  margin: 10px 0; padding: 12px 14px; overflow-x: auto;
  background: #0f172a; color: #e2e8f0; border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
}
.msg .content pre code { background: none; color: inherit; padding: 0; }
.msg .content strong { font-weight: 700; }
/* 答案的四个小节标题（## 答案 / ## 解析 / 易错点和知识点 / 相关例题） */
.msg .content .md-h {
  font-weight: 700; font-size: 15px; color: var(--text);
  margin: 14px 0 6px; padding-left: 8px; border-left: 3px solid var(--primary);
}
.msg .content .md-h:first-child { margin-top: 0; }
/* 答案里的 Markdown 表格（题干对照表、LRU 模拟表等） */
.msg .content table { margin: 8px 0; font-size: 13px; }
.msg .content th, .msg .content td { padding: 6px 8px; white-space: normal; }
.msg .content th { white-space: nowrap; }

.cite-ref {
  display: inline-block; padding: 0 5px; margin: 0 1px;
  border-radius: 5px; background: var(--primary-soft); color: var(--primary-dark);
  font-size: 12px; font-weight: 700; vertical-align: 1px; cursor: pointer;
  border: 1px solid #dbeafe;
}
.cite-ref:hover { background: #dbeafe; }

.meta-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 8px; font-size: 12px; color: var(--text-soft);
}
.citations { margin-top: 10px; display: grid; gap: 8px; }
.citation {
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
}
.citation .head { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-bottom: 5px; }
.citation .no {
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 6px;
  background: var(--primary); color: #fff; font-size: 11px; font-weight: 700;
}
.citation .snippet { color: var(--text); line-height: 1.6; }
.citation details summary { cursor: pointer; color: var(--primary); font-size: 12.5px; margin-top: 6px; }
.citation pre {
  margin: 8px 0 0; padding: 10px; background: #fff; border: 1px solid var(--border);
  border-radius: 6px; white-space: pre-wrap; font-family: inherit; font-size: 13px;
  max-height: 260px; overflow-y: auto; color: var(--text-muted);
}

.composer { border-top: 1px solid var(--border); background: var(--surface); padding: 14px 24px 18px; }
.composer-inner { max-width: 820px; margin: 0 auto; }
.composer .row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { min-height: 52px; max-height: 180px; }
.composer .options { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-top: 10px; }
.composer .tip { color: var(--text-soft); font-size: 12px; margin-left: auto; }
/* ---------------------------------------------------------- 问答附件 */
.btn.attach-btn {
  padding: 8px 11px; font-size: 15px; line-height: 1.2;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.btn.attach-btn:hover { border-color: var(--primary); color: var(--primary); }
/* ---------------------------------------------------------- 语音提问 */
.btn.mic-btn {
  padding: 8px 11px; font-size: 15px; line-height: 1.2;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.btn.mic-btn:hover { border-color: var(--primary); color: var(--primary); }
/* 录音中：按钮转红并呼吸，让考生一眼看出"还在录" */
.btn.mic-btn.recording {
  background: var(--danger); border-color: var(--danger); color: #fff;
  animation: micpulse 1.4s ease-in-out infinite;
}
.btn.mic-btn.busy { opacity: .65; cursor: progress; }
@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .45); }
  50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}
.record-chip {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding: 6px 10px;
  background: #fef2f2; border: 1px solid #fecaca; color: var(--danger);
  border-radius: 8px; font-size: 13px;
}
.record-chip .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
  animation: micpulse 1.4s ease-in-out infinite;
}
.attach-chip {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding: 6px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
.attach-chip .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .rm { cursor: pointer; color: var(--text-muted); font-size: 16px; line-height: 1; }
.attach-chip .rm:hover { color: var(--danger); }
.composer.dragging .composer-inner { outline: 2px dashed var(--primary); outline-offset: 4px; border-radius: 8px; }
.user-attach { font-size: 12.5px; color: var(--text-soft); margin-bottom: 4px; }
.continue-btn {
  margin-top: 10px; padding: 7px 12px; font-size: 13px;
  background: var(--primary-soft); color: var(--primary); border: 1px solid #dbeafe;
}
.continue-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 答案末尾的"下一步建议"：追问做成可点击的按钮，点一下就能接着问 */
.followups { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.followups:empty { display: none; }
.followups .hint { width: 100%; font-size: 12.5px; color: var(--text-soft); }
.followups .followup {
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; text-align: left;
  background: var(--primary-soft); color: var(--primary); border: 1px solid #dbeafe;
}
.followups .followup:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.empty-state { display: grid; place-items: center; height: 100%; text-align: center; color: var(--text-soft); }
.empty-state h2 { color: var(--text); margin: 0 0 8px; font-size: 20px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; max-width: 620px; }
.suggestion {
  padding: 8px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
}
.suggestion:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-soft); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ------------------------------------------------------------------ 上传 */
.dropzone {
  display: grid; place-items: center; gap: 6px;
  padding: 28px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text-muted); transition: .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.dropzone .big { font-size: 26px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .3s; }

/* ------------------------------------------------------------------ 提示 */
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 999; display: grid; gap: 10px; }
.toast {
  min-width: 240px; max-width: 380px; padding: 12px 15px;
  border-radius: var(--radius-sm); font-size: 14px; color: #fff;
  background: #0f172a; box-shadow: var(--shadow-lg); animation: slidein .2s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warn); }
@keyframes slidein { from { opacity: 0; transform: translateY(10px); } }

.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.flex-wrap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.spin {
  display: inline-block;
  width: 14px; height: 14px; border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
