/* ==========================================================================
   Real-Time Audio Waveform Visualizer & Hardware Device Switcher Stylesheet
   Benchmark: Telegram Web voice recording waveform & Zoom/Teams device switcher
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Real-Time Recording Waveform Canvas inside #voice-recorder-bar
   -------------------------------------------------------------------------- */
.voice-recorder-bar {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.28);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  width: 100%;
  box-sizing: border-box;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.voice-recorder-bar.is-paused {
  background: rgba(245, 158, 11, 0.08) !important;
  border-color: rgba(245, 158, 11, 0.35) !important;
}

/* Left Section: Dot, Hands-Free Lock, Timer */
.recorder-left-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.record-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  animation: pulse 1.2s infinite ease-in-out;
  flex-shrink: 0;
}

.voice-recorder-bar.is-paused .record-pulse-dot {
  background: #f59e0b;
  animation: none;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
}

/* Hands-Free Recording Lock Button */
.btn-lock-record {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted, #94a3b8);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  flex-shrink: 0;
  outline: none;
}

.btn-lock-record:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main, #f8fafc);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-lock-record.is-locked {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.35);
  color: #34d399;
}

.btn-lock-record.is-locked:hover {
  background: rgba(16, 185, 129, 0.25);
  border-color: rgba(16, 185, 129, 0.5);
}

.btn-lock-record svg {
  flex-shrink: 0;
}

.record-timer {
  font-size: 14px;
  font-weight: 700;
  color: #fca5a5;
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: center;
}

.voice-recorder-bar.is-paused .record-timer {
  color: #fcd34d;
}

.record-waveform {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 120px;
  height: 36px;
  overflow: hidden;
}

/* Hide legacy static CSS bars when visualizer is initialized */
.record-waveform.has-canvas .bar {
  display: none !important;
}

.voice-record-canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 6px;
  pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(239, 68, 68, 0.35));
}

.voice-recorder-bar.is-paused .voice-record-canvas {
  filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.35));
}

/* --------------------------------------------------------------------------
   Embedded Pre-Send Playback Preview Player inside #voice-recorder-bar
   -------------------------------------------------------------------------- */
.voice-preview-container {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 0 4px;
}

.btn-preview-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  outline: none;
}

.btn-preview-play:hover {
  background: rgba(245, 158, 11, 0.3);
  border-color: rgba(245, 158, 11, 0.6);
  transform: scale(1.05);
}

.btn-preview-play:active {
  transform: scale(0.95);
}

.preview-scrubber-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  height: 24px;
  min-width: 70px;
}

.preview-scrubber-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  overflow: hidden;
  pointer-events: none;
}

.preview-scrubber-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  border-radius: 3px;
  transition: width 0.06s linear;
}

.preview-progress {
  position: relative;
  width: 100%;
  height: 24px;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}

.preview-progress:focus {
  outline: none;
}

.preview-progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fbbf24;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.7);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.preview-progress::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

.preview-progress::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fbbf24;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.7);
  cursor: pointer;
  border: none;
}

.preview-progress::-moz-range-track {
  background: transparent;
  border: none;
}

.preview-time-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 600;
  color: #fcd34d;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

.preview-time-divider {
  color: rgba(255, 255, 255, 0.35);
  margin: 0 1px;
}

/* --------------------------------------------------------------------------
   Recorder Action Buttons
   -------------------------------------------------------------------------- */
.recorder-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-recorder-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  outline: none;
}

.btn-pause-record {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fbbf24;
}

.btn-pause-record:hover {
  background: rgba(245, 158, 11, 0.26);
  border-color: rgba(245, 158, 11, 0.55);
  color: #fef3c7;
}

.btn-resume-record {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #60a5fa;
}

.btn-resume-record:hover {
  background: rgba(59, 130, 246, 0.26);
  border-color: rgba(59, 130, 246, 0.55);
  color: #dbeafe;
}

.btn-cancel-record {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #f87171 !important;
}

.btn-cancel-record:hover {
  background: rgba(239, 68, 68, 0.15) !important;
  color: #fca5a5 !important;
}

