/* ========================================
   CHATBOT STYLES - Manuel Handyman & Remodeling
   Production-ready styles with accessibility and performance
   ======================================== */

:root {
  /* Brand Colors */
  --chatbot-primary: #E6222B;
  --chatbot-primary-dark: #C71F27;
  --chatbot-primary-light: #FF3B47;
  --chatbot-dark: #17161E;
  --chatbot-cream: #FFF4EC;
  --chatbot-white: #FFFFFF;

  /* UI Colors */
  --chatbot-gray-light: #F5F5F5;
  --chatbot-gray: #E0E0E0;
  --chatbot-gray-dark: #666666;
  --chatbot-success: #4ADE80;
  --chatbot-error: #EF4444;

  /* Shadows */
  --chatbot-shadow: rgba(0, 0, 0, 0.15);
  --chatbot-shadow-lg: rgba(0, 0, 0, 0.25);

  /* Z-index */
  --chatbot-z-fab: 9998;
  --chatbot-z-window: 9999;

  /* Transitions */
  --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --chatbot-transition-fast: all 0.2s ease;
}

/* ========================================
   BOTÓN FLOTANTE
   ======================================== */

.chatbot-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--chatbot-shadow-lg);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: chatbot-pulse 2s infinite;
}

.chatbot-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px var(--chatbot-shadow-lg);
}

.chatbot-fab:active {
  transform: scale(0.95);
}

.chatbot-fab svg {
  width: 32px;
  height: 32px;
  fill: var(--chatbot-white);
  transition: transform 0.3s ease;
}

.chatbot-fab.open svg {
  transform: rotate(90deg);
}

/* Animación de pulso */
@keyframes chatbot-pulse {
  0%, 100% {
    box-shadow: 0 4px 12px var(--chatbot-shadow-lg),
                0 0 0 0 rgba(230, 34, 43, 0.4);
  }
  50% {
    box-shadow: 0 4px 12px var(--chatbot-shadow-lg),
                0 0 0 10px rgba(230, 34, 43, 0);
  }
}

/* Desactivar animaciones si el usuario lo prefiere */
@media (prefers-reduced-motion: reduce) {
  .chatbot-fab {
    animation: none;
  }
}

/* ========================================
   VENTANA DEL CHAT
   ======================================== */

.chatbot-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  height: 600px;
  background: var(--chatbot-white);
  border-radius: 20px;
  box-shadow: 0 8px 32px var(--chatbot-shadow-lg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ========================================
   HEADER
   ======================================== */

.chatbot-header {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 20px 20px 0 0;
}

.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chatbot-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--chatbot-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.chatbot-title-area {
  flex: 1;
}

.chatbot-title {
  color: var(--chatbot-white);
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 4px 0;
  line-height: 1.2;
}

.chatbot-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--chatbot-white);
  font-size: 13px;
  opacity: 0.95;
}

.chatbot-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chatbot-success);
  animation: chatbot-blink 2s infinite;
}

@keyframes chatbot-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.chatbot-close-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.chatbot-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chatbot-close-btn svg {
  width: 20px;
  height: 20px;
  stroke: var(--chatbot-white);
  stroke-width: 2;
}

/* ========================================
   ÁREA DE MENSAJES
   ======================================== */

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--chatbot-gray-light);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--chatbot-gray);
  border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: var(--chatbot-gray-dark);
}

/* ========================================
   MENSAJES
   ======================================== */

.chatbot-message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: chatbot-slide-in 0.3s ease-out;
}

@keyframes chatbot-slide-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chatbot-message.assistant {
  align-self: flex-start;
}

.chatbot-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.chatbot-message.user .chatbot-message-avatar {
  background: var(--chatbot-dark);
  color: var(--chatbot-white);
}

.chatbot-message.assistant .chatbot-message-avatar {
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
}

.chatbot-message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.5;
  font-size: 14px;
  word-wrap: break-word;
}

.chatbot-message.user .chatbot-message-bubble {
  background: var(--chatbot-dark);
  color: var(--chatbot-white);
  border-bottom-right-radius: 4px;
}

.chatbot-message.assistant .chatbot-message-bubble {
  background: var(--chatbot-white);
  color: var(--chatbot-dark);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Estilos para contenido markdown en mensajes */
.chatbot-message-bubble strong {
  font-weight: 700;
  color: var(--chatbot-primary);
}

.chatbot-message.user .chatbot-message-bubble strong {
  color: var(--chatbot-cream);
}

.chatbot-message-bubble a {
  color: var(--chatbot-primary);
  text-decoration: underline;
}

.chatbot-message.user .chatbot-message-bubble a {
  color: var(--chatbot-cream);
}

.chatbot-message-bubble ul {
  margin: 8px 0;
  padding-left: 20px;
}

.chatbot-message-bubble li {
  margin: 4px 0;
}

/* ========================================
   TYPING INDICATOR
   ======================================== */

.chatbot-typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.chatbot-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chatbot-gray-dark);
  animation: chatbot-typing 1.4s infinite;
}

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

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

