/**
 * Voice Mode UI Components
 *
 * Refined, professional styling for voice interview mode.
 * Integrates with existing interview UI color scheme and patterns.
 */

/* ============================================
   CSS Variables - Voice Mode Extensions
   ============================================ */
:root {
  /* Voice-specific colors derived from existing palette */
  --voice-recording: #e53935;
  --voice-recording-soft: rgba(229, 57, 53, 0.15);
  --voice-recording-glow: rgba(229, 57, 53, 0.4);
  --voice-processing: #fb8c00;
  --voice-speaking: #43a047;
  --voice-ready: var(--deep-teal, #008080);

  /* Timing */
  --voice-transition: 200ms ease;
  --voice-pulse-duration: 1.5s;
}

/* ============================================
   Voice/Text Mode Toggle
   ============================================ */
.voice-mode-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 20px;
  user-select: none;
}

.voice-mode-toggle__label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--charcoal, #333);
  opacity: 0.6;
  padding: 0 0.5rem;
  transition: opacity var(--voice-transition);
}

.voice-mode-toggle__label.active {
  opacity: 1;
}

.voice-mode-toggle__switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: #ccc;
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--voice-transition);
}

.voice-mode-toggle__switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform var(--voice-transition);
}

.voice-mode-toggle__switch.active {
  background: var(--deep-teal, #008080);
}

.voice-mode-toggle__switch.active::after {
  transform: translateX(20px);
}

.voice-mode-toggle__switch:hover {
  box-shadow: 0 0 0 2px rgba(0, 128, 128, 0.2);
}

/* ============================================
   PTT (Push-to-Talk) Button
   ============================================ */
.ptt-button {
  position: relative;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--deep-teal, #008080);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--voice-transition);
  flex-shrink: 0;

  /* Subtle depth */
  box-shadow:
    0 2px 8px rgba(0, 128, 128, 0.3),
    0 1px 2px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.ptt-button:hover:not(:disabled):not(.recording) {
  transform: scale(1.05);
  box-shadow:
    0 4px 12px rgba(0, 128, 128, 0.4),
    0 2px 4px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.ptt-button:active:not(:disabled),
.ptt-button.recording {
  background: var(--voice-recording);
  box-shadow:
    0 2px 8px var(--voice-recording-glow),
    0 1px 2px rgba(0, 0, 0, 0.1);
}

.ptt-button:disabled {
  background: #b0b0b0;
  cursor: not-allowed;
  box-shadow: none;
}

/* Microphone Icon */
.ptt-button__icon {
  width: 24px;
  height: 24px;
  transition: transform var(--voice-transition);
}

.ptt-button:active:not(:disabled) .ptt-button__icon,
.ptt-button.recording .ptt-button__icon {
  transform: scale(1.1);
}

/* Recording pulse rings */
.ptt-button__pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--voice-recording);
  opacity: 0;
  transform: scale(1);
  pointer-events: none;
}

.ptt-button.recording .ptt-button__pulse {
  animation: ptt-pulse var(--voice-pulse-duration) ease-out infinite;
}

.ptt-button.recording .ptt-button__pulse:nth-child(2) {
  animation-delay: 0.5s;
}

@keyframes ptt-pulse {
  0% {
    opacity: 0.6;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.8);
  }
}

/* Recording duration indicator */
.ptt-button__duration {
  position: absolute;
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--voice-recording);
  opacity: 0;
  transition: opacity var(--voice-transition);
}

.ptt-button.recording .ptt-button__duration {
  opacity: 1;
}

/* ============================================
   Live Caption (Draft Transcript)
   ============================================ */
.live-caption {
  display: none;
  margin-bottom: 1rem;
  animation: live-caption-in 200ms ease-out;
}

.live-caption.visible {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

@keyframes live-caption-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.live-caption__bubble {
  max-width: 80%;
  padding: 0.75rem 1rem;
  background: rgba(0, 128, 128, 0.08);
  border: 2px dashed rgba(0, 128, 128, 0.3);
  border-radius: 12px;
  border-bottom-right-radius: 4px;
  color: var(--charcoal, #333);
  font-style: italic;
  position: relative;
}

.live-caption__bubble::before {
  content: '🎤';
  position: absolute;
  top: -10px;
  right: 12px;
  font-size: 0.875rem;
  background: var(--warm-off-white, #F5F5F5);
  padding: 0 4px;
}

.live-caption__text {
  min-height: 1.4em;
  transition: all 100ms ease;
}

.live-caption__text:empty::after {
  content: 'Listening...';
  opacity: 0.5;
}

/* Subtle shimmer while actively transcribing */
.live-caption.transcribing .live-caption__bubble {
  background: linear-gradient(
    90deg,
    rgba(0, 128, 128, 0.08) 0%,
    rgba(0, 128, 128, 0.12) 50%,
    rgba(0, 128, 128, 0.08) 100%
  );
  background-size: 200% 100%;
  animation: caption-shimmer 1.5s ease-in-out infinite;
}

@keyframes caption-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ============================================
   Voice Status Indicator
   ============================================ */
.voice-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 16px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--charcoal, #333);
  transition: all var(--voice-transition);
}

.voice-status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #999;
  transition: all var(--voice-transition);
}

/* Status: Ready */
.voice-status.ready .voice-status__dot {
  background: var(--voice-ready);
}

/* Status: Recording */
.voice-status.recording {
  background: var(--voice-recording-soft);
  color: var(--voice-recording);
}

.voice-status.recording .voice-status__dot {
  background: var(--voice-recording);
  animation: status-dot-pulse 1s ease-in-out infinite;
}

@keyframes status-dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.2); }
}

