/* ================================================================
   CHATBOT WIDGET — PREMIUM VISUAL REDESIGN
   Academia Virtual · PCEFact Perú
   ================================================================ */

/* ════════════════════════════════════════════
   BOTONES FLOTANTES — Stack vertical ordenado
   De abajo hacia arriba (right: 26px):
     1. Scroll-up  → bottom: 20px   (44px alto → tope en 64px)
     2. WhatsApp   → bottom: 90px   (56px alto → tope en 146px)
     3. Chatbot    → bottom: 170px  (64px alto → tope en 234px)
     4. Facebook   → bottom: 258px  (52px alto → tope en 310px)
   Espaciado mínimo entre botones: 24px
   ════════════════════════════════════════════ */

/* WhatsApp flotante del embed_code — nivel 2 */
.float-whatsapp,
a.float-whatsapp,
div.float-whatsapp {
  bottom: 90px  !important;
  right: 26px   !important;
}

/* ── Custom Properties ── */
#chatbotWidget {
  --cb-primary:       #4f46e5;
  --cb-primary-dark:  #3730a3;
  --cb-primary-mid:   #6366f1;
  --cb-primary-light: #eef2ff;
  --cb-accent:        #06b6d4;
  --cb-success:       #10b981;
  --cb-warning:       #f59e0b;
  --cb-danger:        #ef4444;
  --cb-text:          #1e293b;
  --cb-muted:         #64748b;
  --cb-border:        #e2e8f0;
  --cb-bg:            #f8fafc;
  --cb-white:         #ffffff;
  --cb-shadow-lg:     0 20px 60px rgba(79, 70, 229, .22), 0 4px 20px rgba(0,0,0,.10);
  --cb-radius:        20px;
  --cb-radius-sm:     12px;
  position: fixed;
  bottom: 170px; /* nivel 3 — encima de WhatsApp (90px + 56px + 24px = 170px) */
  right: 26px;
  z-index: 1050;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* ════════════════════════════════════════════
   BURBUJA FLOTANTE
   ════════════════════════════════════════════ */
#chatbotBubble {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3730a3 0%, #4f46e5 45%, #06b6d4 100%);
  background-size: 200% 200%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.55rem;
  color: #fff;
  box-shadow: 0 8px 32px rgba(79, 70, 229, .55),
              0 2px 8px rgba(0,0,0,.15),
              inset 0 1px 0 rgba(255,255,255,.2);
  transition: transform .3s cubic-bezier(.34, 1.56, .64, 1),
              box-shadow .3s ease;
  position: relative;
  z-index: 2;
  animation: cbFloat 3.5s ease-in-out infinite,
             cbGradient 6s ease infinite;
}
#chatbotBubble:hover {
  transform: scale(1.13) translateY(-3px) !important;
  box-shadow: 0 14px 44px rgba(79, 70, 229, .65),
              0 4px 16px rgba(0,0,0,.2),
              inset 0 1px 0 rgba(255,255,255,.25);
  animation: cbGradient 6s ease infinite;
}
@keyframes cbFloat {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}
@keyframes cbGradient {
  0%, 100% { background-position: 0% 50%; }
  50%       { background-position: 100% 50%; }
}
.cb-bubble-icon { line-height: 1; pointer-events: none; }

