/* ═══════════════════════════════════════════════════════════
   Eptss 技术监督知识问答 — 样式（仿 DeepSeek：简洁、克制、留白）
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-elev: #ffffff;
  --text: #191c20;
  --text-2: #6b7280;
  --text-3: #9aa1ab;
  --border: rgba(0, 0, 0, .08);
  --border-strong: rgba(0, 0, 0, .14);
  --accent: #4d6bfe;
  --accent-soft: rgba(77, 107, 254, .09);
  --accent-text: #3a55d9;
  --bubble: #f1f3f9;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 20px rgba(0, 0, 0, .06);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
  --radius: 14px;
  --maxw: 780px;
  --topbar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #16181d;
  --bg-soft: #1e2026;
  --bg-elev: #22252c;
  --text: #e9ebef;
  --text-2: #9ba2ae;
  --text-3: #6d7480;
  --border: rgba(255, 255, 255, .09);
  --border-strong: rgba(255, 255, 255, .16);
  --accent: #6b85ff;
  --accent-soft: rgba(107, 133, 255, .14);
  --accent-text: #a3b4ff;
  --bubble: #262a32;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
}

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

html { height: 100%; }

html, body { min-height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  transition: background .25s ease, color .25s ease;
}

::selection { background: var(--accent-soft); }

/* ───────────────────────── 顶栏 ───────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1080px; height: 100%; margin: 0 auto;
  padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-logo {
  width: 38px; height: 48px; object-fit: contain; flex: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .08));
}

.brand-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }

.brand-name {
  font-size: 15px; font-weight: 500; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.brand-sub { font-size: 11.5px; color: var(--text-3); white-space: nowrap; }

.topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-2);
  padding: 5px 10px 5px 8px; border-radius: 999px;
  background: var(--bg-soft); border: 1px solid var(--border);
}

.status-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: var(--text-3); transition: background .2s;
}
.status-dot.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .16); }
.status-dot.degraded { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .16); }
.status-dot.err { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, .16); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-soft);
  color: var(--text-2); cursor: pointer; transition: all .16s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); transform: translateY(-1px); }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ───────────────────────── 主区 ───────────────────────── */

.main {
  flex: 1; display: flex; flex-direction: column;
  width: 100%; max-width: 1080px; margin: 0 auto;
  padding: 0 20px;
}

/* ── 欢迎页 ── */

.welcome {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 40px 0 24px; gap: 18px;
}

.welcome-title {
  font-size: clamp(22px, 4vw, 32px); font-weight: 500;
  letter-spacing: .4px; line-height: 1.4;
  background: linear-gradient(100deg, var(--text) 30%, var(--accent-text));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-sub {
  font-size: 14px; color: var(--text-2); max-width: 520px; line-height: 1.7;
}

.suggestions {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px; width: 100%; max-width: 560px; margin-top: 10px;
}

.chip {
  font-family: inherit; font-size: 13px; color: var(--text-2);
  text-align: left; padding: 13px 15px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-elev);
  cursor: pointer; transition: all .16s; line-height: 1.5;
  box-shadow: var(--shadow-sm);
}
.chip:hover {
  color: var(--text); border-color: var(--accent);
  background: var(--accent-soft); transform: translateY(-1px);
  box-shadow: var(--shadow);
}

/* ── 消息流 ── */

.thread {
  width: 100%; max-width: var(--maxw); margin: 0 auto;
  padding: 26px 0 20px;
  display: flex; flex-direction: column; gap: 26px;
}

.msg { display: flex; flex-direction: column; gap: 8px; animation: rise .28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); }

.avatar {
  width: 22px; height: 22px; border-radius: 6px; object-fit: contain;
  background: var(--bg-soft); padding: 2px; border: 1px solid var(--border); flex: none;
}

/* 用户消息 */
.msg-user { align-items: flex-end; }
.msg-user .msg-head { flex-direction: row-reverse; }
.msg-user .bubble {
  max-width: 86%; padding: 11px 16px; border-radius: 18px 18px 4px 18px;
  background: var(--bubble); border: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word; font-size: 15px; line-height: 1.7;
}

