/* ============================================================
   apuntadeleste · Widget de chat flotante
   Port del plugin ianagents-chat repintado con el sistema de
   diseño del theme. Namespaceado bajo .ap-fab* para no pisar.
   ============================================================ */

.ap-fab,
.ap-fab *,
.ap-fab *::before,
.ap-fab *::after { box-sizing: border-box; }

/* ── Minimizado: queda sólo la barra del header ────────────── */
.ap-fab__acts { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.ap-fab__min {
  width: 30px; height: 30px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%; background: transparent;
  color: var(--ap-mute, #6B6255); cursor: pointer; padding: 0;
  transition: background .15s, color .15s;
}
.ap-fab__min:hover { background: rgba(108,122,90,0.12); color: var(--ap-green, #6C7A5A); }
.ap-fab__min svg { width: 17px; height: 17px; }
.ap-fab__min:focus-visible { outline: 2px solid var(--ap-green, #6C7A5A); outline-offset: 2px; }

.ap-fab__panel.is-min { height: auto !important; max-height: none !important; }
.ap-fab__panel.is-min .ap-fab__msgs,
.ap-fab__panel.is-min .ap-fab__sugs,
.ap-fab__panel.is-min .ap-fab__inputbar { display: none !important; }
.ap-fab__panel.is-min .ap-fab__head { border-bottom: none; cursor: pointer; }

/* Con el panel abierto el launcher sigue visible (pasa a ser el botón de
   cerrar): sólo se apagan el ping y el badge, que ahí no aportan nada. */
.ap-fab.is-open .ap-fab__ping,
.ap-fab.is-open .ap-fab__badge { display: none !important; }
.ap-fab.is-open .ap-fab__btn { background: var(--ap-ink, #26211B); }

/* ── Wrapper flotante abajo a la derecha ───────────────────── */
.ap-fab {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 2147483000;
  font-family: var(--ap-font-sans, 'Hanken Grotesk', system-ui, sans-serif);
  line-height: 1.4;
  color: var(--ap-ink, #26211B);
}

/* ── Botón launcher circular ───────────────────────────────── */
.ap-fab__btn {
  position: relative;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--ap-green, #6C7A5A);
  color: var(--ap-cream, #FBF8F1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow:
    0 0 18px 2px rgba(108, 122, 90, 0.45),
    0 6px 18px -4px rgba(38, 33, 27, 0.35);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  -webkit-appearance: none;
  appearance: none;
}
.ap-fab__btn:hover {
  transform: scale(1.06);
  background: var(--ap-green-dark, #4C573B);
}
.ap-fab__btn:active { transform: scale(0.97); }
.ap-fab__btn svg { width: 24px; height: 24px; display: block; }

/* ── Anillo pulsante "ping" ────────────────────────────────── */
.ap-fab__ping {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--ap-green, #6C7A5A);
  opacity: 0.45;
  pointer-events: none;
  animation: ap-fab-ping 1.7s cubic-bezier(0, 0, 0.2, 1) infinite;
}
@keyframes ap-fab-ping {
  75%, 100% { transform: scale(1.9); opacity: 0; }
}

/* ── Badge de no leídos ────────────────────────────────────── */
.ap-fab__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #E0533B;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(38, 33, 27, 0.3);
}

/* ── Panel principal ───────────────────────────────────────── */
.ap-fab__panel {
  position: fixed;
  bottom: 90px;
  right: 22px;
  z-index: 2147483000;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 20px;
  background: var(--ap-bg, #F7F2E9);
  border: 1px solid var(--ap-border-3, #ECE2CF);
  box-shadow:
    0 30px 70px -28px rgba(38, 33, 27, 0.5),
    0 0 0 1px rgba(38, 33, 27, 0.04);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  /* Oculto por defecto */
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
}
.ap-fab__panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header del panel ──────────────────────────────────────── */
.ap-fab__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ap-border-2, #EFE7D7);
  background: var(--ap-cream, #FBF8F1);
  flex-shrink: 0;
}
.ap-fab__titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ap-fab__title {
  font-family: var(--ap-font-serif, 'Cormorant Garamond', serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--ap-ink, #26211B);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ap-fab__sub {
  font-size: 11.5px;
  color: var(--ap-mute-2, #8C8175);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
}
.ap-fab__sub::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ap-green, #6C7A5A);
  animation: ap-fab-pulse 1.6s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes ap-fab-pulse {
  0%, 100% { opacity: 0.55; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); box-shadow: 0 0 6px rgba(108, 122, 90, 0.6); }
}

.ap-fab__close {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ap-mute-2, #8C8175);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.18s ease, color 0.18s ease;
}
.ap-fab__close:hover {
  background: var(--ap-surface-4, #F4EEE2);
  color: var(--ap-ink, #26211B);
}
.ap-fab__close svg { width: 16px; height: 16px; display: block; }

/* ── Lista de mensajes ─────────────────────────────────────── */
.ap-fab__msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--ap-border-6, #E0D5C0) transparent;
}
.ap-fab__msgs::-webkit-scrollbar { width: 6px; }
.ap-fab__msgs::-webkit-scrollbar-track { background: transparent; }
.ap-fab__msgs::-webkit-scrollbar-thumb {
  background: var(--ap-border-6, #E0D5C0);
  border-radius: 6px;
}
.ap-fab__msgs::-webkit-scrollbar-thumb:hover { background: var(--ap-mute-3, #9A8C77); }

/* ── Filas de mensaje ──────────────────────────────────────── */
.ap-fab__row { display: flex; }
.ap-fab__row--user { justify-content: flex-end; }
/* La fila del bot contiene DOS hijos: la burbuja y (a veces) las tarjetas de
   propiedades. En flex-row competían por el ancho y la burbuja se aplastaba a
   ~29px (una letra por línea). Se apilan en columna. */
.ap-fab__row--bot {
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
}
.ap-fab__row--bot > .ap-fab__cards { width: 100%; }

/* Contención de las tarjetas: sin min-width:0 el body de la card no se encoge
   y la tarjeta se pasaba 43px del panel (scroll horizontal). */
.ap-fab__cards { grid-template-columns: minmax(0, 1fr); }
.ap-fab__card { max-width: 100%; min-width: 0; }
.ap-fab__card-body { min-width: 0; overflow: hidden; }
.ap-fab__card-price,
.ap-fab__card-name,
.ap-fab__card-specs { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Burbujas ──────────────────────────────────────────────── */
.ap-fab__bubble {
  max-width: 84%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  /* El JS ya convierte los \n del agente en <br>: con pre-wrap se duplicaban
     los saltos y la respuesta se veía desarmada. */
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
  min-width: 0;
}
.ap-fab__row--user .ap-fab__bubble {
  background: var(--ap-ink, #26211B);
  color: var(--ap-cream, #FBF8F1);
  border-bottom-right-radius: 4px;
}
.ap-fab__row--bot .ap-fab__bubble {
  background: #fff;
  border: 1px solid var(--ap-border-2, #EFE7D7);
  color: var(--ap-ink-2, #3A352D);
  border-bottom-left-radius: 4px;
  box-shadow: var(--ap-shadow-soft, 0 1px 2px rgba(38, 33, 27, 0.04));
}
.ap-fab__bubble a {
  color: var(--ap-green, #6C7A5A);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Cards de propiedades dentro del chat ──────────────────── */
.ap-fab__cards {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.ap-fab__card {
  display: flex;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--ap-border-2, #EFE7D7);
  border-radius: 12px;
  padding: 7px;
  text-decoration: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.ap-fab__card:hover {
  border-color: var(--ap-green, #6C7A5A);
  box-shadow: 0 8px 22px -14px rgba(38, 33, 27, 0.35);
  transform: translateY(-1px);
}
.ap-fab__card-media {
  flex: 0 0 68px;
  width: 68px;
  height: 60px;
  border-radius: 9px;
  background-color: #EAE4D6;
  background-size: cover;
  background-position: center;
}
.ap-fab__card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 1px; }
.ap-fab__card-price {
  font-family: var(--ap-font-serif, 'Cormorant Garamond', serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--ap-ink, #26211B);
  line-height: 1.1;
}
.ap-fab__card-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--ap-ink-2, #3A352D);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ap-fab__card-specs {
  font-size: 11px;
  color: var(--ap-mute-2, #8C8175);
  line-height: 1.3;
}

/* ── Dots de "escribiendo…" ────────────────────────────────── */
.ap-fab__dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 11px 14px;
  background: #fff;
  border: 1px solid var(--ap-border-2, #EFE7D7);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}
.ap-fab__dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ap-green, #6C7A5A);
  animation: ap-fab-bounce 1s infinite ease-in-out;
}
.ap-fab__dots span:nth-child(2) { animation-delay: 0.18s; }
.ap-fab__dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes ap-fab-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* ── Sugerencias (chips) ───────────────────────────────────── */
.ap-fab__sugs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 10px;
}
.ap-fab__chip {
  background: #fff;
  border: 1px solid var(--ap-border-3, #ECE2CF);
  color: var(--ap-ink-3, #4A4339);
  font-family: inherit;
  font-size: 11.5px;
  padding: 7px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}
.ap-fab__chip:hover {
  border-color: var(--ap-green, #6C7A5A);
  color: var(--ap-green, #6C7A5A);
  background: rgba(108, 122, 90, 0.06);
}

/* ── Barra de input ────────────────────────────────────────── */
.ap-fab__inputbar {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 14px;
  border-top: 1px solid var(--ap-border-2, #EFE7D7);
  background: #fff;
  flex-shrink: 0;
}
.ap-fab__input {
  flex: 1;
  border: 1px solid var(--ap-border-3, #ECE2CF);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--ap-ink, #26211B);
  background: var(--ap-surface-3, #FAF6EE);
  resize: none;
  min-height: 40px;
  max-height: 110px;
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.ap-fab__input::placeholder { color: var(--ap-mute-4, #A89A85); }
.ap-fab__input:focus {
  border-color: var(--ap-green, #6C7A5A);
  background: #fff;
}
.ap-fab__send {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--ap-green, #6C7A5A);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.18s ease, transform 0.18s ease;
}
.ap-fab__send:hover { background: var(--ap-green-dark, #4C573B); }
.ap-fab__send:active { transform: scale(0.94); }
.ap-fab__send:disabled { opacity: 0.5; cursor: default; }
.ap-fab__send svg { width: 18px; height: 18px; display: block; }

/* ── Accesibilidad: foco visible con teclado ───────────────── */
.ap-fab__btn:focus-visible,
.ap-fab__close:focus-visible,
.ap-fab__send:focus-visible,
.ap-fab__chip:focus-visible,
.ap-fab__card:focus-visible,
.ap-fab__input:focus-visible {
  outline: 2px solid var(--ap-green, #6C7A5A);
  outline-offset: 2px;
}

/* ── Responsive mobile ─────────────────────────────────────── */
@media (max-width: 560px) {
  .ap-fab { bottom: 16px; right: 16px; }
  .ap-fab__btn { width: 52px; height: 52px; }
  .ap-fab__btn svg { width: 22px; height: 22px; }

  .ap-fab__panel {
    left: 12px;
    right: 12px;
    /* deja libre la franja del launcher (16px + 52px + aire): si no, el panel
       le quedaba encima y no se podía cerrar desde el botón flotante */
    bottom: 80px;
    width: auto;
    height: calc(100vh - 150px);
    max-height: none;
    max-width: none;
    border-radius: 18px;
  }
}

/* Aviso de IA dentro del panel flotante: obligación de transparencia (no es
   una persona) + descargo de datos de terceros. */
.ap-fab__ainotice {
  padding: 8px 14px; font-size: 11px; line-height: 1.45;
  color: rgba(38,33,27,.62);
  background: rgba(94,138,160,.10);
  border-bottom: 1px solid rgba(94,138,160,.22);
  flex-shrink: 0;
}
.ap-fab__ainotice strong { color: rgba(38,33,27,.82); font-weight: 700; }
.ap-fab__ainotice a { color: #6C7A5A; font-weight: 600; text-decoration: underline; }
.ap-fab__panel.is-min .ap-fab__ainotice { display: none !important; }
