/**
 * Asistente de consultas. Los colores salen de las variables del sitio, con un valor de
 * respaldo por si el archivo se carga en una página que todavía no las define.
 */

#sd-asistente {
  --sda-azul: var(--azul, #0b3a63);
  --sda-acento: var(--acento, #00a8a8);
  --sda-sup: var(--sup, #fff);
  --sda-tinta: var(--tinta, #12202e);
  --sda-linea: var(--linea, #dbe4ee);
  --sda-gris: var(--gris, #5b6b7c);
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9000;
  font-family: inherit;
}

/* ── La burbuja ───────────────────────────────────────────────────────────── */

.sda-burbuja {
  position: relative;
  width: 58px; height: 58px;
  border: 0; border-radius: 50%;
  background: var(--sda-azul);
  color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 8px 22px -6px rgba(11, 58, 99, .5);
  transition: transform .2s ease, background .2s ease;
}
.sda-burbuja:hover { transform: scale(1.06) }
.sda-burbuja:focus-visible { outline: 3px solid var(--sda-acento); outline-offset: 3px }
.sda-burbuja svg { width: 27px; height: 27px; grid-area: 1/1; transition: opacity .18s ease, transform .18s ease }
.sda-ico-cerrar { opacity: 0; transform: rotate(-90deg) }
.sda-burbuja.sda-abierta .sda-ico-chat { opacity: 0; transform: rotate(90deg) }
.sda-burbuja.sda-abierta .sda-ico-cerrar { opacity: 1; transform: none }

/* El anillo que se expande: sólo cuando el asistente está pidiendo atención. */
.sda-pulso { position: absolute; inset: 0; border-radius: 50%; pointer-events: none }
.sda-llamando .sda-pulso {
  box-shadow: 0 0 0 0 rgba(0, 168, 168, .65);
  animation: sda-anillo 1.9s infinite;
}
@keyframes sda-anillo {
  70%  { box-shadow: 0 0 0 16px rgba(0, 168, 168, 0) }
  100% { box-shadow: 0 0 0 0 rgba(0, 168, 168, 0) }
}

.sda-punto {
  position: absolute; top: -3px; right: -3px;
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: #e23b3b; color: #fff;
  font-size: .72rem; font-weight: 700; line-height: 20px;
  border: 2px solid var(--sda-sup);
  animation: sda-aparece .3s ease;
}
@keyframes sda-aparece { from { transform: scale(0) } to { transform: scale(1) } }

/* ── El globo de aviso ────────────────────────────────────────────────────── */

.sda-globo {
  position: absolute; right: 0; bottom: 72px;
  width: min(258px, 72vw);
  background: var(--sda-sup); color: var(--sda-tinta);
  border: 1px solid var(--sda-linea); border-radius: 14px 14px 4px 14px;
  padding: 13px 15px;
  box-shadow: 0 12px 30px -10px rgba(11, 58, 99, .35);
  cursor: pointer;
  animation: sda-globo-entra .34s cubic-bezier(.22, 1, .36, 1);
}
.sda-globo p { margin: 0; font-size: .88rem; line-height: 1.42 }
.sda-globo-cerrar {
  position: absolute; top: 4px; right: 6px;
  background: none; border: 0; cursor: pointer;
  color: var(--sda-gris); font-size: 1.1rem; line-height: 1; padding: 4px;
}
@keyframes sda-globo-entra {
  from { opacity: 0; transform: translateY(10px) scale(.96) }
}

/* ── El panel ─────────────────────────────────────────────────────────────── */

/* `hidden` sólo trae `display:none` con especificidad mínima, así que cualquier
   `display` declarado después le gana: el panel arrancaba abierto y vacío. */
#sd-asistente [hidden] { display: none !important }

.sda-panel {
  position: absolute; right: 0; bottom: 72px;
  width: min(360px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 130px));
  display: flex; flex-direction: column;
  background: var(--sda-sup);
  border: 1px solid var(--sda-linea); border-radius: 16px;
  box-shadow: 0 22px 50px -16px rgba(11, 58, 99, .45);
  overflow: hidden;
  animation: sda-panel-entra .28s cubic-bezier(.22, 1, .36, 1);
}
@keyframes sda-panel-entra {
  from { opacity: 0; transform: translateY(14px) scale(.97) }
}

.sda-cab {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--sda-azul); color: #fff;
}
.sda-cab img { flex-shrink: 0 }
.sda-cab div { display: flex; flex-direction: column; line-height: 1.3; flex: 1; min-width: 0 }
.sda-cab strong { font-size: .93rem }
.sda-cab span { font-size: .74rem; color: #b9d2e8; display: flex; align-items: center; gap: 5px }
.sda-online {
  width: 7px; height: 7px; border-radius: 50%;
  background: #46d19b; flex-shrink: 0;
  animation: sda-late 2.2s ease-in-out infinite;
}
@keyframes sda-late { 50% { opacity: .35 } }
.sda-cerrar {
  background: none; border: 0; color: #fff; cursor: pointer;
  font-size: 1.4rem; line-height: 1; padding: 2px 6px; border-radius: 6px;
}
.sda-cerrar:hover { background: rgba(255, 255, 255, .16) }

.sda-cuerpo {
  flex: 1; overflow-y: auto;
  padding: 16px 14px;
  display: flex; flex-direction: column; gap: 9px;
  background: var(--fondo, #f4f7fb);
  scroll-behavior: smooth;
}

/* ── Mensajes ─────────────────────────────────────────────────────────────── */

.sda-msj {
  max-width: 84%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: .89rem; line-height: 1.45;
  animation: sda-msj-entra .26s cubic-bezier(.22, 1, .36, 1);
  word-break: break-word;
}
@keyframes sda-msj-entra {
  from { opacity: 0; transform: translateY(7px) }
}
.sda-bot {
  align-self: flex-start;
  background: var(--sda-sup); color: var(--sda-tinta);
  border: 1px solid var(--sda-linea);
  border-bottom-left-radius: 4px;
}
.sda-yo {
  align-self: flex-end;
  background: var(--sda-azul); color: #fff;
  border-bottom-right-radius: 4px;
}

/* Los tres puntitos de "está escribiendo". */
.sda-escribiendo { display: flex; gap: 4px; padding: 13px }
.sda-escribiendo i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--sda-gris); opacity: .5;
  animation: sda-punto-salta 1.3s infinite;
}
.sda-escribiendo i:nth-child(2) { animation-delay: .18s }
.sda-escribiendo i:nth-child(3) { animation-delay: .36s }
@keyframes sda-punto-salta {
  0%, 60%, 100% { transform: none; opacity: .45 }
  30% { transform: translateY(-5px); opacity: 1 }
}

/* ── Opciones y entrada de texto ──────────────────────────────────────────── */

.sda-opciones {
  display: flex; flex-direction: column; gap: 6px;
  align-self: stretch; margin-top: 2px;
  animation: sda-msj-entra .3s cubic-bezier(.22, 1, .36, 1);
}
.sda-opcion {
  text-align: left; width: 100%;
  padding: 10px 13px;
  background: var(--sda-sup); color: var(--sda-azul);
  border: 1px solid var(--sda-acento); border-radius: 10px;
  font: inherit; font-size: .86rem; font-weight: 500;
  cursor: pointer; text-decoration: none; display: block;
  transition: background .16s ease, color .16s ease;
}
.sda-opcion:hover { background: var(--sda-acento); color: #fff }
.sda-opcion:focus-visible { outline: 2px solid var(--sda-azul); outline-offset: 2px }

.sda-pie:empty { display: none }
.sda-entrada {
  display: flex; gap: 8px; align-items: center;
  padding: 11px 12px;
  border-top: 1px solid var(--sda-linea);
  background: var(--sda-sup);
}
.sda-entrada input {
  flex: 1; min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--sda-linea); border-radius: 20px;
  font: inherit; font-size: .88rem;
  background: var(--sda-sup);
  /* Igual que en los formularios: sin esto hereda el color del contenedor. */
  color: var(--sda-tinta) !important;
  -webkit-text-fill-color: var(--sda-tinta);
}
.sda-entrada input:focus { outline: 2px solid var(--sda-acento); outline-offset: -1px; border-color: transparent }
.sda-entrada button {
  flex-shrink: 0;
  width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: var(--sda-acento); color: #fff;
  cursor: pointer; display: grid; place-items: center;
}
.sda-entrada button:hover { background: var(--sda-azul) }
.sda-entrada button svg { width: 17px; height: 17px }

/* ── Teléfonos ────────────────────────────────────────────────────────────── */

@media (max-width: 560px) {
  #sd-asistente { right: 14px; bottom: 14px }
  .sda-panel {
    width: calc(100vw - 24px);
    height: min(72vh, calc(100vh - 110px));
    right: -2px;
  }
}

/* Quien pidió menos animación en su sistema no ve nada moverse. */
@media (prefers-reduced-motion: reduce) {
  #sd-asistente *, #sd-asistente *::before, #sd-asistente *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* La casilla antibot, alineada como un mensaje más de la conversación. */
.sda-antibot {
  align-self: flex-start;
  animation: sda-msj-entra .26s cubic-bezier(.22, 1, .36, 1);
}
