#livestream-chat-container {
  width: 100%;
  max-height: 500px;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  border: 1px solid #e1e5e9;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  position: relative;
}

#chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px;
  text-align: center;
  font-weight: 600;
  font-size: 16px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  max-height: 300px;
  scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar {
  width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
  background: #f1f5f9;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.chat-message {
  margin-bottom: 16px;
  padding: 12px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  border-left: 3px solid #e2e8f0;
  transition: all 0.2s ease;
}

.chat-message:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.chat-message.own-message {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-left: 3px solid #4f46e5;
  margin-left: 20px;
}

.chat-message.sending-message {
  background: #f1f5f9;
  border-left: 3px solid #fbbf24;
  opacity: 0.7;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.message-name {
  font-weight: 600;
  font-size: 14px;
  color: #374151;
}

.own-message .message-name {
  color: rgba(255, 255, 255, 0.9);
}

.message-time {
  font-size: 12px;
  color: #6b7280;
  opacity: 0.8;
}

.own-message .message-time {
  color: rgba(255, 255, 255, 0.7);
}

.sending-text {
  font-size: 12px;
  color: #f59e0b;
  font-style: italic;
}

.message-text {
  font-size: 14px;
  line-height: 1.5;
  color: #1f2937;
  word-wrap: break-word;
}

.own-message .message-text {
  color: rgba(255, 255, 255, 0.95);
}

#chat-user-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
}

#chat-form {
  padding: 16px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
}

.chat-input-container {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

#chat-user-form input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.2s ease;
  font-family: inherit;
}

#chat-input {
  flex: 1;
  padding: 12px 50px 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 25px;
  font-size: 14px;
  transition: all 0.2s ease;
  font-family: inherit;
  outline: none;
  background: #f8fafc;
}

#chat-input:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
  background: #fff;
}

#chat-user-form input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#chat-user-form input:disabled,
#chat-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#chat-user-form button {
  padding: 12px 20px;
  border: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 80px;
}

.send-button-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.send-button-icon:hover {
  transform: translateY(-50%) scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

.send-button-icon:active {
  transform: translateY(-50%) scale(0.95);
}

.send-button-icon:disabled {
  background: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
  transform: translateY(-50%);
  box-shadow: none;
}

.send-button-icon:disabled:hover {
  transform: translateY(-50%);
  box-shadow: none;
}

.send-button-icon svg {
  transition: transform 0.2s ease;
}

.send-button-icon:hover svg {
  transform: translateX(1px);
}

#chat-user-form button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#chat-user-form button:disabled {
  background: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#chat-user-form.hidden,
#chat-form.hidden {
  display: none;
}

/* Connection Status */
.connection-status {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

.connection-status.connected .status-dot {
  background: #10b981;
  animation: none;
}

.connection-status.connecting .status-dot {
  background: #f59e0b;
  animation: connecting-pulse 1s infinite;
}

.connection-status.disconnected .status-dot {
  background: #ef4444;
  animation: error-pulse 0.5s infinite;
}

/* SSE-specific status colors */
.connection-status.connected {
  color: #10b981;
}

.connection-status.connecting {
  color: #f59e0b;
}

.connection-status.disconnected {
  color: #ef4444;
}

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

@keyframes connecting-pulse {
  0% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0.3; transform: scale(1); }
}

@keyframes error-pulse {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}

/* Loading Spinner */
.loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Notifications */
.chat-notification {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #1f2937;
  color: white;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.chat-notification.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.chat-notification.success {
  background: #10b981;
}

.chat-notification.error {
  background: #ef4444;
}

.chat-notification.info {
  background: #3b82f6;
}

/* Typing indicator styles */
.typing-indicator {
  background: #f1f5f9 !important;
  border-left: 3px solid #3b82f6 !important;
  opacity: 0.8;
}

.typing-text {
  font-size: 12px;
  color: #3b82f6;
  font-style: italic;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3b82f6;
  animation: typing-bounce 1.4s infinite;
}

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

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Improved user form styles */
#chat-user-form {
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}

#chat-user-form .form-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#chat-user-form .form-row input {
  flex: 1;
}

#chat-user-form .welcome-message {
  text-align: center;
  color: #374151;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 14px;
}

/* Enhanced button states */
#chat-user-form button:disabled,
#chat-form button:disabled {
  background: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Message character counter */
.message-counter {
  position: absolute;
  bottom: -20px;
  right: 8px;
  font-size: 11px;
  color: #6b7280;
  pointer-events: none;
}

.message-counter.warning {
  color: #f59e0b;
}

.message-counter.danger {
  color: #ef4444;
}

/* Enhanced message animations */
.chat-message.slide-in {
  animation: slideInUp 0.3s ease-out;
}

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

/* Better focus states */
#chat-user-form input:focus,
#chat-form input:focus,
#chat-form textarea:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
  transform: translateY(-1px);
}

/* Pulse animation for new messages */
.chat-message.new-message {
  animation: messagePulse 0.6s ease-out;
}

@keyframes messagePulse {
  0% { transform: scale(0.98); opacity: 0.8; }
  50% { transform: scale(1.02); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Responsive Design */
@media (max-width: 480px) {
  #livestream-chat-container {
    border-radius: 0;
    max-height: 400px;
  }
  
  #chat-header {
    padding: 12px;
    font-size: 14px;
  }
  
  #chat-messages {
    padding: 12px;
    max-height: 250px;
  }
  
  .chat-message {
    padding: 10px;
    margin-bottom: 12px;
  }
  
  #chat-user-form,
  #chat-form {
    padding: 12px;
    gap: 8px;
  }
  
  #chat-user-form input,
  #chat-form input {
    padding: 10px 12px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  #chat-user-form button,
  #chat-form button {
    padding: 10px 16px;
    min-width: 70px;
  }
}
