/**
 * Estilos modernos para el sistema de chat en tiempo real
 * Diseño inspirado en WhatsApp/Telegram con mejoras UX
 */

/* ============================================================
   Contenedor principal del chat
   ============================================================ */
#chatBox {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15) !important;
}

#chatBox.mostrar {
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ============================================================
   Header del chat
   ============================================================ */
.chat-header {
  background: linear-gradient(135deg, #d4af37 0%, #b8941f 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-header button {
  transition: all 0.2s ease;
  border: none;
}

.chat-header button:hover {
  background-color: rgba(255, 255, 255, 0.2) !important;
  transform: scale(1.1);
}

/* ============================================================
   Contenedor de mensajes
   ============================================================ */
.chat-messages-container {
  padding: 16px 12px;
  min-height: 200px;
}

/* ============================================================
   Burbujas de mensaje
   ============================================================ */
.message-wrapper {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  animation: messageSlideIn 0.3s ease-out;
  opacity: 0;
  animation-fill-mode: forwards;
}

.message-wrapper.message-enter {
  opacity: 1;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-mine {
  align-items: flex-end;
}

.message-other {
  align-items: flex-start;
}

.message-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: transform 0.1s ease;
}

.message-mine .message-bubble {
  background: linear-gradient(135deg, #d4af37 0%, #b8941f 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-other .message-bubble {
  background: white;
  color: #333;
  border-bottom-left-radius: 4px;
}

.message-bubble:hover {
  transform: scale(1.02);
}

.message-author {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 4px;
}

.message-text {
  font-size: 0.9rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-time {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-top: 4px;
  text-align: right;
  font-weight: 300;
}

.message-mine .message-time {
  color: rgba(255, 255, 255, 0.8);
}

.message-other .message-time {
  color: #666;
}

/* Estados de mensaje */
.message-read {
  position: relative;
}

.message-read::after {
  content: "✓✓";
  position: absolute;
  bottom: 4px;
  right: 8px;
  font-size: 0.7rem;
  opacity: 0.6;
}

/* ============================================================
   Mensaje de bienvenida
   ============================================================ */
#mensajeBienvenida {
  text-align: center;
  padding: 16px;
  background: rgba(212, 175, 55, 0.1);
  border-radius: 12px;
  margin-bottom: 16px;
  border: 1px solid rgba(212, 175, 55, 0.2);
}

#mensajeBienvenida strong {
  color: #d4af37;
  font-weight: 600;
}

/* ============================================================
   Indicador de escritura (typing)
   ============================================================ */
.typing-indicator {
  padding: 8px 16px;
  margin-bottom: 12px;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: white;
  padding: 10px 16px;
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  max-width: 200px;
}

.typing-bubble span:not(.typing-text) {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #999;
  animation: typingDot 1.4s infinite;
}

.typing-bubble span:nth-child(1) {
  animation-delay: 0s;
}

.typing-bubble span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-bubble span:nth-child(3) {
  animation-delay: 0.4s;
}

.typing-text {
  font-size: 0.85rem;
  color: #666;
  margin-left: 4px;
}

@keyframes typingDot {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.7;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* ============================================================
   Área de entrada de mensajes
   ============================================================ */
.chat-input-container {
  border-top: 1px solid #e0e0e0;
  background: white;
}

.chat-input {
  border: 1px solid #e0e0e0;
  transition: all 0.2s ease;
}

.chat-input:focus {
  border-color: #d4af37;
  box-shadow: 0 0 0 0.2rem rgba(212, 175, 55, 0.25);
  outline: none;
}

.chat-send-btn {
  background: linear-gradient(135deg, #d4af37 0%, #b8941f 100%);
  border: none;
  transition: all 0.2s ease;
}

.chat-send-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.4);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

.chat-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Auto-resize del textarea */
.chat-input {
  overflow-y: hidden;
}

/* ============================================================
   Info del ticket
   ============================================================ */
#chatTicketInfo {
  background: linear-gradient(135deg, #fff6e6 0%, #ffe8cc 100%);
  border-bottom: 2px solid #d4af37;
  font-size: 0.85rem;
  font-weight: 600;
  color: #8b6914;
}

/* ============================================================
   Loading
   ============================================================ */
#chatLoading {
  padding: 20px;
  color: #666;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 576px) {
  #chatBox {
    width: 100% !important;
    height: 100% !important;
    bottom: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
  }

  .message-bubble {
    max-width: 85%;
  }
}

/* ============================================================
   Scrollbar personalizado
   ============================================================ */
.chat-messages-container::-webkit-scrollbar {
  width: 6px;
}

.chat-messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages-container::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.chat-messages-container::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* ============================================================
   Estados de conexión
   ============================================================ */
.chat-connection-status {
  position: absolute;
  top: 50px;
  right: 12px;
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  z-index: 10;
}

.chat-connection-status.connected {
  background: rgba(40, 167, 69, 0.9);
}

.chat-connection-status.disconnected {
  background: rgba(220, 53, 69, 0.9);
}

.chat-connection-status.reconnecting {
  background: rgba(255, 193, 7, 0.9);
}

/* ============================================================
   Animaciones adicionales
   ============================================================ */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.message-bubble.new-message {
  animation: pulse 0.5s ease-in-out;
}

/* ============================================================
   Mejoras de accesibilidad
   ============================================================ */
.chat-input:focus-visible,
.chat-send-btn:focus-visible {
  outline: 2px solid #d4af37;
  outline-offset: 2px;
}

/* ============================================================
   Tema oscuro (opcional, para futuro)
   ============================================================ */
@media (prefers-color-scheme: dark) {
  /* Se puede agregar soporte para tema oscuro aquí */
}

