:root {
  --bg: #eef4fb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ink: #1f2937;
  --muted: #6b7280;
  --card: #ffffff;
  --bubble-user: #2563eb;
  --bubble-ai: #ffffff;
  --border: #e5e7eb;
  --ok: #16a34a;
  --warn: #d97706;
}

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(37, 99, 235, .12), transparent),
    radial-gradient(900px 400px at 0% 110%, rgba(22, 163, 74, .10), transparent),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 12px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 4px 10px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 34px; }
.brand h1 { font-size: 20px; }
.brand p { font-size: 12px; color: var(--muted); margin-top: 2px; }

.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.ghost-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: .15s;
}
.ghost-btn:hover { border-color: var(--primary); color: var(--primary); }

.badge {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
}
.badge.warn { color: var(--warn); border-color: #fcd34d; background: #fffbeb; }
.badge.ok { color: var(--ok); border-color: #bbf7d0; background: #f0fdf4; }

.dot { position: relative; padding-left: 26px; }
.dot::before {
  content: "";
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #9ca3af;
}
.dot.online::before { background: var(--ok); box-shadow: 0 0 6px rgba(22,163,74,.6); }
.dot.offline::before { background: #ef4444; }

/* ---------- 布局 ---------- */
.layout {
  flex: 1;
  display: flex;
  gap: 12px;
  min-height: 0;
  padding-bottom: 12px;
}

.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 10px 40px rgba(31, 41, 55, .08);
  overflow: hidden;
  min-width: 0;
}

/* ---------- 资料速览面板 ---------- */
.panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 10px 40px rgba(31, 41, 55, .08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideIn .2s ease;
}
.panel.hidden { display: none; }
@keyframes slideIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.icon-btn {
  border: none; background: none; cursor: pointer;
  font-size: 14px; color: var(--muted);
}
.panel-body { overflow-y: auto; padding: 12px 14px; font-size: 13px; line-height: 1.7; }
.panel-body h3 { font-size: 13px; margin: 12px 0 4px; color: var(--primary-dark); }
.panel-body h3:first-child { margin-top: 0; }
.panel-body ul { padding-left: 18px; }
.panel-body .tag {
  display: inline-block;
  background: #eff6ff;
  color: var(--primary-dark);
  border-radius: 6px;
  padding: 1px 7px;
  margin: 2px 4px 2px 0;
  font-size: 12px;
}

/* ---------- 消息区 ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg { display: flex; gap: 8px; max-width: 88%; animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg .avatar {
  width: 32px; height: 32px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .avatar { background: #dbeafe; }
.msg.assistant .avatar { background: #dcfce7; }

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.75;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.user .bubble { background: var(--bubble-user); color: #fff; border-top-right-radius: 4px; }
.msg.assistant .bubble { background: var(--bubble-ai); border: 1px solid var(--border); border-top-left-radius: 4px; }

.bubble strong { color: inherit; }

.msg-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.src-chip {
  font-size: 11.5px;
  background: #f3f4f6;
  border: 1px solid var(--border);
  color: #374151;
  border-radius: 999px;
  padding: 2px 9px;
}
.engine-chip {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 4px;
}

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #9ca3af;
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- 快捷问题 ---------- */
.suggestions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 16px 10px;
}
.chip {
  border: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  transition: .15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
.chip:disabled { opacity: .5; cursor: default; }

/* ---------- 输入区 ---------- */
.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 140px;
  outline: none;
  transition: border-color .15s;
}
.composer textarea:focus { border-color: var(--primary); }
.composer button {
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  padding: 10px 20px;
  font-size: 14.5px;
  cursor: pointer;
  transition: .15s;
  flex-shrink: 0;
}
.composer button:hover { background: var(--primary-dark); }
.composer button:disabled { opacity: .55; cursor: not-allowed; }

.footnote {
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  padding: 6px 12px 12px;
}

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  .brand p { display: none; }
  .panel { position: fixed; right: 8px; top: 60px; bottom: 12px; width: min(320px, 92vw); z-index: 20; }
  .msg { max-width: 96%; }
}
