/* CazaBot — chatbot flotante */
:root {
  --cb-dark: #1a1a1a;
  --cb-green: #2a7d4f;
  --cb-green-dark: #1f6840;
  --cb-bg: #f7f9f8;
  --cb-text: #1a1a1a;
  --cb-text-light: #6b7280;
  --cb-bubble-user: #2a7d4f;
  --cb-bubble-bot: #ffffff;
  --cb-border: #e5e7eb;
}

/* === Burbuja flotante === */
.cb-toggle {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--cb-green);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(42, 125, 79, 0.45);
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9990;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: cbBubblePulse 4s ease-in-out infinite;
  font-family: 'Barlow', sans-serif;
}
.cb-toggle:hover { transform: scale(1.06); box-shadow: 0 8px 26px rgba(42,125,79,.55); }
.cb-toggle .cb-badge {
  position: absolute;
  top: 4px; right: 4px;
  width: 12px; height: 12px;
  background: #2ecc71;
  border-radius: 50%;
  border: 2px solid #fff;
  animation: cbBadgePulse 2s infinite;
}
@keyframes cbBubblePulse {
  0%, 100% { box-shadow: 0 6px 22px rgba(42,125,79,.45); }
  50% { box-shadow: 0 6px 22px rgba(42,125,79,.45), 0 0 0 14px rgba(42,125,79,0); }
}
@keyframes cbBadgePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46,204,113,.7); }
  70% { box-shadow: 0 0 0 8px rgba(46,204,113,0); }
}
.cb-toggle.cb-hidden { display: none; }

/* === Ventana === */
.cb-window {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 340px;
  height: 500px;
  background: var(--cb-bg);
  border-radius: 16px;
  box-shadow: 0 16px 50px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9991;
  font-family: 'Barlow', sans-serif;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(.22,.61,.36,1), opacity 0.22s;
}
.cb-window.cb-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* === Header === */
.cb-header {
  background: var(--cb-dark);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.cb-header img {
  width: 32px; height: 32px; border-radius: 50%;
  background: #fff; padding: 2px;
}
.cb-header .cb-title {
  flex: 1;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.cb-header .cb-title .cb-status {
  font-size: 11px;
  font-weight: 500;
  color: #8eb;
  margin-top: 2px;
}
.cb-header .cb-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  opacity: 0.7;
  padding: 0 4px;
  font-family: inherit;
  line-height: 1;
}
.cb-header .cb-close:hover { opacity: 1; }

/* === Aviso RGPD === */
.cb-privacy {
  background: #fff8e1;
  border-bottom: 1px solid #f0d97d;
  color: #5a3e00;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 8px 14px;
  flex-shrink: 0;
}

/* === Área de mensajes === */
.cb-messages {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.cb-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: cbMsgIn 0.25s ease-out;
}
@keyframes cbMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.cb-msg.cb-bot {
  align-self: flex-start;
  background: var(--cb-bubble-bot);
  color: var(--cb-text);
  border: 1px solid var(--cb-border);
  border-bottom-left-radius: 4px;
}
.cb-msg.cb-user {
  align-self: flex-end;
  background: var(--cb-bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.cb-msg.cb-error {
  background: #fef0ec;
  color: #8b2a00;
  border: 1px solid #f4c2b0;
  align-self: flex-start;
  font-size: 13px;
}
.cb-msg a { color: inherit; text-decoration: underline; }
.cb-msg.cb-user a { color: #fff; }

/* === Indicador escribiendo === */
.cb-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--cb-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.cb-typing span {
  width: 7px; height: 7px;
  background: var(--cb-green);
  border-radius: 50%;
  display: inline-block;
  animation: cbTypingDot 1.2s infinite;
}
.cb-typing span:nth-child(2) { animation-delay: 0.15s; }
.cb-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cbTypingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* === Input === */
.cb-input-wrap {
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid var(--cb-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  /* Respeta el home indicator del iPhone X+ */
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.cb-input {
  flex: 1;
  min-width: 0;            /* sin esto el textarea desborda en flex */
  border: 1px solid var(--cb-border);
  border-radius: 22px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 16px;          /* 16px previene zoom automatico iOS al enfocar */
  outline: none;
  resize: none;
  max-height: 100px;
  background: #fafafa;
  color: var(--cb-text);
  line-height: 1.4;
  box-sizing: border-box;
}
.cb-input:focus { border-color: var(--cb-green); background: #fff; }
.cb-send {
  background: var(--cb-green);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px; height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  padding: 0;
}
.cb-send:hover { background: var(--cb-green-dark); }
.cb-send:disabled { background: #cfd6d3; cursor: not-allowed; }

/* === Mobile fullscreen === */
@media (max-width: 600px) {
  .cb-window {
    bottom: 0; right: 0; left: 0; top: 0;
    width: 100%;
    /* dvh = dynamic viewport height: se ajusta cuando aparece la barra del navegador
       o el teclado en iOS/Android. 100% rompe esto. */
    height: 100dvh;
    /* Fallback para navegadores que no soportan dvh */
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .cb-toggle { bottom: 16px; right: 16px; }
  .cb-header { padding: 12px 14px; }
  .cb-header img { width: 28px; height: 28px; }
  .cb-header .cb-title { font-size: 14px; }

  .cb-input-wrap {
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    gap: 6px;
  }
  .cb-input {
    padding: 9px 12px;
    border-radius: 20px;
  }
  .cb-send {
    width: 38px; height: 38px;
  }
  .cb-send svg { width: 16px; height: 16px; }
}

/* Pantallas muy estrechas (iPhone SE, 320px) */
@media (max-width: 360px) {
  .cb-input-wrap { padding: 6px 8px; gap: 5px; }
  .cb-input { padding: 8px 10px; font-size: 16px; }
  .cb-send { width: 36px; height: 36px; }
}
