client-chat-widget
Version: 
Widget de chat embebible (React + SignalR) con theming por CSS tokens y montaje dinámico.
707 lines (623 loc) • 16.4 kB
CSS
/* =====================================================================
   LEGACY VARIABLES (to be removed) + bridge to design tokens
   We now define tokens in tokens.css. These map old variable names to
   new token names to avoid breaking existing components during migration.
   ===================================================================== */
.gtc-chat-root:root, :root {
  /* Bridge mapping */
  --chat-primary: var(--chat-color-primary, #3b82f6);
  --chat-primary-hover: var(--chat-color-primary-accent, #2563eb);
  --chat-secondary: var(--chat-color-text-muted, #94a3b8);
  --chat-success: var(--chat-color-success, #16a34a);
  --chat-danger: var(--chat-color-danger, #f87171);
  --chat-warning: var(--chat-color-warning, #fbbf24);
  --chat-bg: var(--chat-color-bg, #ffffff);
  --chat-bg-light: var(--chat-color-bg-soft, #fdfefe);
  --chat-bg-border: var(--chat-color-border, #e5e7eb);
  --chat-text: var(--chat-color-text, #1e293b);
  --chat-text-light: var(--chat-color-text-muted, #64748b);
  --chat-radius: var(--chat-radius, 14px);
  --chat-shadow: var(--chat-shadow, 0 6px 18px rgba(0, 0, 0, 0.08));
  --chat-transition: var(--chat-transition, all 0.2s ease);
  --chat-font: var(--chat-font-family, system-ui, sans-serif);
}
/* Reset y componentes base */
.gtc-chat-root .chat-widget-window,
.gtc-chat-root .chat-widget-window * {
  box-sizing: border-box;
  font-family: var(--chat-font);
  -webkit-font-smoothing: antialiased;
}
/* FAB */
.gtc-chat-root .chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  background: var(--chat-primary);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--chat-shadow);
  transition: var(--chat-transition);
  cursor: pointer;
  z-index: 1000;
}
.gtc-chat-root .chat-fab:hover {
  background: var(--chat-primary-hover);
  transform: translateY(-2px);
}
.gtc-chat-root .chat-fab .unread-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--chat-danger);
  color: white;
  border-radius: 12px;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  border: 2px solid white;
}
/* Ventana principal */
.gtc-chat-root .chat-widget-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 360px;
  height: 500px;
  background: var(--chat-bg);
  backdrop-filter: saturate(140%) blur(6px);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999;
  animation: slideUp 0.3s ease;
  border: 1px solid var(--chat-bg-border);
}
.gtc-chat-root .chat-widget-window.minimized {
  height: 60px;
}
.gtc-chat-root .chat-widget-window.maximized {
  width: 400px;
  height: 600px;
}
/* Header */
.gtc-chat-root .chat-header {
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-hover));
  color: white;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--chat-radius) var(--chat-radius) 0 0;
}
.gtc-chat-root .chat-header-info {
  flex: 1;
  min-width: 0;
}
.gtc-chat-root .chat-title {
  font-weight: 600;
  font-size: 1rem;
  margin: 0 0 2px 0;
  line-height: 1.3;
}
.gtc-chat-root .chat-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  opacity: 0.9;
}
.gtc-chat-root .status-indicator {
  width: 8px;
  height: 8px;
  background: var(--chat-success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
.gtc-chat-root .status-indicator.offline {
  background: var(--chat-secondary);
  animation: none;
}
.gtc-chat-root .chat-header-actions {
  display: flex;
  gap: 4px;
}
.gtc-chat-root .header-btn,
.gtc-chat-root .close-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--chat-transition);
}
.gtc-chat-root .header-btn:hover,
.gtc-chat-root .close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}
.gtc-chat-root .close-btn:hover {
  background: var(--chat-danger);
}
/* Mensajes */
.gtc-chat-root .chat-messages {
  flex: 1;
  padding: 16px;
  background: var(--chat-bg-light);
  overflow-y: auto;
  scroll-behavior: smooth;
}
.gtc-chat-root .chat-messages::-webkit-scrollbar {
  width: 6px;
}
.gtc-chat-root .chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-secondary);
  border-radius: 3px;
}
.gtc-chat-root .empty-chat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--chat-text-light);
  text-align: center;
  padding: 24px;
}
.gtc-chat-root .message-bubble {
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}
.gtc-chat-root .message-bubble.client {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.gtc-chat-root .message-bubble.agent,
.gtc-chat-root .message-bubble.system {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.gtc-chat-root .message-content {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
  line-height: 1.4;
  box-shadow: var(--chat-shadow);
}
.gtc-chat-root .message-bubble.client .message-content {
  background: var(--chat-primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.gtc-chat-root .message-bubble.agent .message-content {
  background: white;
  color: var(--chat-text);
  border: 1px solid var(--chat-bg-border);
  border-bottom-left-radius: 4px;
}
.gtc-chat-root .message-bubble.system .message-content {
  background: var(--chat-warning);
  color: var(--chat-text);
  border-radius: 8px;
  font-size: 0.875rem;
  max-width: 100%;
  text-align: center;
  font-style: italic;
}
.gtc-chat-root .message-time {
  font-size: 0.75rem;
  color: var(--chat-text-light);
  margin-top: 4px;
  opacity: 0.8;
}
/* Input */
.gtc-chat-root .chat-input {
  padding: 16px;
  background: white;
  border-top: 1px solid var(--chat-bg-light);
  border-radius: 0 0 var(--chat-radius) var(--chat-radius);
}
.gtc-chat-root .chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--chat-bg-light);
  border-radius: var(--chat-radius);
  padding: 8px 12px;
  border: 2px solid transparent;
  transition: var(--chat-transition);
  min-height: 48px;
}
.gtc-chat-root .chat-input-area:focus-within {
  border-color: var(--chat-primary);
  background: white;
}
/* Emoji picker layering */
.gtc-chat-root .emoji-picker-wrapper {
  position: absolute;
  bottom: 64px; /* sits above input */
  right: 8px;
  z-index: 1200;
  animation: fadeIn 0.18s ease;
}
.gtc-chat-root .emoji-picker-container {
  box-shadow: var(--chat-shadow);
  border: 1px solid var(--chat-bg-border);
  border-radius: 12px;
  overflow: hidden;
  backdrop-filter: blur(6px) saturate(140%);
}
/* Focus ring utility */
.gtc-chat-root .emoji-btn:focus-visible,
.gtc-chat-root .file-upload-btn:focus-visible,
.gtc-chat-root .send-btn:focus-visible {
  box-shadow: var(--chat-focus-ring, 0 0 0 3px rgba(59,130,246,.45));
  outline: none;
}
.gtc-chat-root .chat-input-area.disabled {
  background: var(--chat-bg-border);
  opacity: 0.7;
  flex-direction: column;
  padding: 20px;
  text-align: center;
  gap: 12px;
}
.gtc-chat-root .message-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.875rem;
  color: var(--chat-text);
  padding: 8px 0;
  resize: none;
  max-height: 120px;
  min-height: 20px;
  line-height: 1.4; 
}
.gtc-chat-root .message-input::placeholder {
  color: var(--chat-text-light);
}
.gtc-chat-root .chat-input-actions {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}
.gtc-chat-root .input-btn,
.gtc-chat-root .file-upload-btn {
  border: none;
  background: transparent;
  color: var(--chat-text-light);
  cursor: pointer;
  transition: var(--chat-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 8px;
  width: 36px;
  height: 36px;
}
.gtc-chat-root .input-btn:hover,
.gtc-chat-root .file-upload-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--chat-primary);
}
.gtc-chat-root .send-btn {
  background: var(--chat-primary);
  color: white;
  margin-left: 4px;
}
.gtc-chat-root .send-btn:hover:not(:disabled) {
  background: var(--chat-primary-hover);
}
.gtc-chat-root .send-btn:disabled {
  background: var(--chat-secondary);
  cursor: not-allowed;
  opacity: 0.6;
}
.gtc-chat-root input[type="file"] {
  display: none;
}
/* Archivos */
.gtc-chat-root .message-attachments {
  margin-top: 8px;
}
.gtc-chat-root .attachment {
  margin-bottom: 8px;
  border-radius: 8px;
  overflow: hidden;
}
.gtc-chat-root .attachment-image {
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--chat-transition);
  border: 1px solid var(--chat-bg-border);
  object-fit: cover;
}
.gtc-chat-root .attachment-image:hover {
  transform: scale(1.02);
}
.gtc-chat-root .attachment-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  border: 1px solid var(--chat-bg-border);
  cursor: pointer;
  transition: var(--chat-transition);
}
.gtc-chat-root .attachment-file:hover {
  background: rgba(255, 255, 255, 0.8);
}
.gtc-chat-root .file-name {
  font-size: 0.875rem;
  color: var(--chat-text);
  font-weight: 500;
}
.gtc-chat-root .file-size {
  font-size: 0.75rem;
  color: var(--chat-text-light);
  margin-left: auto;
}
/* Preview */
.gtc-chat-root .file-preview {
  position: relative;
  margin-bottom: 8px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--chat-bg-light);
  background: white;
}
.gtc-chat-root .file-preview img {
  width: 100%;
  max-height: 120px;
  object-fit: cover;
}
.gtc-chat-root .file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--chat-bg-light);
}
.gtc-chat-root .file-info-text {
  flex: 1;
  min-width: 0;
}
.gtc-chat-root .file-info-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--chat-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gtc-chat-root .file-info-size {
  font-size: 0.75rem;
  color: var(--chat-text-light);
}
.gtc-chat-root .cancel-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--chat-transition);
}
.gtc-chat-root .cancel-btn:hover {
  background: rgba(0, 0, 0, 0.8);
}
/* Estados especiales */
.gtc-chat-root .chat-closed-notice {
  color: var(--chat-text-light);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-style: italic;
}
.gtc-chat-root .start-new-chat-btn {
  background: var(--chat-primary);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--chat-transition);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--chat-shadow);
}
.gtc-chat-root .start-new-chat-btn:hover {
  background: var(--chat-primary-hover);
}
/* Modal de imagen optimizado */
.gtc-chat-root .image-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  animation: fadeIn 0.3s ease;
  padding: 20px;
}
.gtc-chat-root .image-modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.gtc-chat-root .image-modal img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: var(--chat-radius);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}
.gtc-chat-root .image-modal-controls {
  position: absolute;
  top: 20px;
  right: 20px;
}
.gtc-chat-root .image-modal-close {
  background: rgba(0, 0, 0, 0.7);
  border: none;
  color: white;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--chat-transition);
}
.gtc-chat-root .image-modal-close:hover {
  background: var(--chat-danger);
}
.gtc-chat-root .image-modal-info {
  margin-top: 16px;
  padding: 12px 20px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: var(--chat-radius);
  color: white;
  font-size: 0.875rem;
  text-align: center;
}
/* Indicadores */
.gtc-chat-root .typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: white;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--chat-bg-border);
}
.gtc-chat-root .typing-dot {
  width: 6px;
  height: 6px;
  background: var(--chat-secondary);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}
