/*
 * chatbot.css — Widget de chatbot Espinaltech
 * Decision-tree, vanilla JS, sin dependencias externas
 * Paleta: dark navy + accent naranja Espinaltech
 */

/* ============ FAB (botón flotante) ============ */
.cb-fab{
  position:fixed;bottom:36px;right:28px;z-index:9999;
  width:60px;height:60px;border-radius:50%;
  background:linear-gradient(180deg,#ff9a1c 0%, #ff8c00 100%);
  color:#1a0d00;
  display:flex;align-items:center;justify-content:center;
  font-size:24px;cursor:pointer;border:none;
  box-shadow:
    0 1px 0 rgba(255,255,255,.25) inset,
    0 0 0 1px rgba(255,140,0,.5),
    0 14px 32px -8px rgba(255,140,0,.55),
    0 4px 8px rgba(0,0,0,.3);
  transition:transform .25s ease, box-shadow .25s ease;
  animation:cb-fab-pulse 2.6s ease-in-out infinite;
}
.cb-fab:hover{
  transform:translateY(-3px) scale(1.05);
  box-shadow:
    0 1px 0 rgba(255,255,255,.3) inset,
    0 0 0 1px rgba(255,140,0,.7),
    0 18px 40px -8px rgba(255,140,0,.7),
    0 4px 8px rgba(0,0,0,.35);
}
.cb-fab.cb-open{
  animation:none;
  background:linear-gradient(180deg,#1d1f2c,#161827);
  color:#fff;
  box-shadow:0 8px 24px -8px rgba(0,0,0,.5);
}
.cb-fab .cb-fab-badge{
  position:absolute;top:-4px;right:-4px;
  width:20px;height:20px;border-radius:50%;
  background:#12d38f;color:#0a1126;
  font:700 11px/1 'Inter',system-ui,sans-serif;
  display:flex;align-items:center;justify-content:center;
  border:2px solid #0b1124;
  animation:cb-fab-blink 1.6s ease-in-out infinite;
}
.cb-fab.cb-open .cb-fab-badge{display:none}
@keyframes cb-fab-pulse{
  0%,100%{box-shadow:0 1px 0 rgba(255,255,255,.25) inset,0 0 0 1px rgba(255,140,0,.5),0 14px 32px -8px rgba(255,140,0,.55),0 4px 8px rgba(0,0,0,.3),0 0 0 0 rgba(255,140,0,.4)}
  70%{box-shadow:0 1px 0 rgba(255,255,255,.25) inset,0 0 0 1px rgba(255,140,0,.5),0 14px 32px -8px rgba(255,140,0,.55),0 4px 8px rgba(0,0,0,.3),0 0 0 16px rgba(255,140,0,0)}
}
@keyframes cb-fab-blink{0%,100%{opacity:1}50%{opacity:.4}}

/* ============ PANEL ============ */
.cb-panel{
  position:fixed;bottom:108px;right:28px;z-index:9998;
  width:380px;max-width:calc(100vw - 48px);
  height:560px;max-height:calc(100vh - 140px);
  background:linear-gradient(180deg,#0d1330 0%, #080d1f 100%);
  border:1px solid rgba(255,140,0,.18);
  border-radius:16px;
  box-shadow:
    0 30px 60px -20px rgba(0,0,0,.7),
    0 60px 120px -30px rgba(255,140,0,.12),
    0 1px 0 rgba(255,255,255,.05) inset;
  display:flex;flex-direction:column;
  overflow:hidden;
  font-family:'Inter',system-ui,sans-serif;
  opacity:0;transform:translateY(20px) scale(.96);
  pointer-events:none;
  transition:opacity .25s ease, transform .25s cubic-bezier(.22,.92,.43,1);
}
.cb-panel.cb-show{
  opacity:1;transform:none;pointer-events:auto;
}

/* Header */
.cb-head{
  display:flex;align-items:center;gap:12px;
  padding:16px 18px;
  border-bottom:1px solid rgba(255,255,255,.06);
  background:linear-gradient(180deg,rgba(255,140,0,.08),transparent);
}
.cb-head .cb-avatar{
  width:42px;height:42px;border-radius:50%;
  background:radial-gradient(circle at 50% 35%, #f5eedf 0%, #e6dcc4 100%);
  display:flex;align-items:center;justify-content:center;
  border:1.5px solid rgba(255,140,0,.35);
  box-shadow:0 0 16px rgba(255,140,0,.28);
  flex-shrink:0;
  position:relative;
  overflow:visible;
}
.cb-head .cb-avatar::after{
  content:'';position:absolute;bottom:-2px;right:-2px;
  width:11px;height:11px;border-radius:50%;background:#12d38f;
  border:2px solid #0d1330;box-shadow:0 0 8px #12d38f;
  animation:cb-fab-blink 1.6s ease-in-out infinite;
}
.cb-head .cb-info{flex:1;min-width:0}
.cb-head .cb-name{font:700 17px/1.2 'Inter';color:#fff;letter-spacing:-.01em}
.cb-head .cb-name-tag{font:500 12.5px/1 'IBM Plex Mono',monospace;color:#ff8c00;letter-spacing:.06em;margin-left:2px}
.cb-head .cb-status{font:500 12.5px/1.2 'IBM Plex Mono',monospace;color:#7fd3c4;letter-spacing:.06em;text-transform:uppercase;margin-top:4px}
.cb-head .cb-close{
  width:30px;height:30px;border-radius:8px;
  background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.08);
  color:#aab3ce;cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  font-size:14px;transition:.2s ease;
}
.cb-head .cb-close:hover{background:rgba(255,255,255,.1);color:#fff}

/* Body */
.cb-body{
  flex:1;overflow-y:auto;
  padding:18px;
  display:flex;flex-direction:column;gap:14px;
  scroll-behavior:smooth;
}
.cb-body::-webkit-scrollbar{width:6px}
.cb-body::-webkit-scrollbar-thumb{background:rgba(255,255,255,.1);border-radius:3px}

/* Mensaje del bot */
.cb-msg{
  display:flex;gap:10px;align-items:flex-start;
  animation:cb-fade-in .35s cubic-bezier(.22,.92,.43,1) both;
}
.cb-msg .cb-mavatar{
  width:30px;height:30px;border-radius:50%;
  background:radial-gradient(circle at 50% 35%, #f5eedf 0%, #e6dcc4 100%);
  display:flex;align-items:center;justify-content:center;
  flex-shrink:0;
  border:1px solid rgba(255,140,0,.25);
  box-shadow:0 0 8px rgba(255,140,0,.2);
  overflow:visible;
}
.cb-msg .cb-bubble{
  background:#161e3b;border:1px solid rgba(255,255,255,.06);
  padding:12px 16px;border-radius:14px;border-top-left-radius:4px;
  font:400 15px/1.6 'Inter';color:#e7eaf3;
  max-width:84%;
  white-space:pre-wrap;
}
.cb-msg .cb-bubble b{color:#fff;font-weight:600}
.cb-msg .cb-bubble .cb-link{color:#7fd3c4;text-decoration:underline;cursor:pointer}

/* Mensaje del usuario */
.cb-msg.cb-me{justify-content:flex-end}
.cb-msg.cb-me .cb-bubble{
  background:linear-gradient(180deg,rgba(255,140,0,.18),rgba(255,140,0,.08));
  border:1px solid rgba(255,140,0,.25);
  border-top-left-radius:14px;border-top-right-radius:4px;
  color:#fff;
}
.cb-msg.cb-me .cb-mavatar{display:none}

/* Typing indicator */
.cb-typing{display:flex;gap:4px;padding:10px 14px}
.cb-typing span{
  width:6px;height:6px;border-radius:50%;background:#7d86a3;
  animation:cb-typing 1.2s ease-in-out infinite;
}
.cb-typing span:nth-child(2){animation-delay:.2s}
.cb-typing span:nth-child(3){animation-delay:.4s}
@keyframes cb-typing{
  0%,60%,100%{transform:translateY(0);opacity:.4}
  30%{transform:translateY(-4px);opacity:1}
}

/* Opciones (botones) */
.cb-options{
  display:flex;flex-direction:column;gap:6px;
  margin-top:4px;
  animation:cb-fade-in .3s ease-out both;
  animation-delay:.1s;
}
.cb-opt{
  display:flex;align-items:center;gap:12px;
  padding:12px 16px;
  background:rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.08);
  border-radius:10px;
  font:600 14.5px/1.35 'Inter';color:#e7eaf3;
  text-align:left;cursor:pointer;
  transition:.2s ease;
  letter-spacing:-.005em;
}
.cb-opt i{color:#ff8c00;font-size:13px;flex-shrink:0;width:16px}
.cb-opt:hover{
  background:rgba(255,140,0,.1);
  border-color:rgba(255,140,0,.4);
  transform:translateX(3px);
}
.cb-opt.cb-opt-back{
  background:transparent;
  border-color:rgba(255,255,255,.06);
  color:#7d86a3;font-weight:500;
}
.cb-opt.cb-opt-back i{color:#7d86a3}

/* Input field */
.cb-input-wrap{
  padding:12px 14px;
  border-top:1px solid rgba(255,255,255,.06);
  background:rgba(0,0,0,.2);
  display:flex;gap:8px;align-items:center;
}
.cb-input{
  flex:1;
  background:rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.08);
  border-radius:10px;
  padding:12px 14px;
  font:500 14.5px/1.4 'Inter';color:#fff;
  outline:none;
  transition:border-color .2s ease;
}
.cb-input::placeholder{color:#7d86a3}
.cb-input:focus{border-color:rgba(255,140,0,.5)}
.cb-send{
  width:40px;height:40px;border-radius:10px;
  background:linear-gradient(180deg,#ff9a1c,#ff8c00);
  color:#1a0d00;border:none;cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  font-size:14px;
  transition:.2s ease;flex-shrink:0;
}
.cb-send:hover{transform:translateY(-1px);box-shadow:0 8px 16px -4px rgba(255,140,0,.5)}
.cb-send:disabled{opacity:.4;cursor:not-allowed;transform:none}

/* Quick escape — email + whatsapp siempre visibles */
.cb-quick{
  padding:12px 14px;
  display:flex;align-items:center;gap:10px;flex-wrap:wrap;
  border-top:1px solid rgba(255,255,255,.06);
  background:rgba(255,140,0,.04);
  font:500 12.5px/1 'Inter',system-ui,sans-serif;
}
.cb-quick-lb{color:#7d86a3;font-size:12.5px}
.cb-quick-link{
  display:inline-flex;align-items:center;gap:6px;
  padding:7px 12px;border-radius:8px;
  background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.08);
  color:#e7eaf3;font-weight:600;font-size:12.5px;
  text-decoration:none;
  transition:.2s ease;
}
.cb-quick-link i{color:var(--accent,#ff8c00);font-size:13px}
.cb-quick-link:hover{
  background:rgba(255,140,0,.12);
  border-color:rgba(255,140,0,.3);
  transform:translateY(-1px);
}
.cb-quick-link:nth-child(3) i{color:#25d366}

/* Footer */
.cb-foot{
  padding:9px 14px;
  text-align:center;
  font:500 11px/1.3 'IBM Plex Mono',monospace;
  color:#5d7597;letter-spacing:.16em;text-transform:uppercase;
  border-top:1px solid rgba(255,255,255,.04);
}
.cb-foot b{color:var(--accent,#ff8c00)}

/* Done state */
.cb-done{
  text-align:center;padding:24px 16px;
}
.cb-done .cb-done-ic{
  width:54px;height:54px;border-radius:50%;
  background:rgba(18,211,143,.15);
  border:2px solid rgba(18,211,143,.4);
  color:#12d38f;font-size:22px;
  display:inline-flex;align-items:center;justify-content:center;
  margin-bottom:14px;
  animation:cb-pop .5s cubic-bezier(.22,.92,.43,1);
}
.cb-done h4{font:700 16px/1.3 'Inter';color:#fff;margin-bottom:6px;letter-spacing:-.01em}
.cb-done p{font:400 13px/1.5 'Inter';color:#aab3ce}

@keyframes cb-fade-in{
  from{opacity:0;transform:translateY(8px)}
  to{opacity:1;transform:none}
}
@keyframes cb-pop{
  0%{transform:scale(.5);opacity:0}
  60%{transform:scale(1.15)}
  100%{transform:scale(1);opacity:1}
}

/* ============ MASCOTA BOT (SVG) ============ */
.cb-bot{
  width:100%;height:100%;
  display:block;
  overflow:visible;
  animation:cb-bot-bob 4.5s ease-in-out infinite;
  transform-origin:50% 60%;
}
@keyframes cb-bot-bob{
  0%,100%{transform:translateY(0) rotate(0deg)}
  25%{transform:translateY(-1.5px) rotate(-1.2deg)}
  75%{transform:translateY(-1px) rotate(1.2deg)}
}

/* antena pulsa con glow */
.cb-bot .bot-antenna-ball{
  filter:drop-shadow(0 0 4px #ff8c00);
  transform-origin:30px 5px;
  transform-box:fill-box;
  animation:cb-bot-antenna 1.8s ease-in-out infinite;
}
@keyframes cb-bot-antenna{
  0%,100%{opacity:1;transform:scale(1)}
  50%{opacity:.55;transform:scale(.82)}
}

/* ojos parpadean cada ~5s */
.cb-bot .bot-eye{
  transform-origin:center;
  transform-box:fill-box;
  animation:cb-bot-blink 5s steps(1,end) infinite;
}
.cb-bot .bot-eye-r{animation-delay:.05s}
@keyframes cb-bot-blink{
  0%,92%,100%{transform:scaleY(1)}
  93%,96%{transform:scaleY(.12)}
}

/* ojos miran a los lados sutilmente cada cierto tiempo */
.cb-bot .bot-eyes{
  animation:cb-bot-look 9s ease-in-out infinite;
  transform-origin:30px 29px;
  transform-box:fill-box;
}
@keyframes cb-bot-look{
  0%,40%,100%{transform:translateX(0)}
  50%,60%{transform:translateX(-1.2px)}
  72%,82%{transform:translateX(1.2px)}
}

/* mejillas pulsan suave */
.cb-bot .bot-cheek{
  animation:cb-bot-cheek 3.5s ease-in-out infinite;
  transform-origin:center;
  transform-box:fill-box;
}
.cb-bot .bot-cheek-r{animation-delay:.4s}
@keyframes cb-bot-cheek{
  0%,100%{opacity:.5;transform:scale(1)}
  50%{opacity:.7;transform:scale(1.1)}
}

/* mascota cuando el bot está "escribiendo" */
.cb-typing-active .cb-bot .bot-mouth{
  transform-origin:30px 41.5px;
  transform-box:fill-box;
  animation:cb-bot-talk .35s ease-in-out infinite alternate;
}
@keyframes cb-bot-talk{
  0%{transform:scaleY(1) scaleX(1)}
  100%{transform:scaleY(.45) scaleX(.7)}
}
.cb-typing-active .cb-bot{animation-duration:1.6s}
.cb-typing-active .cb-bot .bot-antenna-ball{animation-duration:.8s}

/* hover en avatar grande: bot se inclina hacia el cursor */
.cb-head .cb-avatar:hover .cb-bot{
  animation-play-state:paused;
  transform:translateY(-2px) rotate(3deg) scale(1.05);
  transition:transform .3s cubic-bezier(.22,.92,.43,1);
}

/* ============ RESPONSIVE ============ */
@media(max-width:480px){
  .cb-fab{bottom:80px;right:16px;width:54px;height:54px;font-size:22px}
  .cb-panel{
    bottom:144px;right:12px;left:12px;width:auto;max-width:none;
    height:calc(100vh - 180px);
  }
}
@media(max-width:760px) and (min-width:481px){
  .cb-fab{bottom:64px;right:20px}
  .cb-panel{bottom:132px;right:20px}
}
@media(prefers-reduced-motion:reduce){
  .cb-fab,.cb-fab-badge,.cb-typing span,.cb-msg{animation:none !important}
}
