/* WebRTC and Chat Interface Styles */

/* Connection status indicators */
.connect-status {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 500;
  margin: 0.25rem 0;
}

.connect-status.connecting {
  background-color: var(--warning-color);
  color: #212529;
}

.connect-status.connected {
  background-color: var(--success-color);
  color: white;
}

.connect-status.disconnected {
  background-color: var(--secondary-color);
  color: white;
}

.connect-status.error {
  background-color: var(--danger-color);
  color: white;
}

/* Chat interface */
.chat-container {
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  overflow: hidden;
  background-color: var(--card-bg);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.chat-header {
  background-color: var(--primary-color);
  color: white;
  padding: 0.75rem 1rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-messages {
  height: 300px;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  position: relative;
}

.user-message {
  align-self: flex-end;
  background-color: var(--primary-color);
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.assistant-message {
  align-self: flex-start;
  background-color: #f0f2f5;
  color: var(--text-color);
  border-bottom-left-radius: 0.25rem;
}

.system-message {
  align-self: center;
  background-color: #f8f9fa;
  color: #6c757d;
  font-size: 0.85rem;
  border-radius: 0.5rem;
  max-width: 90%;
  text-align: center;
}

.chat-input {
  display: flex;
  padding: 0.75rem;
  border-top: 1px solid var(--border-color);
}

.chat-input input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 1.5rem;
  outline: none;
}

.chat-input button {
  margin-left: 0.5rem;
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--primary-color);
  color: white;
  border: none;
}

/* Dark mode adjustments */
.dark-mode .assistant-message {
  background-color: #3a3b3c;
  color: #e4e6eb;
}

.dark-mode .system-message {
  background-color: #3a3b3c;
  color: #b0b3b8;
}

.dark-mode .chat-input input {
  background-color: #3a3b3c;
  color: #e4e6eb;
  border-color: #4a4b4c;
}

/* Voice input button */
.voice-button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  margin-left: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.voice-button.active {
  background-color: var(--danger-color);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
  }
}

/* WebRTC and Voice Integration Styles */

/* WebRTC Connection Status Indicator */
.webrtc-status {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  background-color: rgba(0, 0, 0, 0.05);
}

.webrtc-status.connected {
  color: #388e3c;
}

.webrtc-status.connecting {
  color: #f57c00;
}

.webrtc-status.disconnected {
  color: #d32f2f;
}

.webrtc-status i {
  margin-right: 4px;
}

/* Voice Controls */
.voice-controls {
  display: flex;
  align-items: center;
  margin: 8px 0;
  padding: 8px;
  border-radius: 4px;
  background-color: rgba(0, 0, 0, 0.05);
}

.voice-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background-color: #f0f0f0;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
}

.voice-button:hover {
  background-color: #e0e0e0;
}

.voice-button.active {
  background-color: #4caf50;
  color: white;
}

.voice-button.recording {
  animation: pulse 1.5s infinite;
}

.voice-settings-button {
  margin-left: 8px;
  background-color: transparent;
  border: none;
  color: #666;
  cursor: pointer;
}

.voice-settings-button:hover {
  color: #333;
}

/* WebRTC Audio Visualizer */
.audio-visualizer {
  height: 30px;
  width: 100%;
  margin: 8px 0;
  background-color: rgba(0, 0, 0, 0.02);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.audio-visualizer-bars {
  display: flex;
  height: 100%;
  align-items: flex-end;
  justify-content: space-between;
}

.visualizer-bar {
  width: 2px;
  background-color: #4caf50;
  margin: 0 1px;
  transition: height 0.1s ease;
}

/* Settings Panel */
.voice-settings-panel {
  margin-top: 8px;
  padding: 12px;
  border-radius: 4px;
  background-color: #f5f5f5;
  border: 1px solid #e0e0e0;
}

.voice-settings-panel h4 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: #333;
}

.settings-row {
  margin-bottom: 8px;
}

.settings-row label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.8rem;
  color: #666;
}

