/* ═══════════════════════════════════════════════════════════════════════════
   Asistente virtual — ventana que abre el botón flotante fuera de horario.
   Ver assets/js/chatbot.js. Hereda la paleta de base.css; el tema claro se
   redefine abajo como el resto del sitio (html[data-theme="light"]).
   ═══════════════════════════════════════════════════════════════════════════ */

.jtchat {
  --jtchat-bg: rgba(var(--brand-ink-soft-rgb), 0.98);
  --jtchat-text: var(--brand-sand);
  --jtchat-muted: rgba(var(--brand-sand-rgb), 0.66);
  --jtchat-line: rgba(var(--brand-canopy-rgb), 0.16);
  --jtchat-bot: rgba(var(--brand-canopy-rgb), 0.08);
  --jtchat-me: var(--brand-water);
  --jtchat-me-text: #fff;
  --jtchat-field: rgba(var(--brand-canopy-rgb), 0.07);
  --jtchat-fab-gap: 0.75rem;

  position: fixed;
  right: 1.5rem;
  /* Encima del botón: su bottom (5.5rem) + su alto (3.25rem) + un respiro. */
  bottom: calc(5.5rem + 3.25rem + var(--jtchat-fab-gap));
  z-index: 1036;
  display: flex;
  flex-direction: column;
  width: min(23.5rem, calc(100vw - 3rem));
  height: min(38rem, calc(100svh / var(--jt-zoom, 1) - 11rem));
  min-height: 22rem;
  background: var(--jtchat-bg);
  color: var(--jtchat-text);
  border: 1px solid var(--jtchat-line);
  border-radius: 1.25rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  font-family: var(--font-body);
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 200ms ease, transform 220ms ease;
}

.jtchat.is-visible {
  opacity: 1;
  transform: none;
}

/* ── Cabecera ─────────────────────────────────────────────────────────── */
.jtchat-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 0.9rem 0.9rem 1rem;
  border-bottom: 1px solid var(--jtchat-line);
}

