/* ============================================================
   ChatBot AI Pro — Public Widget Styles
   ============================================================ */

/* ── CSS Variables (overridden via JS) ───────────────────────── */
:root {
  --cbw-primary:   #6366f1;
  --cbw-primary2:  #8b5cf6;
  --cbw-radius:    18px;
  --cbw-shadow:    0 8px 32px rgba(99,102,241,.22), 0 2px 8px rgba(0,0,0,.10);
  --cbw-font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --cbw-z:         2147483647;
}

/* ── Accessibility helpers ───────────────────────────────────── */
.cbw-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Icon base */
.cbw-icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  line-height: 0;
}

/* Focus ring — visible only on keyboard navigation */
#chatbot-widget *:focus { outline: none; }
#chatbot-widget *:focus-visible {
  outline: 2px solid var(--cbw-primary);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  #chatbot-widget *, #chatbot-toggle-btn * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── Animated typing dots (on the toggle button open icon) ──────── */
@keyframes cbw-dot-bounce {
  0%, 55%, 100% { transform: translateY(0);    opacity: .7; }
  28%            { transform: translateY(-5px); opacity: 1;  }
}
.cbw-dot   { animation: cbw-dot-bounce 1.5s ease-in-out infinite; }
.cbw-dot-2 { animation-delay: .22s; }
.cbw-dot-3 { animation-delay: .44s; }

/* ── Floating Toggle Button ────────────────────────────────────── */
#chatbot-toggle-btn {
  position:            fixed           !important;
  z-index:             var(--cbw-z)    !important;
  width:               62px            !important;
  height:              62px            !important;
  border-radius:       50%             !important;
  background:          linear-gradient(135deg, var(--cbw-primary) 0%, var(--cbw-primary2) 100%) !important;
  border:              none            !important;
  cursor:              pointer         !important;
  display:             flex            !important;
  align-items:         center          !important;
  justify-content:     center          !important;
  box-shadow:          var(--cbw-shadow) !important;
  transition:          transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .25s ease;
  outline:             none            !important;
  -webkit-tap-highlight-color: transparent;
  padding:             0               !important;
  text-transform:      none            !important;
  letter-spacing:      0               !important;
  line-height:         1               !important;
  appearance:          none            !important;
  -webkit-appearance:  none            !important;
  min-height:          unset           !important;
  font-size:           0               !important;
}
#chatbot-toggle-btn:hover {
  transform: scale(1.08) !important;
  box-shadow: 0 12px 40px rgba(99,102,241,.35), 0 4px 12px rgba(0,0,0,.12) !important;
}
#chatbot-toggle-btn:active { transform: scale(.95) !important; }

/* Pulse ring behind the button */
#chatbot-toggle-btn::before {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cbw-primary), var(--cbw-primary2));
  opacity: 0;
  animation: cbw-pulse 2.5s ease-out infinite;
  z-index: -1;
  pointer-events: none;
}
@keyframes cbw-pulse {
  0%   { transform: scale(.9);  opacity: .6; }
  70%  { transform: scale(1.4); opacity: 0;  }
  100% { transform: scale(1.4); opacity: 0;  }
}

/* Hover tooltip label (shows to the side of the button) */
#chatbot-toggle-btn::after {
  content: attr(data-label);
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(8px);
  background: #fff;
  color: var(--cbw-primary);
  padding: 6px 14px;
  border-radius: 24px;
  font-size: 13px;
  font-family: var(--cbw-font);
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 3px 14px rgba(0,0,0,.13);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  font-size: 13px;
}
body.chatbot-pos-left #chatbot-toggle-btn::after {
  right: auto;
  left: calc(100% + 12px);
  transform: translateY(-50%) translateX(-8px);
}
#chatbot-toggle-btn:hover::after,
#chatbot-toggle-btn:focus-visible::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}
.chatbot-open #chatbot-toggle-btn::after { display: none; }

/* Icon visibility toggle */
#chatbot-toggle-btn .cbw-icon-open  { display: flex; align-items: center; justify-content: center; }
#chatbot-toggle-btn .cbw-icon-close { display: none; }
.chatbot-open #chatbot-toggle-btn .cbw-icon-open  { display: none; }
.chatbot-open #chatbot-toggle-btn .cbw-icon-close { display: flex; align-items: center; justify-content: center; }

