.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 110px);
  height: calc(100dvh - 80px);
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-user-meta {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.chat-user-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-billing-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: var(--primary-50);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--primary-200);
}

.billing-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.billing-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--primary-800);
  letter-spacing: 0.05em;
}

.billing-val {
  font-size: 1rem;
  font-weight: 800;
  color: var(--primary-900);
}

.messages-pane {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: #fbfcfd;
}

.message-row {
  display: flex;
  flex-direction: column;
  max-width: 70%;
}

.message-row.sent {
  align-self: flex-end;
  align-items: flex-end;
}

.message-row.received {
  align-self: flex-start;
  align-items: flex-start;
}

.message-bubble {
  padding: 0.8rem 1.1rem;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.4;
  position: relative;
  word-break: break-word;
}

.message-row.sent .message-bubble {
  background: var(--primary-700);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-row.received .message-bubble {
  background: #f1f5f9;
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.message-attachment-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  margin-top: 0.35rem;
}

.chat-input-bar {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: white;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
}

.chat-input-normal {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.chat-input {
  flex: 1;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border-color);
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
}

.chat-input:focus {
  border-color: var(--primary-600);
}

.chat-mic-btn {
  background: #f1f5f9;
  border: 1.5px solid var(--border-color);
  color: var(--text-secondary);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  flex-shrink: 0;
}

.chat-mic-btn:hover {
  background: var(--primary-50);
  color: var(--primary-700);
  border-color: var(--primary-200);
  transform: scale(1.04);
}

.chat-mic-btn.active, .chat-mic-btn:active {
  background: var(--danger-light);
  color: var(--danger);
  border-color: var(--danger);
  transform: scale(0.96);
}

.typing-indicator {
  padding: 0.5rem 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 28px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  display: inline-block;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Reconnection Session Divider */
.chat-session-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1.25rem 0;
  width: 100%;
}

.chat-session-divider .divider-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, #cbd5e1, #cbd5e1, transparent);
}

.chat-session-divider .divider-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.9rem;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #475569;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-session-divider .divider-pill svg {
  color: #059669;
}

/* System Message in Chat */
.chat-system-message {
  display: flex;
  justify-content: center;
  margin: 0.5rem 0;
  width: 100%;
}

.system-message-bubble {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #475569;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
}

.system-message-bubble .system-time {
  font-size: 0.68rem;
  color: #94a3b8;
  margin-left: 0.25rem;
}

/* Messages from previous session subtle styling */
.message-row.previous-session-msg {
  opacity: 0.88;
}

/* ============================================================
   AUDIO RECORDING, PREVIEW & BUBBLE STYLES
   ============================================================ */

/* Recording Bar */
.chat-recording-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: #fff5f5;
  border: 1.5px solid #fecaca;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-full);
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  animation: slideUpFade 0.2s ease-out;
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.recording-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.recording-pulse-dot {
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  animation: recBlink 1s infinite alternate;
}

@keyframes recBlink {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0.3; transform: scale(0.75); }
}

.recording-title {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--danger);
  letter-spacing: 0.05em;
}

.recording-timer {
  font-family: monospace;
  font-size: 1rem;
  font-weight: 800;
  color: var(--danger);
}

.recording-waveform {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: 1;
  max-width: 140px;
  height: 24px;
  justify-content: center;
}

.wave-bar {
  width: 3px;
  height: 6px;
  background: var(--danger);
  border-radius: 2px;
  animation: waveAnim 1s infinite ease-in-out alternate;
}

.wave-bar:nth-child(1) { animation-delay: 0.1s; height: 14px; }
.wave-bar:nth-child(2) { animation-delay: 0.3s; height: 8px; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; height: 18px; }
.wave-bar:nth-child(4) { animation-delay: 0.4s; height: 12px; }
.wave-bar:nth-child(5) { animation-delay: 0.25s; height: 22px; }
.wave-bar:nth-child(6) { animation-delay: 0.5s; height: 16px; }
.wave-bar:nth-child(7) { animation-delay: 0.15s; height: 10px; }
.wave-bar:nth-child(8) { animation-delay: 0.35s; height: 20px; }
.wave-bar:nth-child(9) { animation-delay: 0.45s; height: 8px; }
.wave-bar:nth-child(10) { animation-delay: 0.2s; height: 14px; }

@keyframes waveAnim {
  0% { transform: scaleY(0.3); opacity: 0.6; }
  100% { transform: scaleY(1); opacity: 1; }
}

.recording-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-rec-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-rec-ctrl.btn-cancel {
  background: #ffffff;
  color: #b91c1c;
  border-color: #fca5a5;
}
.btn-rec-ctrl.btn-cancel:hover {
  background: #fee2e2;
}