@keyframes chatbot-typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* ========================================
   OPCIONES RÁPIDAS
   ======================================== */

.chatbot-quick-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 12px;
  background: var(--chatbot-gray-light);
}

.chatbot-quick-option {
  background: var(--chatbot-white);
  border: 1px solid var(--chatbot-gray);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  color: var(--chatbot-dark);
  font-weight: 500;
}

.chatbot-quick-option:hover {
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
  border-color: var(--chatbot-primary);
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(230, 34, 43, 0.2);
}

.chatbot-quick-option:active {
  transform: translateY(0);
}

/* ========================================
   INPUT ÁREA
   ======================================== */

.chatbot-input-wrapper {
  padding: 16px 20px;
  background: var(--chatbot-white);
  border-top: 1px solid var(--chatbot-gray);
  display: flex;
  gap: 12px;
  align-items: center;
}

.chatbot-input-container {
  flex: 1;
  position: relative;
}

.chatbot-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--chatbot-gray);
  border-radius: 24px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  resize: none;
  max-height: 100px;
  overflow-y: auto;
}

.chatbot-input:focus {
  border-color: var(--chatbot-primary);
}

.chatbot-input::placeholder {
  color: var(--chatbot-gray-dark);
}

.chatbot-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chatbot-send-btn:hover:not(:disabled) {
  background: var(--chatbot-primary-dark);
  transform: scale(1.05);
}

.chatbot-send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.chatbot-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chatbot-send-btn svg {
  width: 20px;
  height: 20px;
  fill: var(--chatbot-white);
}

/* ========================================
   BOTÓN DE LIMPIAR CHAT
   ======================================== */

.chatbot-clear-btn {
  background: transparent;
  border: none;
  color: var(--chatbot-gray-dark);
  font-size: 12px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 12px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chatbot-clear-btn:hover {
  background: rgba(230, 34, 43, 0.1);
  color: var(--chatbot-primary);
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 480px) {
  .chatbot-window {
    width: calc(100vw - 32px);
    height: calc(100vh - 120px);
    right: 16px;
    bottom: 90px;
    border-radius: 16px;
  }

  .chatbot-fab {
    width: 56px;
    height: 56px;
    bottom: 20px;
    right: 20px;
  }

  .chatbot-fab svg {
    width: 28px;
    height: 28px;
  }

  .chatbot-header {
    padding: 16px;
  }

  .chatbot-avatar {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .chatbot-title {
    font-size: 15px;
  }

  .chatbot-status {
    font-size: 12px;
  }

  .chatbot-messages {
    padding: 16px;
  }

  .chatbot-message {
    max-width: 90%;
  }

  .chatbot-input-wrapper {
    padding: 12px 16px;
  }
}

/* ========================================
   ESTADOS ESPECIALES
   ======================================== */

.chatbot-message.system .chatbot-message-bubble {
  background: var(--chatbot-cream);
  border-left: 3px solid var(--chatbot-primary);
  font-style: italic;
}

.chatbot-message.error .chatbot-message-bubble {
  background: #FEE2E2;
  border-left: 3px solid var(--chatbot-error);
  color: #991B1B;
}

/* Indicador visual cuando el mensaje es fallback (sin IA) */
.chatbot-message.fallback .chatbot-message-bubble::after {
  content: '⚡';
  position: absolute;
  bottom: 4px;
  right: 8px;
  font-size: 10px;
  opacity: 0.5;
}

/* ========================================
   ANIMACIONES ADICIONALES
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  .chatbot-window,
  .chatbot-message,
  .chatbot-quick-option {
    animation: none;
    transition: none;
  }

  .chatbot-typing-dot {
    animation: none;
  }

  .chatbot-status-dot {
    animation: none;
  }
}

/* ========================================
   ACCESIBILIDAD
   ======================================== */

.chatbot-fab:focus,
.chatbot-send-btn:focus,
.chatbot-quick-option:focus,
.chatbot-close-btn:focus {
  outline: 2px solid var(--chatbot-primary);
  outline-offset: 2px;
}

/* ========================================
   BADGE DE NOTIFICACIÓN (opcional)
   ======================================== */

.chatbot-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  border: 2px solid var(--chatbot-white);
}