/* Notification dot */
#chatbot-notif-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 13px;
  height: 13px;
  background: #ef4444;
  border: 2px solid #fff;
  border-radius: 50%;
  animation: cbw-bounce .6s ease infinite alternate;
  display: none;
  pointer-events: none;
}
#chatbot-notif-dot.is-visible { display: block; }
@keyframes cbw-bounce {
  from { transform: translateY(0); }
  to   { transform: translateY(-3px); }
}

/* Position — stacked above WhatsApp / other fixed widgets by default */
#chatbot-toggle-btn { bottom: var(--cbw-btn-bottom, 96px); right: var(--cbw-btn-right, 28px); }
body.chatbot-pos-left #chatbot-toggle-btn { right: auto; left: var(--cbw-btn-right, 28px); }

/* ── Chat Window ──────────────────────────────────────────────── */
#chatbot-window {
  position: fixed;
  z-index: calc(var(--cbw-z) - 1);
  bottom: calc(var(--cbw-btn-bottom, 96px) + 74px);
  right: var(--cbw-btn-right, 28px);
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 560px;
  max-height: calc(100vh - 160px);
  background: #fff;
  border-radius: var(--cbw-radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(99,102,241,.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--cbw-font);
  font-size: 14px;
  color: #1e293b;

  /* Slide-up animation */
  transform: translateY(24px) scale(.97);
  opacity: 0;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.16,1,.3,1), opacity .25s ease;
}
body.chatbot-pos-left #chatbot-window { right: auto; left: var(--cbw-btn-right, 28px); }

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

/* ── CRITICAL: fight WP / Elementor / theme button overrides ──── */
/* Elementor sets min-height, padding, background on every button.  */
/* Without this the header X renders as a large pink pill button.   */
#chatbot-window .cbw-header__close,
#chatbot-window .cbw-header__reset,
#chatbot-window .cbw-header__close:hover,
#chatbot-window .cbw-header__reset:hover,
#chatbot-window .cbw-header__close:focus,
#chatbot-window .cbw-header__reset:focus,
#chatbot-window .cbw-header__close:active {
  display:            inline-flex  !important;
  align-items:        center       !important;
  justify-content:    center       !important;
  width:              32px         !important;
  height:             32px         !important;
  min-width:          32px         !important;
  max-width:          32px         !important;
  min-height:         32px         !important;
  max-height:         32px         !important;
  padding:            0            !important;
  margin:             0            !important;
  background:         rgba(255,255,255,.18) !important;
  border:             1.5px solid rgba(255,255,255,.28) !important;
  border-radius:      50%          !important;
  color:              #ffffff      !important;
  line-height:        1            !important;
  font-size:          0            !important;
  cursor:             pointer      !important;
  flex-shrink:        0            !important;
  box-shadow:         none         !important;
  text-shadow:        none         !important;
  letter-spacing:     0            !important;
  text-transform:     none         !important;
  position:           relative     !important;
  z-index:            2            !important;
  appearance:         none         !important;
  -webkit-appearance: none         !important;
  overflow:           hidden       !important;
}
#chatbot-window .cbw-header__close:hover,
#chatbot-window .cbw-header__reset:hover {
  background: rgba(255,255,255,.35) !important;
  transform: scale(1.1);
}
#chatbot-window .cbw-header__close svg,
#chatbot-window .cbw-header__reset svg { pointer-events: none; }

#chatbot-window #chatbot-send-btn,
#chatbot-window #chatbot-send-btn:hover,
#chatbot-window #chatbot-send-btn:focus {
  width:              40px  !important;
  height:             40px  !important;
  min-width:          40px  !important;
  min-height:         40px  !important;
  padding:            0     !important;
  background:         linear-gradient(135deg, var(--cbw-primary), var(--cbw-primary2)) !important;
  border:             none  !important;
  border-radius:      50%   !important;
  flex-shrink:        0     !important;
  display:            inline-flex  !important;
  align-items:        center       !important;
  justify-content:    center       !important;
  color:              #fff  !important;
  box-shadow:         0 2px 8px rgba(99,102,241,.28) !important;
  cursor:             pointer      !important;
  appearance:         none  !important;
  -webkit-appearance: none  !important;
}
#chatbot-window #chatbot-send-btn:hover   { opacity: .9  !important; }
#chatbot-window #chatbot-send-btn:active  { transform: scale(.93) !important; }
#chatbot-window #chatbot-send-btn:disabled { opacity: .45 !important; transform: none !important; cursor: not-allowed !important; }

