:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f0f4f8;
  --ink: #152235;
  --muted: #64748b;
  --line: #dce3eb;
  --accent: #1769e0;
  --accent-strong: #0f55bd;
  --accent-soft: #eaf2ff;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 18px 48px rgba(40, 65, 100, 0.12);
  font-family: "Segoe UI", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }

button, textarea { font: inherit; }

button { cursor: pointer; }

button:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(23, 105, 224, 0.22);
  outline-offset: 2px;
}

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 340px;
  background: var(--surface);
  overflow: hidden;
}

.history-panel, .sources-panel {
  min-height: 100dvh;
  background: var(--bg);
  padding: 20px 16px;
}

.history-panel { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.sources-panel { border-left: 1px solid var(--line); }

.brand-row { display: flex; align-items: center; gap: 11px; min-height: 46px; }
.brand-row strong, .brand-row span { display: block; }
.brand-row strong { font-size: 15px; }
.brand-row span { color: var(--muted); font-size: 12px; margin-top: 3px; }

.brand-mark {
  width: 38px;
  height: 38px;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

.new-chat {
  width: 100%;
  margin: 24px 0 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
  border-radius: var(--radius);
  font-weight: 650;
  transition: border-color .18s ease, transform .18s ease;
}

.new-chat:hover { border-color: var(--accent); }
.new-chat:active, .send-button:active, .prompt-question:active { transform: translateY(1px); }

.history-list { display: flex; flex-direction: column; gap: 4px; overflow: auto; flex: 1; }

.history-item {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item:hover, .history-item.active { background: var(--accent-soft); color: var(--ink); }

.library-summary { border-top: 1px solid var(--line); padding-top: 16px; }
.summary-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 650; }
.live-badge { color: var(--accent-strong); background: var(--accent-soft); padding: 3px 7px; border-radius: 8px; font-size: 11px; }
.library-summary dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.library-summary dl div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.library-summary dt { color: var(--muted); font-size: 11px; }
.library-summary dd { margin: 4px 0 0; font-weight: 700; font-size: 17px; }
.library-summary p { color: var(--muted); font-size: 11px; line-height: 1.55; margin: 0; }

.chat-shell { min-width: 0; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; background: var(--surface); }

.chat-header {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  z-index: 4;
}

.chat-title { min-width: 0; flex: 1; }
.chat-title strong, .chat-title span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title strong { font-size: 15px; }
.chat-title span { color: var(--muted); font-size: 11px; margin-top: 4px; }

.mode-switch { display: flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--bg); }
.mode-switch button { border: 0; background: transparent; color: var(--muted); border-radius: 7px; padding: 6px 10px; font-size: 12px; }
.mode-switch button.active { background: var(--surface); color: var(--accent-strong); box-shadow: 0 2px 8px rgba(40, 65, 100, 0.10); }

.header-action, .icon-text { border: 0; background: transparent; color: var(--muted); padding: 7px 8px; border-radius: 8px; }
.header-action:hover, .icon-text:hover { background: var(--surface-soft); color: var(--ink); }

.conversation { overflow-y: auto; padding: 0 max(28px, calc((100% - 860px) / 2)); scroll-behavior: smooth; }

.welcome { min-height: calc(100dvh - 174px); display: grid; align-content: center; gap: 42px; padding: 52px 0; }
.welcome-copy { max-width: 620px; }
.product-label { color: var(--accent-strong); font-size: 13px; font-weight: 700; }
.welcome h1 { margin: 14px 0 18px; font-size: clamp(36px, 5vw, 62px); letter-spacing: -0.05em; line-height: 1.08; }
.welcome-copy p { max-width: 42ch; margin: 0; color: var(--muted); font-size: 16px; line-height: 1.75; }

.prompt-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.prompt-group { border-top: 2px solid var(--ink); padding-top: 13px; }
.prompt-group h2 { font-size: 14px; margin: 0 0 5px; }
.prompt-group > p { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 0 0 12px; min-height: 36px; }
.prompt-question { width: 100%; border: 0; background: transparent; color: var(--ink); text-align: left; padding: 8px 0; line-height: 1.45; font-size: 13px; }
.prompt-question:hover { color: var(--accent-strong); }

.message { padding: 28px 0 6px; animation: rise .25s ease-out both; }
.message.user { display: flex; justify-content: flex-end; }
.message.user .message-content { max-width: min(78%, 640px); background: var(--accent-soft); border-radius: var(--radius) var(--radius) 4px var(--radius); padding: 13px 16px; line-height: 1.65; }
.assistant-row { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; max-width: 800px; }
.assistant-mark { width: 34px; height: 34px; display: block; object-fit: contain; flex: 0 0 auto; }
.assistant-body { min-width: 0; }
.assistant-name { color: var(--muted); font-size: 12px; margin: 0 0 9px; }
.answer-content { font-size: 15px; line-height: 1.82; color: #1c2a3b; }
.answer-content h2, .answer-content h3 { margin: 24px 0 8px; line-height: 1.35; }
.answer-content h2 { font-size: 18px; }
.answer-content h3 { font-size: 16px; }
.answer-content p { margin: 0 0 12px; }
.answer-content ul, .answer-content ol { padding-left: 22px; margin: 8px 0 16px; }
.answer-content li { margin-bottom: 7px; }
.answer-content table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 13px; }
.answer-content th, .answer-content td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; vertical-align: top; }
.answer-content th { background: var(--surface-soft); font-weight: 700; }
.answer-actions { display: flex; gap: 8px; margin-top: 16px; }
.answer-actions button { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 8px; padding: 6px 9px; font-size: 12px; }
.answer-actions button:hover { color: var(--accent-strong); border-color: #9abced; }

.loading-lines { width: min(520px, 90%); display: grid; gap: 9px; padding-top: 4px; }
.loading-lines span { display: block; height: 10px; border-radius: 5px; background: #e5ebf2; animation: pulse 1.4s ease-in-out infinite; }
.loading-lines span:nth-child(2) { width: 82%; }
.loading-lines span:nth-child(3) { width: 56%; }

.error-box { color: var(--danger); background: #fff1f0; border: 1px solid #ffd0cc; border-radius: var(--radius); padding: 12px 14px; }

.composer-wrap { padding: 12px max(28px, calc((100% - 860px) / 2)) 18px; background: var(--surface); }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; border: 1px solid #cbd5e1; border-radius: var(--radius); padding: 10px 10px 10px 15px; box-shadow: 0 8px 28px rgba(40, 65, 100, 0.09); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.12); }
.composer textarea { width: 100%; max-height: 150px; resize: none; border: 0; outline: 0; padding: 7px 0; line-height: 1.55; color: var(--ink); background: transparent; }
.composer textarea::placeholder { color: #8a98aa; }
.send-button { border: 0; background: var(--accent); color: #fff; min-width: 66px; min-height: 40px; border-radius: 10px; font-weight: 700; }
.send-button:hover { background: var(--accent-strong); }
.send-button:disabled { cursor: wait; opacity: .55; }
.composer-note { margin: 7px 2px 0; color: var(--muted); font-size: 11px; }

.sources-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.sources-header strong, .sources-header span { display: block; }
.sources-header strong { font-size: 16px; }
.sources-header span { color: var(--muted); font-size: 11px; margin-top: 5px; }
.source-list { padding-top: 8px; overflow-y: auto; max-height: calc(100dvh - 90px); }
.source-empty { padding: 40px 8px; color: var(--muted); }
.source-empty strong { color: var(--ink); font-size: 14px; }
.source-empty p { font-size: 12px; line-height: 1.7; }
.source-item { border-bottom: 1px solid var(--line); padding: 14px 2px; }
.source-item button { width: 100%; border: 0; background: transparent; text-align: left; padding: 0; color: var(--ink); }
.source-item h3 { font-size: 13px; line-height: 1.5; margin: 0; overflow-wrap: anywhere; }
.source-meta { color: var(--accent-strong); font-size: 11px; display: block; margin-top: 5px; }
.source-snippet { color: var(--muted); font-size: 12px; line-height: 1.7; margin: 10px 0 0; display: none; }
.source-item.open .source-snippet { display: block; }

.scrim { display: none; }
.mobile-only { display: none; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

@media (max-width: 1120px) {
  .app { grid-template-columns: 240px minmax(0, 1fr); }
  .sources-panel { position: fixed; right: 0; top: 0; width: min(380px, 88vw); transform: translateX(105%); transition: transform .22s ease; z-index: 20; box-shadow: var(--shadow); }
  .sources-panel.open { transform: translateX(0); }
  .scrim.visible { display: block; position: fixed; inset: 0; background: rgba(18, 31, 47, .38); z-index: 15; }
}

@media (max-width: 760px) {
  .app { display: block; min-height: 100dvh; }
  .mobile-only { display: inline-flex; }
  .history-panel { position: fixed; left: 0; top: 0; width: min(320px, 88vw); transform: translateX(-105%); transition: transform .22s ease; z-index: 20; box-shadow: var(--shadow); }
  .history-panel.open { transform: translateX(0); }
  .chat-shell { min-height: 100dvh; }
  .chat-header { min-height: 60px; padding: 8px 12px; gap: 7px; position: sticky; top: 0; }
  .chat-title span { display: none; }
  .mode-switch button { padding: 6px 8px; }
  .conversation { padding: 0 17px; }
  .welcome { min-height: calc(100dvh - 160px); align-content: start; padding: 46px 0 28px; gap: 34px; }
  .welcome h1 { font-size: 39px; max-width: 9ch; }
  .welcome-copy p { font-size: 14px; }
  .prompt-groups { grid-template-columns: 1fr; gap: 18px; }
  .prompt-group > p { min-height: 0; }
  .message { padding-top: 22px; }
  .message.user .message-content { max-width: 88%; }
  .assistant-row { grid-template-columns: 30px minmax(0, 1fr); gap: 9px; }
  .assistant-mark { width: 30px; height: 30px; }
  .answer-content { font-size: 15px; line-height: 1.78; }
  .answer-content table { display: block; overflow-x: auto; white-space: nowrap; }
  .composer-wrap { padding: 10px 12px max(12px, env(safe-area-inset-bottom)); position: sticky; bottom: 0; }
  .composer { padding-left: 12px; }
  .composer-note { display: none; }
}
