/**
 * ============================================================
 * VOICE CALL UI — FIXED
 * ============================================================
 *
 * Bugs fixed vs. the previous version:
 *
 * 1. `.voice-shell` declared `display: none;` and then, further
 *    down the SAME rule, `display: flex;`. The second declaration
 *    always won, so the modal was visible full-screen from the
 *    moment the page loaded — that's the giant orb sitting on top
 *    of the chat in the screenshots. Fixed: base state is
 *    `display: none`, and a new `.is-open` class (added by JS only
 *    when the user taps the mic icon) is what turns it on.
 *
 * 2. `position: fixed` positioned the modal relative to the whole
 *    page/iframe, not the chat widget, so it could cover or overlap
 *    things outside the widget (like the floating launcher button).
 *    Fixed: it's now `position: absolute` inside `.preview-panel`,
 *    which already establishes the positioning context
 *    (`position: relative`), so the voice UI is always contained
 *    within the chat card's own bounds.
 */

/* ============================================================
   VOICE SHELL — hidden by default, shown only via .is-open
   ============================================================ */

.voice-shell {
  display: none;

  position: absolute;
  inset: 0;
  z-index: 60;

  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);

  align-items: center;
  justify-content: center;
  flex-direction: column;

  border-radius: inherit;
  overflow: hidden;
}

.voice-shell.is-open {
  display: flex;
  animation: voiceModalFadeIn 0.3s ease-out;
}

/* Minimized state: small corner widget instead of full overlay. */
.voice-shell.is-open.is-collapsed {
  position: absolute;
  bottom: 12px;
  right: 12px;
  top: auto;
  left: auto;
  inset: auto 12px 12px auto;
  width: 220px;
  height: auto;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  align-items: stretch;
  justify-content: flex-end;
  animation: none;
}

/* ============================================================
   VOICE DIALOG — modal content
   ============================================================ */

.voice-dialog {
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 32px 24px;
  max-width: 340px;
  width: 90%;
  text-align: center;
  animation: voiceModalSlideUp 0.3s ease-out;
  position: relative;
}

.voice-shell.is-collapsed .voice-dialog {
  border-radius: 12px;
  padding: 14px;
  max-width: 100%;
  width: 100%;
  animation: none;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

/* ============================================================
   CLOSE BUTTON
   ============================================================ */

.voice-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: none;
  background: #f0f0f0;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transition: all 0.2s ease;
  z-index: 10;
}

.voice-close-btn:hover { background: #e0e0e0; transform: scale(1.05); }
.voice-close-btn:active { transform: scale(0.95); }
.voice-shell.is-collapsed .voice-close-btn { display: none; }

/* ============================================================
   VOICE ORB VISUALIZATION
   ============================================================ */

.voice-orb-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(59, 130, 246, 0.2);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: voiceOrbRingPulse 2s ease-in-out infinite;
}

.voice-orb-ring.voice-orb-ring-one { width: 120px; height: 120px; animation-delay: 0s; }
.voice-orb-ring.voice-orb-ring-two { width: 156px; height: 156px; animation-delay: 0.3s; }

.voice-orb {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
  box-shadow: 0 10px 40px rgba(59, 130, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.voice-orb.is-listening { animation: voiceOrbListening 1.5s ease-in-out infinite; }
.voice-orb.is-thinking { animation: voiceOrbThinking 0.8s ease-in-out infinite; }
.voice-orb.is-speaking { animation: voiceOrbSpeaking 0.6s ease-in-out infinite; }

.voice-orb-core {
  width: 40px;
  height: 40px;
  background: white;
  border-radius: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.voice-orb-core::before { content: '🎤'; }

.voice-orb-cloud, .voice-orb-particle {
  position: absolute;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
}

.voice-orb-cloud-one { width: 18px; height: 18px; top: 15%; left: 20%; animation: voiceOrbParticleFloat 3s ease-in-out infinite; }
.voice-orb-cloud-two { width: 14px; height: 14px; top: 20%; right: 15%; animation: voiceOrbParticleFloat 3.5s ease-in-out infinite 0.5s; }
.voice-orb-particle-one { width: 10px; height: 10px; bottom: 20%; left: 15%; animation: voiceOrbParticleFloat 2.8s ease-in-out infinite 0.3s; }
.voice-orb-particle-two { width: 12px; height: 12px; bottom: 15%; right: 18%; animation: voiceOrbParticleFloat 3.2s ease-in-out infinite 0.7s; }
.voice-orb-particle-three { width: 9px; height: 9px; top: 50%; right: 10%; animation: voiceOrbParticleFloat 2.6s ease-in-out infinite 0.2s; }

.voice-shell.is-collapsed .voice-orb { width: 52px; height: 52px; margin-bottom: 10px; }
.voice-shell.is-collapsed .voice-orb-ring { display: none; }

/* ============================================================
   VOICE COPY
   ============================================================ */

.voice-copy { margin-bottom: 22px; }
.voice-shell.is-collapsed .voice-copy { margin-bottom: 10px; }

#voice-title { font-size: 18px; font-weight: 600; color: #111; margin: 0 0 6px 0; line-height: 1.3; }
.voice-shell.is-collapsed #voice-title { font-size: 13px; font-weight: 600; margin-bottom: 3px; }

#voice-subtitle { font-size: 13px; color: #666; margin: 0; }
.voice-shell.is-collapsed #voice-subtitle { font-size: 11px; color: #888; }

/* ============================================================
   VOICE CONTROLS
   ============================================================ */

.voice-controls { display: flex; flex-direction: column; gap: 10px; }
.voice-shell.is-collapsed .voice-controls { gap: 6px; }

.voice-button {
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
  position: relative;
  overflow: hidden;
}

.voice-button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(59, 130, 246, 0.35); }
.voice-button:active:not(:disabled) { transform: translateY(0); }
.voice-button:disabled { opacity: 0.6; cursor: not-allowed; }
.voice-shell.is-collapsed .voice-button { padding: 9px 14px; font-size: 12px; }

.voice-button-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  display: inline-block;
  animation: voiceButtonIconPulse 1.5s ease-in-out infinite;
}

.voice-button.is-listening .voice-button-icon { animation: voiceButtonIconListen 1s ease-in-out infinite; }
.voice-button.is-thinking .voice-button-icon { animation: voiceButtonIconThink 0.8s ease-in-out infinite; }
.voice-button.is-speaking .voice-button-icon { animation: voiceButtonIconSpeak 0.6s ease-in-out infinite; }

/* ============================================================
   STATUS & METADATA
   ============================================================ */

.voice-status-meta { display: flex; justify-content: center; align-items: center; gap: 10px; font-size: 12px; color: #666; }
.voice-shell.is-collapsed .voice-status-meta { font-size: 10px; justify-content: space-between; }

#voice-status { display: flex; align-items: center; gap: 6px; }
#voice-status::before { content: ''; width: 7px; height: 7px; background: #10b981; border-radius: 50%; display: inline-block; animation: voiceStatusPulse 2s ease-in-out infinite; }

.voice-shell.is-error #voice-status::before { background: #ef4444; }
.voice-shell.is-error #voice-status { color: #ef4444; }

#voice-remaining { font-size: 11px; color: #999; }
.voice-shell.is-collapsed #voice-remaining { font-size: 9px; }

/* ============================================================
   MINI TOGGLE (restores from collapsed) — contained in the panel
   ============================================================ */

.voice-mini-toggle {
  display: none;
  position: absolute;
  bottom: 68px;
  right: 12px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
  color: white;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  z-index: 55;
  transition: all 0.2s ease;
  animation: voiceMinToggleSlideUp 0.3s ease-out;
}

.voice-mini-toggle.is-visible { display: flex; align-items: center; gap: 6px; }
.voice-mini-toggle:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4); }
.voice-mini-toggle::before { content: '🎤'; font-size: 14px; }

