* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: #ffffff;
  color: #1f2329;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* 顶栏（沿用既定约束：无标题文字，设备ID左对齐完整显示，登录按钮右对齐） */
#topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: #2b3a67;
}
#user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; color: rgba(255,255,255,0.92); min-width: 0; flex: 1 1 auto; }
#user-name { word-break: break-all; line-height: 1.35; text-align: left; min-width: 0; margin-right: auto; }
.link-btn {
  border: none; background: rgba(255,255,255,0.16); color: #ffffff;
  border-radius: 16px; padding: 5px 14px; font-size: 13px; cursor: pointer;
}
.link-btn:hover { background: rgba(255,255,255,0.28); }
.link-btn.off { opacity: 0.45; }

/* 消息区（豆包：纯白背景） */
#chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 16px calc(10px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

/* 空状态（豆包：居中问候语 + 推荐问题卡片） */
.welcome {
  margin: auto;
  width: 100%;
  max-width: 560px;
  text-align: center;
  padding: 20px 0;
}
.welcome-icon {
  width: 64px; height: 64px;
  margin: 0 auto 18px;
  border-radius: 20px;
  background: linear-gradient(135deg, #165dff, #6aa0ff);
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
  box-shadow: 0 8px 20px rgba(22,93,255,0.25);
}
.welcome-title { font-size: 24px; font-weight: 700; color: #1f2329; margin-bottom: 6px; }
.welcome-sub { font-size: 15px; color: #86909c; margin-bottom: 26px; }
.welcome-tip { font-size: 12px; color: #c9cdd4; margin-top: 22px; }
.suggest { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.suggest-item {
  background: #ffffff;
  border: 1px solid #e5e6eb;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 15px;
  color: #1f2329;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: border-color .12s, box-shadow .12s;
}
.suggest-item:hover { border-color: #bcc6f7; box-shadow: 0 2px 10px rgba(22,93,255,0.06); }
.suggest-item .s-arrow { color: #c9cdd4; font-size: 16px; flex: 0 0 auto; }

/* 消息气泡 */
.msg {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 16px;
  max-width: 100%;
}
.msg.user { justify-content: flex-end; }
.msg.ai { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.msg.user .bubble {
  background: #a8e6cf; color: #1f2329;
  border-top-right-radius: 4px;
}
.msg.user .bubble::after {
  content: '';
  position: absolute;
  top: 10px; right: -6px;
  border: 6px solid transparent;
  border-left-color: #a8e6cf;
  border-right: 0;
}
.msg.ai .bubble {
  background: #f0f0f0; color: #1f2329;
  border: none;
  border-top-left-radius: 4px;
}

/* 每条 AI 回答下方的朗读按钮 */
.speak-bar { flex-basis: 100%; display: flex; margin-top: 5px; }
.msg.user .speak-bar { justify-content: flex-end; }
.msg.ai .speak-bar { justify-content: flex-start; }
.speak-btn {
  border: none; background: #f2f3f5; color: #4e5969;
  border-radius: 14px; padding: 3px 14px; font-size: 13px; cursor: pointer;
}
.speak-btn:hover { background: #e8eaed; }

/* 语音气泡（图中样式：波形图标 + 时长） */
.audio-box {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0; margin: 0;
  cursor: pointer;
  background: transparent;
}
.audio-icon { display: inline-flex; align-items: center; gap: 2px; font-size: 0; }
.audio-icon i {
  display: inline-block;
  width: 3px; border-radius: 2px;
  background: currentColor;
  height: 8px;
}
.audio-icon i:nth-child(1) { height: 6px; }
.audio-icon i:nth-child(2) { height: 12px; }
.audio-icon i:nth-child(3) { height: 16px; }
.audio-icon i:nth-child(4) { height: 10px; }
.audio-icon.playing i { animation: wave 0.9s ease-in-out infinite; }
.audio-icon.playing i:nth-child(1) { animation-delay: 0s; }
.audio-icon.playing i:nth-child(2) { animation-delay: .15s; }
.audio-icon.playing i:nth-child(3) { animation-delay: .3s; }
.audio-icon.playing i:nth-child(4) { animation-delay: .45s; }
@keyframes wave { 0%,100% { transform: scaleY(0.5); } 50% { transform: scaleY(1.2); } }
.audio-dur { font-size: 14px; font-weight: 600; line-height: 1; }

.msg.user .bubble { color: #176b4d; }
.msg.user .bubble::after { border-left-color: #a8e6cf; }
.msg.ai .audio-box { background: #f2f3f5; border-radius: 10px; padding: 8px 10px; }
.msg.ai .audio-box audio { height: 32px; max-width: 210px; }
.transcript {
  font-size: 13px;
  color: #176b4d;
  border-top: 1px dashed rgba(23,107,77,0.35);
  padding-top: 6px;
  margin-top: 6px;
}
.msg.ai .transcript { color: #4e5969; border-top-color: #d0d3da; }
.transcript-label { opacity: 0.75; font-size: 12px; margin-right: 4px; }

/* 时间 */
.time {
  font-size: 11px; color: #a9aeb8;
  text-align: center; margin: 4px 0;
}
.msg .time-side { display: none; }

/* 底部输入区（豆包：悬浮圆角卡片） */
#inputbar {
  flex: 0 0 auto;
  background: transparent;
  padding: 0 12px calc(12px + env(safe-area-inset-bottom));
}
.input-card {
  background: #ffffff;
  border: 1px solid #e5e6eb;
  border-radius: 24px;
  box-shadow: 0 4px 20px rgba(31,35,41,0.08);
  padding: 8px;
  position: relative;
}
.input-main { display: flex; align-items: center; gap: 8px; }
.voice-btn {
  flex: 1;
  height: 44px;
  border-radius: 20px;
  border: none;
  background: #f2f3f5;
  color: #4e5969;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: background .12s;
}
.voice-btn:active, .voice-btn.recording {
  background: #165dff; color: #fff;
}
.voice-btn:disabled { background: #f2f3f5; color: #c9cdd4; cursor: default; }
#text-input {
  flex: 1;
  height: 44px;
  border: none;
  background: #f2f3f5;
  border-radius: 20px;
  padding: 0 18px;
  font-size: 15px;
  outline: none;
}
.toggle-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border: none; border-radius: 50%;
  background: #f2f3f5;
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.toggle-btn:hover { background: #e8eaed; }
.toggle-btn:disabled { background: #f2f3f5; color: #c9cdd4; cursor: default; }
.send-btn.busy, .voice-btn.busy, .toggle-btn.busy { opacity: 0.55; cursor: default; }
.send-btn {
  flex: 0 0 auto;
  height: 44px; padding: 0 22px;
  border: none; border-radius: 20px;
  background: #165dff; color: #fff; font-size: 15px; font-weight: 500; cursor: pointer;
}
.send-btn:disabled { background: #c9cdd4; cursor: default; }
.voice-status {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-size: 13px; color: #f53f3f; display: none;
  background: rgba(255,255,255,0.92); border-radius: 10px; padding: 3px 10px;
  pointer-events: none;
}

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  width: 84%; max-width: 320px;
  background: #fff; border-radius: 14px;
  padding: 20px 18px;
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; text-align: center; }
.modal input {
  width: 100%; height: 40px;
  border: 1px solid #d0d3da; border-radius: 10px;
  padding: 0 12px; font-size: 14px; margin-bottom: 10px; outline: none;
}
.modal input:focus { border-color: #165dff; }
.m-error { color: #f53f3f; font-size: 12px; min-height: 16px; margin-bottom: 6px; }
.modal-btns { display: flex; gap: 8px; }
.modal-btns button {
  flex: 1; height: 38px; border-radius: 10px; font-size: 14px; cursor: pointer; border: none;
}
.btn-primary { background: #165dff; color: #fff; }
.btn-ghost { background: #f2f3f5; color: #1f2329; }
.modal-tip { margin-top: 10px; font-size: 12px; color: #86909c; text-align: center; }

/* 正在输入指示 */
.typing { display: inline-flex; gap: 2px; align-items: center; color: #8f959e; }
.typing .typing-text { font-size: 13px; }
.typing .typing-dots { display: inline-flex; gap: 3px; margin-left: 2px; }
.typing .typing-dots i {
  width: 5px; height: 5px; border-radius: 50%; background: #a9aeb8;
  animation: blink 1.2s infinite;
}
.typing .typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing .typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% {opacity:.3} 40% {opacity:1} }

/* 欢迎页紧凑模式（调出历史后保留为一行，新问题后消失） */
.welcome.compact {
  margin: 14px 0 18px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: #f7f8fa;
  border-radius: 14px;
  max-width: 100%;
}
.welcome.compact .welcome-icon {
  width: 34px; height: 34px;
  margin: 0;
  border-radius: 10px;
  font-size: 18px;
  box-shadow: none;
  flex: 0 0 auto;
}
.welcome.compact .welcome-title { font-size: 15px; margin-bottom: 0; }
.welcome.compact .welcome-sub,
.welcome.compact .welcome-tip,
.welcome.compact .suggest { display: none; }

/* 回答后追加的 3 个相关问题 */
.related {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 78%;
  margin: -6px 0 18px;
}
.rel-item {
  border: 1px solid #e5e6eb;
  background: #ffffff;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  color: #1f2329;
  text-align: left;
  cursor: pointer;
  transition: border-color .12s;
}
.rel-item:hover { border-color: #bcc6f7; }

/* ---------- 图/视频生成 ---------- */
.gen-tools { display:flex; gap:8px; padding:0 14px 6px; justify-content:flex-end; }
.gen-tool-btn { font-size:13px; padding:5px 12px; border-radius:14px; border:1px solid #d0d3da; background:#fff; color:#1f2329; cursor:pointer; white-space:nowrap; }
.gen-tool-btn:active { background:#eef0f3; }
.gen-box { margin-top:8px; display:flex; flex-direction:column; gap:8px; }
.gen-card { border-radius:10px; overflow:hidden; background:#f7f8fa; border:1px solid #e5e6eb; }
.gen-loading { padding:14px; font-size:13px; color:#4e5969; text-align:center; }
.gen-loading::after { content:''; display:inline-block; width:14px; height:14px; margin-left:6px; vertical-align:-2px; border:2px solid #c9cdd4; border-top-color:#3370ff; border-radius:50%; animation:gen-spin .8s linear infinite; }
@keyframes gen-spin { to { transform:rotate(360deg); } }
.gen-placeholder { padding:12px 14px; font-size:13px; color:#4e5969; display:flex; align-items:center; justify-content:space-between; gap:10px; }
.gen-btn { font-size:13px; padding:5px 12px; border-radius:14px; border:none; background:#3370ff; color:#fff; cursor:pointer; white-space:nowrap; }
.gen-btn:active { opacity:.85; }
.gen-error { padding:12px 14px; font-size:13px; color:#f53f3f; display:flex; align-items:center; justify-content:space-between; gap:10px; }
.gen-img { display:block; width:100%; max-height:420px; object-fit:contain; }
.gen-video { display:block; width:100%; max-height:420px; background:#000; }
