.hidden { display: none !important; }

:root {
  --bg: #16151c;
  --bg-panel: #1e1d26;
  --bg-bubble-user: #3a6ea5;
  --bg-bubble-ai: #262532;
  --text: #e8e6f0;
  --text-dim: #9a97a8;
  --accent: #b8925a;
  --accent-soft: rgba(184, 146, 90, .18);
  --border: #323140;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  height: 100vh;
  overflow: hidden;
}

.app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Header ---------- */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 18px; font-weight: 700; letter-spacing: 2px; }
.logo .sub { font-size: 12px; color: var(--accent); margin-left: 8px; font-weight: 400; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.ai-switch {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-dim); cursor: pointer;
}
.ai-switch input { accent-color: var(--accent); }

.icon-btn {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px;
  width: 34px; height: 34px; font-size: 16px; cursor: pointer;
  transition: all .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Messages（对话列整体居中） ---------- */
.messages {
  flex: 1; overflow-y: auto;
  padding: 24px 16px;
  scroll-behavior: smooth;
  display: flex; flex-direction: column; align-items: center;
}
.msg { display: flex; margin-bottom: 18px; width: 100%; max-width: 840px; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }
.msg .bubble {
  max-width: 780px;
  padding: 14px 18px;
  border-radius: 14px;
  line-height: 1.75;
  font-size: 14.5px;
}
.msg.user .bubble { background: var(--bg-bubble-user); border-bottom-right-radius: 4px; }
.msg.assistant .bubble {
  background: var(--bg-bubble-ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.welcome .bubble { max-width: 720px; }
.msg.welcome h2 { margin-bottom: 10px; color: var(--accent); }
.msg.welcome ul { margin: 8px 0 8px 20px; }
.msg.welcome .example { cursor: pointer; }
.msg.welcome .example:hover code { color: var(--accent); }
.muted { color: var(--text-dim); font-size: 13px; margin-top: 8px; }

/* markdown */
.bubble h1, .bubble h2, .bubble h3 { margin: 14px 0 8px; }
.bubble h2 { font-size: 18px; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.bubble h3 { font-size: 15.5px; color: var(--accent); }
.bubble p { margin: 6px 0; }
.bubble ul { margin: 6px 0 6px 20px; }
.bubble code {
  background: rgba(255,255,255,.08);
  padding: 1px 6px; border-radius: 4px; font-size: 13px;
}
.bubble blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 12px; margin: 8px 0;
  color: var(--text-dim); background: var(--accent-soft);
  border-radius: 0 8px 8px 0; font-size: 13px;
}
.bubble table {
  border-collapse: collapse; margin: 10px 0; width: 100%;
  font-size: 13.5px;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px; text-align: center;
}
.bubble th { background: rgba(184,146,90,.12); color: var(--accent); }
.bubble tr td:first-child, .bubble tr th:first-child { white-space: nowrap; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

.cursor { display: inline-block; width: 8px; height: 16px; background: var(--accent);
  vertical-align: text-bottom; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Input（与消息列同宽居中，背景通栏） ---------- */
.input-bar {
  display: flex; gap: 10px;
  /* 左右内边距把内容挤到中央 872px 列内（视口窄时回退 16px） */
  padding: 14px max(16px, calc((100% - 872px) / 2));
  background: var(--bg-panel); border-top: 1px solid var(--border);
}
#input {
  flex: 1; resize: none; max-height: 140px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: 14.5px; font-family: inherit;
  outline: none; transition: border .15s;
}
#input:focus { border-color: var(--accent); }
#btnSend {
  background: var(--accent); color: #1a1a1a; border: none;
  border-radius: 12px; padding: 0 24px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
}
#btnSend:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  width: 460px; max-width: 92vw;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-body label { display: block; font-size: 13px; color: var(--text-dim); margin: 12px 0 6px; }
.modal-body select, .modal-body input {
  width: 100%; padding: 10px 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; outline: none;
}
.modal-body select:focus, .modal-body input:focus { border-color: var(--accent); }
.primary-btn {
  margin-top: 14px; width: 100%;
  background: var(--accent); color: #1a1a1a; border: none;
  border-radius: 8px; padding: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
}

/* ---------- 历史会话列表 ---------- */
.history-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 2px; margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-dim);
}
.history-toolbar .chat-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.history-toolbar .chat-toggle input { accent-color: var(--accent); }
.history-toolbar .toolbar-actions { display: flex; gap: 12px; }
.history-toolbar .h-act { cursor: pointer; transition: color .15s; }
.history-toolbar .h-act:hover { color: var(--accent); }
.history-toolbar .h-act.danger:hover { color: #e06c6c; }
.history-list { max-height: 52vh; overflow-y: auto; }
.history-item {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 8px; cursor: pointer; transition: border .15s;
}
.history-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.history-item .h-title { font-size: 14px; margin-bottom: 4px; }
.history-item .h-tag {
  font-size: 12.5px; color: var(--accent); margin-bottom: 4px;
  font-family: "KaiTi", "STKaiti", serif; letter-spacing: 1px;
}
.history-item .h-meta { font-size: 12px; color: var(--text-dim); display: flex; gap: 10px; align-items: center; }
.history-item .h-actions { margin-left: auto; display: flex; gap: 12px; }
.history-item .h-act { cursor: pointer; transition: color .15s; }
.history-item .h-act:hover { color: var(--accent); }
.history-item .h-del:hover { color: #e06c6c; }
.history-item.active { border-color: var(--accent); }
.history-empty { text-align: center; color: var(--text-dim); padding: 24px 0; }

/* ---------- 报告全屏视图 ---------- */
.report-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; background: var(--bg);
}
.report-overlay.hidden { display: none; }
.report-toc {
  width: 220px; flex: 0 0 220px;
  background: var(--bg-panel); border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column;
}
.toc-head { font-size: 12px; color: var(--text-dim); letter-spacing: 2px; margin-bottom: 12px; }
.toc-list { flex: 1; overflow-y: auto; }
.toc-item {
  padding: 7px 10px; font-size: 13px; color: var(--text-dim);
  border-radius: 8px; cursor: pointer; margin-bottom: 2px;
}
.toc-item:hover { color: var(--text); background: rgba(184,146,90,.12); }
.toc-item.active { color: var(--accent); background: var(--accent-soft); }
.toc-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.toc-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; cursor: pointer; transition: all .15s;
}
.toc-btn:hover { color: var(--accent); border-color: var(--accent); }
.report-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.report-topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-panel); font-size: 15px; font-weight: 600;
}
.report-paper {
  flex: 1; overflow-y: auto;
  padding: 28px max(20px, calc((100% - 860px) / 2));
  line-height: 1.85; font-size: 14.5px;
}
.report-paper section { margin-bottom: 28px; }
.report-paper h1 {
  font-size: 24px; color: var(--accent);
  border-bottom: 2px solid var(--accent); padding-bottom: 10px; margin-bottom: 8px;
}
.report-paper h2 {
  font-size: 18px; color: var(--accent);
  border-bottom: 1px solid var(--border); padding-bottom: 6px; margin: 22px 0 10px;
}
.report-paper h3 { font-size: 15.5px; color: var(--accent); margin: 14px 0 6px; }
.report-paper p { margin: 7px 0; }
.report-paper ul { margin: 6px 0 6px 20px; }
.report-paper code { background: rgba(255,255,255,.08); padding: 1px 6px; border-radius: 4px; }
.report-paper blockquote {
  border-left: 3px solid var(--accent); padding: 4px 12px; margin: 8px 0;
  color: var(--text-dim); background: var(--accent-soft);
  border-radius: 0 8px 8px 0; font-size: 13px;
}
.report-paper table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13.5px; }
.report-paper th, .report-paper td { border: 1px solid var(--border); padding: 6px 10px; text-align: center; }
.report-paper th { background: rgba(184,146,90,.12); color: var(--accent); }
.report-paper hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