/* ============================================================
   CHAT FORM — compact mic toggle button next to Send
   ============================================================ */

.preview-panel { position: relative; z-index: 1; overflow: hidden; }

.chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-form #chat-input { flex: 1 1 auto; min-width: 0; }

.chat-form button[type="submit"] { flex: 0 0 auto; }

.voice-toggle-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes voiceModalFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes voiceModalSlideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
@keyframes voiceOrbRingPulse { 0%, 100% { opacity: 0.3; transform: translate(-50%, -50%) scale(1); } 50% { opacity: 0.1; transform: translate(-50%, -50%) scale(1.1); } }
@keyframes voiceOrbListening { 0%, 100% { transform: scale(1); box-shadow: 0 10px 40px rgba(59, 130, 246, 0.3); } 50% { transform: scale(1.05); box-shadow: 0 10px 50px rgba(59, 130, 246, 0.4); } }
@keyframes voiceOrbThinking { 0%, 100% { transform: scale(1); } 50% { transform: scale(0.98); } }
@keyframes voiceOrbSpeaking { 0%, 100% { transform: scale(1); box-shadow: 0 10px 40px rgba(59, 130, 246, 0.3); } 25% { transform: scale(1.03); box-shadow: 0 10px 45px rgba(59, 130, 246, 0.35); } 50% { transform: scale(1); } 75% { transform: scale(1.02); box-shadow: 0 10px 45px rgba(59, 130, 246, 0.35); } }
@keyframes voiceOrbParticleFloat { 0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.3; } 50% { transform: translate(var(--tx, 8px), var(--ty, -8px)) scale(0.8); opacity: 0.5; } }
@keyframes voiceButtonIconPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }
@keyframes voiceButtonIconListen { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }
@keyframes voiceButtonIconThink { 0%, 100% { transform: scale(1); } 50% { transform: scale(0.9); } }
@keyframes voiceButtonIconSpeak { 0%, 100% { transform: scaleY(0.8); } 25% { transform: scaleY(1.1); } 50% { transform: scaleY(0.9); } 75% { transform: scaleY(1); } }
@keyframes voiceStatusPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes voiceMinToggleSlideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 480px) {
  .voice-dialog { max-width: 100%; width: 100%; padding: 26px 18px; border-radius: 12px; }
  .voice-orb { width: 84px; height: 84px; margin-bottom: 16px; }
  .voice-orb-ring { display: none; }
  #voice-title { font-size: 16px; }
  #voice-subtitle { font-size: 12px; }
  .voice-button { padding: 10px 18px; font-size: 13px; }
  .voice-mini-toggle { bottom: 60px; right: 10px; padding: 8px 14px; font-size: 12px; }
  .voice-shell.is-collapsed { width: 190px; }
}

/* ============================================================
   DARK MODE
   ============================================================ */

@media (prefers-color-scheme: dark) {
  .voice-dialog { background: #1f2937; color: white; }
  .voice-close-btn { background: #374151; }
  .voice-close-btn:hover { background: #4b5563; }
  #voice-title { color: white; }
  #voice-subtitle, .voice-status-meta { color: #d1d5db; }
}