* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  background: #000;
  overflow: hidden;
}
.page {
  position: relative;
  max-width: 480px;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
  background: #000;
}

/* ===== 背景视频（全屏） ===== */
.video-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.video-bg video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.video-bg video.active {
  display: block;
}

/* ===== 覆盖层通用 ===== */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

/* ===== 未通话状态 ===== */
.overlay.idle {
  justify-content: flex-end;
  align-items: center;
}

/* ===== 通话中状态 ===== */
.overlay.calling {
  background: rgba(0,0,0,0.3);
}
/* 右上：用户摄像头 */
.camera-panel {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: 8px;
  width: 120px;
  height: 160px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  z-index: 2;
  background: #1a1a2e;
}
.camera-panel video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* 镜像 */
}

/* ===== 消息区 ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 180px 14px 10px; /* 顶部留出视频窗空间 */
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(to bottom, transparent 0, #000 60px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 60px);
}

/* ===== 用户语音气泡 ===== */
.voice-msg {
  position: relative;
  align-self: flex-end;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 78%;
  margin-bottom: 12px;
  padding: 10px 13px;
  border-radius: 8px;
  background: #95ec69;
  color: #1a1a2e;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  animation: msg-in 0.25s ease-out;
}
.voice-msg::after {
  content: "";
  position: absolute;
  right: -5px;
  top: 12px;
  width: 10px;
  height: 10px;
  background: #95ec69;
  transform: rotate(45deg);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.voice-msg .wave {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 2.5px;
  height: 16px;
}
.voice-msg .wave i {
  width: 3px;
  border-radius: 2px;
  background: #1a1a2e;
  height: 5px;
}
.voice-msg .wave i:nth-child(1) { height: 6px; }
.voice-msg .wave i:nth-child(2) { height: 12px; }
.voice-msg .wave i:nth-child(3) { height: 16px; }
.voice-msg .wave i:nth-child(4) { height: 9px; }
.voice-msg.live .wave i {
  animation: wave-bounce 0.9s ease-in-out infinite;
}
.voice-msg.live .wave i:nth-child(2) { animation-delay: 0.15s; }
.voice-msg.live .wave i:nth-child(3) { animation-delay: 0.3s; }
.voice-msg.live .wave i:nth-child(4) { animation-delay: 0.45s; }
@keyframes wave-bounce {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1.2); }
}
.voice-msg.playable { cursor: pointer; }
.voice-msg.playable:active { opacity: 0.85; }

