/* ============================================================
   盟豪智能问答演示 · 样式
   品牌色：主橙 #E67034（--c-brand）、强调青绿 #239C94（--c-brand-accent）
   —— 两个品牌色由 public/app.js 依据 /api/config 的 brand 字段注入，
      如需改色只需改 .env 的 BRAND_COLOR_PRIMARY / BRAND_COLOR_ACCENT，无需改本文件。
   ============================================================ */

:root {
  /* 设计 Token —— 所有颜色走变量，禁止在规则里硬编码色值 */
  --c-bg: #f4f6f7;
  --c-surface: #ffffff;
  --c-surface-2: #eef2f4;
  --c-ink: #16202b;
  --c-muted: #5b6b7a;
  --c-border: #e2e8f0;

  /* 品牌色（可被 app.js 覆盖） */
  --c-brand: #E67034;             /* 主橙：Logo / 强调文字 / 来源标题 */
  --c-brand-accent: #239C94;      /* 强调青绿：主交互色 / 用户气泡 */

  --c-accent: var(--c-brand-accent);
  --c-accent-hover: #1C8C85;
  --c-accent-press: #1B827B;
  --c-accent-soft: rgba(35, 156, 148, 0.12);
  --c-accent-bg-hover: #E6F4F2;
  --c-on-accent: #ffffff;
  --c-accent2: var(--c-brand);
  --c-accent2-press: #D6612B;
  --c-accent2-soft: rgba(230, 112, 52, 0.12);
  --c-user-bubble: var(--c-brand-accent);
  --c-bot-bubble: #eef2f4;
  --c-source-bg: #f7f9fa;
  --c-source-border: #d8e2e6;
  --c-err: #b42318;
  --c-ok: #239C94;
  --shadow-1: 0 1px 2px rgba(16, 32, 43, 0.06), 0 4px 16px rgba(16, 32, 43, 0.06);
  --c-scrim: rgba(16, 32, 43, 0.55);
  --radius-1: 10px;
  --radius-2: 14px;
  --font: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
  --maxw: 760px;
  --t-hover: 0.2s ease;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--c-ink);
  background: var(--c-bg);
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: 100%;
  max-width: var(--maxw);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  box-shadow: var(--shadow-1);
}

/* ===== 顶栏 ===== */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
}
.topbar .logo {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--c-accent2);
  color: var(--c-on-accent);
  display: grid; place-items: center;
}
.topbar .logo svg { width: 18px; height: 18px; }
.topbar .brand { min-width: 0; }
.topbar .title {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .sub { font-size: 0.78rem; color: var(--c-muted); }
.topbar .spacer { flex: 1; }

/* 状态徽章：已连接（青绿）/ MOCK（橙）/ 离线（灰） */
.badge {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--c-accent-soft);
  color: var(--c-accent);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c-ok); }
.badge.mock { background: var(--c-accent2-soft); color: var(--c-accent2); }
.badge.mock .dot { background: var(--c-accent2); }
.badge.offline { background: var(--c-surface-2); color: var(--c-muted); }
.badge.offline .dot { background: var(--c-muted); }

/* ===== 消息区 ===== */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { display: flex; gap: 10px; max-width: 100%; }
.msg .avatar {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
}
.msg .avatar svg { width: 17px; height: 17px; }
.msg.bot .avatar { background: var(--c-surface-2); color: var(--c-accent2); }
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--c-accent); color: var(--c-on-accent); }
.bubble {
  padding: 10px 13px;
  border-radius: var(--radius-1);
  line-height: 1.65;
  font-size: 0.94rem;
  word-break: break-word;
  max-width: calc(100% - 44px);
}

/* Markdown 渲染内容 */
.bubble p { margin: 0 0 8px 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble li { margin-bottom: 3px; }
.bubble strong, .bubble b { font-weight: 700; }
.bubble em, .bubble i { font-style: italic; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 10px 0 6px; line-height: 1.4; }
.bubble h1 { font-size: 1.1rem; }
.bubble h2 { font-size: 1.03rem; }
.bubble h3, .bubble h4 { font-size: 0.97rem; }
.bubble code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.bubble pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: var(--radius-1);
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.85em;
}
.bubble pre code { background: none; padding: 0; color: inherit; }

/* Markdown 表格 */
.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.88rem;
  display: block;
  overflow-x: auto;
}
.bubble th, .bubble td {
  border: 1px solid var(--c-border);
  padding: 7px 10px;
  text-align: left;
  white-space: nowrap;
}
.bubble th {
  background: var(--c-surface-2);
  font-weight: 700;
  color: var(--c-accent);
}
.bubble tr:nth-child(even) td { background: rgba(230, 112, 52, 0.03); }
.bubble blockquote {
  border-left: 3px solid var(--c-accent);
  margin: 8px 0;
  padding: 6px 12px;
  color: var(--c-muted);
  background: var(--c-surface-2);
  border-radius: 0 var(--radius-1) var(--radius-1) 0;
}

/* 产品列表可点击链接：默认橙、悬停/聚焦切换为青绿 */
.bubble a.product-link {
  color: var(--c-accent2);
  text-decoration: underline;
  text-decoration-color: var(--c-accent2-soft);
  text-underline-offset: 3px;
  cursor: pointer;
  transition: color var(--t-hover), text-decoration-color var(--t-hover);
}
.bubble a.product-link:hover,
.bubble a.product-link:focus-visible {
  color: var(--c-accent);
  text-decoration-color: var(--c-accent);
  outline: none;
}
.bubble a.product-link:active { color: var(--c-accent-press); }

