/* ============================================================
   Academic Web — 优雅学术风格样式
   设计基调：纸张白 + 墨黑 + 学术蓝点缀，衬线标题，圆角卡片
   ============================================================ */

:root {
  --bg: #f7f6f3;
  --bg-paper: #ffffff;
  --ink: #1f2328;
  --ink-soft: #5a6068;
  --ink-faint: #9aa0a8;
  --accent: #2f5fe0;
  --accent-soft: #e8effc;
  --border: #e6e4de;
  --danger: #c0392b;
  --success: #1e8e5a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(30, 30, 30, 0.06), 0 4px 14px rgba(30, 30, 30, 0.05);
  --font-serif: "Noto Serif SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------------- 侧边栏 ---------------- */
#sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-paper);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-icon { font-size: 22px; }
.brand-name {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.feature-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 14px; }

.feature-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14.5px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.feature-btn:hover { background: var(--bg); color: var(--ink); }
.feature-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.feature-btn .icon { width: 20px; text-align: center; }

/* 新会话按钮（本站对外公开，不展示历史会话列表） */
.new-chat-section {
  flex: 1;
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.new-chat-btn {
  width: 100%;
  border: 1px dashed var(--border);
  background: transparent;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.new-chat-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 10px;
  font-size: 12.5px;
  text-align: center;
}
.sidebar-footer a { color: var(--ink-faint); text-decoration: none; }
.sidebar-footer a:hover { color: var(--accent); }

/* ---------------- 主区域 ---------------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--bg-paper);
  border-bottom: 1px solid var(--border);
}

.model-selector { display: flex; align-items: center; gap: 8px; }
.model-selector label { font-size: 13px; color: var(--ink-faint); }
.model-selector select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 13.5px;
  cursor: pointer;
  outline: none;
  max-width: 320px;
}
.model-selector select:focus { border-color: var(--accent); }

.endpoint-badge {
  font-size: 12px;
  color: var(--ink-faint);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-mono);
}

/* ---------------- 视图通用 ---------------- */
.view { flex: 1; display: none; flex-direction: column; min-height: 0; }
.view.active { display: flex; }

/* ---------------- 对话视图 ---------------- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px clamp(16px, 8vw, 120px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg { display: flex; gap: 12px; max-width: 100%; }
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  background: var(--bg-paper);
  border: 1px solid var(--border);
}
.msg.user .msg-avatar { background: var(--accent-soft); border-color: transparent; }
.msg-body {
  flex: 1;
  min-width: 0;
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.msg.user .msg-body { background: #f2f6ff; border-color: #dbe7fd; }
.msg-meta { font-size: 12px; color: var(--ink-faint); margin-bottom: 6px; display: flex; gap: 10px; }
.msg-content { word-wrap: break-word; }
.msg-content p { margin: 0.5em 0; }
.msg-content p:first-child { margin-top: 0; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content pre {
  background: #282c34;
  color: #e6e6e6;
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}
.msg-content code {
  font-family: var(--font-mono);
  background: rgba(120, 120, 120, 0.12);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}
.msg-content pre code { background: none; padding: 0; }
.msg-content table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 13.5px; }
.msg-content th, .msg-content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg-content th { background: var(--bg); }
.msg-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 4px 14px;
  color: var(--ink-soft);
  background: var(--bg);
  border-radius: 0 8px 8px 0;
}
.msg-content ul, .msg-content ol { padding-left: 22px; margin: 6px 0; }
.msg-content h1, .msg-content h2, .msg-content h3 { font-family: var(--font-serif); margin: 14px 0 8px; }

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

/* 输入区 */
.chat-input-area {
  padding: 14px clamp(16px, 8vw, 120px) 18px;
  background: var(--bg-paper);
  border-top: 1px solid var(--border);
}
.chat-input-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  transition: border-color 0.15s;
}
.chat-input-box:focus-within { border-color: var(--accent); }
.chat-input-box textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  max-height: 180px;
  color: var(--ink);
}
.btn-send {
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14.5px;
  padding: 8px 18px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-send:hover { opacity: 0.88; }
.btn-send:disabled { background: var(--ink-faint); cursor: not-allowed; }
.chat-input-hint { font-size: 12px; color: var(--ink-faint); margin-top: 6px; padding-left: 4px; }

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  gap: 10px;
}
.chat-empty .big { font-size: 44px; }
.chat-empty .title { font-family: var(--font-serif); font-size: 22px; color: var(--ink-soft); }

/* ---------------- 任务视图（润色/翻译） ---------------- */
.task-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px clamp(16px, 6vw, 80px);
}
.task-card {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.task-title {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}
.task-desc { font-size: 13px; color: var(--ink-faint); margin-bottom: 14px; }

.task-options { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.seg-group { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.seg-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.seg-btn.active { background: var(--bg-paper); color: var(--accent); font-weight: 600; box-shadow: var(--shadow); }

.task-textarea {
  width: 100%;
  min-height: 160px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  background: var(--bg);
  color: var(--ink);
}
.task-textarea:focus { border-color: var(--accent); background: var(--bg-paper); }

.task-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.btn-primary {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14.5px;
  padding: 9px 22px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { background: var(--ink-faint); cursor: not-allowed; }
.btn-ghost {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-paper);
  color: var(--ink-soft);
  font-size: 13.5px;
  padding: 8px 16px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); }

.task-result {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.task-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.task-result-title { font-family: var(--font-serif); font-size: 16px; font-weight: 700; }
.task-result-body { min-height: 60px; }
.task-result-placeholder { color: var(--ink-faint); font-size: 13.5px; }

/* ---------------- PDF 翻译视图 ---------------- */
.arxiv-input-row { display: flex; gap: 10px; margin-bottom: 4px; }
.arxiv-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font-mono);
  outline: none;
  background: var(--bg);
  color: var(--ink);
}
.arxiv-input:focus { border-color: var(--accent); background: var(--bg-paper); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 12px;
  color: var(--ink-faint);
  font-size: 12.5px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--border);
}

.pdf-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-faint);
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg);
}
.pdf-drop:hover, .pdf-drop.dragover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.pdf-drop .big { font-size: 40px; margin-bottom: 8px; }
.pdf-file-info {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-top: 14px;
}
.pdf-file-info .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-file-info .size { color: var(--ink-faint); font-size: 13px; }

.pdf-log {
  background: #282c34;
  color: #c8d0e0;
  border-radius: 10px;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 14px;
}
.pdf-log .log-line { margin: 1px 0; }
.pdf-log .log-line.err { color: #ff7b72; }
.pdf-log .log-line.ok { color: #7ee787; }

.pdf-results { display: flex; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.pdf-download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  background: var(--bg-paper);
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s;
}
.pdf-download:hover { border-color: var(--accent); color: var(--accent); box-shadow: var(--shadow); }
.pdf-download .kind {
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 4px;
  padding: 1px 6px;
}

/* 状态提示 */
.status-line { font-size: 13px; margin-top: 10px; }
.status-line.ok { color: var(--success); }
.status-line.err { color: var(--danger); }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d4d1ca; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #b8b5ae; }
::-webkit-scrollbar-track { background: transparent; }

/* 移动端适配 */
@media (max-width: 768px) {
  #sidebar { width: 64px; padding: 14px 6px; }
  .brand-name, .feature-btn span:not(.icon), .new-chat-section, .sidebar-footer { display: none; }
  .feature-btn { justify-content: center; padding: 10px; }
  .chat-messages, .chat-input-area, .task-container { padding-left: 12px; padding-right: 12px; }
}