/* ===== AI 回复气泡 ===== */
.ai-msg {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 85%;
  margin-bottom: 14px;
  background: none;
  box-shadow: none;
  padding: 0;
  animation: msg-in 0.25s ease-out;
}
.ai-msg .content {
  position: relative;
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 13px;
  border-radius: 8px;
  background: #ffffff;
  color: #1a1a2e;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  min-height: 20px;
}
.ai-msg .content::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 12px;
  width: 10px;
  height: 10px;
  background: #ffffff;
  transform: rotate(45deg);
}
.ai-msg .wave {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 16px;
  width: 18px;
}
.ai-msg .wave i {
  width: 3px;
  border-radius: 2px;
  background: #1a1a2e;
  height: 5px;
}
.ai-msg .wave i:nth-child(1) { height: 6px; }
.ai-msg .wave i:nth-child(2) { height: 12px; }
.ai-msg .wave i:nth-child(3) { height: 16px; }
.ai-msg .wave i:nth-child(4) { height: 9px; }
.ai-msg.live .wave i,
.ai-msg.playing .wave i {
  animation: wave-bounce 0.9s ease-in-out infinite;
}
.ai-msg.live .wave i:nth-child(2),
.ai-msg.playing .wave i:nth-child(2) { animation-delay: 0.15s; }
.ai-msg.live .wave i:nth-child(3),
.ai-msg.playing .wave i:nth-child(3) { animation-delay: 0.3s; }
.ai-msg.live .wave i:nth-child(4),
.ai-msg.playing .wave i:nth-child(4) { animation-delay: 0.45s; }
.ai-msg.playable { cursor: pointer; }
.ai-msg.playable:active .content { opacity: 0.85; }
.ai-msg.playing .content { background: #f0f0f0; }
.ai-msg .typing-dots { display: inline-flex; gap: 3px; }
.ai-msg .typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #999;
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.ai-msg .typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.ai-msg .typing-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* ===== 底部通话控制栏 ===== */
.call-bar {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 10px 0 calc(34px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
}
.call-btn {
  width: 68px;
  height: 68px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #34c759;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
}
.call-btn svg {
  width: 32px;
  height: 32px;
  fill: #fff;
}
.call-btn:active { opacity: 0.85; }
.call-btn.calling {
  background: #ff3b30;
}
.call-btn.calling svg {
  transform: rotate(135deg);
}
.call-btn.hangup {
  background: #ff3b30;
}
.call-btn.hangup svg rect {
  fill: #fff;
}

/* ===== idle 双按钮（通话 + 录音转写） ===== */
.call-bar.idle-bar {
  gap: 28px;
}
.call-btn.rec {
  background: #0a84ff;
}

/* ===== 录音类型选择弹层（点击录音按钮弹出，底部动作面板） ===== */
.mode-picker {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(0, 0, 0, 0.45);
}
.mode-sheet {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.mode-sheet-title {
  text-align: center;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  padding: 4px 0 6px;
}
.mode-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
  border: none;
  border-radius: 14px;
  background: rgba(28, 30, 40, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mode-option:active { background: rgba(50, 53, 68, 0.96); }
.mode-option-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}
.mode-option-desc {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
}
.mode-cancel {
  padding: 13px 16px;
  border: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.mode-cancel:active { background: rgba(255, 255, 255, 0.24); }

/* ===== 门诊录音转写 ===== */
.overlay.transcribe {
  background: linear-gradient(180deg, #11182a 0%, #0a0e18 100%);
  z-index: 3;
}
.ts-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.ts-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #555;
  flex-shrink: 0;
}
.ts-dot.on {
  background: #ff3b30;
  animation: ts-blink 1.2s ease-in-out infinite;
}
@keyframes ts-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.ts-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
}
.ts-swap {
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ts-swap:active { opacity: 0.7; }
.ts-messages {
  flex: 1;
  min-height: 0;               /* flex 关键：允许收缩，避免长缓冲文本把它挤破重叠 */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}
.ts-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  margin-bottom: 14px;
  animation: msg-in 0.25s ease-out;
}
.ts-msg .ts-role {
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  margin-bottom: 4px;
}
.ts-msg .ts-bubble {
  padding: 10px 13px;
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.55;
  color: #1a1a2e;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.ts-msg.doctor {
  align-self: flex-start;
  align-items: flex-start;
}
.ts-msg.doctor .ts-bubble {
  background: #ffffff;
  border-top-left-radius: 2px;
}
.ts-msg.patient {
  align-self: flex-end;
  align-items: flex-end;
}
.ts-msg.patient .ts-bubble {
  background: #95ec69;
  border-top-right-radius: 2px;
}
.ts-msg.unknown {
  align-self: flex-start;
}
.ts-msg.unknown .ts-bubble {
  background: #e8e8ee;
}
.ts-msg.live {
  align-self: flex-start;
}
.ts-msg.live .ts-role { display: none; }
.ts-msg.live .ts-bubble {
  background: rgba(255,255,255,0.16);
  color: rgba(255,255,255,0.9);
  font-style: italic;
  box-shadow: none;
}
/* 缓冲区展示条：界面偏下方、停止按钮上方 */
.ts-buffer {
  flex-shrink: 0;
  margin: 0 14px 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.07);
  border: 1px dashed rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.82);
  font-size: 13.5px;
  line-height: 1.5;
  max-height: 96px;            /* 固定上限，超出内部滚动，绝不顶到对话区 */
  overflow-y: auto;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}
.ts-buffer .ts-buffer-label {
  display: block;
  font-size: 11px;
  color: rgba(255,255,255,0.42);
  margin-bottom: 3px;
  letter-spacing: 0.5px;
}
/* 缓冲区逐句换行显示 */
.ts-buffer .ts-buffer-text {
  white-space: pre-line;
}
/* 可回放的气泡 */
.ts-msg.playable {
  cursor: pointer;
  transition: opacity 0.15s;
}
.ts-msg.playable:hover .ts-bubble {
  filter: brightness(0.96);
}
.ts-msg.playing .ts-bubble {
  outline: 2px solid #3b82f6;
  outline-offset: 1px;
}
/* 用户视频框下方状态（人脸/人声各占一行） */
.cam-status {
  position: absolute;
  /* camera-panel: right 8px, top 8px+safe-area, height 160px -> 下方 6px 处 */
  top: calc(174px + env(safe-area-inset-top));
  right: 8px;
  width: 120px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  z-index: 2;
}
.cam-badge {
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.4;
  color: #fff;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .2s;
}
.cam-badge.on { background: rgba(46, 160, 67, .88); }
.cam-badge.warn { background: rgba(217, 119, 6, .92); }
/* ===== 电子病历：翻转切换视图 ===== */
.ts-view {
  flex: 1;
  min-height: 0;
  position: relative;
  margin: 12px 14px 10px;
  perspective: 1200px;
  transition: transform 0.55s cubic-bezier(0.4, 0.1, 0.35, 1.15);
  transform-style: preserve-3d;
}
.ts-view.flip { transform: rotateY(180deg); }

.ts-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 14px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.35);
}
.ts-front { background: #101623; }
.ts-back {
  transform: rotateY(180deg);
  background: #fff;
}

/* 对话记录区保留原气泡滚动样式（ts-face 已管 overflow/pseudo 滚动条时单独设 Y） */
.ts-messages { overflow-y: auto; padding: 4px 8px; -webkit-overflow-scrolling: touch; }

/* 病历视图 */
.ts-emr { display: flex; flex-direction: column; background: #fff; }
.emr-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #f0f2f5;
  background: #fafbfe;
  flex-shrink: 0;
}
.emr-title {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a2e;
  letter-spacing: 0.3px;
}
.emr-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  font-size: 14.5px;
  line-height: 1.8;
  color: #222;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}
.emr-copy {
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 12px;
  padding: 3.5px 13px;
  border-radius: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  backdrop-filter: blur(4px);
  transition: background 0.2s;
}
.emr-copy:hover { background: rgba(255,255,255,0.28); }
.emr-copy:active { opacity: 0.75; }

/* ===== 底部操作栏：停止 + 电子病历按钮（卡片化美化） ===== */
.call-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent 0%, rgba(255,255,255,0.03) 100%);
}
.call-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.16s, box-shadow 0.16s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  -webkit-tap-highlight-color: transparent;
}
.call-btn:active:not(:disabled) {
  transform: scale(0.92);
}
.call-btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }
.call-btn svg { width: 26px; height: 26px; fill: #fff; }

/* 停止录音按钮 */
.call-btn.hangup {
  background: linear-gradient(145deg, #e30016 0%, #c5000f 100%);
}
.call-btn.hangup:active:not(:disabled) {
  box-shadow: 0 2px 8px rgba(227, 0, 22, 0.45);
}

/* 电子病历按钮 */
.call-btn.emr {
  background: linear-gradient(145deg, #ffba6b 0%, #fa8c16 100%);
  box-shadow: 0 4px 18px rgba(250, 140, 22, 0.4);
}
.call-btn.emr svg { fill: #fff; }
.call-btn.emr.active {
  background: linear-gradient(145deg, #fa8c16 0%, #e07800 100%);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.18), 0 2px 8px rgba(250,140,22,0.6);
}
.call-btn.emr.loading svg {
  animation: emrPulse 1.05s ease-in-out infinite;
}
.call-btn.emr:disabled {
  background: #555a66;
  box-shadow: none;
}
.call-btn.emr:disabled svg { fill: #9aa0ab; }

@keyframes emrPulse {
  0%, 100% { opacity: 0.85; transform: scale(0.92); }
  50%      { opacity: 1; transform: scale(1.1); }
}
