/* 微信式左右语音气泡 — 极简单页 */

/* 防止组件自身的 display 样式覆盖 HTML hidden 属性。 */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { background: #ededed; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
               "Helvetica Neue", Arial, sans-serif;
  background: #ededed;
  color: #111;
  display: flex;
  flex-direction: column;
  /* 100vh 在部分手机浏览器中会把底部工具栏也算进去。
     优先使用 JS 提供的当前可见高度，其次使用动态视口单位。 */
  height: var(--app-height, 100dvh);
  min-height: 0;
  overflow: hidden;
}

/* ------- Top bar ------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #f7f7f7;
  border-bottom: 1px solid #d8d8d8;
  flex: 0 0 auto;
}
.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: #111;
}
.btn-clear {
  background: #fff;
  border: 1px solid #d0d0d0;
  color: #555;
  border-radius: 4px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn-clear:hover { background: #f0f0f0; }

/* ------- Messages ------- */
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #ededed;
}
.bubble-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}
.bubble-row.is-user    { flex-direction: row-reverse; }
.bubble-row.is-ai      { flex-direction: row; }

.avatar {
  width: 36px; height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: #fff;
  border: 1px solid #e0e0e0;
  flex: 0 0 36px;
}

.bubble {
  max-width: 70%;
  padding: 9px 12px 10px;
  border-radius: 8px;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,0.04);
  font-size: 14px;
  line-height: 1.55;
}

/* 用户气泡（右侧，浅绿） */
.bubble-row.is-user .bubble {
  background: #95ec69;
  color: #111;
  border-top-right-radius: 2px;
}
/* AI 气泡（左侧，白色） */
.bubble-row.is-ai .bubble {
  background: #ffffff;
  color: #111;
  border-top-left-radius: 2px;
}

.bubble-row.is-user .bubble::after {
  content: "";
  position: absolute;
  right: -6px; top: 12px;
  border: 6px solid transparent;
  border-left-color: #95ec69;
  border-right: 0;
}
.bubble-row.is-ai .bubble::after {
  content: "";
  position: absolute;
  left: -6px; top: 12px;
  border: 6px solid transparent;
  border-right-color: #ffffff;
  border-left: 0;
}

/* 语音气泡：横长方形 + 三道音波 + 时长 */
.bubble.is-audio {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 120px;
  cursor: pointer;
  user-select: none;
}
.wave {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  width: 22px;
  height: 18px;
  flex: 0 0 22px;
}
.wave span {
  display: block;
  width: 3px;
  background: #111;
  border-radius: 1px;
  animation: wave-pulse 1.1s infinite ease-in-out;
}
.wave span:nth-child(1) { height: 6px;  animation-delay: 0s; }
.wave span:nth-child(2) { height: 12px; animation-delay: 0.15s; }
.wave span:nth-child(3) { height: 18px; animation-delay: 0.3s; }
.wave span:nth-child(4) { height: 10px; animation-delay: 0.45s; }

.bubble.is-playing .wave span { animation-play-state: running; }
.bubble:not(.is-playing) .wave span { animation-play-state: paused; opacity: 0.5; }

.audio-meta {
  font-size: 12px;
  color: rgba(0,0,0,0.55);
  margin-left: 4px;
}

/* 显示文本按钮（只 AI 侧有） */
.show-text-btn {
  background: rgba(0,0,0,0.05);
  border: none;
  border-radius: 4px;
  color: #555;
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  margin-left: 8px;
}
.show-text-btn:hover { background: rgba(0,0,0,0.1); }

.text-panel {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(0,0,0,0.12);
}
.text-panel-en { color: #111; font-weight: 500; }
.text-panel-zh { color: #555; margin-top: 4px; font-size: 13px; }

/* 系统消息 */
.sys-msg {
  align-self: center;
  background: rgba(0,0,0,0.06);
  color: #666;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  margin: 4px auto;
}

/* 错误气泡 */
.bubble.is-error {
  background: #fff1f0 !important;
  color: #c0392b !important;
  border: 1px solid #f5c6cb;
}

/* ------- Composer ------- */
.composer {
  flex: 0 0 auto;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  background: #f7f7f7;
  border-top: 1px solid #d8d8d8;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.rec-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #c0392b;
}
.rec-dot {
  width: 10px; height: 10px;
  background: #c0392b;
  border-radius: 50%;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }
@keyframes wave-pulse {
  0%, 100% { transform: scaleY(0.4); }
  50%      { transform: scaleY(1); }
}

.btn-record {
  width: 76%;
  max-width: 360px;
  height: 56px;
  border-radius: 28px;
  border: 1px solid #d0d0d0;
  background: #ffffff;
  font-size: 15px;
  font-weight: 500;
  color: #111;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.05s, background 0.15s;
  user-select: none;
  -webkit-user-select: none;
}
.btn-record:active,
.btn-record.is-recording {
  background: #95ec69;
  border-color: #7ad052;
  transform: scale(0.98);
}
.mic-icon { font-size: 18px; }

/* ------- Confirm modal ------- */
.confirm-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.confirm-card {
  background: #fff;
  border-radius: 8px;
  width: 280px;
  padding: 22px 20px 16px;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.2);
}
.confirm-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.confirm-sub { font-size: 13px; color: #666; margin-bottom: 18px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions button {
  flex: 1;
  height: 38px;
  border-radius: 6px;
  border: 1px solid #d0d0d0;
  font-size: 14px;
  cursor: pointer;
}
.btn-secondary { background: #fff; color: #333; }
.btn-secondary:hover { background: #f0f0f0; }
.btn-danger { background: #c0392b; color: #fff; border-color: #c0392b; }
.btn-danger:hover { background: #a93226; }

/* error toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: rgba(0,0,0,0.78);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 200;
}