.settings-row select,
.settings-row input {
  width: 100%;
  padding: 6px;
  border-radius: 4px;
  border: 1px solid #ddd;
  font-size: 0.85rem;
}

.settings-row input[type='range'] {
  height: 6px;
  background-color: #ddd;
}

.settings-row input[type='checkbox'] {
  width: auto;
  margin-right: 6px;
}

.auto-listen-option {
  display: flex;
  align-items: center;
  margin-top: 8px;
}

.auto-listen-option label {
  margin-bottom: 0;
  margin-left: 4px;
}

/* Animation for recording pulse */
@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Audio Controls */
.audio-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  padding: 15px;
  background-color: rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  z-index: 900;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  /* Prevent layout shifts */
  contain: content;
  /* Add better touch area for mobile */
  touch-action: manipulation;
  width: 100%;
}

/* For fixing mobile layout - integrate with chat */
.audio-controls.integrated {
  position: static;
  bottom: auto;
  right: auto;
  margin: 0;
  width: 100%;
  box-shadow: none;
  background-color: rgba(255, 255, 255, 0.08);
  border-radius: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  z-index: 10;
}

.push-to-talk-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 140px;
  padding: 12px 20px;
  font-weight: 600;
  transition: all 0.2s ease;
  border-radius: 30px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  background-color: #1a73e8;
  color: white;
  border: none;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .audio-controls {
    width: 100%;
    position: static;
    bottom: auto;
    right: auto;
    margin-bottom: 10px;
  }

  .transcript-display {
    max-height: 100px;
  }
}

/* More integrated design for push-to-talk within chat */
.conversation-area .audio-controls {
  margin-top: 10px;
  margin-bottom: 0;
  padding: 10px;
}

.conversation-area .input-mode-toggle {
  margin-bottom: 5px;
}

.conversation-area .transcript-display {
  max-height: 80px;
  min-height: 0;
  background-color: rgba(255, 255, 255, 0.1);
}

.push-to-talk-btn i {
  margin-right: 5px;
  font-size: 1.2em;
}

.push-to-talk-btn.active {
  background-color: #dc3545 !important;
  border-color: #dc3545 !important;
  color: white;
  animation: button-pulse 1.5s infinite;
}

@keyframes button-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
  }
}

.push-to-talk-btn:hover {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.transcript-display {
  background-color: #f9f9f9;
  border: 1px solid #eee;
  border-radius: 8px;
  height: 150px;
  overflow-y: auto;
  margin: 10px 0;
  padding: 10px;
  font-size: 0.9em;
  width: 100%;
  min-height: 150px;
}

.transcript-entry {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
  line-height: 1.4;
}

.transcript-entry.status {
  color: #666;
  font-style: italic;
  text-align: center;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .audio-controls {
    background-color: rgba(30, 30, 30, 0.7);
  }

  .push-to-talk-btn {
    background-color: #2c7be5;
  }

  .transcript-display {
    background-color: #333;
    border-color: #444;
    color: #fff;
  }

  .transcript-entry {
    border-bottom-color: #444;
  }

  .transcript-entry.status {
    color: #aaa;
  }
}

/* Chat Bubble Styles */
.webcrt-bubble-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.webcrt-chat-bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4285f4, #34a853);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  font-size: 24px;
}

.webcrt-chat-bubble:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
}

.webcrt-notification-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: #ff4081;
  color: white;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Chat Interface Container */
.webcrt-agent-container {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 350px;
  height: 500px;
  background-color: white;
  border-radius: 16px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 1px solid #e0e0e0;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .webcrt-agent-container {
    background-color: #2d2d2d;
    border: 1px solid #444;
    color: #f0f0f0;
  }
}

/* Header styles */
.webcrt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #4285f4, #34a853);
  color: white;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.webcrt-title {
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
}

.webcrt-close-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.webcrt-close-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Connect status indicator */
.connect-status {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  margin-left: auto;
  margin-right: 10px;
}

.connect-status.connecting {
  background-color: #ffab40;
  color: #703f00;
}

