/* Bacata AI Chat Widget — v1.0.0 */

/* ── Variables (sobreescritas por JS con el color del admin) ── */
:root {
  --bacata-primary:        #1a237e;
  --bacata-primary-dark:   #0d1b5e;
  --bacata-secondary:      #1565c0;
  --bacata-white:          #ffffff;
  --bacata-text:           #212121;
  --bacata-text-light:     #757575;
  --bacata-bg:             #f5f5f5;
  --bacata-bot-bubble:     #f3e5f5;
  --bacata-user-bubble:    var(--bacata-primary);
  --bacata-radius:         16px;
  --bacata-shadow:         0 8px 32px rgba(0,0,0,0.18);
  --bacata-z:              99999;
  --bacata-window-opacity: 1;
}

/* ── Contenedor principal ── */
.bacata-chat-container {
  position: fixed !important;
  bottom: 24px;
  right: 24px;
  z-index: 2147483647 !important;  /* máximo z-index posible */
  pointer-events: auto !important;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  isolation: isolate;
}

/* Posiciones */
.bacata-pos-bottom-right  { bottom: 24px; right: 24px; left: auto; top: auto; }
.bacata-pos-bottom-left   { bottom: 24px; left: 24px;  right: auto; top: auto; }
.bacata-pos-bottom-center { bottom: 24px; left: 50%; transform: translateX(-50%); right: auto; top: auto; }
.bacata-pos-top-right     { top: 24px; right: 24px; bottom: auto; left: auto; }
.bacata-pos-top-left      { top: 24px; left: 24px;  bottom: auto; right: auto; }
.bacata-pos-top-center    { top: 24px; left: 50%; transform: translateX(-50%); bottom: auto; right: auto; }

/* Ventana abre hacia arriba (posiciones top) */
.bacata-pos-top-right .bacata-chat-window,
.bacata-pos-top-left  .bacata-chat-window,
.bacata-pos-top-center .bacata-chat-window {
  bottom: auto;
  top: 60px;
}
/* Ventana abre hacia la izquierda */
.bacata-pos-bottom-left .bacata-chat-window,
.bacata-pos-top-left    .bacata-chat-window {
  right: auto;
  left: 0;
}
/* Ventana centrada */
.bacata-pos-bottom-center .bacata-chat-window,
.bacata-pos-top-center    .bacata-chat-window {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

/* ── Botón toggle (píldora) ── */
.bacata-chat-toggle {
  pointer-events: auto !important;
  height: 48px;
  padding: 0 20px 0 14px;
  border-radius: 999px;
  background: var(--bacata-primary);
  color: var(--bacata-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  box-shadow: 0 4px 18px rgba(26,35,126,0.40);
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
  position: relative;
  outline: none;
  white-space: nowrap;
}
.bacata-chat-toggle:hover {
  transform: scale(1.04);
  background: var(--bacata-primary-dark);
  box-shadow: 0 6px 24px rgba(26,35,126,0.55);
}
.bacata-chat-toggle:focus-visible {
  outline: 3px solid rgba(26,35,126,0.4);
  outline-offset: 3px;
}
.bacata-toggle-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}
.bacata-icon-small  .bacata-toggle-icon { font-size: 18px; }
.bacata-icon-medium .bacata-toggle-icon { font-size: 22px; }
.bacata-icon-large  .bacata-toggle-icon { font-size: 28px; }

/* Tamaños del botón */
.bacata-btn-compact .bacata-chat-toggle { height: 36px; padding: 0 14px 0 10px; font-size: 12px; }
.bacata-btn-normal  .bacata-chat-toggle { height: 48px; padding: 0 20px 0 14px; font-size: 14px; }
.bacata-btn-large   .bacata-chat-toggle { height: 60px; padding: 0 24px 0 18px; font-size: 15px; }
.bacata-btn-compact .bacata-chat-toggle.is-open { width: 36px; padding: 0; }
.bacata-btn-large   .bacata-chat-toggle.is-open  { width: 60px; padding: 0; }
.bacata-toggle-text {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
/* Cuando el chat está abierto, ocultar texto y mostrar solo X */
.bacata-chat-toggle.is-open {
  padding: 0;
  width: 48px;
  justify-content: center;
}
.bacata-chat-toggle.is-open .bacata-toggle-text,
.bacata-chat-toggle.is-open .bacata-toggle-icon { display: none; }

/* Badge de notificación */
.bacata-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: bacata-pulse 1.5s ease-in-out infinite;
}

@keyframes bacata-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.15); }
}

/* ── Ventana de chat ── */
.bacata-chat-window {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 360px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  background: var(--bacata-white);
  border-radius: var(--bacata-radius);
  box-shadow: var(--bacata-shadow);
  overflow: hidden;
  animation: bacata-slide-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  opacity: var(--bacata-window-opacity);
  backdrop-filter: blur(4px);
}
.bacata-chat-container.position-left .bacata-chat-window {
  right: auto;
  left: 0;
}