/* Tooltip de invitación */
#chatbotTooltip {
  position: absolute;
  bottom: 72px;
  right: 0;
  background: #fff;
  border-radius: 14px 14px 4px 14px;
  padding: 10px 16px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--cb-text);
  box-shadow: 0 8px 28px rgba(0,0,0,.14);
  white-space: nowrap;
  animation: cbTooltipIn .4s cubic-bezier(.34,1.56,.64,1) forwards;
  pointer-events: none;
  border: 1px solid var(--cb-border);
}
#chatbotTooltip::after {
  content: '';
  position: absolute;
  bottom: -7px; right: 18px;
  border: 7px solid transparent;
  border-top-color: #fff;
  border-bottom: none;
}
@keyframes cbTooltipIn {
  from { opacity: 0; transform: translateY(10px) scale(.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Badge contador de mensajes no leídos */
#chatbotBadge {
  position: absolute;
  top: -4px; right: -4px;
  width: 22px; height: 22px;
  background: var(--cb-danger);
  border: 3px solid #fff;
  border-radius: 50%;
  font-size: .65rem;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  animation: cbBadgeIn .4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes cbBadgeIn {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* Pulse ring */
#chatbotBubblePulse {
  display: none;
  position: absolute;
  top: 0; left: 0;
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(79, 70, 229, .3);
  animation: cbPulse 1.6s ease-out infinite;
  z-index: 1;
  pointer-events: none;
}
@keyframes cbPulse {
  0%   { transform: scale(1);   opacity: .8; }
  100% { transform: scale(2.4); opacity: 0;  }
}

/* ════════════════════════════════════════════
   VENTANA DEL CHAT
   ════════════════════════════════════════════ */
#chatbotWindow {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 370px;
  max-height: 580px;
  background: var(--cb-white);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1),
              opacity .28s ease;
  border: 1px solid rgba(79, 70, 229, .08);
}
#chatbotWindow.cb-hidden {
  transform: scale(.82) translateY(24px);
  opacity: 0;
  pointer-events: none;
}
#chatbotWindow.cb-visible {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ════════════════════════════════════════════
   HEADER
   ════════════════════════════════════════════ */
.cb-header {
  background: linear-gradient(135deg, #3730a3 0%, #4f46e5 55%, #6366f1 100%);
  padding: 16px 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
/* Decoración círculo difuminado en header */
.cb-header::before {
  content: '';
  position: absolute;
  top: -20px; right: -20px;
  width: 100px; height: 100px;
  background: rgba(255,255,255,.07);
  border-radius: 50%;
  pointer-events: none;
}
.cb-header::after {
  content: '';
  position: absolute;
  bottom: -30px; left: 30%;
  right: 0;
  height: 40px;
  background: var(--cb-white);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  pointer-events: none;
}

/* Avatar del bot */
.cb-header-avatar {
  width: 46px;
  height: 46px;
  background: rgba(255,255,255,.2);
  border: 2px solid rgba(255,255,255,.35);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #fff;
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 0 0 4px rgba(255,255,255,.1);
}
.cb-online-dot {
  position: absolute;
  bottom: 0px; right: 0px;
  width: 13px; height: 13px;
  background: var(--cb-success);
  border: 2.5px solid var(--cb-primary);
  border-radius: 50%;
  animation: cbOnlinePulse 2s ease-in-out infinite;
}
@keyframes cbOnlinePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,.5); }
  50%       { box-shadow: 0 0 0 5px rgba(16,185,129,.0); }
}

.cb-header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cb-header-info strong {
  color: #fff;
  font-size: .95rem;
  font-weight: 700;
  line-height: 1.2;
}
.cb-header-info .cb-status-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .73rem;
  color: rgba(255,255,255,.8);
}
.cb-status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cb-success);
  display: inline-block;
  animation: cbOnlinePulse 2s ease-in-out infinite;
}

.cb-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 2;
}
.cb-wa-btn {
  width: 32px; height: 32px;
  background: rgba(255,255,255,.15);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff !important;
  font-size: 1.05rem;
  text-decoration: none !important;
  transition: background .2s, transform .2s;
}
.cb-wa-btn:hover {
  background: #25d366;
  transform: scale(1.05);
  color: #fff !important;
}
.cb-close-btn {
  width: 32px; height: 32px;
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: .9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .2s;
}
.cb-close-btn:hover {
  background: rgba(255,255,255,.3);
  transform: rotate(90deg);
}

/* ════════════════════════════════════════════
   CUERPO / MENSAJES
   ════════════════════════════════════════════ */
.cb-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  min-height: 180px;
  max-height: 280px;
  background: #fafbff;
}
.cb-body::-webkit-scrollbar { width: 3px; }
.cb-body::-webkit-scrollbar-track { background: transparent; }
.cb-body::-webkit-scrollbar-thumb {
  background: #dde3f0;
  border-radius: 4px;
}

