/* ==========================================================================
   «Pregúntanos» — el agente de IA de avsystems.es en un botón flotante.
   Desde el 01/12/2026 está en todas las páginas: botón abajo a la derecha que
   abre el chat en un panel (en el móvil, una hoja que sube desde abajo).
   Usa la paleta de landing.css (variables de :root). Lógica en js/agente.js,
   que monta el botón y el panel.
   ========================================================================== */

/* Botón flotante */
.agente-lanzador {
  position: fixed;
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  z-index: 950;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: var(--ink-contrast);
  font: 600 0.98rem var(--font-display);
  cursor: pointer;
  box-shadow: 0 14px 34px -10px rgba(17, 20, 30, 0.45), 0 4px 12px -4px rgba(17, 20, 30, 0.25);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s ease, box-shadow 0.25s ease;
  animation: agente-aparece 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.6s both;
}
.agente-lanzador:hover { transform: translateY(-2px); background: var(--ink-soft); }
.agente-lanzador:focus-visible { outline: 3px solid var(--accent-ice); outline-offset: 3px; }
.agente-lanzador i { font-size: 1.15rem; }
.agente-lanzador-cerrar { display: none; }
.agente-lanzador[aria-expanded="true"] .agente-lanzador-abrir { display: none; }
.agente-lanzador[aria-expanded="true"] .agente-lanzador-cerrar { display: inline-block; }
/* El puntito verde: «está aquí y contesta» */
.agente-lanzador-punto {
  position: absolute;
  top: 6px;
  left: 38px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22C55E;
  border: 2px solid var(--ink);
  animation: agente-latido 2.2s infinite;
}
.agente-lanzador[aria-expanded="true"] .agente-lanzador-punto { display: none; }
@keyframes agente-aparece { from { opacity: 0; transform: translateY(16px) scale(0.9); } to { opacity: 1; transform: none; } }

/* Si algún día se activa el botón de WhatsApp (js/whatsapp.js), va encima */
.whatsapp-flotante:not([hidden]) ~ .agente-lanzador { bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }

/* Con la ventana del formulario abierta, el botón se aparta */
html.ventana-abierta .agente-lanzador { display: none; }

/* Panel del chat */
.agente-panel {
  position: fixed;
  right: 22px;
  bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  z-index: 1100;
  width: min(400px, calc(100vw - 44px));
  height: min(620px, calc(100dvh - 120px));
  animation: agente-sube 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.agente-panel[hidden] { display: none; }
@keyframes agente-sube { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }

.agente-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  background: var(--bg-canvas);
  box-shadow: 0 40px 80px -30px rgba(17, 20, 30, 0.45), 0 12px 30px -18px rgba(17, 20, 30, 0.25);
  overflow: hidden;
}

/* Botón de cerrar de la cabecera */
.agente-titulos { flex: 1; min-width: 0; }
.agente-cerrar {
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-pure);
  font-size: 1.1rem;
  cursor: pointer;
}
.agente-cerrar:hover { background: var(--bg-canvas); }
.agente-cerrar:focus-visible { outline: 2px solid var(--accent-ice); outline-offset: 2px; }