.msg.bot .bubble { background: var(--c-bot-bubble); color: var(--c-ink); border: 1px solid var(--c-border); }
.msg.user .bubble { background: var(--c-user-bubble); color: var(--c-on-accent); }

/* 固定开场白 · 一问一答对话式预设问答 */
.welcome-qa {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-2);
  padding: 12px 12px 10px;
  box-shadow: var(--shadow-1);
}
.welcome-stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.welcome-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px dashed var(--c-border);
  padding-top: 10px;
}
.welcome-nav-btn {
  appearance: none;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-accent);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.84rem;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.welcome-nav-btn:hover:not(:disabled) { background: var(--c-accent-soft); border-color: var(--c-accent); }
.welcome-nav-btn:active:not(:disabled) {
  background: var(--c-accent-press);
  color: var(--c-on-accent);
  border-color: var(--c-accent-press);
}
.welcome-nav-btn:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.welcome-nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.welcome-counter {
  font-size: 0.82rem;
  color: var(--c-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
}

/* 建议问题 / 下一步建议 chips */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.chip {
  appearance: none;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-accent2);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 0.82rem;
  font-family: var(--font);
  line-height: 1.4;
  cursor: pointer;
  text-align: left;
  max-width: 100%;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.chip:hover,
.chip:focus-visible { background: var(--c-accent-bg-hover); border-color: var(--c-accent); color: var(--c-accent); outline: none; }
.chip:active { background: var(--c-accent-press); color: var(--c-on-accent); border-color: var(--c-accent-press); }

/* 回答后的下一步问题建议：浅橙背景 + 细橙边框 */
.suggestions .chip {
  background: #FFF6E8;
  border: 1px solid rgba(230, 112, 52, 0.45);
  color: var(--c-accent2);
}
.suggestions .chip:hover,
.suggestions .chip:focus-visible {
  background: var(--c-accent-bg-hover);
  border-color: var(--c-accent);
  color: var(--c-accent);
  outline: none;
}
.suggestions .chip:active {
  background: var(--c-accent-press);
  border-color: var(--c-accent-press);
  color: var(--c-on-accent);
}

/* 图片 */
.bubble img { max-width: 240px; border-radius: 8px; display: block; margin-top: 8px; border: 1px solid var(--c-border); }

/* ===== 来源卡片（sources） ===== */
.sources {
  margin-top: 8px;
  border-top: 1px dashed var(--c-source-border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sources-title {
  font-size: 0.74rem;
  color: var(--c-muted);
  letter-spacing: 0.04em;
}
.source {
  background: var(--c-source-bg);
  border: 1px solid var(--c-source-border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.8rem;
}
.source .name {
  font-weight: 700;
  color: var(--c-accent2);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color var(--t-hover);
}
.source .name svg { width: 13px; height: 13px; flex: 0 0 auto; }
.source .name .doc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source .snippet { color: var(--c-muted); margin-top: 3px; line-height: 1.5; }

/* 来源折叠：超过默认条数的卡片用 [hidden] 隐藏 */
.source[hidden] { display: none; }

/* 「展开全部 N 条 / 收起」开关 */
.sources-toggle {
  align-self: flex-start;
  appearance: none;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-accent);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.76rem;
  font-family: var(--font);
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.sources-toggle:hover,
.sources-toggle:focus-visible { background: var(--c-accent-soft); border-color: var(--c-accent); outline: none; }
.sources-toggle:active { background: var(--c-accent-press); color: var(--c-on-accent); border-color: var(--c-accent-press); }

/* 打字光标 */
.cursor::after {
  content: '▍';
  margin-left: 1px;
  color: var(--c-accent2);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* 错误气泡 */
.msg.bot.err .bubble { background: #fdecea; border-color: var(--c-err); color: var(--c-err); }

/* ===== 输入区 ===== */
.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--c-border);
  padding: 12px 14px 14px;
  background: var(--c-surface);
}
.composer .row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-1);
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 0.94rem;
  line-height: 1.5;
  color: var(--c-ink);
  background: var(--c-surface);
  max-height: 140px;
  outline: none;
}
.composer textarea:focus { border-color: var(--c-accent); }
.composer textarea::placeholder { color: var(--c-muted); }
.send {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border: none;
  border-radius: var(--radius-1);
  background: var(--c-accent);
  color: var(--c-on-accent);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background 0.15s ease;
}
.send:hover { background: var(--c-accent-press); }
.send:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.send:disabled { opacity: 0.5; cursor: not-allowed; }
.send svg { width: 20px; height: 20px; }
.hint { font-size: 0.72rem; color: var(--c-muted); margin-top: 7px; text-align: center; }

/* ===== 访问口令遮罩 ===== */
.gate {
  position: fixed;
  inset: 0;
  background: var(--c-scrim);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}
.gate[hidden] { display: none; }
.gate-box {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-2);
  padding: 22px 22px 18px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-1);
}
.gate-title { font-size: 1.05rem; font-weight: 700; }
.gate-sub { font-size: 0.85rem; color: var(--c-muted); margin: 6px 0 14px; }
.gate-row { display: flex; gap: 10px; align-items: stretch; }
.gate-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-1);
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 0.94rem;
  color: var(--c-ink);
  background: var(--c-surface);
  outline: none;
}
.gate-row input:focus { border-color: var(--c-accent); }
.gate-err { font-size: 0.8rem; color: var(--c-err); margin-top: 10px; }
.gate-err[hidden] { display: none; }

/* ===== 响应式 ===== */
@media (max-width: 600px) {
  .app { max-width: 100%; }
  .topbar .sub { display: none; }
}

/* ===== 可访问性 ===== */
:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }

/* 尊重「减少动效」偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
