/* wapaflow — burbuja de Wap-IA (agente.js). Autocontenida: no depende de las variables de la página donde se muestra (sitio o aplicación). */
.wf-ag { --ag-fuente: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --ag-azul: #255A97; --ag-turquesa: #0E7C88; --ag-marino: #163965; --ag-noche: #0E2744; --ag-texto: #33465F; --ag-borde: #D5DEEA; --ag-niebla: #EAF1F9; --ag-blanco: #fff;
  position: fixed; right: 18px; bottom: 18px; z-index: 250; font: 400 14px/1.45 var(--ag-fuente); color: var(--ag-texto); }
.wf-ag *, .wf-ag *::before, .wf-ag *::after { box-sizing: border-box; }
.wf-ag [hidden] { display: none !important; }

/* La burbuja */
.wf-ag-boton { display: flex; align-items: center; justify-content: center; width: 58px; height: 58px; margin: 0 0 0 auto; padding: 0; border: 0; border-radius: 50%;
  background: linear-gradient(135deg, #20BBC9, var(--ag-azul)); color: #fff; cursor: pointer; box-shadow: 0 6px 20px rgba(14, 39, 68, .32); transition: transform .15s ease, box-shadow .15s ease; }
.wf-ag-boton:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(14, 39, 68, .38); }
.wf-ag-boton:focus-visible, .wf-ag-cerrar:focus-visible, .wf-ag-enviar:focus-visible, .wf-ag-chip:focus-visible, .wf-ag-enlace:focus-visible, .wf-ag-prim:focus-visible, .wf-ag-sec:focus-visible,
.wf-ag-pie textarea:focus-visible, .wf-ag-campo input:focus-visible, .wf-ag-campo textarea:focus-visible, .wf-ag-mensajes:focus-visible { outline: 3px solid #0E7C88; outline-offset: 2px; }
.wf-ag-boton svg { width: 26px; height: 26px; }
.wf-ag-oculto { display: none; }
.wf-ag-teaser { position: absolute; right: 70px; bottom: 10px; max-width: 220px; padding: 9px 14px; border-radius: 14px 14px 4px 14px; background: var(--ag-blanco); color: var(--ag-noche);
  font-weight: 500; font-size: 13px; box-shadow: 0 6px 20px rgba(14, 39, 68, .22); cursor: pointer; animation: wf-ag-entra .35s ease; }

/* El panel */
.wf-ag-panel { position: absolute; right: 0; bottom: 0; display: flex; flex-direction: column; width: 380px; max-width: calc(100vw - 24px); height: 600px; max-height: calc(100vh - 36px); max-height: calc(100dvh - 36px);
  overflow: hidden; border: 1px solid var(--ag-borde); border-radius: 16px; background: var(--ag-blanco); box-shadow: 0 18px 50px rgba(14, 39, 68, .35); animation: wf-ag-entra .22s ease; }
.wf-ag-cab { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: linear-gradient(135deg, var(--ag-noche), var(--ag-marino)); color: #fff; }
.wf-ag-avatar { flex: none; width: 36px; height: 36px; padding: 5px; border-radius: 50%; background: #fff; }
.wf-ag-titulos { display: flex; flex: 1; min-width: 0; flex-direction: column; }
.wf-ag-titulos strong { font-size: 15px; font-weight: 700; }
.wf-ag-titulos span { font-size: 11.5px; line-height: 1.3; color: #C9D8EA; }
.wf-ag-cerrar { flex: none; display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: #fff; cursor: pointer; }
.wf-ag-cerrar:hover { background: rgba(255, 255, 255, .15); }
.wf-ag-cerrar svg { width: 20px; height: 20px; }
.wf-ag-cuerpo { display: flex; flex: 1; min-height: 0; flex-direction: column; }

/* Mensajes */
.wf-ag-mensajes { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px; background: #F6F9FC; scroll-behavior: smooth; overscroll-behavior: contain; }
.wf-ag-msg { max-width: 88%; margin: 0 0 10px; padding: 9px 12px; border-radius: 14px; overflow-wrap: anywhere; }
.wf-ag-msg p { margin: 0 0 6px; }
.wf-ag-msg p:last-child, .wf-ag-msg ul:last-child, .wf-ag-msg ol:last-child { margin-bottom: 0; }
.wf-ag-msg ul, .wf-ag-msg ol { margin: 0 0 6px; padding-left: 20px; }
.wf-ag-msg li { margin: 2px 0; }
.wf-ag-msg a { color: var(--ag-azul); font-weight: 600; text-decoration: underline; }
.wf-ag-agente { background: var(--ag-blanco); border: 1px solid var(--ag-borde); border-bottom-left-radius: 4px; color: var(--ag-texto); }
.wf-ag-yo { margin-left: auto; background: var(--ag-azul); color: #fff; border-bottom-right-radius: 4px; }
.wf-ag-aviso { max-width: 100%; background: #FFF6E5; border: 1px solid #F0D9A8; color: #6B4B00; font-size: 13px; }
.wf-ag-escribiendo { display: inline-flex; gap: 4px; padding: 12px 14px; }
.wf-ag-punto { width: 7px; height: 7px; border-radius: 50%; background: #9DB2CB; animation: wf-ag-salta 1.1s infinite ease-in-out; }
.wf-ag-punto:nth-child(2) { animation-delay: .15s; }
.wf-ag-punto:nth-child(3) { animation-delay: .3s; }
.wf-ag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.wf-ag-chip { padding: 6px 11px; border: 1px solid var(--ag-azul); border-radius: 999px; background: var(--ag-blanco); color: var(--ag-azul); font: 600 12.5px/1.2 var(--ag-fuente); cursor: pointer; }
.wf-ag-chip:hover { background: var(--ag-niebla); }

/* Escribir */
.wf-ag-pie { display: flex; align-items: flex-end; gap: 8px; margin: 0; padding: 10px 12px; border-top: 1px solid var(--ag-borde); background: var(--ag-blanco); }
.wf-ag-pie textarea { flex: 1; min-height: 40px; max-height: 110px; padding: 9px 12px; resize: none; border: 1px solid var(--ag-borde); border-radius: 12px; background: #fff; color: var(--ag-noche); font: 400 14px/1.4 var(--ag-fuente); }
.wf-ag-pie textarea:disabled { background: #F1F4F8; }
.wf-ag-enviar { flex: none; display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 12px; background: var(--ag-azul); color: #fff; cursor: pointer; }
.wf-ag-enviar:disabled { background: #9DB2CB; cursor: default; }
.wf-ag-enviar svg { width: 20px; height: 20px; }
.wf-ag-legal { margin: 0; padding: 6px 12px 10px; background: var(--ag-blanco); font-size: 11.5px; line-height: 1.4; color: #5B6B82; }
.wf-ag-enlace { padding: 0; border: 0; background: none; color: var(--ag-azul); font: 700 11.5px/1.4 var(--ag-fuente); text-decoration: underline; cursor: pointer; }

/* Hablar con una persona */
.wf-ag-persona { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; background: var(--ag-blanco); }
.wf-ag-persona p { margin: 0 0 10px; }
.wf-ag-gracias { font-size: 16px; font-weight: 700; color: var(--ag-noche); }
.wf-ag-campo { margin: 0 0 10px; }
.wf-ag-campo label { display: block; margin: 0 0 3px; font-size: 12.5px; font-weight: 600; color: var(--ag-noche); }
.wf-ag-campo input, .wf-ag-campo textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--ag-borde); border-radius: 10px; background: #fff; color: var(--ag-noche); font: 400 14px/1.4 var(--ag-fuente); }
.wf-ag-campo textarea { resize: vertical; }
.wf-ag-casilla { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 8px; font-size: 12.5px; line-height: 1.4; }
.wf-ag-casilla input { flex: none; width: 17px; height: 17px; margin: 1px 0 0; }
.wf-ag-casilla a { color: var(--ag-azul); }
.wf-ag-error { min-height: 1.4em; margin: 0 0 6px; color: #B42318; font-size: 12.5px; font-weight: 600; }
.wf-ag-acciones { display: flex; gap: 8px; }
.wf-ag-prim, .wf-ag-sec { flex: 1; padding: 10px 12px; border-radius: 10px; font: 700 14px/1.2 var(--ag-fuente); cursor: pointer; }
.wf-ag-prim { border: 0; background: var(--ag-azul); color: #fff; }
.wf-ag-prim:disabled { background: #9DB2CB; cursor: default; }
.wf-ag-sec { border: 1px solid var(--ag-azul); background: #fff; color: var(--ag-azul); }
.wf-ag-trampa { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

@keyframes wf-ag-entra { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes wf-ag-salta { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* Teléfono: una tarjeta COMPACTA con margen alrededor (no la pantalla entera). Se mide contra la parte REALMENTE visible (--wf-vh y --wf-fondo los pone agente.js desde visualViewport: con el
   teclado abierto o las barras del navegador, 100vh/100dvh engañan y el chat se salía de la pantalla); si no hay visualViewport quedan los valores de respaldo. */
@media (max-width: 600px) {
  .wf-ag { right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px) + var(--wf-fondo, 0px)); }
  .wf-ag-boton { width: 52px; height: 52px; }
  .wf-ag-panel { position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px) + var(--wf-fondo, 0px)); width: auto; max-width: none;
    height: min(520px, calc(var(--wf-vh, 100vh) * .78)); max-height: calc(var(--wf-vh, 100vh) - 20px - env(safe-area-inset-bottom, 0px)); }
  .wf-ag.wf-ag-teclado .wf-ag-panel { height: calc(var(--wf-vh, 100vh) - 20px - env(safe-area-inset-bottom, 0px)); }   /* teclado abierto: todo el alto que queda */
  .wf-ag-cab { padding: 10px 12px; }
  .wf-ag-avatar { width: 32px; height: 32px; }
  .wf-ag-mensajes { padding: 10px; }
  .wf-ag-msg { max-width: 92%; padding: 8px 11px; }
  .wf-ag-pie { padding: 8px 10px; }
  .wf-ag-legal { padding: 4px 10px 8px; font-size: 11px; }
  .wf-ag-persona { padding: 12px; }
  .wf-ag-pie textarea, .wf-ag-campo input, .wf-ag-campo textarea { font-size: 16px; }   /* 16 px: iOS no amplía la página al enfocar el campo */
}
@media (max-width: 600px) and (max-height: 560px) {   /* teléfono bajito (o girado): aún más compacto */
  .wf-ag-chips { margin-top: 6px; }
  .wf-ag-titulos span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .wf-ag-boton, .wf-ag-panel, .wf-ag-teaser, .wf-ag-punto { animation: none; transition: none; }
  .wf-ag-mensajes { scroll-behavior: auto; }
}
/* Al imprimir (por ejemplo el manual) la burbuja no sale */
@media print { .wf-ag { display: none !important; } }
