/**
 * Chatbot Inmobiliario CTR
 * Botón flotante + ventana de chat. Animaciones suaves.
 * No afecta SEO ni rendimiento; se carga de forma asíncrona.
 */

/* ===== Variables (heredan tema claro/oscuro si existen) ===== */
.ctr-chatbot-root {
  --chatbot-primary: #003dff;
  --chatbot-primary-dark: #0029b3;
  --chatbot-bg: #ffffff;
  --chatbot-bg-msg-user: #003dff;
  --chatbot-bg-msg-bot: #f0f2f5;
  --chatbot-text: #1a1a1a;
  --chatbot-text-inverse: #ffffff;
  --chatbot-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  --chatbot-radius: 12px;
  --chatbot-radius-btn: 50%;
  --chatbot-z: 9998;
}

[data-theme="dark"] .ctr-chatbot-root {
  --chatbot-bg: #242526;
  --chatbot-bg-msg-bot: #3a3b3c;
  --chatbot-text: #e4e6eb;
  --chatbot-text-inverse: #ffffff;
  --chatbot-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ===== Contenedor raíz ===== */
.ctr-chatbot-root {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: var(--chatbot-z);
  font-family: var(--font-body, 'Roboto', sans-serif);
  font-size: 15px;
  line-height: 1.5;
  color: var(--chatbot-text);
  pointer-events: none;
}

.ctr-chatbot-root * {
  box-sizing: border-box;
}

.ctr-chatbot-root .ctr-chatbot-trigger,
.ctr-chatbot-root .ctr-chatbot-window,
.ctr-chatbot-root .ctr-chatbot-window * {
  pointer-events: auto;
}

/* ===== Botón flotante ===== */
.ctr-chatbot-trigger {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: var(--chatbot-radius-btn);
  background: var(--chatbot-primary);
  color: var(--chatbot-text-inverse);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--chatbot-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ctr-chatbot-trigger:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 28px rgba(0, 61, 255, 0.35);
}

.ctr-chatbot-trigger:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 61, 255, 0.35);
}

/* Pulse sutil (solo cuando ventana cerrada) */
.ctr-chatbot-root:not(.ctr-chatbot-open) .ctr-chatbot-trigger {
  animation: ctr-chatbot-pulse 2.5s ease-in-out infinite;
}

@keyframes ctr-chatbot-pulse {
  0%, 100% { box-shadow: var(--chatbot-shadow); }
  50% { box-shadow: 0 4px 28px rgba(0, 61, 255, 0.4); }
}

.ctr-chatbot-trigger svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

/* ===== Ventana de chat ===== */
.ctr-chatbot-window {
  position: absolute;
  bottom: 86px;
  right: 20px;
  width: min(380px, calc(100vw - 40px));
  max-height: min(520px, calc(100vh - 120px));
  background: var(--chatbot-bg);
  border-radius: var(--chatbot-radius);
  box-shadow: var(--chatbot-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

.ctr-chatbot-root.ctr-chatbot-open .ctr-chatbot-window {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header ===== */
.ctr-chatbot-header {
  padding: 14px 16px;
  background: var(--chatbot-primary);
  color: var(--chatbot-text-inverse);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ctr-chatbot-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.ctr-chatbot-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.2s;
}

.ctr-chatbot-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ctr-chatbot-close svg {
  width: 20px;
  height: 20px;
}

/* Mensajes ===== */
.ctr-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
  max-height: 320px;
}

.ctr-chatbot-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.ctr-chatbot-msg strong {
  font-weight: 600;
}

.ctr-chatbot-msg-user {
  align-self: flex-end;
  background: var(--chatbot-bg-msg-user);
  color: var(--chatbot-text-inverse);
}

.ctr-chatbot-msg-bot {
  align-self: flex-start;
  background: var(--chatbot-bg-msg-bot);
  color: var(--chatbot-text);
}

/* Cards (propiedades / proyectos) ===== */
.ctr-chatbot-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.ctr-chatbot-card {
  display: block;
  background: var(--chatbot-bg);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s, box-shadow 0.2s;
}

[data-theme="dark"] .ctr-chatbot-card {
  border-color: rgba(255, 255, 255, 0.1);
}

.ctr-chatbot-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.ctr-chatbot-card-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  background: #eee;
}

.ctr-chatbot-card-body {
  padding: 10px 12px;
}

.ctr-chatbot-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0 0 4px 0;
}

.ctr-chatbot-card-meta {
  font-size: 0.8rem;
  color: var(--chatbot-text);
  opacity: 0.85;
  margin: 0 0 6px 0;
}

.ctr-chatbot-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ctr-chatbot-btn-card {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.2s;
}

.ctr-chatbot-btn-card:hover {
  opacity: 0.9;
}

.ctr-chatbot-btn-card.ctr-chatbot-btn-primary {
  background: var(--chatbot-primary);
  color: var(--chatbot-text-inverse);
}

.ctr-chatbot-btn-card.ctr-chatbot-btn-secondary {
  background: var(--chatbot-bg-msg-bot);
  color: var(--chatbot-text);
}

/* Input + enviar ===== */
.ctr-chatbot-input-wrap {
  padding: 12px 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
  background: var(--chatbot-bg);
}

[data-theme="dark"] .ctr-chatbot-input-wrap {
  border-top-color: rgba(255, 255, 255, 0.1);
}

.ctr-chatbot-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.ctr-chatbot-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 20px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--chatbot-bg);
  color: var(--chatbot-text);
  transition: border-color 0.2s;
}

.ctr-chatbot-input::placeholder {
  opacity: 0.6;
}

.ctr-chatbot-input:focus {
  outline: none;
  border-color: var(--chatbot-primary);
}

.ctr-chatbot-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--chatbot-primary);
  color: var(--chatbot-text-inverse);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.2s;
}

.ctr-chatbot-send:hover:not(:disabled) {
  opacity: 0.9;
  transform: scale(1.05);
}

.ctr-chatbot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ctr-chatbot-send svg {
  width: 20px;
  height: 20px;
}

/* Typing indicator ===== */
.ctr-chatbot-typing {
  align-self: flex-start;
  padding: 12px 16px;
  background: var(--chatbot-bg-msg-bot);
  border-radius: 14px;
  display: flex;
  gap: 4px;
}

.ctr-chatbot-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chatbot-text);
  opacity: 0.5;
  animation: ctr-chatbot-bounce 1.2s ease-in-out infinite;
}

.ctr-chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.ctr-chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ctr-chatbot-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-4px); }
}

/* Ocultar cuando no hay API ===== */
.ctr-chatbot-root.ctr-chatbot-no-api {
  display: none;
}