.jtchat-avatar,
.jtchat-icon-btn {
  flex: 0 0 2.25rem;
  width: 2.25rem;
  height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.jtchat-avatar {
  background: var(--brand-water);
  color: #fff;
  font-size: 0.95rem;
}

.jtchat-head-text {
  flex: 1 1 auto;
  min-width: 0;
}

.jtchat-title {
  margin: 0;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
  color: var(--jtchat-text);
}

.jtchat-sub {
  margin: 0.15rem 0 0;
  font-size: 0.72rem;
  color: var(--jtchat-muted);
  line-height: 1.2;
}

.jtchat-icon-btn {
  border: 0;
  background: transparent;
  color: var(--jtchat-muted);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.jtchat-icon-btn:hover,
.jtchat-icon-btn:focus-visible {
  background: var(--jtchat-field);
  color: var(--jtchat-text);
}

/* ── Aviso de asesores disponibles ────────────────────────────────────── */
.jtchat-advisors {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  font-size: 0.78rem;
  background: rgba(37, 211, 102, 0.1);
  border-bottom: 1px solid var(--jtchat-line);
}

.jtchat-advisors-btn {
  flex: 0 0 auto;
  padding: 0.35rem 0.8rem;
  border-radius: 2rem;
  background: #25d366;
  color: #0b2014;
  font-weight: 700;
  text-decoration: none;
}

.jtchat-advisors-btn:hover { color: #0b2014; filter: brightness(1.05); }

/* Fuera del turno de los Guías: el acceso se ve (así se sabe que existe y
   cuándo vuelve), pero apagado. */
.jtchat-advisors--off {
  background: rgba(255, 255, 255, 0.04);
  color: var(--jtchat-muted);
}

.jtchat-advisors-btn:disabled {
  border: 0;
  font: inherit;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  color: var(--jtchat-muted);
  cursor: not-allowed;
  filter: none;
}

/* ── Conversación ─────────────────────────────────────────────────────── */
.jtchat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 1rem;
}

/* flex-shrink: 0 porque la conversación es una columna flex con scroll: cuando
   se llena, el navegador encoge a los hijos para que quepan. El texto aguanta
   (su min-height automático lo protege), pero la burbuja de imagen lleva
   overflow: hidden, que anula esa protección, y quedaba aplastada a 0 px: solo
   se veía la raya de su borde. */
.jtchat-msg {
  flex-shrink: 0;
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.86rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.jtchat-msg--bot {
  align-self: flex-start;
  background: var(--jtchat-bot);
  border: 1px solid var(--jtchat-line);
  border-bottom-left-radius: 0.3rem;
}

.jtchat-msg--yo {
  align-self: flex-end;
  background: var(--jtchat-me);
  color: var(--jtchat-me-text);
  border-bottom-right-radius: 0.3rem;
}

.jtchat-msg--nota {
  align-self: center;
  max-width: 100%;
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  color: var(--jtchat-muted);
  text-align: center;
}

/* Aviso de seguimiento fuera de turno: no es VIDA hablando, es la casa
   diciéndole que lo buscarán. Centrado y en tono cálido, como una tarjeta. */
.jtchat-msg--aviso {
  align-self: center;
  max-width: 92%;
  text-align: center;
  font-size: 0.8rem;
  color: var(--jtchat-text, inherit);
  background: rgba(200, 192, 126, 0.12);
  border: 1px solid rgba(200, 192, 126, 0.35);
}

/* Botón dentro de un aviso: cerrar la sesión o empezar de nuevo. */
.jtchat-aviso-btn {
  display: block;
  margin: 0.6rem auto 0;
  padding: 0.35rem 0.9rem;
  border: 1px solid rgba(200, 192, 126, 0.5);
  border-radius: 2rem;
  background: transparent;
  color: var(--jtchat-text);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.jtchat-aviso-btn:hover { background: rgba(200, 192, 126, 0.16); }

/* PDF que entrega VIDA: tarjeta del lado del asistente, toda clicable. */
.jtchat-doc {
  align-self: flex-start;
  width: 85%;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid rgba(200, 192, 126, 0.4);
  border-bottom-left-radius: 0.3rem;
  background: var(--jtchat-bot);
  color: var(--jtchat-text);
  text-decoration: none;
}

.jtchat-doc:hover { color: var(--jtchat-text); border-color: rgba(200, 192, 126, 0.7); }

.jtchat-doc-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.6rem;
  background: rgba(200, 192, 126, 0.16);
  color: #c8c07e;
  font-size: 1.1rem;
}

.jtchat-doc-text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.jtchat-doc-text small { color: var(--jtchat-muted); font-size: 0.72rem; }

.jtchat-doc-cta {
  flex: 0 0 auto;
  padding: 0.3rem 0.75rem;
  border-radius: 2rem;
  background: #c8c07e;
  color: #071316;
  font-size: 0.75rem;
  font-weight: 700;
}

html[data-theme="light"] .jtchat-doc-icon { color: #7a6830; }

/* Render del catálogo. Va del lado del asistente, como una burbuja más, pero sin
   relleno: la imagen ES la burbuja. */
.jtchat-msg--img {
  align-self: flex-start;
  width: 85%;                     /* ancho fijo: antes de cargar, la imagen no mide nada */
  max-width: 85%;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--jtchat-line);
  border-bottom-left-radius: 0.3rem;
  background: var(--jtchat-bot);
  line-height: 0;                 /* mata el hueco bajo la imagen */
}

.jtchat-msg--img img {
  display: block;
  width: 100%;
  height: auto;
}

/* Las verticales se comen la ventana en un teléfono: se les pone techo y se
   recorta por el centro, que es donde está el tema en estos renders. */
.jtchat-msg--img-alta img {
  max-height: 15rem;
  object-fit: cover;
  object-position: center;
}

.jtchat-msg strong { font-weight: 700; }

.jtchat-typing {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.75rem 0.9rem;
}

.jtchat-typing span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: jtchat-dot 1.2s ease-in-out infinite;
}

.jtchat-typing span:nth-child(2) { animation-delay: 0.15s; }
.jtchat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes jtchat-dot {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40%           { opacity: 0.9;  transform: translateY(-3px); }
}

/* ── Sugerencias ──────────────────────────────────────────────────────── */
.jtchat-suggest {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  padding: 0 1rem 0.75rem;
}

.jtchat-chip {
  padding: 0.4rem 0.8rem;
  border-radius: 2rem;
  border: 1px solid rgba(var(--brand-canopy-rgb), 0.32);
  background: transparent;
  color: var(--jtchat-text);
  font: inherit;
  font-size: 0.76rem;
  cursor: pointer;
  transition: background 160ms ease;
}

.jtchat-chip:hover,
.jtchat-chip:focus-visible { background: var(--jtchat-field); }

/* ── Campo de texto ───────────────────────────────────────────────────── */
.jtchat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--jtchat-line);
}

.jtchat-input {
  flex: 1 1 auto;
  min-height: 2.75rem;
  max-height: 7.5rem;
  resize: none;
  padding: 0.7rem 0.9rem;
  border-radius: 1.375rem;
  border: 1px solid var(--jtchat-line);
  background: var(--jtchat-field);
  color: var(--jtchat-text);
  font: inherit;
  /* 16px evita que iOS haga zoom al enfocar el campo. */
  font-size: 1rem;
  line-height: 1.3;
}