@keyframes bacata-slide-up {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ── Header ── */
.bacata-chat-header {
  background: var(--bacata-primary);
  color: var(--bacata-white);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.bacata-chat-avatar {
  font-size: 24px;
  flex-shrink: 0;
}
.bacata-chat-header-info {
  flex: 1;
  min-width: 0;
}
.bacata-chat-bot-name {
  display: block;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bacata-chat-status {
  font-size: 11px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 4px;
}
.bacata-status-dot {
  width: 7px;
  height: 7px;
  background: #69f0ae;
  border-radius: 50%;
  display: inline-block;
  animation: bacata-blink 2s ease-in-out infinite;
}
@keyframes bacata-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}
.bacata-chat-minimize {
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.bacata-chat-minimize:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

/* ── Área de mensajes ── */
.bacata-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: var(--bacata-bg);
  min-height: 200px;
  max-height: 320px;
}
.bacata-chat-messages::-webkit-scrollbar { width: 4px; }
.bacata-chat-messages::-webkit-scrollbar-track { background: transparent; }
.bacata-chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* ── Burbujas ── */
.bacata-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: bacata-msg-in 0.2s ease;
}
@keyframes bacata-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bacata-msg.bot {
  background: var(--bacata-white);
  color: var(--bacata-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.bacata-msg.user {
  background: var(--bacata-user-bubble);
  color: var(--bacata-white);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* ── Typing indicator ── */
.bacata-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bacata-white);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.bacata-typing span {
  width: 7px;
  height: 7px;
  background: #bdbdbd;
  border-radius: 50%;
  animation: bacata-bounce 1.2s ease-in-out infinite;
}
.bacata-typing span:nth-child(2) { animation-delay: 0.2s; }
.bacata-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bacata-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-7px); }
}

/* ── Input area ── */
.bacata-chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e0e0e0;
  background: var(--bacata-white);
  flex-shrink: 0;
}
.bacata-chat-input {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
  color: var(--bacata-text);
  transition: border-color 0.2s;
}
.bacata-chat-input:focus {
  border-color: var(--bacata-primary);
}
.bacata-chat-input::placeholder {
  color: #bdbdbd;
}
.bacata-chat-send {
  height: 38px;
  min-width: 38px;
  padding: 0 14px;
  border-radius: 10px;
  background: var(--bacata-primary);
  color: var(--bacata-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-shrink: 0;
  align-self: center;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  outline: none;
  box-shadow: 0 2px 8px rgba(26,35,126,0.25);
}
.bacata-chat-send:hover:not(:disabled) {
  background: var(--bacata-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(26,35,126,0.35);
}
.bacata-chat-send:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: none;
}
.bacata-chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}
.bacata-chat-send:focus-visible {
  outline: 3px solid rgba(26,35,126,0.35);
  outline-offset: 2px;
}

/* ── Footer ── */
.bacata-chat-footer {
  text-align: center;
  font-size: 11px;
  color: var(--bacata-text-light);
  padding: 6px 12px 8px;
  border-top: 1px solid #f0f0f0;
  background: #fafafa;
  flex-shrink: 0;
}
.bacata-chat-footer a {
  color: var(--bacata-secondary);
  text-decoration: none;
}
.bacata-chat-footer a:hover {
  text-decoration: underline;
}

/* ── Respuestas rápidas (quick replies) ── */
.bacata-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 4px 0 6px;
  align-self: flex-start;
  width: 100%;
  animation: bacata-msg-in 0.2s ease;
}
.bacata-qr-btn {
  background: var(--bacata-white);
  color: var(--bacata-primary);
  border: 1.5px solid var(--bacata-primary);
  border-radius: 18px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  white-space: nowrap;
  line-height: 1.3;
}
.bacata-qr-btn:hover {
  background: var(--bacata-primary);
  color: var(--bacata-white);
}

/* ── Pre-chat form ── */
.bacata-prechat-wrap {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  background: var(--bacata-bg);
}
.bacata-prechat-inner {
  width: 100%;
}
.bacata-prechat-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--bacata-text);
  margin: 0 0 6px 0;
}
.bacata-prechat-subtitle {
  font-size: 13px;
  color: var(--bacata-text-light);
  margin: 0 0 18px 0;
  line-height: 1.5;
}
.bacata-prechat-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.bacata-pc-input {
  width: 100%;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  color: var(--bacata-text);
  transition: border-color 0.2s;
  box-sizing: border-box;
}
.bacata-pc-input:focus {
  border-color: var(--bacata-primary);
}
.bacata-pc-btn {
  width: 100%;
  padding: 11px 0;
  background: var(--bacata-primary);
  color: var(--bacata-white);
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.bacata-pc-btn:hover:not(:disabled) {
  background: var(--bacata-primary-dark);
  transform: translateY(-1px);
}
.bacata-pc-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.bacata-pc-skip {
  display: block;
  text-align: center;
  margin-top: 12px;
  font-size: 12px;
  color: var(--bacata-text-light);
  text-decoration: none;
}
.bacata-pc-skip:hover {
  color: var(--bacata-primary);
  text-decoration: underline;
}

/* ── Responsive ── */
@media (max-width: 420px) {
  .bacata-chat-container {
    bottom: 16px;
    right: 16px;
  }
  .bacata-chat-window {
    width: calc(100vw - 32px);
    right: -8px;
  }
  .bacata-chat-container.position-left .bacata-chat-window {
    left: -8px;
  }
}