/* 助手消息 */
.msg-ai .body { width: 100%; min-width: 0; }

/* ── 推理过程 ── */

.think {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-soft); overflow: hidden; margin-bottom: 12px;
}
.think > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 13px; font-size: 13px; color: var(--text-2);
  transition: color .15s, background .15s;
}
.think > summary::-webkit-details-marker { display: none; }
.think > summary:hover { color: var(--text); background: var(--accent-soft); }
.think-ico {
  width: 15px; height: 15px; flex: none; color: var(--accent);
  transition: transform .22s ease;
}
.think[open] .think-ico { transform: rotate(90deg); }
.think-label { font-weight: 500; }
.think-meta { margin-left: auto; font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.think-content {
  padding: 2px 15px 14px; font-size: 13.5px; line-height: 1.8;
  color: var(--text-2); white-space: pre-wrap; word-break: break-word;
  border-top: 1px solid var(--border); padding-top: 12px;
}

/* ── 正文（markdown） ── */

.md { font-size: 15px; line-height: 1.85; word-break: break-word; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 {
  font-weight: 600; line-height: 1.5; margin: 20px 0 10px;
}
.md h1 { font-size: 1.3em; } .md h2 { font-size: 1.18em; }
.md h3 { font-size: 1.08em; } .md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 1.5em; }
.md li { margin: 4px 0; }
.md li > p { margin: 0; }
.md a { color: var(--accent-text); text-decoration: none; border-bottom: 1px solid transparent; }
.md a:hover { border-bottom-color: currentColor; }
.md strong { font-weight: 600; }
.md blockquote {
  margin: 12px 0; padding: 2px 0 2px 14px;
  border-left: 3px solid var(--accent); color: var(--text-2);
}
.md code {
  font-family: var(--mono); font-size: .88em;
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 5px;
}
.md pre {
  margin: 12px 0; padding: 13px 15px; border-radius: 10px;
  background: var(--bg-soft); border: 1px solid var(--border);
  overflow-x: auto; font-size: 13px; line-height: 1.65;
}
.md pre code { background: none; border: none; padding: 0; font-size: inherit; }
.md hr { margin: 18px 0; border: none; border-top: 1px solid var(--border); }
.md table { width: 100%; margin: 12px 0; border-collapse: collapse; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--bg-soft); font-weight: 500; }

/* 打字光标 */
.cursor {
  display: inline-block; width: 2px; height: 1.05em;
  background: var(--accent); vertical-align: text-bottom;
  margin-left: 2px; animation: blink 1s step-end infinite; border-radius: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── 来源 ── */

.sources { margin-top: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); overflow: hidden; }
.sources > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 13px; font-size: 12.5px; color: var(--text-2);
}
.sources > summary::-webkit-details-marker { display: none; }
.sources > summary:hover { color: var(--text); background: var(--accent-soft); }
.sources-ico { width: 14px; height: 14px; flex: none; color: var(--accent); }
.sources-count {
  font-size: 11px; font-weight: 500; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-text);
  font-variant-numeric: tabular-nums;
}
.sources-list { border-top: 1px solid var(--border); }
.src { display: flex; align-items: baseline; gap: 10px; padding: 8px 13px; font-size: 12.5px; }
.src + .src { border-top: 1px solid var(--border); }
.src-rank {
  flex: none; width: 19px; height: 19px; border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-variant-numeric: tabular-nums;
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-2);
  transform: translateY(2px);
}
.src-body { min-width: 0; flex: 1; }
.src-name { color: var(--text); word-break: break-all; line-height: 1.5; }
.src-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 2px; font-size: 11.5px; color: var(--text-3); }
.src-path { font-family: var(--mono); font-size: 11px; word-break: break-all; }
.src-ch {
  padding: 0 6px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--bg-soft); font-size: 10.5px;
}

/* ── 消息脚注（检索/用量） ── */

.msg-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px;
  margin-top: 10px; font-size: 11.5px; color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.msg-foot .sep { opacity: .4; }

/* ── 错误条 ── */