.jtchat-input::placeholder { color: var(--jtchat-muted); }

.jtchat-input:focus {
  outline: none;
  border-color: rgba(var(--brand-canopy-rgb), 0.45);
}

.jtchat-send {
  flex: 0 0 2.75rem;
  width: 2.75rem;
  height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--brand-water);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  transition: filter 160ms ease, opacity 160ms ease;
}

.jtchat-send:hover { filter: brightness(1.12); }
.jtchat-send:disabled { opacity: 0.5; cursor: default; filter: none; }

/* ── Pie ──────────────────────────────────────────────────────────────── */
.jtchat-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0 1rem 0.8rem;
  text-align: center;
}

.jtchat-wa {
  font-size: 0.8rem;
  font-weight: 600;
  color: #25d366;
  text-decoration: none;
}

.jtchat-wa:hover { color: #25d366; text-decoration: underline; }

.jtchat-wa--off,
.jtchat-wa--off:hover {
  color: var(--jtchat-muted);
  text-decoration: none;
  cursor: not-allowed;
}

/* Con VIDA en WhatsApp: un solo acceso, como botón, a cualquier hora. */
.jtchat-wa--vida {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  padding: 0.5rem 1.15rem;
  border: 1px solid rgba(37, 211, 102, 0.55);
  border-radius: 2rem;
  background: rgba(37, 211, 102, 0.1);
  font-size: 0.82rem;
  line-height: 1.2;
  transition: background-color 0.18s ease, border-color 0.18s ease;
}

.jtchat-wa--vida .fa-whatsapp { font-size: 1.05rem; }

/* Fuera del horario de los Guías (sin VIDA en WhatsApp) el botón no se muestra. */
.jtchat-wa[hidden] { display: none; }

.jtchat-wa--vida:hover {
  background: rgba(37, 211, 102, 0.18);
  border-color: #25d366;
  text-decoration: none;
}

.jtchat-wa--vida:focus-visible {
  outline: 2px solid #25d366;
  outline-offset: 2px;
}

.jtchat-legal {
  margin: 0;
  font-size: 0.68rem;
  line-height: 1.35;
  color: var(--jtchat-muted);
}

.jtchat-privacy {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ── Botón flotante en modo asistente ─────────────────────────────────── */
.whatsapp-fab.is-chat-open .fa-whatsapp { display: none; }

.whatsapp-fab.is-chat-open::before {
  content: "\f00d";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  font-size: 1.25rem;
}

/* ── Tema claro ───────────────────────────────────────────────────────── */
html[data-theme="light"] .jtchat {
  --jtchat-bg: rgba(247, 243, 235, 0.98);
  --jtchat-text: #1a2b2e;
  --jtchat-muted: rgba(26, 43, 46, 0.62);
  --jtchat-line: rgba(26, 43, 46, 0.12);
  --jtchat-bot: rgba(26, 43, 46, 0.05);
  --jtchat-field: rgba(26, 43, 46, 0.05);
  box-shadow: 0 24px 60px rgba(26, 43, 46, 0.18);
}

html[data-theme="light"] .jtchat-chip { border-color: rgba(26, 43, 46, 0.2); }
html[data-theme="light"] .jtchat-wa,
html[data-theme="light"] .jtchat-wa:hover { color: #128c4a; }
html[data-theme="light"] .jtchat-wa--off,
html[data-theme="light"] .jtchat-wa--off:hover { color: var(--jtchat-muted); }
html[data-theme="light"] .jtchat-wa--vida { border-color: rgba(18, 140, 74, 0.45); background: rgba(18, 140, 74, 0.07); }
html[data-theme="light"] .jtchat-wa--vida:hover { border-color: #128c4a; background: rgba(18, 140, 74, 0.13); }
html[data-theme="light"] .jtchat-advisors--off { background: rgba(26, 43, 46, 0.05); }
html[data-theme="light"] .jtchat-advisors-btn:disabled { background: rgba(26, 43, 46, 0.08); }

/* ── Teléfono: ventana a pantalla completa ────────────────────────────── */
@media (max-width: 575.98px) {
  .jtchat {
    inset: 0;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
    transform: translateY(16px);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .jtchat-head { padding-top: calc(0.9rem + env(safe-area-inset-top)); }

  /* La ventana ya trae su botón de cerrar y taparía el flotante de todos modos. */
  body.jtchat-abierto .whatsapp-fab { opacity: 0; pointer-events: none; }
  body.jtchat-abierto { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .jtchat { transition: none; }
  .jtchat-typing span { animation: none; opacity: 0.6; }
}

@media print {
  .jtchat { display: none !important; }
}