/* ── Window Header ────────────────────────────────────────────── */
.cbw-header {
  background: linear-gradient(135deg, var(--cbw-primary) 0%, var(--cbw-primary2) 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.cbw-header::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='200' height='200' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='180' cy='-20' r='120' fill='rgba(255,255,255,.06)'/%3E%3C/svg%3E") no-repeat right top;
}
.cbw-header__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.4);
}
.cbw-header__info { flex: 1; min-width: 0; position: relative; z-index: 1; }
.cbw-header__title {
  font-size: .95rem;
  font-weight: 700;
  color: #fff;
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cbw-header__subtitle {
  font-size: .72rem;
  color: rgba(255,255,255,.85);
  display: flex;
  align-items: center;
  gap: 5px;
}
.cbw-header__subtitle::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  animation: cbw-pulse-dot 2s ease infinite;
}
@keyframes cbw-pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: .5; }
}
.cbw-header__close {
  /* Base styles — overridden above with !important for theme conflicts */
  background: rgba(255,255,255,.18);
  border: 1.5px solid rgba(255,255,255,.28);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.cbw-header__reset {
  background: rgba(255,255,255,.18);
  border: 1.5px solid rgba(255,255,255,.28);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

/* ── Messages Area ────────────────────────────────────────────── */
.cbw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8fafc;
  scroll-behavior: smooth;
}
.cbw-messages::-webkit-scrollbar { width: 4px; }
.cbw-messages::-webkit-scrollbar-track { background: transparent; }
.cbw-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* Message row */
.cbw-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: cbw-msg-in .25s ease;
}
@keyframes cbw-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cbw-msg--user  { flex-direction: row-reverse; }
.cbw-msg--bot   { flex-direction: row; }

.cbw-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  flex-shrink: 0;
  align-self: flex-end;
}
.cbw-msg--bot .cbw-msg__avatar {
  background: linear-gradient(135deg, var(--cbw-primary), var(--cbw-primary2));
  color: #fff;
}
.cbw-msg--user .cbw-msg__avatar { display: none; }

