/* BURBUJA DEL CHAT */
#chat-bubble {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 56px;
  height: 56px;
  background: #ffffff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  z-index: 99998;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

#chat-bubble img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 50%;
}

/* TEASER / MENSAJE EMERGENTE TIPO BURBUJA */
#chat-teaser {
  position: fixed;
  bottom: 40px;
  right: 100px;
  max-width: 260px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
  padding: 8px 10px;
  font-size: 13px;
  z-index: 99997;
  display: none;
  align-items: center;
  gap: 8px;
}

#chat-teaser-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

#chat-teaser-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#chat-teaser-content {
  position: relative;
  padding-right: 18px;
}

#chat-teaser-close {
  position: absolute;
  top: -4px;
  right: -2px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: #888;
}

#chat-teaser-text { line-height: 1.3; }

/* CAJA DEL CHAT (DESKTOP) */
#chat-box {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 340px;
  max-height: 480px;
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #ccc;
  display: none;
  flex-direction: column;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 99999;
  overflow: hidden;
}

#chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
}

#chat-header-logo { height: 26px; width: auto; object-fit: contain; }
#chat-header-title { font-size: 14px; font-weight: 600; }

#chat-header-close {
  margin-left: auto;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  color: #555;
}

#chat-messages {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  font-size: 14px;
  background: #f9f9f9;
  -webkit-overflow-scrolling: touch;
}

.msg-row { margin-bottom: 6px; }

.msg-sender {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 2px;
}

.msg-bubble {
  display: inline-block;
  padding: 6px 9px;
  border-radius: 10px;
  max-width: 90%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-admin .msg-bubble{
  background:#e7efff;
  border:1px solid #c5d6ff;
  color:#111;
}

.msg-bot .msg-bubble { background: #ffffff; border: 1px solid #ddd; }

.msg-user { text-align: right; }
.msg-user .msg-bubble { background: #0c7702; color: #ffffff; }

#chat-input {
  border-top: 1px solid #ddd;
  padding: 8px;
  display: flex;
  gap: 5px;
  background: #fff;
  flex-shrink: 0;
}

#chat-input input {
  flex: 1;
  padding: 6px;
  border: 1px solid #aaa;
  border-radius: 6px;
  font-size: 14px;
  min-width: 0;
}

#chat-input button {
  padding: 6px 10px;
  background: #0c7702;
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

/* ENLACES DENTRO DEL CHAT (BOT) */
#chat-messages .msg-bot a,
#chat-messages .msg-bot a:visited {
  color: #0c7702;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
#chat-messages .msg-bot a:hover { opacity: 0.85; text-decoration: underline; }

/* TYPING INDICATOR (3 puntos) */
.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid #ddd;
}
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #999;
  animation: agodots 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2){ animation-delay: .15s; }
.typing-dot:nth-child(3){ animation-delay: .30s; }

@keyframes agodots {
  0%, 80%, 100% { transform: translateY(0); opacity: .4; }
  40% { transform: translateY(-3px); opacity: 1; }
}

/* RESPONSIVE (MÓVIL) */
@media (max-width: 600px) {
  #chat-bubble { bottom: 16px; right: 16px; }
  #chat-teaser { right: 84px; bottom: 20px; max-width: calc(100vw - 120px); }

  /* En móvil: chat tipo app fullscreen */
  #chat-box {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100vw;
    
    height: auto;
    max-height: none;
    
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
  
   /* ✅ evita que el header quede bajo notch/barra */
  #chat-header{
    padding-top: max(8px, env(safe-area-inset-top, 0px));
  }
  
  /* ✅ evita que el input quede tapado por barra inferior */
  #chat-input {
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }

  #chat-messages { padding: 12px; font-size: 15px; }
  #chat-input { padding: 10px; gap: 8px; }
  #chat-input input { padding: 10px; font-size: 16px; } /* evita zoom iOS */
  #chat-input button { padding: 10px 12px; font-size: 15px; }
}

/* cuando el chat está abierto en móvil, bloqueamos scroll de fondo */
body.agorabot-chat-open { overflow: hidden !important; touch-action: none; }