.connect-status.connected {
  background-color: #4caf50;
  color: white;
}

.connect-status.disconnected {
  background-color: #9e9e9e;
  color: white;
}

.connect-status.failed {
  background-color: #f44336;
  color: white;
}

/* Chat container */
.chat-container {
  flex-grow: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #f9f9f9;
}

@media (prefers-color-scheme: dark) {
  .chat-container {
    background-color: #1e1e1e;
  }
}

/* Message styles */
.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 18px;
  margin-bottom: 8px;
  position: relative;
  animation: messageAppear 0.3s ease-out;
}

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

.user-message {
  align-self: flex-end;
  background-color: #e3f2fd;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

.assistant-message {
  align-self: flex-start;
  background-color: #e8f5e9;
  border-bottom-left-radius: 4px;
}

.system-message {
  align-self: center;
  background-color: #f5f5f5;
  border-radius: 12px;
  font-size: 0.9em;
  color: #757575;
  text-align: center;
  max-width: 90%;
}

@media (prefers-color-scheme: dark) {
  .user-message {
    background-color: #1e3a5f;
    color: #e6f0fa;
  }

  .assistant-message {
    background-color: #1b4332;
    color: #e0f2e9;
  }

  .system-message {
    background-color: #424242;
    color: #bdbdbd;
  }
}

.message-content {
  word-break: break-word;
}

/* Input container */
.input-container {
  display: flex;
  align-items: center;
  padding: 12px;
  background-color: white;
  border-top: 1px solid #e0e0e0;
  position: relative;
}

@media (prefers-color-scheme: dark) {
  .input-container {
    background-color: #2d2d2d;
    border-top: 1px solid #444;
  }
}

.chat-input {
  flex-grow: 1;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  resize: none;
  max-height: 100px;
  min-height: 40px;
  outline: none;
  transition: border 0.2s;
  background-color: #f5f5f5;
}

.chat-input:focus {
  border-color: #4285f4;
  box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}

@media (prefers-color-scheme: dark) {
  .chat-input {
    background-color: #424242;
    border-color: #555;
    color: #f0f0f0;
  }

  .chat-input:focus {
    border-color: #4285f4;
  }
}

.send-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background-color: #4285f4;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 10px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.send-button:hover {
  background-color: #2a75f3;
}

.send-button:disabled {
  background-color: #9e9e9e;
  cursor: not-allowed;
}

/* Audio indicator */
.audio-indicator {
  position: absolute;
  right: 60px;
  bottom: 12px;
  display: flex;
  align-items: flex-end;
  height: 20px;
  gap: 3px;
}

.audio-indicator span {
  display: inline-block;
  width: 4px;
  height: 8px;
  background-color: #4285f4;
  border-radius: 2px;
  animation: audioWave 1.2s infinite ease-in-out;
}

.audio-indicator span:nth-child(2) {
  animation-delay: 0.2s;
  height: 10px;
}

.audio-indicator span:nth-child(3) {
  animation-delay: 0.4s;
  height: 14px;
}

@keyframes audioWave {
  0%,
  100% {
    transform: scaleY(0.5);
  }
  50% {
    transform: scaleY(1);
  }
}

/* Audio controls */
.audio-controls {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 12px;
  background-color: #f5f5f5;
  border-top: 1px solid #e0e0e0;
}

@media (prefers-color-scheme: dark) {
  .audio-controls {
    background-color: #2a2a2a;
    border-top: 1px solid #444;
  }
}

.push-to-talk-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  background-color: #4285f4;
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
  gap: 6px;
}

.push-to-talk-btn:hover {
  background-color: #2a75f3;
}

.push-to-talk-btn.active {
  background-color: #f44336;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(244, 67, 54, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(244, 67, 54, 0);
  }
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.volume-control label {
  font-size: 12px;
  color: #757575;
}

@media (prefers-color-scheme: dark) {
  .volume-control label {
    color: #bdbdbd;
  }
}

#volumeSlider {
  width: 80px;
  cursor: pointer;
}

