/* ============ 基础 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --side: #1e2a38;
  --side-text: #c9d4e0;
  --accent: #2f6fed;
  --accent-weak: #e8f0fe;
  --user-bubble: #2f6fed;
  --bot-bubble: #ffffff;
  --text: #26303b;
  --muted: #8a94a1;
  --border: #e4e8ee;
  --radius: 12px;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.layout { display: flex; height: 100vh; overflow: hidden; }

/* ============ 侧边栏 ============ */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--side);
  color: var(--side-text);
  display: flex; flex-direction: column;
  padding: 18px 14px;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; }
.logo img { width: 38px; height: 38px; border-radius: 9px; }
.logo b { display: block; color: #fff; font-size: 16px; }
.logo small { font-size: 11px; color: #7d8ea1; }

.agent-nav { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.agent-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  cursor: default; transition: background .2s;
  position: relative;
}
.agent-item.active { background: rgba(255,255,255,.08); }
.agent-item img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.agent-meta b { display: block; font-size: 13px; color: #e8eef5; }
.agent-meta small { font-size: 11px; color: #7d8ea1; }
.agent-item .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #3a4a5c; margin-left: auto; transition: all .2s;
}
.agent-item.active .dot { background: #4ade80; box-shadow: 0 0 6px #4ade80; }

.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; display: flex; align-items: center; gap: 8px; }
.whoami { font-size: 12px; color: #7d8ea1; overflow: hidden; text-overflow: ellipsis; }

/* ============ 主区 ============ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 48px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px;
  font-size: 13px; color: var(--muted);
}

.chat-list { flex: 1; overflow-y: auto; padding: 24px 8%; }
.welcome { text-align: center; padding: 60px 0 20px; color: var(--muted); }
.welcome img { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 14px; }
.welcome h2 { color: var(--text); margin-bottom: 10px; }
.welcome p { max-width: 520px; margin: 0 auto 18px; line-height: 1.7; font-size: 14px; }
.tips { display: flex; flex-direction: column; gap: 8px; }
.tips span {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font-size: 13px; cursor: pointer; transition: all .15s;
}
.tips span:hover { border-color: var(--accent); color: var(--accent); }

/* ============ 消息气泡 ============ */
.msg { display: flex; gap: 10px; margin-bottom: 20px; }
.msg .avatar { width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0; }
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.msg .bubble {
  max-width: 76%; padding: 12px 16px; border-radius: var(--radius);
  line-height: 1.75; word-break: break-word;
}
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-top-right-radius: 4px; }
.msg.bot .bubble { background: var(--bot-bubble); border: 1px solid var(--border); border-top-left-radius: 4px; }

.bubble .md p { margin: 0 0 8px; }
.bubble .md p:last-child { margin-bottom: 0; }
.bubble .md strong { font-weight: 600; }
.bubble .md code { background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.bubble .md ul { margin: 4px 0 8px 18px; }

/* 引用角标 */
sup.ref {
  display: inline-block; min-width: 16px; text-align: center;
  background: var(--accent-weak); color: var(--accent);
  border-radius: 4px; font-size: 11px; padding: 0 3px; margin: 0 2px;
  cursor: pointer; user-select: none;
}
sup.ref:hover { background: var(--accent); color: #fff; }

/* 教师卡片 */
.teacher-card {
  background: linear-gradient(135deg, #fff8ec, #fdf2dd);
  border: 1px solid #f3e2bd; border-left: 4px solid #eab308;
  border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; font-size: 14px;
}
.teacher-card .md p { margin-bottom: 2px; }

/* 课程表格 */
.course-table-wrap { overflow-x: auto; margin: 8px 0; }
table.course-table { border-collapse: collapse; width: 100%; font-size: 13px; }
table.course-table th, table.course-table td {
  border: 1px solid var(--border); padding: 7px 10px; text-align: left; white-space: nowrap;
}
table.course-table th { background: #f7f9fb; }
table.course-table a { color: var(--accent); text-decoration: none; }

/* 检索上下文面板 */
.contexts-panel { margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 8px; }
.contexts-panel summary {
  cursor: pointer; font-size: 12px; color: var(--muted); user-select: none;
}
.contexts-list { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.context-item {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; color: #55606c; line-height: 1.6;
}
.context-item .ctx-src { display: block; color: var(--accent); margin-top: 3px; word-break: break-all; }

/* 点赞点踩 */
.thumbs { margin-top: 10px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.thumbs button {
  border: 1px solid var(--border); background: #fff; border-radius: 6px;
  padding: 2px 8px; cursor: pointer; font-size: 13px;
}
.thumbs button.selected { border-color: var(--accent); background: var(--accent-weak); }

/* ============ 输入区 ============ */
.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 14px 8% 18px; background: var(--bg);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 14px; font-size: 15px; font-family: inherit; line-height: 1.5;
  max-height: 140px; outline: none; background: #fff;
}
.composer textarea:focus { border-color: var(--accent); }

.btn { border: none; border-radius: 10px; padding: 10px 18px; font-size: 14px; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:disabled { background: #a5c1f5; cursor: not-allowed; }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.25); color: var(--side-text); }

/* ============ 弹窗 ============ */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,32,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
  background: #fff; border-radius: 14px; padding: 24px; width: 320px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-card h3 { margin-bottom: 2px; }
.modal-card label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.modal-card input {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none;
}
.modal-card input:focus { border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions .ghost { border-color: var(--border); color: var(--muted); }
.modal-tip { font-size: 12px; color: var(--muted); }

/* 流式光标 */
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ============ 响应式 ============ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .chat-list, .composer { padding-left: 12px; padding-right: 12px; }
  .msg .bubble { max-width: 90%; }
}