.gtc-chat-root .typing-dot:nth-child(2) { animation-delay: 0.2s; }
.gtc-chat-root .typing-dot:nth-child(3) { animation-delay: 0.4s; }
/* Animaciones */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.8; }
}
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}
/* Responsive */
@media (max-width: 480px) {
  .gtc-chat-root .chat-widget-window {
    width: calc(100vw - 40px);
    height: calc(100vh - 120px);
    bottom: 10px;
    right: 20px;
    left: 20px;
  }
  
  .gtc-chat-root .chat-fab {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }
  
  .gtc-chat-root .message-content {
    max-width: 90%;
  }
  
  .gtc-chat-root .image-modal {
    padding: 16px;
  }
  
  .gtc-chat-root .image-modal-close {
    width: 36px;
    height: 36px;
  }
}
/* Accesibilidad: foco visible */
.gtc-chat-root .chat-fab:focus-visible,
.gtc-chat-root .input-btn:focus-visible,
.gtc-chat-root .file-upload-btn:focus-visible,
.gtc-chat-root .send-btn:focus-visible,
.gtc-chat-root .close-btn:focus-visible,
.gtc-chat-root .header-btn:focus-visible,
.gtc-chat-root .start-new-chat-btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--chat-primary) 60%, white);
  outline-offset: 2px;
}
/* Modo oscuro automático básico */
@media (prefers-color-scheme: dark) {
  :root {
    --chat-bg: #1f2937;
    --chat-bg-light: #273548;
    --chat-bg-border: #334155;
    --chat-text: #f1f5f9;
    --chat-text-light: #94a3b8;
    --chat-shadow: 0 4px 12px rgba(0,0,0,0.6);
  }
  .chat-widget-window { background: var(--chat-bg); }
  .chat-input { background: var(--chat-bg); }
  .chat-input-area { background: var(--chat-bg-light); }
  .message-bubble.agent .message-content { background: var(--chat-bg); border-color: var(--chat-bg-border); }
  .message-bubble.system .message-content { background: var(--chat-warning); }
  .attachment-file { background: var(--chat-bg-light); }
  .attachment-file:hover { background: var(--chat-bg); }
  .file-preview { background: var(--chat-bg); }
  .file-info { background: var(--chat-bg-light); }
}