/**
 * HDH Chatbot Reutilizable - Hoja de Estilos Maestra v1.0
 * Desarrollado para HDH Consultores / EMPRESA IA
 * Prefijo aislado: .hdh-bot-
 * Variables CSS configurables en tiempo de ejecución
 */

:root {
  --hdh-primary: #0f766e;
  --hdh-primary-hover: #115e59;
  --hdh-accent: #0d9488;
  --hdh-accent-hover: #0f766e;
  --hdh-header-bg: #0f766e;
  --hdh-whatsapp: #25d366;
  --hdh-whatsapp-hover: #128c7e;

  --hdh-bg-window: #ffffff;
  --hdh-bg-chat: #f8fafc;
  --hdh-bubble-bot: #ffffff;
  --hdh-bubble-user: #0d9488;
  --hdh-border: #e2e8f0;

  --hdh-text: #1e293b;
  --hdh-text-user: #ffffff;
  --hdh-text-muted: #64748b;
  --hdh-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --hdh-radius-window: 18px;
  --hdh-radius-bubble: 14px;
  --hdh-radius-btn: 9999px;
  --hdh-shadow-window: 0 20px 30px -10px rgba(15, 23, 42, 0.25), 0 10px 15px -5px rgba(0, 0, 0, 0.05);
  --hdh-shadow-launcher: 0 10px 20px -3px rgba(15, 118, 110, 0.4);
  --hdh-z-index: 999999;
}

/* Raíz del Widget */
.hdh-bot-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--hdh-z-index);
  font-family: var(--hdh-font);
  box-sizing: border-box;
  user-select: none;
}

.hdh-bot-root *,
.hdh-bot-root *::before,
.hdh-bot-root *::after {
  box-sizing: inherit;
  margin: 0;
  padding: 0;
}

/* Toast de Previsualización */
.hdh-bot-toast {
  position: absolute;
  bottom: 76px;
  right: 0;
  background: #ffffff;
  color: var(--hdh-text);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--hdh-border);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  max-width: 300px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.hdh-bot-toast.hdh-show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.hdh-bot-toast-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.hdh-bot-toast-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  margin-left: 6px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

.hdh-bot-toast-close:hover {
  color: #0f172a;
}

/* Botón Lanzador Flotante */
.hdh-bot-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--hdh-header-bg);
  color: #ffffff;
  border: none;
  outline: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--hdh-shadow-launcher);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

.hdh-bot-launcher:hover {
  transform: scale(1.06);
  background: var(--hdh-primary-hover);
}

.hdh-bot-launcher svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.hdh-bot-launcher .hdh-bot-icon-close {
  display: none;
}

.hdh-bot-launcher.hdh-active .hdh-bot-icon-chat {
  display: none;
}

.hdh-bot-launcher.hdh-active .hdh-bot-icon-close {
  display: block;
}

.hdh-bot-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
  background: var(--hdh-whatsapp);
  border: 2px solid #ffffff;
  border-radius: 50%;
}

/* Ventana de Chat */
.hdh-bot-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  height: 580px;
  max-height: calc(100vh - 100px);
  background: var(--hdh-bg-window);
  border-radius: var(--hdh-radius-window);
  box-shadow: var(--hdh-shadow-window);
  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.16, 1, 0.3, 1);
  border: 1px solid var(--hdh-border);
}

.hdh-bot-window.hdh-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Cabecera del Asistente */
.hdh-bot-header {
  background: var(--hdh-header-bg);
  color: #ffffff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.hdh-bot-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hdh-bot-avatar-wrap {
  position: relative;
  width: 38px;
  height: 38px;
}

.hdh-bot-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.2);
}

.hdh-bot-online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: var(--hdh-whatsapp);
  border: 2px solid var(--hdh-header-bg);
  border-radius: 50%;
}

.hdh-bot-profile-info h4 {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
}

.hdh-bot-profile-info p {
  font-size: 12px;
  color: #cbd5e1;
  margin-top: 2px;
}

.hdh-bot-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hdh-bot-btn-icon {
  background: transparent;
  border: none;
  color: #ffffff;
  opacity: 0.85;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, background 0.15s;
}

.hdh-bot-btn-icon:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