.mute-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid #e0e0e0;
  background-color: white;
  cursor: pointer;
  transition: all 0.2s;
}

.mute-btn:hover {
  background-color: #f5f5f5;
}

@media (prefers-color-scheme: dark) {
  .mute-btn {
    background-color: #2d2d2d;
    border-color: #555;
    color: #f0f0f0;
  }

  .mute-btn:hover {
    background-color: #3d3d3d;
  }
}

/* Transcript display */
.transcript-display {
  padding: 8px 12px;
  background-color: #f0f0f0;
  border-bottom: 1px solid #e0e0e0;
  font-size: 13px;
  color: #555;
  max-height: 80px;
  overflow-y: auto;
  transition: max-height 0.3s;
}

.transcript-display:empty {
  padding: 0;
  max-height: 0;
  border-bottom: none;
}

@media (prefers-color-scheme: dark) {
  .transcript-display {
    background-color: #333;
    border-bottom: 1px solid #444;
    color: #bdbdbd;
  }
}

.transcript-entry {
  margin-bottom: 4px;
  animation: fadeIn 0.3s;
}

.transcript-entry.status {
  font-style: italic;
  opacity: 0.7;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Media Queries for Responsiveness */
@media (max-width: 576px) {
  .webcrt-agent-container {
    width: 100%;
    height: 80vh;
    bottom: 70px;
    right: 0;
    border-radius: 16px 16px 0 0;
  }

  .webcrt-bubble-container {
    bottom: 10px;
    right: 10px;
  }

  .chat-container {
    padding: 10px;
  }

  .webcrt-header {
    padding: 10px;
  }
}

/* Input Mode Toggle */
.input-mode-toggle {
  width: 100%;
  margin-bottom: 10px;
  /* Prevent this element from causing layout shifts */
  height: 24px;
  display: flex;
  align-items: center;
}

.toggle-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type='checkbox'] {
  margin-right: 8px;
}

.toggle-text {
  font-size: 0.9em;
  font-weight: 500;
}

/* Dark mode support for toggle */
@media (prefers-color-scheme: dark) {
  .toggle-text {
    color: #fff;
  }
}

/* ModernChat specific styles to integrate with push-to-talk */
.cs-main-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 15px;
}

.cs-message-list {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cs-input-area {
  display: flex;
  padding: 10px;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 0 0 15px 15px;
}

.cs-input {
  flex: 1;
  padding: 10px 15px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  background-color: rgba(255, 255, 255, 0.2);
  color: inherit;
  outline: none;
}

.cs-send-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #1a73e8;
  color: white;
  border: none;
  margin-left: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cs-send-button:hover {
  background-color: #1557b0;
}

/* Dark mode support for chat */
@media (prefers-color-scheme: dark) {
  .cs-main-container {
    background-color: rgba(30, 30, 30, 0.7);
  }

  .cs-input {
    background-color: rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.1);
    color: white;
  }

  .cs-input-area {
    background-color: rgba(0, 0, 0, 0.2);
  }
}

/* Improved integration between chat and push-to-talk on mobile */
@media (max-width: 768px) {
  .cs-main-container {
    border-radius: 12px;
  }

  .audio-controls.integrated {
    padding: 8px;
    margin: 0;
  }

  .audio-controls.integrated .push-to-talk-btn {
    font-size: 0.9rem;
    padding: 10px 15px;
  }

  .audio-controls.integrated .transcript-display {
    max-height: 60px;
    min-height: 40px;
    padding: 5px;
    margin: 5px 0;
    font-size: 0.85rem;
  }

  .audio-controls.integrated .input-mode-toggle {
    margin-bottom: 5px;
    font-size: 0.85rem;
  }

  /* Ensure push-to-talk is visually connected to the chat interface */
  .conversation-area .audio-controls.integrated + .cs-input-area {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }
}

/* Override any ModernChat styles that might interfere */
.cs-main-container .audio-controls.integrated {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  height: auto !important;
  overflow: visible !important;
}