.btn-send-record {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* Small screens / Mobile adjustments */
@media (max-width: 640px) {
  .voice-recorder-bar {
    gap: 8px;
    padding: 8px 10px;
    flex-wrap: wrap;
  }
  .recorder-left-section {
    gap: 6px;
  }
  .record-waveform,
  .voice-preview-container {
    min-width: 90px;
  }
  .recorder-actions {
    gap: 6px;
  }
  .btn-recorder-action span,
  .btn-cancel-record span,
  .btn-send-record span {
    font-size: 11px;
  }
}

/* --------------------------------------------------------------------------
   2. Hardware Device Settings Modal (#modal-device-settings)
   -------------------------------------------------------------------------- */
.device-settings-modal {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1200;
  animation: modalFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.device-modal-card {
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-card, #1e293b);
  border: 1px solid var(--border-color, #334155);
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05);
  padding: 0;
  overflow: hidden;
}

.device-modal-card .modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color, #334155);
  margin-bottom: 0;
  background: rgba(15, 23, 42, 0.5);
}

.modal-title-with-icon {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-main, #f8fafc);
}

.modal-title-with-icon svg {
  color: var(--primary, #3b82f6);
  flex-shrink: 0;
}

.modal-title-with-icon h3 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.2px;
}

.device-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Section Box */
.device-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 16px;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.device-section:hover {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
}

.device-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.device-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-main, #f8fafc);
  margin: 0;
}

.device-label svg {
  color: var(--text-muted, #94a3b8);
  flex-shrink: 0;
}

.device-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.device-badge.device-badge-warn {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.3);
}

.device-select {
  width: 100%;
  padding: 10px 14px;
  background: #0f172a;
  color: var(--text-main, #f8fafc);
  border: 1px solid var(--border-color, #334155);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.device-select:focus {
  border-color: var(--primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.device-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   3. Live Microphone Volume Meter Bar
   -------------------------------------------------------------------------- */
.mic-test-container {
  margin-top: 12px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 12px;
}

.mic-test-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.mic-level-label {
  font-size: 12px;
  color: var(--text-muted, #94a3b8);
  display: flex;
  align-items: center;
  gap: 4px;
}

.mic-level-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #10b981;
  min-width: 38px;
  text-align: right;
  transition: color 0.1s ease;
}

.mic-level-value.level-high {
  color: #f59e0b;
}

.mic-level-value.level-clip {
  color: #ef4444;
}

.mic-meter-track {
  position: relative;
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.mic-meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 5px;
  background: linear-gradient(90deg, #10b981 0%, #34d399 50%, #f59e0b 80%, #ef4444 100%);
  transition: width 0.05s ease-out;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

.mic-meter-peak {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #ffffff;
  border-radius: 1.5px;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.9);
  transition: left 0.12s ease-out;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   4. Speaker & Camera Test Controls
   -------------------------------------------------------------------------- */
.speaker-test-container {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.speaker-test-tip {
  font-size: 12px;
  color: var(--text-muted, #94a3b8);
}

.camera-preview-box {
  margin-top: 12px;
}

.camera-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.camera-preview-tip {
  font-size: 12px;
  color: var(--text-muted, #94a3b8);
}

.camera-preview-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 200px;
  background: #000000;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color, #334155);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

.camera-preview-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror view for camera preview */
}

.camera-preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim, #64748b);
  gap: 8px;
  font-size: 13px;
}

/* Buttons in Device Modal */
.btn-sm {
  padding: 6px 14px;
  font-size: 12.5px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s ease;
}

.btn-outline-primary {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #60a5fa;
}

.btn-outline-primary:hover {
  background: rgba(59, 130, 246, 0.2);
  border-color: #3b82f6;
  color: #93c5fd;
}

.btn-outline-primary.btn-active {
  background: #ef4444;
  border-color: #ef4444;
  color: #ffffff;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color, #334155);
  color: var(--text-muted, #94a3b8);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main, #f8fafc);
}

.device-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color, #334155);
  margin-top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.5);
}

/* --------------------------------------------------------------------------
   5. Active Call Control Bar Device Settings Button
   -------------------------------------------------------------------------- */
.call-buttons .call-tool-btn.btn-device-settings {
  background: rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
}

.call-buttons .call-tool-btn.btn-device-settings:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  transform: translateY(-2px);
}

/* Pulse animation for active testing mic button */
@keyframes micPulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.8; }
  100% { transform: scale(1); opacity: 1; }
}

.test-mic-icon.pulsing {
  display: inline-block;
  animation: micPulse 1s infinite ease-in-out;
}

/* --------------------------------------------------------------------------
   6. Mobile Responsive Adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .device-modal-card {
    width: 95vw;
    margin: 10px;
    max-height: 94vh;
  }

  .device-modal-body {
    padding: 16px;
    gap: 14px;
  }

  .device-modal-footer {
    padding: 12px 16px;
    flex-direction: column-reverse;
    gap: 10px;
  }

  .device-modal-footer button {
    width: 100%;
    justify-content: center;
  }
}
