* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: #fff;
  color: #1f2937;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

/* ---------- 空状态 welcome ---------- */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  /* 参考 Gemini：中心柔和淡蓝光晕，向四周自然过渡到纯白 */
  background: radial-gradient(circle at 50% 42%, #cfe6ff 0%, #e3f1ff 25%, #f0f8ff 50%, #ffffff 85%);
}
.welcome.hidden { display: none; }

.welcome-title {
  font-size: 32px;
  font-weight: 500;
  color: #111827;
  margin: 0 0 32px 0;
  text-align: center;
  letter-spacing: -0.5px;
}

/* ---------- 对话状态 chat ---------- */
.chat {
  display: none;
  flex-direction: column;
  height: 100%;
  /* 对话页同样带淡蓝氛围，从顶部中心向四周变浅 */
  background: radial-gradient(circle at 50% 0%, #e8f4ff 0%, #f8fbff 45%, #ffffff 75%);
}
.chat.open { display: flex; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 120px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- 通用输入框组件 ---------- */
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 8px 8px 8px 14px;
  box-shadow: 0 4px 24px rgba(31, 111, 235, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
}
.input-wrap:focus-within {
  border-color: #bfdbfe;
  box-shadow: 0 4px 28px rgba(59, 130, 246, 0.12);
}

.input-wrap textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: #1f2937;
  font-size: 15px;
  line-height: 1.5;
  padding: 10px 4px;
  max-height: 120px;
  min-height: 24px;
  outline: none;
  font-family: inherit;
}
.input-wrap textarea::placeholder { color: #9ca3af; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.icon-btn:hover { background: #f3f4f6; color: #374151; }
.icon-btn svg { display: block; }

/* 麦克风按钮：长按录音态 */
.icon-btn.mic { user-select: none; -webkit-user-select: none; touch-action: none; }
.icon-btn.mic.recording {
  background: #ef4444;
  color: #fff;
  animation: mic-pulse 1.2s infinite;
}
@keyframes mic-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  70%  { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* 语音输入状态提示条 */
.voice-toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%) translateY(8px);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(17, 24, 39, 0.88);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 60;
  backdrop-filter: blur(4px);
}
.voice-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.voice-toast.err { background: rgba(220, 38, 38, 0.92); }
.voice-toast.ok  { background: rgba(5, 150, 105, 0.92); }
.voice-toast.err .voice-wave, .voice-toast.ok .voice-wave { display: none; }

/* 聆听声浪动画 */
.voice-wave { display: flex; align-items: center; gap: 3px; height: 16px; }
.voice-wave i {
  width: 3px; border-radius: 2px; background: #fff;
  animation: wave 1s infinite ease-in-out;
}
.voice-wave i:nth-child(1) { height: 6px;  animation-delay: 0s; }
.voice-wave i:nth-child(2) { height: 12px; animation-delay: .15s; }
.voice-wave i:nth-child(3) { height: 16px; animation-delay: .3s; }
.voice-wave i:nth-child(4) { height: 12px; animation-delay: .45s; }
.voice-wave i:nth-child(5) { height: 6px;  animation-delay: .6s; }
@keyframes wave {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1.15); }
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #4a9eff;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.send-btn:hover { background: #3b8ee6; }
.send-btn:active { transform: scale(0.96); }

.stop-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: #111827;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  flex-shrink: 0;
}
.stop-btn:hover { background: #f3f4f6; }

/* ---------- 空状态输入框特殊宽度 ---------- */
.welcome-input { max-width: 680px; }

/* ---------- 对话底部输入框 ---------- */
.composer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 16px 24px 16px;
  /* 半透明白色上淡，既让底部背景蓝光隐约透出，又保证输入区可读 */
  background: linear-gradient(to top, rgba(255,255,255,0.98) 55%, rgba(255,255,255,0.55) 80%, rgba(255,255,255,0));
  pointer-events: none;
}
.composer .input-wrap { pointer-events: auto; }

/* ---------- 消息气泡 ---------- */
.msg {
  max-width: 80%;
  line-height: 1.65;
  font-size: 15px;
  word-break: break-word;
  white-space: normal;
}
.msg.user {
  align-self: flex-end;
  background: #f3f4f6;
  color: #111827;
  padding: 12px 16px;
  border-radius: 22px;
  border-bottom-right-radius: 6px;
}
.msg.bot {
  align-self: flex-start;
  color: #1f2937;
  padding: 4px 2px;
  max-width: 88%;
}