/* Cabecera */
.agente-barra {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--glass-border);
  background: var(--bg-subtle);
}
.agente-avatar { flex: none; width: 40px; height: 40px; border-radius: 12px; overflow: hidden; }
.agente-avatar img { display: block; width: 100%; height: 100%; }
.agente-barra b { display: block; color: var(--text-pure); font-size: 0.98rem; font-family: var(--font-display); }
.agente-barra small { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 0.8rem; }
.agente-punto {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent-mint);
  animation: agente-latido 2.2s infinite;
}
.agente-chat.en-pausa .agente-punto { background: var(--text-muted); animation: none; }
@keyframes agente-latido {
  0% { box-shadow: 0 0 0 0 rgba(6, 122, 83, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(6, 122, 83, 0); }
  100% { box-shadow: 0 0 0 0 rgba(6, 122, 83, 0); }
}

/* Conversación */
.agente-mensajes {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.agente-burbuja {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 0.98rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: agente-entra 0.28s ease-out;
}
.agente-burbuja.visitante {
  align-self: flex-end;
  background: var(--ink);
  color: var(--ink-contrast);
  border-bottom-right-radius: 5px;
}
.agente-burbuja.agente {
  align-self: flex-start;
  background: var(--bg-subtle);
  color: var(--text-pure);
  border-bottom-left-radius: 5px;
}
.agente-burbuja.sistema {
  align-self: center;
  max-width: 92%;
  padding: 4px 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.86rem;
  text-align: center;
}
@keyframes agente-entra { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Lo que propone el agente debajo de su respuesta */
.agente-acciones {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: -2px 0 4px 4px;
  animation: agente-entra 0.28s ease-out;
}
.agente-acciones .btn { padding: 8px 16px; font-size: 0.85rem; }
.agente-enlace {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--glass-border-hover);
  color: var(--text-pure);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.agente-enlace:hover { background: var(--bg-subtle); border-color: var(--text-muted); }
.agente-enlace i { font-size: 0.75rem; }

/* Escribiendo… */
.agente-escribiendo { display: inline-flex; gap: 4px; padding: 15px; }
.agente-escribiendo i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted);
  animation: agente-salto 1.2s infinite ease-in-out;
}
.agente-escribiendo i:nth-child(2) { animation-delay: 0.15s; }
.agente-escribiendo i:nth-child(3) { animation-delay: 0.3s; }
@keyframes agente-salto { 0%, 60%, 100% { transform: none; opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Preguntas de ejemplo */
.agente-sugerencias { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 14px; }
.agente-sugerencias[hidden] { display: none; }
.agente-sugerencias button {
  font: inherit;
  font-size: 0.86rem;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--glass-border-hover);
  background: var(--bg-canvas);
  color: var(--text-pure);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.agente-sugerencias button:hover { border-color: var(--text-muted); background: var(--bg-subtle); }
.agente-sugerencias button:focus-visible { outline: 2px solid var(--accent-ice); outline-offset: 2px; }

/* Caja para escribir */
.agente-formulario {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--glass-border);
}
.agente-formulario input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1rem;
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--glass-border-hover);
  background: var(--bg-canvas);
  color: var(--text-pure);
}
.agente-formulario input:focus { outline: 2px solid var(--accent-ice); outline-offset: 1px; }
.agente-formulario button {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--ink);
  color: var(--ink-contrast);
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}
.agente-formulario button:hover { background: var(--ink-soft); transform: translateY(-1px); }
.agente-formulario button:focus-visible { outline: 2px solid var(--accent-ice); outline-offset: 2px; }
.agente-formulario button:disabled,
.agente-formulario input:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.agente-aviso {
  margin: 0;
  padding: 0 16px 12px;
  color: var(--text-muted);
  font-size: 0.7rem;
  line-height: 1.45;
  text-align: center;
}
.agente-aviso a { color: var(--text-body); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (max-width: 768px) {
  /* En el móvil, solo el icono con su texto corto, sin tapar contenido */
  .agente-lanzador { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); height: 52px; padding: 0 18px 0 16px; font-size: 0.92rem; }
  .agente-lanzador-punto { left: 34px; }
  .whatsapp-flotante:not([hidden]) ~ .agente-lanzador { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  /* Abierto, el chat es una hoja que ocupa casi toda la pantalla y el botón se esconde */
  html.agente-abierto .agente-lanzador { display: none; }
  html.agente-abierto { overflow: hidden; }
  .agente-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 88dvh;
    animation-name: agente-sube-movil;
  }
  .agente-chat { border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .agente-mensajes { padding: 18px 14px; }
  .agente-burbuja { max-width: 90%; font-size: 0.95rem; }
  /* Las preguntas de ejemplo en una fila que se desliza */
  .agente-sugerencias {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 0 14px 12px;
  }
  .agente-sugerencias::-webkit-scrollbar { display: none; }
  .agente-sugerencias button { flex: 0 0 auto; white-space: nowrap; }
}
@keyframes agente-sube-movil { from { transform: translateY(100%); } to { transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .agente-burbuja, .agente-acciones, .agente-escribiendo i, .agente-punto,
  .agente-lanzador, .agente-lanzador-punto, .agente-panel { animation: none; }
}
