/* ============================================================
   Asistente IA del sitio (chat-ia.js). Todo va prefijado con .ianx- para no
   chocar con los estilos del sitio. Convive con el botón flotante de WhatsApp
   de motion.js: si la página lo tiene, la burbuja del chat se sube encima.
   ============================================================ */

.ianx-launcher {
  position: fixed; right: 20px; bottom: 20px; z-index: 9996;
  width: 60px; height: 60px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--mk-primario, #191d66); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 10px 28px rgba(25, 29, 102, .38);
  transition: transform .2s ease, opacity .2s ease;
}
.ianx-launcher:hover { transform: translateY(-2px); }
.ianx-launcher:focus-visible { outline: 3px solid var(--mk-secundario, #35aad5); outline-offset: 3px; }
.ianx-launcher svg { width: 28px; height: 28px; fill: currentColor; }
.ianx-launcher .ianx-punto {
  position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--mk-secundario, #35aad5); border: 2px solid #fff;
}
body.ianx-con-wa .ianx-launcher { bottom: 88px; }
body.ianx-con-wa .ianx-saludo { bottom: 158px; }
/* Con el panel de WhatsApp abierto, la burbuja del chat se aparta. */
body:has(.mk-wa-panel.mk-open) .ianx-launcher,
body:has(.mk-wa-panel.mk-open) .ianx-saludo { opacity: 0; pointer-events: none; }
body.ianx-abierto .ianx-launcher,
body.ianx-abierto .ianx-saludo { opacity: 0; pointer-events: none; }

/* Saludo proactivo (no llama a la IA: es un texto fijo) */
.ianx-saludo {
  position: fixed; right: 20px; bottom: 90px; z-index: 9996;
  max-width: min(290px, calc(100vw - 40px));
  background: #fff; color: #12142e; border-radius: 14px; padding: 14px 36px 14px 16px;
  font: 500 14px/1.45 "Rubik", system-ui, sans-serif;
  box-shadow: 0 16px 40px rgba(18, 20, 46, .22); cursor: pointer;
  animation: ianx-entra .35s cubic-bezier(.2, .8, .2, 1);
}
.ianx-saludo button {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border: none; border-radius: 50%;
  background: transparent; color: #5b5f78; font-size: 18px; line-height: 1; cursor: pointer;
}
.ianx-saludo button:hover { background: #eef0f7; }

/* Panel */
.ianx-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 9997;
  width: 380px; height: min(620px, calc(100vh - 40px));
  display: flex; flex-direction: column; overflow: hidden;
  background: #fff; color: #12142e; border-radius: 18px;
  box-shadow: 0 24px 64px rgba(18, 20, 46, .32);
  font: 400 14.5px/1.5 "Rubik", system-ui, sans-serif;
  animation: ianx-entra .28s cubic-bezier(.2, .8, .2, 1);
}
.ianx-panel[hidden] { display: none; }
@keyframes ianx-entra { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.ianx-cabecera {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--mk-primario, #191d66); color: #fff;
}
.ianx-avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--mk-secundario, #35aad5); font-weight: 700; font-size: 15px;
}
.ianx-cabecera .ianx-titulo { flex: 1; min-width: 0; }
.ianx-cabecera strong { display: block; font-size: 15px; }
.ianx-cabecera span { display: block; font-size: 12px; opacity: .8; }
.ianx-cerrar {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255, 255, 255, .12); color: #fff; font-size: 20px; line-height: 1;
}
.ianx-cerrar:hover { background: rgba(255, 255, 255, .22); }
.ianx-cerrar:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.ianx-mensajes {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
  background: #f6f7fb; overscroll-behavior: contain;
}
.ianx-msg { max-width: 86%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.ianx-msg.ianx-bot { align-self: flex-start; background: #fff; border: 1px solid #e6e8f2; border-bottom-left-radius: 4px; }
.ianx-msg.ianx-yo { align-self: flex-end; background: var(--mk-primario, #191d66); color: #fff; border-bottom-right-radius: 4px; }
.ianx-msg.ianx-aviso { align-self: center; max-width: 100%; background: transparent; color: #5b5f78; font-size: 12.5px; text-align: center; padding: 2px 8px; }
.ianx-msg a { color: var(--mk-secundario-texto, #257795); font-weight: 600; text-decoration: underline; }
.ianx-msg.ianx-yo a { color: #fff; }

.ianx-escribiendo { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; background: #fff; border: 1px solid #e6e8f2; border-radius: 14px; }
.ianx-escribiendo i { width: 7px; height: 7px; border-radius: 50%; background: #9aa0bd; animation: ianx-bote 1.2s infinite ease-in-out; }
.ianx-escribiendo i:nth-child(2) { animation-delay: .15s; }
.ianx-escribiendo i:nth-child(3) { animation-delay: .3s; }
@keyframes ianx-bote { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-5px); opacity: 1; } }

.ianx-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ianx-chip {
  border: 1px solid var(--mk-secundario, #35aad5); background: #fff; color: var(--mk-primario, #191d66);
  border-radius: 999px; padding: 7px 12px; font: 500 13px/1.2 "Rubik", system-ui, sans-serif; cursor: pointer;
}
.ianx-chip:hover { background: #eaf6fb; }

/* Tarjeta de confirmación de cita */
.ianx-cita { align-self: stretch; background: #fff; border: 1px solid var(--mk-secundario, #35aad5); border-radius: 14px; padding: 14px; }
.ianx-cita h4 { margin: 0 0 8px; font-size: 14.5px; color: var(--mk-primario, #191d66); }
.ianx-cita dl { margin: 0 0 10px; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; }
.ianx-cita dt { color: #5b5f78; }
.ianx-cita dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.ianx-cita label { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: #3b3f5c; margin-bottom: 10px; cursor: pointer; }
.ianx-cita label input { margin-top: 2px; flex: none; }
.ianx-cita .ianx-acciones { display: flex; gap: 8px; flex-wrap: wrap; }
.ianx-btn {
  border: none; border-radius: 10px; padding: 9px 14px; cursor: pointer;
  font: 600 13.5px/1.2 "Rubik", system-ui, sans-serif;
}
.ianx-btn-primario { background: var(--mk-primario, #191d66); color: #fff; }
.ianx-btn-primario:disabled { opacity: .45; cursor: not-allowed; }
.ianx-btn-secundario { background: #eef0f7; color: #12142e; }

.ianx-pie { border-top: 1px solid #e6e8f2; padding: 10px 12px 8px; background: #fff; }
.ianx-form { display: flex; gap: 8px; align-items: flex-end; }
.ianx-form textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 120px; padding: 10px 12px;
  border: 1px solid #d5d8e6; border-radius: 12px; font: 400 14.5px/1.4 "Rubik", system-ui, sans-serif; color: #12142e;
}
.ianx-form textarea:focus { outline: none; border-color: var(--mk-secundario, #35aad5); box-shadow: 0 0 0 3px rgba(53, 170, 213, .2); }
.ianx-enviar {
  flex: none; width: 42px; height: 42px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--mk-primario, #191d66); color: #fff; display: grid; place-items: center;
}
.ianx-enviar:disabled { opacity: .45; cursor: not-allowed; }
.ianx-enviar svg { width: 20px; height: 20px; fill: currentColor; }
.ianx-legal { margin: 6px 2px 0; font-size: 11px; color: #7a7f99; line-height: 1.35; }
.ianx-legal a { color: inherit; }

@media (max-width: 480px) {
  .ianx-panel { right: 8px; left: 8px; bottom: 8px; width: auto; height: calc(100dvh - 16px); border-radius: 16px; }
  .ianx-launcher { right: 16px; bottom: 16px; }
  body.ianx-con-wa .ianx-launcher { bottom: 84px; }
  .ianx-saludo { right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .ianx-panel, .ianx-saludo { animation: none; }
  .ianx-escribiendo i { animation: none; }
}