@media print {
  body { overflow: visible; background: #fff; color: #222; }
  .app, .report-toc, .report-topbar { display: none !important; }
  .report-overlay { position: static; display: block; background: #fff; }
  .report-paper { overflow: visible; padding: 0; color: #222; }
  .report-paper section { page-break-inside: avoid; }
  .report-paper h1, .report-paper h2, .report-paper h3 { color: #7a5c28; }
  .report-paper th { background: #f5efe3; color: #7a5c28; }
  .report-paper th, .report-paper td { border-color: #bbb; }
  .report-paper blockquote { background: #f7f3ea; color: #555; }
}

/* scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ---------- P1/P2 增补 ---------- */
.chips { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0 4px; }
.chip {
  border: 1px solid var(--accent); color: var(--accent);
  border-radius: 20px; padding: 5px 12px; font-size: 13px;
  cursor: pointer; transition: all .15s;
}
.chip:hover { background: var(--accent-soft); }

#toast {
  position: fixed; bottom: 92px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #2b2a36; color: var(--text);
  border: 1px solid var(--accent);
  padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; pointer-events: none;
  transition: all .25s; z-index: 400; max-width: 86vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.toc-toggle { display: none; }
.toc-item.generating { color: var(--accent); }
.toc-item.generating::before { content: "◌ "; }
.toc-item.done::before { content: "✓ "; color: var(--accent); }
.history-filter {
  width: 100%; padding: 8px 10px; margin-bottom: 8px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; outline: none;
}
.history-filter:focus { border-color: var(--accent); }
.settings-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.leap-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); cursor: pointer; }
.leap-line input { width: auto; accent-color: var(--accent); }
.leap-line.hidden { display: none; }

/* ---------- 账号认证 ---------- */
.auth-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-overlay.hidden { display: none; }
.auth-card {
  width: 380px; max-width: 94vw;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 26px;
}
.auth-logo { text-align: center; font-size: 22px; font-weight: 700; letter-spacing: 3px; color: var(--accent); margin-bottom: 18px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tab {
  flex: 1; padding: 9px; border: 1px solid var(--border);
  background: transparent; color: var(--text-dim);
  border-radius: 10px; font-size: 14px; cursor: pointer;
}
.auth-tab.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.auth-body label { display: block; font-size: 12.5px; color: var(--text-dim); margin: 10px 0 5px; }
.auth-body input {
  width: 100%; padding: 10px 12px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none;
}
.auth-body input:focus { border-color: var(--accent); }
.auth-msg { min-height: 18px; font-size: 12.5px; color: #e8b96a; margin: 8px 0; }
.auth-note { text-align: center; font-size: 12px; color: var(--text-dim); margin-top: 14px; }

.user-area { display: flex; align-items: center; gap: 8px; margin-left: auto; margin-right: 8px; font-size: 13px; }
.user-phone { color: var(--text-dim); }
.role-tag { color: var(--accent); font-size: 12px; border: 1px solid var(--accent); border-radius: 8px; padding: 0 6px; }
.admin-link { color: var(--accent); font-size: 13px; text-decoration: none; }
.admin-link:hover { text-decoration: underline; }

/* ---------- 移动端响应式（≤768px） ---------- */
@media (max-width: 768px) {
  .header { padding: 10px 12px; gap: 8px; }
  .logo { font-size: 16px; letter-spacing: 1px; }
  .logo .sub { display: none; }
  .ai-switch span { display: none; }
  .header-actions { gap: 6px; }
  .icon-btn { width: 32px; height: 32px; font-size: 14px; }

  .messages { padding: 14px 8px; }
  .msg { max-width: 100%; }
  .msg .bubble { max-width: 100%; padding: 12px 13px; font-size: 14px; }
  .msg.welcome .bubble { max-width: 100%; }
  .bubble table { display: block; overflow-x: auto; }
  .bubble th, .bubble td { padding: 5px 8px; font-size: 12.5px; }

  .input-bar { padding: 10px 12px; }
  #input { font-size: 14px; padding: 10px 12px; }
  #btnSend { padding: 0 16px; }

  .modal-box { padding: 16px; }
  .history-toolbar { flex-wrap: wrap; gap: 8px; }
  .history-item .h-actions { margin-left: 0; flex-wrap: wrap; gap: 8px; }

  /* 报告目录改为抽屉 */
  .report-toc {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 210;
    width: 240px; transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 0 0 30px rgba(0,0,0,.55);
  }
  .report-toc.open { transform: none; }
  .toc-toggle { display: inline-flex; }
  .report-paper { padding: 18px 14px; }
  .report-paper table { display: block; overflow-x: auto; }
}

/* ---------- 管理后台·模型配置 ---------- */
.model-config { display: block; }
.mc-title { font-size: 14px; font-weight: 600; color: var(--accent); margin-bottom: 10px; }
.mc-grid { display: flex; gap: 12px; flex-wrap: wrap; }
.mc-grid > div { flex: 1; min-width: 180px; }
.mc-grid label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.mc-grid input, .mc-grid select {
  width: 100%; box-sizing: border-box; padding: 8px 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font-size: 13px; outline: none;
}
.mc-grid input:focus, .mc-grid select:focus { border-color: var(--accent); }