.btn-rec-ctrl.btn-stop {
  background: #ffffff;
  color: #475569;
  border-color: #cbd5e1;
}
.btn-rec-ctrl.btn-stop:hover {
  background: #f1f5f9;
}

.btn-rec-ctrl.btn-send {
  background: var(--primary-700);
  color: #ffffff;
}
.btn-rec-ctrl.btn-send:hover {
  background: var(--primary-800);
}

/* Audio Preview Bar */
.chat-preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: #f8fafc;
  border: 1.5px solid var(--border-color);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-full);
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  animation: slideUpFade 0.2s ease-out;
}

.preview-player {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
}

.btn-preview-play {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-700);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
  transition: transform 0.1s ease;
}

.btn-preview-play:hover {
  transform: scale(1.06);
}

.preview-scrubber {
  flex: 1;
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
}

.preview-fill {
  height: 100%;
  background: var(--primary-600);
  width: 0%;
  border-radius: 3px;
  transition: width 0.1s linear;
}

.preview-time {
  font-size: 0.8rem;
  font-family: monospace;
  font-weight: 700;
  color: var(--text-secondary);
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Error & Retry Bar */
.chat-audio-error-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: #fff1f2;
  border: 1px solid #fecdd3;
  padding: 0.45rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  color: #be123c;
  font-weight: 600;
}

/* Audio Message Bubble in Chat History */
.message-bubble.audio-bubble {
  min-width: 250px;
  max-width: 320px;
  padding: 0.75rem 1rem;
}

.audio-message-player {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  user-select: none;
}

.audio-play-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.message-row.sent .audio-play-toggle {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}
.message-row.sent .audio-play-toggle:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.05);
}

.message-row.received .audio-play-toggle {
  background: var(--primary-700);
  color: white;
}
.message-row.received .audio-play-toggle:hover {
  background: var(--primary-800);
  transform: scale(1.05);
}

.audio-waveform-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
  padding: 0.35rem 0;
}

.audio-waveform-track {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}

.message-row.sent .audio-waveform-track {
  background: rgba(255, 255, 255, 0.3);
}

.message-row.received .audio-waveform-track {
  background: #cbd5e1;
}

.audio-waveform-progress {
  height: 100%;
  border-radius: 3px;
  width: 0%;
  transition: width 0.08s linear;
}

.message-row.sent .audio-waveform-progress {
  background: #ffffff;
}

.message-row.received .audio-waveform-progress {
  background: var(--primary-700);
}

.audio-duration-display {
  font-size: 0.78rem;
  font-family: monospace;
  font-weight: 700;
  flex-shrink: 0;
}

.message-row.sent .audio-duration-display {
  color: rgba(255, 255, 255, 0.9);
}

.message-row.received .audio-duration-display {
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  .chat-main-wrapper {
    padding: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
    height: 100dvh;
    height: 100vh;
  }

  .chat-container {
    height: 100dvh;
    height: 100vh;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  .chat-header {
    padding: 0.65rem 0.85rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .chat-user-meta {
    gap: 0.5rem;
  }

  .chat-user-avatar {
    width: 36px;
    height: 36px;
  }

  .chat-billing-bar {
    gap: 0.75rem;
    padding: 0.35rem 0.75rem;
    width: 100%;
    justify-content: space-between;
  }

  .billing-label {
    font-size: 0.62rem;
  }

  .billing-val {
    font-size: 0.88rem;
  }

  .messages-pane {
    padding: 0.85rem 0.75rem;
  }

  .message-row {
    max-width: 88%;
  }

  .chat-input-bar {
    padding: 0.65rem 0.75rem max(0.65rem, env(safe-area-inset-bottom)) 0.75rem;
  }

  .chat-input {
    font-size: 16px !important;
    padding: 0.65rem 0.95rem;
  }

  .chat-recording-bar {
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }

  .recording-waveform {
    display: none;
  }

  .btn-rec-ctrl span {
    display: none;
  }

  .btn-rec-ctrl {
    padding: 0.5rem;
  }

  .message-bubble.audio-bubble {
    min-width: 200px;
    max-width: 260px;
  }
}

@media (max-width: 480px) {
  .chat-billing-bar {
    gap: 0.4rem;
    padding: 0.3rem 0.5rem;
  }

  .billing-item {
    align-items: center;
  }

  #btnEndCall {
    padding: 0.35rem 0.65rem !important;
    font-size: 0.75rem !important;
  }

  .chat-mic-btn {
    width: 40px;
    height: 40px;
  }

  #sendBtn {
    padding: 0.65rem 1rem !important;
    font-size: 0.88rem !important;
  }
}