/* Mensajes */
.cb-msg {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 90%;
  animation: cbMsgIn .28s cubic-bezier(.34, 1.4, .64, 1) forwards;
}
@keyframes cbMsgIn {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.cb-msg--user {
  margin-left: auto;
  flex-direction: row-reverse;
}
.cb-msg--bot { margin-right: auto; }

/* Avatar bot */
.cb-avatar {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .35);
}

/* Burbujas de mensaje */
.cb-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: .855rem;
  line-height: 1.6;
  word-break: break-word;
  position: relative;
  max-width: 100%;
}
.cb-msg--bot .cb-bubble {
  background: #fff;
  color: var(--cb-text);
  border-bottom-left-radius: 5px;
  box-shadow: 0 2px 10px rgba(0,0,0,.07);
  border: 1px solid var(--cb-border);
}
.cb-msg--user .cb-bubble {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 14px rgba(79, 70, 229, .35);
}
.cb-msg--bot .cb-bubble a  { color: #4f46e5; text-decoration: underline; }
.cb-msg--user .cb-bubble a { color: rgba(255,255,255,.9); }

/* Timestamp */
.cb-msg-time {
  font-size: .62rem;
  color: #b0bec5;
  margin-top: 2px;
  display: block;
  text-align: right;
}
.cb-msg--bot .cb-msg-time  { text-align: left; margin-left: 37px; }
.cb-msg--user .cb-msg-time { text-align: right; }

/* Typing indicator */
.cb-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--cb-border);
  border-radius: 18px 18px 18px 5px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  width: fit-content;
}
.cb-typing span {
  width: 8px; height: 8px;
  background: #c7d0e8;
  border-radius: 50%;
  animation: cbTypeBounce 1s infinite;
}
.cb-typing span:nth-child(2) { animation-delay: .18s; }
.cb-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes cbTypeBounce {
  0%, 80%, 100% { transform: translateY(0); background: #c7d0e8; }
  40%           { transform: translateY(-7px); background: #4f46e5; }
}

/* Follow-up feedback */
.cb-followup {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: .76rem;
  color: var(--cb-muted);
  padding: 4px 2px;
  animation: cbMsgIn .28s ease forwards;
}
.cb-fu-btn {
  border: 1.5px solid var(--cb-border);
  background: #fff;
  border-radius: 20px;
  padding: 4px 13px;
  font-size: .75rem;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}
.cb-fu-yes:hover { background: #dcfce7; border-color: #10b981; color: #059669; }
.cb-fu-no:hover  { background: #fef3c7; border-color: #f59e0b; color: #d97706; }

/* ════════════════════════════════════════════
   RESPUESTAS RÁPIDAS (FAQ chips)
   ════════════════════════════════════════════ */
.cb-quick-replies {
  padding: 10px 14px 8px;
  border-top: 1px solid #f0f2fa;
  flex-shrink: 0;
  background: var(--cb-white);
}
.cb-qr-label {
  font-size: .67rem;
  font-weight: 700;
  color: #a5b4c8;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.cb-qr-label i { color: var(--cb-warning); font-size: .75rem; }

.cb-qr-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 88px;
  overflow-y: auto;
}
.cb-qr-list::-webkit-scrollbar { height: 3px; }
.cb-qr-list::-webkit-scrollbar-thumb { background: #dde3f0; border-radius: 3px; }

.cb-qr-btn {
  background: var(--cb-primary-light);
  border: 1.5px solid #c7d2fe;
  border-radius: 20px;
  padding: 5px 13px;
  font-size: .77rem;
  font-weight: 500;
  color: #4338ca;
  cursor: pointer;
  transition: all .22s cubic-bezier(.34, 1.3, .64, 1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 5px;
}
.cb-qr-btn:hover {
  background: var(--cb-primary);
  color: #fff;
  border-color: var(--cb-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, .3);
}
.cb-qr-btn i { font-size: .8rem; opacity: .8; }

/* ════════════════════════════════════════════
   INPUT AREA
   ════════════════════════════════════════════ */
.cb-input-area {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 10px 12px 10px;
  border-top: 1px solid #f0f2fa;
  flex-shrink: 0;
  background: var(--cb-white);
}
#chatbotInput {
  flex: 1;
  border: 1.5px solid var(--cb-border);
  border-radius: 24px 0 0 24px;
  padding: 10px 16px;
  font-size: .855rem;
  outline: none;
  color: var(--cb-text);
  transition: border-color .2s, box-shadow .2s;
  background: #f8fafc;
  font-family: inherit;
}
#chatbotInput:focus {
  border-color: var(--cb-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .1);
}
#chatbotInput::placeholder { color: #b0bcc8; }
#chatbotSendBtn {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  border: none;
  border-radius: 0 24px 24px 0;
  color: #fff;
  font-size: .95rem;
  cursor: pointer;
  transition: background .2s, transform .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .35);
}
#chatbotSendBtn:hover {
  background: linear-gradient(135deg, #3730a3, #4f46e5);
  transform: scale(1.05);
}
#chatbotSendBtn:active { transform: scale(.97); }

/* ════════════════════════════════════════════
   FOOTER DEL CHAT
   ════════════════════════════════════════════ */
.cb-footer {
  text-align: center;
  font-size: .63rem;
  color: #b0bec5;
  padding: 5px 14px 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--cb-white);
}
.cb-footer a { color: #b0bec5; text-decoration: none; }
.cb-footer a:hover { color: var(--cb-primary); }
.cb-footer-divider { opacity: .4; }

/* Powered badge */
.cb-powered {
  background: var(--cb-primary-light);
  border: 1px solid #c7d2fe;
  border-radius: 20px;
  padding: 2px 9px;
  font-size: .6rem;
  font-weight: 600;
  color: #4338ca;
  letter-spacing: .02em;
}

/* ════════════════════════════════════════════
   TARJETA DE BIENVENIDA
   ════════════════════════════════════════════ */
.cb-welcome-card {
  background: linear-gradient(135deg, #eef2ff 0%, #f0fdf9 100%);
  border: 1px solid #c7d2fe;
  border-radius: var(--cb-radius-sm);
  padding: 14px;
  margin: 4px 0;
  animation: cbMsgIn .3s ease forwards;
}
.cb-welcome-card p {
  font-size: .83rem;
  color: var(--cb-text);
  margin: 0 0 10px;
  line-height: 1.5;
}
.cb-wc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cb-wc-btn {
  background: #fff;
  border: 1.5px solid #c7d2fe;
  border-radius: 20px;
  padding: 5px 13px;
  font-size: .77rem;
  font-weight: 600;
  color: #4338ca;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 1px 4px rgba(79,70,229,.1);
}
.cb-wc-btn:hover {
  background: var(--cb-primary);
  color: #fff;
  border-color: var(--cb-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, .3);
}

/* ════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* Mobile — misma lógica:
     1. Scroll   bottom: 14px
     2. WhatsApp bottom: 74px  (14 + 44 + 16)
     3. Chatbot  bottom: 150px (74 + 56 + 20)
  */
  .float-whatsapp,
  a.float-whatsapp,
  div.float-whatsapp {
    bottom: 74px !important;
    right: 14px  !important;
  }
  #scrollToTop {
    bottom: 14px !important;
    right: 14px  !important;
  }
  #chatbotWidget {
    bottom: 150px;
    right: 14px;
  }
  #chatbotWindow {
    width: calc(100vw - 20px);
    right: -14px;
    border-radius: 18px 18px 0 0;
    bottom: 72px;
    max-height: 75vh;
  }
  #chatbotBubble {
    width: 54px;
    height: 54px;
    font-size: 1.35rem;
  }
  #chatbotBubblePulse { width: 54px; height: 54px; }
  #chatbotTooltip { display: none; }
}