.err-bar {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 11px 14px; border-radius: 10px; font-size: 13.5px;
  background: rgba(239, 68, 68, .09); border: 1px solid rgba(239, 68, 68, .28);
  color: #b91c1c;
}
[data-theme="dark"] .err-bar { color: #fca5a5; }
.err-bar svg { flex: none; width: 16px; height: 16px; margin-top: 2px; }

/* ── 底部输入区 ── */

.composer-wrap {
  position: sticky; bottom: 0; z-index: 20;
  padding: 12px 20px 14px;
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

.composer { max-width: var(--maxw); margin: 0 auto; }

.composer-box {
  border: 1px solid var(--border-strong); border-radius: 22px;
  background: var(--bg-elev); box-shadow: var(--shadow);
  padding: 6px 6px 6px 16px;
  transition: border-color .18s, box-shadow .18s;
}
.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}

.composer-input {
  width: 100%; border: none; outline: none; resize: none;
  background: transparent; color: var(--text);
  font-family: inherit; font-size: 15px; line-height: 1.65;
  padding: 10px 0 4px; max-height: 200px; display: block;
}
.composer-input::placeholder { color: var(--text-3); }

.composer-actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding-top: 2px;
}
.composer-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }

.model-tag {
  font-size: 11.5px; color: var(--text-2);
  padding: 3px 9px; border-radius: 7px;
  background: var(--bg-soft); border: 1px solid var(--border);
}

.toggle-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: inherit; font-size: 11.5px; color: var(--text-2);
  background: none; border: none; cursor: pointer; padding: 3px 2px;
  transition: color .15s;
}
.toggle-btn:hover { color: var(--text); }
.toggle-track {
  width: 28px; height: 16px; border-radius: 999px; flex: none;
  background: var(--border-strong); position: relative; transition: background .18s;
}
.toggle-knob {
  position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .18s ease;
}
.toggle-btn[aria-pressed="true"] { color: var(--accent-text); }
.toggle-btn[aria-pressed="true"] .toggle-track { background: var(--accent); }
.toggle-btn[aria-pressed="true"] .toggle-knob { transform: translateX(12px); }

.send-btn {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  border: none; cursor: pointer; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); transition: all .16s;
}
.send-btn:hover:not(:disabled) { filter: brightness(1.08); transform: scale(1.06); }
.send-btn:disabled { opacity: .38; cursor: not-allowed; }
.send-btn .stop-square { display: none; }
/* 生成中：切换为停止键（浅底深色方块），点击中断本次生成 */
.send-btn.is-stop { background: var(--text); }
.send-btn.is-stop:hover { transform: scale(1.06); filter: none; }
.send-btn.is-stop .icon-send { display: none; }
.send-btn.is-stop .stop-square { display: block; width: 11px; height: 11px; border-radius: 2px; background: var(--bg); }

.composer-hint {
  text-align: center; font-size: 11.5px; color: var(--text-3);
  margin-top: 9px;
}

/* ── 响应式 ── */

@media (max-width: 620px) {
  :root { --maxw: 100%; }
  .topbar-inner, .main, .composer-wrap { padding-left: 14px; padding-right: 14px; }
  .brand-sub { display: none; }
  .suggestions { grid-template-columns: 1fr; }
  .msg-user .bubble { max-width: 94%; }
  .composer-wrap { padding-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* 滚动条 */
.thread::-webkit-scrollbar, .think-content::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
::-webkit-scrollbar-track { background: transparent; }

/* ═══════════════ 模式切换（普通检索 / 深度思考）═══════════════ */

.mode-switch {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px; border-radius: 9px;
  background: var(--bg-soft); border: 1px solid var(--border);
}
.mode-btn {
  font-family: inherit; font-size: 11.5px; color: var(--text-2);
  background: none; border: none; cursor: pointer;
  padding: 3px 10px; border-radius: 7px;
  transition: color .15s, background .15s, box-shadow .15s;
  white-space: nowrap;
}
.mode-btn:hover { color: var(--text); }
.mode-btn[aria-checked="true"] {
  color: var(--accent-text); background: var(--bg-elev);
  box-shadow: var(--shadow-sm); font-weight: 500;
}
.mode-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
