/* ============================================================================
   ASISTENTE Y BOTON DE SUBIR
   ----------------------------------------------------------------------------
   Grupo de acciones flotantes en la esquina inferior derecha. Se separan en dos
   piezas porque tienen pesos distintos: el asistente es la accion principal
   (color de marca, mas grande) y subir es una ayuda secundaria (blanco, mas
   discreto). Si los dos tuvieran el mismo peso, no se sabria cual pulsar.
   ========================================================================== */

.acciones-flotantes {
  position: fixed;
  right: clamp(14px, 3vw, 26px);
  bottom: clamp(14px, 3vw, 26px);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp-3);
  pointer-events: none;              /* el contenedor no estorba al navegar */
}
.acciones-flotantes > * { pointer-events: auto; }

/* ---------- Boton redondo base ---------- */
.boton-flotante {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--g-border);
  background: var(--g-bg);
  color: var(--g-primary);
  cursor: pointer;
  box-shadow: 0 6px 20px -6px rgba(18, 41, 63, .35);
  transition: transform var(--t-base), box-shadow var(--t-base), background var(--t-base), opacity var(--t-base);
}
.boton-flotante:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px -8px rgba(18, 41, 63, .45);
}
.boton-flotante:focus-visible {
  outline: 3px solid var(--g-accent);
  outline-offset: 3px;
}
.boton-flotante svg { width: 22px; height: 22px; }

/* ---------- Subir: secundario, y solo cuando hace falta ---------- */
.boton-subir {
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
}
.boton-subir.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ---------- Asistente: accion principal ---------- */
.boton-asistente {
  width: 60px;
  height: 60px;
  background: linear-gradient(150deg, #1c3f66 0%, #24507f 100%);
  color: #fff;
  border-color: transparent;
  position: relative;
}
.boton-asistente svg { width: 26px; height: 26px; }
.boton-asistente:hover { background: linear-gradient(150deg, #16324f 0%, #1c3f66 100%); }

/* Aviso de que hay algo nuevo, sin ser invasivo */
.boton-asistente::after {
  content: "";
  position: absolute;
  top: 2px; right: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--g-accent);
  border: 2px solid #fff;
  opacity: 0;
  transition: opacity var(--t-base);
}
.boton-asistente.novedad::after { opacity: 1; }

@media (max-width: 480px) {
  .boton-flotante { width: 46px; height: 46px; }
  .boton-asistente { width: 54px; height: 54px; }
}

/* ============================================================================
   PANEL DEL ASISTENTE
   ========================================================================== */

.asistente {
  position: fixed;
  right: clamp(14px, 3vw, 26px);
  bottom: calc(clamp(14px, 3vw, 26px) + 128px);
  z-index: 61;
  width: min(400px, calc(100vw - 28px));
  max-height: min(620px, calc(100vh - 180px));
  display: flex;
  flex-direction: column;
  background: var(--g-bg);
  border: 1px solid var(--g-border);
  border-radius: var(--r-lg);
  box-shadow: 0 26px 60px -18px rgba(18, 41, 63, .45);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.98);
  transition: opacity var(--t-base), transform var(--t-base), visibility var(--t-base);
}
.asistente.abierto {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.asistente__cabecera {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: linear-gradient(150deg, #1c3f66 0%, #24507f 100%);
  color: #fff;
  flex-shrink: 0;
}
.asistente__avatar {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .16);
}
.asistente__titulo { font-size: .98rem; font-weight: 700; line-height: 1.2; }
.asistente__estado {
  font-size: .76rem; color: rgba(255, 255, 255, .75);
  display: flex; align-items: center; gap: 5px; margin-top: 2px;
}
.asistente__punto {
  width: 7px; height: 7px; border-radius: 50%; background: #4ade80;
}
.asistente__cerrar {
  margin-left: auto;
  background: transparent; border: 0; color: #fff; cursor: pointer;
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  transition: background var(--t-fast);
}
.asistente__cerrar:hover { background: rgba(255, 255, 255, .14); }
.asistente__cerrar:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- Conversacion ---------- */
.asistente__hilo {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  background: var(--g-bg-soft);
  scroll-behavior: smooth;
}

.mensaje {
  max-width: 88%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: 16px;
  font-size: .92rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.mensaje--bot {
  align-self: flex-start;
  background: var(--g-bg);
  border: 1px solid var(--g-border);
  border-bottom-left-radius: 5px;
  color: var(--g-text);
}
.mensaje--usuario {
  align-self: flex-end;
  background: var(--g-primary);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.mensaje--error {
  align-self: stretch;
  max-width: 100%;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: .86rem;
}

/* Indicador de "escribiendo" */
.mensaje--pensando {
  align-self: flex-start;
  background: var(--g-bg);
  border: 1px solid var(--g-border);
  padding: var(--sp-3) var(--sp-4);
  border-radius: 16px;
  border-bottom-left-radius: 5px;
  display: flex; gap: 4px; align-items: center;
}
.mensaje--pensando span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--g-text-muted);
  animation: asistente-punto 1.3s infinite ease-in-out;
}
.mensaje--pensando span:nth-child(2) { animation-delay: .18s; }
.mensaje--pensando span:nth-child(3) { animation-delay: .36s; }
@keyframes asistente-punto {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30%           { opacity: 1;  transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .mensaje--pensando span { animation: none; opacity: .6; }
}

/* Sugerencias iniciales */
.asistente__sugerencias {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
  padding: 0 var(--sp-5) var(--sp-4);
  background: var(--g-bg-soft);
}
.sugerencia {
  border: 1px solid var(--g-border);
  background: var(--g-bg);
  color: var(--g-primary);
  font-size: .82rem; font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.sugerencia:hover { border-color: var(--g-primary); background: var(--g-primary-light); }
.sugerencia:focus-visible { outline: 2px solid var(--g-accent); outline-offset: 2px; }

/* ---------- Escritura ---------- */
.asistente__form {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--g-border);
  background: var(--g-bg);
  flex-shrink: 0;
}
.asistente__campo {
  flex: 1;
  padding: 11px var(--sp-4);
  border: 1.5px solid var(--g-border-control, #6b7280);
  border-radius: 999px;
  font: inherit;
  font-size: .92rem;
  min-width: 0;
}
.asistente__campo:focus {
  border-color: var(--g-primary);
  outline: 3px solid var(--g-accent);
  outline-offset: 1px;
}
.asistente__enviar {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 50%; border: 0;
  background: var(--g-accent); color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
}
.asistente__enviar:hover:not(:disabled) { transform: scale(1.05); }
.asistente__enviar:disabled { opacity: .5; cursor: not-allowed; }
.asistente__enviar:focus-visible { outline: 3px solid var(--g-primary); outline-offset: 2px; }

.asistente__aviso {
  padding: 0 var(--sp-5) var(--sp-4);
  font-size: .74rem;
  color: var(--g-text-muted);
  background: var(--g-bg);
  line-height: 1.45;
}

/* En movil ocupa la pantalla completa: un panel pequeno con teclado abierto es
   inservible. */
@media (max-width: 560px) {
  .asistente {
    right: 0; left: 0; bottom: 0;
    width: 100%;
    max-height: 88vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
}