.hdh-bot-btn-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Área de Mensajes */
.hdh-bot-messages {
  flex: 1;
  background: var(--hdh-bg-chat);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

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

/* Filas y Burbujas */
.hdh-msg-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.hdh-msg-row.hdh-msg-user {
  justify-content: flex-end;
}

.hdh-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-top: 4px;
}

.hdh-msg-body {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hdh-bubble {
  padding: 11px 15px;
  border-radius: var(--hdh-radius-bubble);
  font-size: 13.5px;
  line-height: 1.48;
  position: relative;
  word-wrap: break-word;
}

.hdh-msg-bot .hdh-bubble {
  background: var(--hdh-bubble-bot);
  color: var(--hdh-text);
  border: 1px solid var(--hdh-border);
  border-top-left-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}

.hdh-msg-user .hdh-bubble {
  background: var(--hdh-bubble-user);
  color: var(--hdh-text-user);
  border-top-right-radius: 4px;
  max-width: 82%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.hdh-time {
  display: block;
  font-size: 10px;
  color: var(--hdh-text-muted);
  text-align: right;
  margin-top: 4px;
}

.hdh-msg-user .hdh-time {
  color: rgba(255, 255, 255, 0.75);
}

/* Tarjetas y Botones de Acción Rápida */
.hdh-card {
  background: #ffffff;
  border: 1px solid var(--hdh-border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.hdh-card-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--hdh-text);
  margin-bottom: 8px;
}

.hdh-quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.hdh-quick-btn {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: var(--hdh-primary);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.hdh-quick-btn:hover {
  background: var(--hdh-primary);
  color: #ffffff;
  border-color: var(--hdh-primary);
  transform: translateY(-1px);
}

/* Indicador de Escritura */
.hdh-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  width: fit-content;
}

.hdh-dot {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: hdhBlink 1.4s infinite ease-in-out;
}

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

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

@keyframes hdhBlink {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Tarjeta de Derivación a WhatsApp */
.hdh-whatsapp-card {
  background: #ffffff;
  border: 1.5px solid #bbf7d0;
  border-radius: 14px;
  padding: 14px;
  margin-top: 8px;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.12);
}

.hdh-whatsapp-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #15803d;
  font-weight: 700;
  margin-bottom: 10px;
}

.hdh-whatsapp-header svg {
  width: 22px;
  height: 22px;
  fill: var(--hdh-whatsapp);
}

.hdh-summary-box {
  background: #f0fdf4;
  border: 1px solid #dcfce7;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.6;
  color: #166534;
  margin-bottom: 12px;
}

.hdh-btn-whatsapp-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--hdh-whatsapp);
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
  font-size: 13.5px;
  padding: 11px 16px;
  border-radius: 10px;
  transition: background 0.2s ease, transform 0.15s ease;
  min-height: 44px;
}

.hdh-btn-whatsapp-cta:hover {
  background: var(--hdh-whatsapp-hover);
  transform: translateY(-1px);
}

.hdh-btn-whatsapp-cta svg {
  width: 20px;
  height: 20px;
  fill: #ffffff;
}

/* Pie de Entrada */
.hdh-bot-footer {
  padding: 12px;
  background: #ffffff;
  border-top: 1px solid var(--hdh-border);
  flex-shrink: 0;
}

.hdh-bot-input-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.hdh-bot-input-form:focus-within {
  border-color: var(--hdh-accent);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.hdh-bot-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13.5px;
  color: var(--hdh-text);
  outline: none;
}

.hdh-bot-send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--hdh-header-bg);
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}

.hdh-bot-send:hover {
  background: var(--hdh-primary-hover);
  transform: scale(1.05);
}

.hdh-bot-send svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.hdh-bot-branding {
  font-size: 10px;
  color: #94a3b8;
  text-align: center;
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Adaptación Móvil (Responsive <= 480px) */
@media (max-width: 480px) {
  .hdh-bot-root {
    bottom: 16px;
    right: 16px;
  }

  .hdh-bot-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
    z-index: var(--hdh-z-index);
  }

  .hdh-bot-toast {
    max-width: calc(100vw - 32px);
    bottom: 80px;
  }

  .hdh-quick-btn,
  .hdh-btn-whatsapp-cta,
  .hdh-bot-send {
    min-height: 44px;
  }
}