.cbw-msg__bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.55;
  font-size: .875rem;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.cbw-msg--bot .cbw-msg__bubble {
  background: #fff;
  color: #1e293b;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.cbw-msg--user .cbw-msg__bubble {
  background: linear-gradient(135deg, var(--cbw-primary) 0%, var(--cbw-primary2) 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.cbw-msg__time {
  display: block;
  font-size: .68rem;
  opacity: .6;
  margin-top: 4px;
  text-align: right;
}
.cbw-msg--bot .cbw-msg__time { text-align: left; }

/* Quick actions */
.cbw-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: 36px;
  animation: cbw-msg-in .25s ease;
}
.cbw-quick-action {
  border: 1px solid rgba(99,102,241,.22);
  background: #fff;
  color: var(--cbw-primary);
  border-radius: 999px;
  padding: 8px 12px;
  font-family: var(--cbw-font);
  font-size: .8rem;
  font-weight: 650;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  transition: background .18s, border-color .18s, transform .15s;
}
.cbw-quick-action:hover {
  background: #f5f3ff;
  border-color: rgba(99,102,241,.38);
  transform: translateY(-1px);
}

/* Typing indicator */
.cbw-typing {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.cbw-typing__dots {
  background: #fff;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.cbw-typing__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cbw-primary);
  animation: cbw-dot 1.2s ease infinite;
}
.cbw-typing__dot:nth-child(2) { animation-delay: .2s; }
.cbw-typing__dot:nth-child(3) { animation-delay: .4s; }
@keyframes cbw-dot {
  0%, 80%, 100% { transform: scale(.7); opacity: .4; }
  40%            { transform: scale(1);  opacity: 1;  }
}

/* ── Lead capture form ───────────────────────────────────────── */
.cbw-lead-form {
  width: min(100%, 292px);
  max-width: calc(100% - 36px);
  padding: 14px;
  background: linear-gradient(135deg, #f0f4ff 0%, #faf5ff 100%);
  border: 1px solid #e0e7ff;
  animation: cbw-msg-in .3s ease;
}
.cbw-msg--lead .cbw-msg__bubble {
  max-width: calc(100% - 36px);
  border-bottom-left-radius: 16px;
}
.cbw-lead-form__title {
  font-size: .95rem;
  font-weight: 700;
  color: #1e293b;
  margin: 0 0 3px;
}
.cbw-lead-form__subtitle {
  font-size: .78rem;
  color: #64748b;
  margin: 0 0 14px;
}
.cbw-lead-form__fields { display: flex; flex-direction: column; gap: 8px; }
.cbw-lead-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #c4b5fd;
  border-radius: 10px;
  font-size: .85rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  font-family: var(--cbw-font);
  background: #fff;
  color: #1e293b;
}
.cbw-lead-input:focus {
  border-color: var(--cbw-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.cbw-lead-input--error { border-color: #ef4444 !important; }

/* Consentimiento */
.cbw-lead-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  font-size: .76rem;
  line-height: 1.45;
  color: #475569;
  cursor: pointer;
}
.cbw-lead-consent input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 2px 0 0;
  flex-shrink: 0;
  accent-color: var(--cbw-primary);
  cursor: pointer;
}
.cbw-lead-consent a {
  color: var(--cbw-primary);
  text-decoration: underline;
}

.cbw-lead-error {
  margin: 8px 0 0;
  font-size: .78rem;
  font-weight: 600;
  color: #b91c1c;
}
.cbw-lead-error[hidden] { display: none; }

.cbw-lead-form__actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.cbw-lead-submit {
  flex: 1;
  padding: 9px 14px;
  background: linear-gradient(135deg, var(--cbw-primary), var(--cbw-primary2));
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s, transform .15s;
  font-family: var(--cbw-font);
}
.cbw-lead-submit:hover   { opacity: .9; }
.cbw-lead-submit:active  { transform: scale(.97); }
.cbw-lead-skip {
  background: transparent;
  border: 1.5px solid #c4b5fd;
  color: var(--cbw-primary);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: .8rem;
  cursor: pointer;
  transition: all .2s;
  font-family: var(--cbw-font);
}
.cbw-lead-skip:hover { background: #ede9fe; }

/* ── Input bar ───────────────────────────────────────────────── */
.cbw-input-bar {
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
.cbw-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: .875rem;
  outline: none;
  resize: none;
  max-height: 100px;
  min-height: 40px;
  font-family: var(--cbw-font);
  color: #1e293b;
  background: #f8fafc;
  transition: border-color .2s, box-shadow .2s, background .2s;
  line-height: 1.5;
  overflow-y: auto;
}
.cbw-input:focus {
  border-color: var(--cbw-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
  background: #fff;
}
.cbw-input::placeholder { color: #94a3b8; }
.cbw-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cbw-primary), var(--cbw-primary2));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .2s, transform .15s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 2px 8px rgba(99,102,241,.25);
}
.cbw-send-btn:hover   { opacity: .9; transform: scale(1.08); }
.cbw-send-btn:active  { transform: scale(.93); }
.cbw-send-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.cbw-send-btn svg { pointer-events: none; }

/* ── Powered by ──────────────────────────────────────────────── */
.cbw-footer {
  text-align: center;
  padding: 5px 12px 8px;
  font-size: .65rem;
  color: #94a3b8;
  background: #fff;
  flex-shrink: 0;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  #chatbot-window {
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 18px 18px 0 0;
    height: 85vh;
    height: 85dvh;        /* dvh respeta la barra de URL dinámica del navegador */
    max-height: 100vh;
    max-height: 100dvh;
  }
  #chatbot-toggle-btn {
    bottom: 20px;
    right: 20px;
  }
  body.chatbot-pos-left #chatbot-toggle-btn { left: 20px; right: auto; }

  /* Con el chat abierto la ventana ocupa todo el ancho y llega hasta abajo,
     de modo que el botón flotante cae justo encima de la barra de escritura
     y tapa el botón de enviar (además va por encima: su z-index es mayor
     que el de la ventana). En móvil se oculta mientras el chat está abierto;
     para cerrar está la X de la cabecera. */
  body.chatbot-open #chatbot-toggle-btn { display: none !important; }

  /* Deja libre el indicador de inicio en iPhone */
  .cbw-footer { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
}