/* bot 内容区 markdown */
.answer h1, .answer h2, .answer h3 {
  margin: 18px 0 10px;
  color: #111827;
  font-weight: 600;
}
.answer h1 { font-size: 20px; }
.answer h2 { font-size: 18px; }
.answer h3 { font-size: 16px; }
.answer p { margin: 10px 0; }
.answer ul, .answer ol { margin: 10px 0; padding-left: 22px; }
.answer li { margin: 4px 0; }
.answer pre {
  background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 12px; overflow-x: auto; font-size: 13px;
}
.answer code { font-family: "SFMono-Regular", Consolas, monospace; background: #f3f4f6; padding: 1px 4px; border-radius: 4px; }
.answer pre code { background: transparent; padding: 0; }
.answer strong { color: #111827; }

/* ---------- 分派与可观测性元信息 ---------- */
.dispatch {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed #e5e7eb;
  font-size: 12px;
  color: #6b7280;
}
.dispatch-title { margin-bottom: 6px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.badge.local { background: #ecfdf5; color: #059669; border-color: #a7f3d0; }
.badge.cloud { background: #f5f3ff; color: #7c3aed; border-color: #ddd6fe; }
.steps { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.step { font-size: 11px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.step.err { color: #dc2626; }

.msg-foot { margin-top: 10px; display: flex; align-items: center; gap: 10px; }
.trace-id { font-size: 11px; color: #9ca3af; font-family: monospace; }
.eval-btn {
  background: #f9fafb; color: #4a9eff; border: 1px solid #e5e7eb;
  border-radius: 6px; padding: 3px 10px; font-size: 11px; cursor: pointer;
}
.eval-btn:hover { border-color: #bfdbfe; }
.eval-btn:disabled { opacity: .7; cursor: default; }

/* ---------- 用户反馈框 ---------- */
.feedback-box {
  margin-top: 8px; padding: 10px; background: #f8fafc; border: 1px solid #e5e7eb;
  border-radius: 8px; display: flex; flex-direction: column; gap: 8px;
}
.feedback-input {
  width: 100%; min-height: 60px; resize: vertical; box-sizing: border-box;
  border: 1px solid #d1d5db; border-radius: 6px; padding: 8px; font-size: 13px;
  font-family: inherit; outline: none;
}
.feedback-input:focus { border-color: #4a9eff; }
.feedback-row { display: flex; gap: 8px; align-items: center; }
.feedback-ok { color: #16a34a; font-size: 12px; }
.feedback-err { color: #dc2626; font-size: 12px; }

/* ---------- 思考动画 ---------- */
.thinking { display: flex; gap: 4px; align-items: center; }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #d1d5db; animation: blink 1.2s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.2} 40%{opacity:1} }

/* ---------- 可观测性按钮 ---------- */
.obs-btn {
  position: fixed;
  right: 18px;
  top: 14px;
  z-index: 40;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(6px);
  color: #6b7280;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
.obs-btn:hover { color: #4a9eff; border-color: #bfdbfe; }

/* ---------- 可观测性侧板 ---------- */
.obs-panel {
  position: fixed;
  top: 0; right: 0;
  width: 360px;
  height: 100vh;
  background: #fff;
  border-left: 1px solid #e5e7eb;
  box-shadow: -4px 0 24px rgba(0,0,0,0.06);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.obs-panel.open { transform: translateX(0); }
.obs-head {
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}
.obs-body { flex: 1; overflow-y: auto; padding: 14px 16px; font-size: 13px; }
.obs-loading { color: #6b7280; }
.obs-stats { display: flex; gap: 10px; margin-bottom: 12px; }
.obs-stats > div {
  flex: 1; text-align: center; background: #f9fafb;
  border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px 4px;
}
.obs-stats b { display: block; font-size: 18px; color: #111827; }
.obs-stats span { font-size: 11px; color: #6b7280; }
.obs-intents { margin-bottom: 12px; line-height: 2; }
.chip {
  display: inline-block; font-size: 11px; background: #f9fafb;
  border: 1px solid #e5e7eb; border-radius: 999px; padding: 2px 8px; margin: 2px;
}
.obs-list-title { color: #6b7280; margin: 6px 0; }
.obs-item {
  padding: 8px 10px; border: 1px solid #e5e7eb; border-radius: 8px;
  margin-bottom: 6px; cursor: pointer; background: #f9fafb;
}
.obs-item:hover { border-color: #bfdbfe; }
.obs-item.err { border-color: #fecaca; }
.obs-item.bad { border-color: #fecaca; background: #fef2f2; }
.obs-q { font-size: 13px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.obs-st { font-size: 10px; padding: 1px 7px; border-radius: 999px; font-weight: 500; white-space: nowrap; }
.obs-st-approved { background: #ecfdf5; color: #047857; }
.obs-st-rejected { background: #fef2f2; color: #b91c1c; }
.obs-st-pending { background: #fff7ed; color: #c2410c; }
.obs-meta { font-size: 11px; color: #6b7280; margin-top: 3px; }
.obs-detail .obs-back {
  background: #f9fafb; color: #6b7280; border: 1px solid #e5e7eb;
  border-radius: 6px; padding: 4px 10px; cursor: pointer; margin-bottom: 10px;
}
.obs-d-q { margin-bottom: 6px; }
.obs-d-meta, .obs-d-eval { font-size: 12px; color: #6b7280; margin: 6px 0; }
.obs-d-eval { color: #059669; }
.obs-d-ans { white-space: pre-wrap; word-break: break-word; color: #374151; }

/* 滚动条 */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

@media (max-width: 640px) {
  .welcome-title { font-size: 24px; }
  .msg { max-width: 90%; }
  .obs-panel { width: 100%; }
}