/* Status: Processing */
.voice-status.processing {
  background: rgba(251, 140, 0, 0.1);
  color: var(--voice-processing);
}

.voice-status.processing .voice-status__dot {
  background: var(--voice-processing);
  animation: status-dot-spin 1s linear infinite;
}

@keyframes status-dot-spin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(0.8); }
  100% { transform: rotate(360deg) scale(1); }
}

/* Status: Speaking (AI responding) */
.voice-status.speaking {
  background: rgba(67, 160, 71, 0.1);
  color: var(--voice-speaking);
}

.voice-status.speaking .voice-status__dot {
  background: var(--voice-speaking);
  animation: status-dot-wave 0.8s ease-in-out infinite;
}

@keyframes status-dot-wave {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.5); }
}

/* ============================================
   Voice Input Container
   (Replaces text input when voice mode active)
   ============================================ */
.voice-input-container {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: white;
  border-top: 1px solid #e0e0e0;
  min-height: 76px;
}

.voice-input-container.active {
  display: flex;
}

.voice-input-hint {
  font-size: 0.875rem;
  color: var(--charcoal, #333);
  opacity: 0.6;
  text-align: center;
}

.voice-input-hint strong {
  opacity: 1;
  color: var(--deep-teal, #008080);
}

/* ============================================
   AI Speaking Indicator (on message bubble)
   ============================================ */
.chat-bubble.speaking {
  position: relative;
}

.chat-bubble.speaking::after {
  content: '🔊';
  position: absolute;
  top: -8px;
  left: 12px;
  font-size: 0.875rem;
  animation: speaker-pulse 1s ease-in-out infinite;
}

@keyframes speaker-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============================================
   Mobile PTT Button (Toggle Mode)
   ============================================ */
.ptt-button.mobile {
  /* Ensure minimum 60px touch target on mobile */
  min-width: 64px;
  min-height: 64px;
  /* Visual feedback for toggle state */
  transition: all var(--voice-transition), transform 0.1s ease;
}

.ptt-button.mobile:active {
  transform: scale(0.95);
}

/* Mobile toggle visual indicator */
.ptt-button.mobile.recording {
  /* Slightly larger when recording to emphasize active state */
  transform: scale(1.05);
}

.ptt-button.mobile.recording:active {
  transform: scale(1);
}

/* Mobile container adjustments */
.voice-input-container.mobile {
  flex-direction: column;
  gap: 0.75rem;
}

.voice-input-container.mobile .voice-input-hint {
  order: 1;
  font-size: 0.8rem;
}

/* ============================================
   Tap-to-Hear Overlay (iOS Autoplay Fallback)
   ============================================ */
.tap-to-hear-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: tap-to-hear-fade-in 0.2s ease-out;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

@keyframes tap-to-hear-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.tap-to-hear-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem 3rem;
  background: white;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: tap-to-hear-scale-in 0.2s ease-out;
}

@keyframes tap-to-hear-scale-in {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.tap-to-hear-icon {
  font-size: 3rem;
  animation: tap-to-hear-pulse 1.5s ease-in-out infinite;
}

@keyframes tap-to-hear-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

.tap-to-hear-text {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--charcoal, #333);
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 640px) {
  .ptt-button {
    width: 64px;
    height: 64px;
  }

  .ptt-button__icon {
    width: 28px;
    height: 28px;
  }

  .voice-input-container {
    flex-direction: column;
    gap: 0.75rem;
  }

  .voice-input-hint {
    order: 1;
  }

  /* Ensure tap-to-hear is touch-friendly */
  .tap-to-hear-content {
    padding: 1.5rem 2rem;
    margin: 1rem;
  }

  .tap-to-hear-icon {
    font-size: 2.5rem;
  }

  .tap-to-hear-text {
    font-size: 1rem;
  }
}

/* ============================================
   Reduced Motion Support
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .ptt-button__pulse,
  .voice-status__dot,
  .live-caption__bubble,
  .chat-bubble.speaking::after,
  .tap-to-hear-overlay,
  .tap-to-hear-content,
  .tap-to-hear-icon {
    animation: none !important;
  }

  .ptt-button.recording .ptt-button__pulse {
    opacity: 0.3;
    transform: scale(1.3);
  }

  .ptt-button.mobile,
  .ptt-button.mobile.recording {
    transform: none !important;
  }
}
