/* Asistente virtual — PS Grupo Hunting.
   Reutiliza las variables de marca declaradas en core/base.html.

   Todos los selectores van anclados a #psgh-chat a propósito: la landing aplica
   estilos globales por etiqueta (`section{padding:108px 0}`, `footer{...}`,
   `p{margin-top:0}`) y el widget usa esas mismas etiquetas. Sin el ancla, esas
   reglas ganan por especificidad y deforman el panel.

   No hay variante oscura, y es una decisión: el sitio es claro en todas sus
   páginas, así que un panel negro flotando sobre una portada blanca no se leería
   como una preferencia atendida sino como algo a medio cargar. */

#psgh-chat {
  --chat-w: 404px;
  --chat-h: min(660px, calc(100dvh - 132px));
  --chat-radius: 24px;
  --chat-gap: 24px;

  /* Superficies y tinta. Se declaran aquí y no se usan literales más abajo:
     ajustar el contraste del panel es tocar estas seis líneas. */
  --chat-surface: #fff;
  --chat-canvas: #f5f8fc;
  --chat-text: #16273c;
  --chat-soft: #667c93;
  --chat-line: rgba(7, 17, 31, .09);
  --chat-brand: var(--blue, #2f8cff);
  --chat-brand-ink: var(--blue-deep, #004d94);
  --chat-fill: var(--gradient, linear-gradient(115deg, #2f8cff, #bd5cff));

  /* Sombra en dos planos: una difusa que apoya el panel sobre la página y una
     corta que le da el canto. Una sola sombra grande se ve como una mancha. */
  --chat-lift: 0 2px 8px rgba(7, 17, 31, .06), 0 28px 70px -12px rgba(7, 17, 31, .28);

  position: fixed;
  right: var(--chat-gap);
  /* En móvil la barra del navegador se come el borde inferior. */
  bottom: calc(var(--chat-gap) + env(safe-area-inset-bottom, 0px));
  z-index: 80;
  font-family: var(--sans, Inter, "Segoe UI", sans-serif);
}

/* --- Lanzador --- */
#psgh-chat .chat-launcher {
  position: relative;
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-left: auto;
  padding: .55rem 1.15rem .55rem .6rem;
  border: 0;
  border-radius: 999px;
  background: var(--chat-fill);
  color: #fff;
  font-family: inherit;
  font-weight: 750;
  font-size: .93rem;
  letter-spacing: -.01em;
  cursor: pointer;
  box-shadow: 0 16px 38px rgba(68, 96, 232, .34);
  transition: transform .25s, box-shadow .25s;
}
#psgh-chat .chat-launcher:hover { transform: translateY(-3px); box-shadow: 0 22px 48px rgba(68, 96, 232, .42); }
#psgh-chat .chat-launcher:focus-visible { outline: 3px solid rgba(47, 140, 255, .45); outline-offset: 3px; }

#psgh-chat .chat-launcher-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .18);
}
#psgh-chat .chat-launcher-icon svg { position: absolute; width: 21px; height: 21px; transition: opacity .2s, transform .2s; }
#psgh-chat .icon-close { opacity: 0; transform: rotate(-45deg) scale(.6); }
#psgh-chat.is-open .icon-chat { opacity: 0; transform: rotate(45deg) scale(.6); }
#psgh-chat.is-open .icon-close { opacity: 1; transform: none; }
#psgh-chat.is-open .chat-launcher-label { display: none; }

/* Punto de aviso mientras el visitante no ha abierto el chat. */
#psgh-chat .chat-launcher::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #34d399;
  opacity: 0;
  transition: opacity .3s;
}
#psgh-chat.has-nudge .chat-launcher::after { opacity: 1; }

/* --- Globo de invitación ---
   Aparece una vez, dice algo concreto y se puede cerrar sin abrir el panel: un
   punto verde parpadeando no explica para qué sirve el botón. */
#psgh-chat .chat-teaser {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  width: max-content;
  max-width: min(280px, calc(100vw - 48px));
  padding: .75rem .8rem .75rem .95rem;
  border: 1px solid var(--chat-line);
  border-radius: 16px 16px 4px 16px;
  background: var(--chat-surface);
  box-shadow: var(--chat-lift);
  cursor: pointer;
  animation: teaser-in .5s cubic-bezier(.2, .9, .3, 1) both;
}
#psgh-chat .chat-teaser[hidden] { display: none; }
#psgh-chat .chat-teaser p {
  margin: 0;
  color: var(--chat-text);
  font-size: .84rem;
  line-height: 1.45;
}
#psgh-chat .chat-teaser-close {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  margin-top: -.1rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--chat-soft);
  cursor: pointer;
  transition: background .2s, color .2s;
}
#psgh-chat .chat-teaser-close:hover { background: var(--chat-canvas); color: var(--chat-text); }
#psgh-chat .chat-teaser-close svg { width: 12px; height: 12px; }
@keyframes teaser-in { from { opacity: 0; transform: translateY(8px) scale(.96); } }

/* --- Panel --- */
#psgh-chat .chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  display: flex;
  flex-direction: column;
  width: var(--chat-w);
  height: var(--chat-h);
  margin: 0;
  padding: 0;
  border: 1px solid var(--chat-line);
  border-radius: var(--chat-radius);
  background: var(--chat-surface);
  box-shadow: var(--chat-lift);
  overflow: hidden;
  transform-origin: bottom right;
}
#psgh-chat .chat-panel[hidden] { display: none; }

#psgh-chat .chat-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: .85rem;
  margin: 0;
  padding: 1rem 1.05rem;
  background: var(--ink, #07111f);
  color: #fff;
}
/* Filo de marca arriba y un lavado del mismo gradiente encima del negro: el
   encabezado deja de ser una barra oscura y pasa a ser parte del sistema. */
#psgh-chat .chat-head::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--chat-fill);
}
#psgh-chat .chat-head::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--gradient-soft, linear-gradient(135deg, rgba(47, 140, 255, .12), rgba(189, 92, 255, .12)));
  pointer-events: none;
}
#psgh-chat .chat-head > * { position: relative; z-index: 1; }
#psgh-chat .chat-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 13px;
  background: rgba(255, 255, 255, .1);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
  overflow: hidden;
}
#psgh-chat .chat-avatar img { width: 26px; height: 26px; object-fit: contain; }
#psgh-chat .chat-head-copy { display: grid; gap: .15rem; min-width: 0; }
#psgh-chat .chat-head-copy strong { font-size: .98rem; letter-spacing: -.02em; }
#psgh-chat .chat-head-copy span { display: flex; align-items: center; gap: .4rem; color: #a9bccf; font-size: .74rem; }
#psgh-chat .chat-head-copy i { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 4px rgba(52, 211, 153, .16); }

#psgh-chat .chat-head-actions { display: flex; gap: .3rem; margin-left: auto; }
#psgh-chat .chat-icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  cursor: pointer;
  transition: background .2s;
}
#psgh-chat .chat-icon-btn[hidden] { display: none; }
#psgh-chat .chat-icon-btn:hover { background: rgba(255, 255, 255, .2); }
#psgh-chat .chat-icon-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
#psgh-chat .chat-icon-btn svg { width: 17px; height: 17px; }

/* --- Conversación --- */
#psgh-chat .chat-body { position: relative; display: flex; flex: 1; min-height: 0; }
#psgh-chat .chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: 1.15rem 1.05rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--chat-canvas);
  scrollbar-width: thin;
  scrollbar-color: rgba(7, 17, 31, .18) transparent;
}
#psgh-chat .chat-log:focus-visible { outline: 2px solid var(--chat-brand); outline-offset: -2px; }
#psgh-chat .chat-log::-webkit-scrollbar { width: 8px; }
#psgh-chat .chat-log::-webkit-scrollbar-thumb { background: rgba(7, 17, 31, .16); border-radius: 8px; }
#psgh-chat .chat-log::-webkit-scrollbar-track { background: transparent; }

#psgh-chat .chat-msg { display: flex; max-width: 88%; }
#psgh-chat .chat-msg.user { align-self: flex-end; justify-content: flex-end; }
#psgh-chat .chat-msg.bot { align-self: flex-start; }

#psgh-chat .chat-bubble {
  margin: 0;
  padding: .72rem .95rem;
  border-radius: 18px;
  font-size: .92rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#psgh-chat .chat-msg.bot .chat-bubble {
  border: 1px solid var(--chat-line);
  border-bottom-left-radius: 6px;
  background: var(--chat-surface);
  color: var(--chat-text);
  box-shadow: 0 1px 2px rgba(7, 17, 31, .04), 0 8px 20px -8px rgba(7, 17, 31, .12);
}
#psgh-chat .chat-msg.user .chat-bubble {
  border-bottom-right-radius: 6px;
  background: var(--chat-fill);
  color: #fff;
  box-shadow: 0 8px 22px -8px rgba(68, 96, 232, .5);
}
#psgh-chat .chat-bubble a { color: var(--chat-brand-ink); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
#psgh-chat .chat-msg.user .chat-bubble a { color: #fff; }
#psgh-chat .chat-bubble ul { margin: .4rem 0 0; padding-left: 1.1rem; }
#psgh-chat .chat-bubble li { margin-bottom: .2rem; }
#psgh-chat .chat-bubble strong { font-weight: 750; }

#psgh-chat .chat-msg.error .chat-bubble {
  border-color: rgba(214, 60, 84, .28);
  background: #fff5f6;
  color: #a62437;
}
#psgh-chat .chat-retry {
  display: block;
  margin-top: .6rem;
  padding: .35rem .8rem;
  border: 1px solid rgba(214, 60, 84, .35);
  border-radius: 999px;
  background: #fff;
  color: #a62437;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
#psgh-chat .chat-retry:hover { background: #ffe9ec; border-color: rgba(214, 60, 84, .55); }

/* Indicador de escritura / acción en curso. */
#psgh-chat .chat-typing {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  color: var(--chat-soft);
  font-size: .82rem;
}
#psgh-chat .chat-dots { display: inline-flex; gap: 3px; }
#psgh-chat .chat-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--violet, #bd5cff); animation: dot 1.1s infinite; }
#psgh-chat .chat-dots i:nth-child(2) { animation-delay: .16s; }
#psgh-chat .chat-dots i:nth-child(3) { animation-delay: .32s; }
@keyframes dot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* Volver abajo: aparece solo si el visitante subió a releer algo mientras la
   respuesta sigue creciendo. */
#psgh-chat .chat-to-bottom {
  position: absolute;
  left: 50%;
  bottom: .7rem;
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .8rem .35rem .6rem;
  border: 1px solid var(--chat-line);
  border-radius: 999px;
  background: var(--chat-surface);
  color: var(--chat-text);
  font-family: inherit;
  font-size: .76rem;
  font-weight: 650;
  cursor: pointer;
  transform: translateX(-50%);
  box-shadow: 0 8px 22px -8px rgba(7, 17, 31, .4);
  animation: to-bottom-in .25s ease-out;
}
#psgh-chat .chat-to-bottom[hidden] { display: none; }
#psgh-chat .chat-to-bottom:hover { border-color: rgba(47, 140, 255, .4); }
#psgh-chat .chat-to-bottom svg { width: 14px; height: 14px; }
@keyframes to-bottom-in { from { opacity: 0; transform: translate(-50%, 6px); } }

/* --- Sugerencias --- */
#psgh-chat .chat-suggestions {
  display: flex;
  gap: .4rem;
  margin: 0;
  padding: .7rem 1.05rem 0;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--chat-surface);
}
#psgh-chat .chat-suggestions::-webkit-scrollbar { display: none; }
#psgh-chat .chat-suggestions[hidden] { display: none; }
#psgh-chat .chat-chip {
  flex: 0 0 auto;
  padding: .48rem .85rem;
  border: 1px solid rgba(47, 140, 255, .26);
  border-radius: 999px;
  background: rgba(47, 140, 255, .07);
  color: var(--chat-brand-ink);
  font-family: inherit;
  font-size: .8rem;
  font-weight: 650;
  cursor: pointer;
}
#psgh-chat .chat-chip:hover { background: rgba(47, 140, 255, .14); border-color: rgba(47, 140, 255, .45); }

/* --- Entrada --- */
#psgh-chat .chat-form {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  margin: 0;
  padding: .8rem 1.05rem .55rem;
  background: var(--chat-surface);
}
#psgh-chat .chat-honeypot { position: absolute; left: -9999px; }
#psgh-chat .chat-field { position: relative; flex: 1; min-width: 0; display: flex; }
#psgh-chat .chat-form textarea {
  flex: 1;
  max-height: 116px;
  padding: .72rem .9rem;
  border: 1px solid rgba(7, 17, 31, .12);
  border-radius: 14px;
  background: var(--chat-canvas);
  color: var(--ink, #07111f);
  font: inherit;
  font-size: .92rem;
  line-height: 1.45;
  resize: none;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
#psgh-chat .chat-form textarea:focus {
  border-color: var(--chat-brand);
  background: var(--chat-surface);
  box-shadow: 0 0 0 4px rgba(47, 140, 255, .12);
}
#psgh-chat .chat-form textarea:disabled { opacity: .6; }
/* Cuánto queda antes del tope. Solo se asoma cerca del final. */
#psgh-chat .chat-count {
  position: absolute;
  right: .6rem;
  bottom: .35rem;
  padding: 0 .25rem;
  border-radius: 6px;
  background: var(--chat-surface);
  color: var(--chat-soft);
  font-size: .68rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
#psgh-chat .chat-count[hidden] { display: none; }
#psgh-chat .chat-count.is-tight { color: #c0334a; font-weight: 700; }

#psgh-chat .chat-send,
#psgh-chat .chat-stop {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 13px;
  color: #fff;
  cursor: pointer;
  transition: transform .2s, opacity .2s, background .2s;
}
#psgh-chat .chat-send { background: var(--chat-fill); }
#psgh-chat .chat-send[hidden], #psgh-chat .chat-stop[hidden] { display: none; }
#psgh-chat .chat-send:hover:not(:disabled) { transform: translateY(-2px); }
#psgh-chat .chat-send:disabled { opacity: .45; cursor: not-allowed; }
#psgh-chat .chat-send svg { width: 18px; height: 18px; }
/* Detener no es una acción de marca: se ve como lo que es, un freno. */
#psgh-chat .chat-stop { background: var(--ink, #07111f); }
#psgh-chat .chat-stop:hover { background: #22344a; }
#psgh-chat .chat-stop svg { width: 20px; height: 20px; }
#psgh-chat .chat-send:focus-visible,
#psgh-chat .chat-stop:focus-visible,
#psgh-chat .chat-chip:focus-visible,
#psgh-chat .chat-retry:focus-visible,
#psgh-chat .chat-to-bottom:focus-visible,
#psgh-chat .chat-teaser-close:focus-visible {
  outline: 2px solid var(--chat-brand);
  outline-offset: 2px;
}

#psgh-chat .chat-foot {
  margin: 0;
  padding: 0 1.05rem calc(.8rem + env(safe-area-inset-bottom, 0px));
  color: #8496a9;
  font-size: .7rem;
  line-height: 1.5;
  text-align: center;
}
#psgh-chat .chat-foot a { color: var(--chat-brand-ink); font-weight: 650; }

/* --- Movimiento de marca ---
   Mismo ancla #psgh-chat que el resto del archivo. Los keyframes propios llevan
   nombres distintos a los de arriba para no redefinirlos por orden de cascada. */

/* El lanzador entra una vez cargada la página y llama la atención con
   discreción mientras el visitante no ha abierto la conversación. */
#psgh-chat .chat-launcher { animation: launcher-in .7s cubic-bezier(.34, 1.38, .64, 1) .9s both; }
@keyframes launcher-in { from { opacity: 0; transform: translateY(18px) scale(.85); } }

#psgh-chat .chat-launcher-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .55);
  opacity: 0;
}
#psgh-chat.has-nudge:not(.is-open) .chat-launcher-icon::after { animation: halo 2.4s cubic-bezier(.65, .05, .36, 1) infinite; }
@keyframes halo {
  0% { opacity: .8; transform: scale(1); }
  70%, 100% { opacity: 0; transform: scale(1.75); }
}
#psgh-chat.has-nudge:not(.is-open) .chat-launcher {
  animation: launcher-in .7s cubic-bezier(.34, 1.38, .64, 1) .9s both,
             nudge 5s ease-in-out 2.5s infinite;
}
@keyframes nudge {
  0%, 88%, 100% { transform: translateY(0) rotate(0); }
  91% { transform: translateY(-4px) rotate(-2.5deg); }
  95% { transform: translateY(-4px) rotate(2.5deg); }
}

#psgh-chat .chat-panel { animation: chat-pop .42s cubic-bezier(.34, 1.32, .64, 1); }
@keyframes chat-pop { from { opacity: 0; transform: translateY(20px) scale(.94); } }

#psgh-chat .chat-msg { animation: msg-pop .34s cubic-bezier(.16, 1, .3, 1); }
@keyframes msg-pop { from { opacity: 0; transform: translateY(10px) scale(.97); } }

#psgh-chat .chat-avatar img { animation: avatar-float 4.5s cubic-bezier(.65, .05, .36, 1) infinite; }
@keyframes avatar-float { 50% { transform: translateY(-2.5px) scale(1.06); } }

#psgh-chat .chat-head-copy i { animation: online 2.6s cubic-bezier(.65, .05, .36, 1) infinite; }
@keyframes online { 50% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); } }
/* Mientras se escribe, el punto deja de anunciar «en línea» y late al ritmo
   del trabajo: es la misma señal contando otra cosa. */
#psgh-chat.is-busy .chat-head-copy i { animation-duration: 1.1s; }

#psgh-chat .chat-chip { transition: background .2s, border-color .2s, transform .25s cubic-bezier(.34, 1.38, .64, 1); }
#psgh-chat .chat-chip:hover { transform: translateY(-2px); }
#psgh-chat .chat-send svg { transition: transform .3s cubic-bezier(.34, 1.38, .64, 1); }
#psgh-chat .chat-send:hover:not(:disabled) svg { transform: translateX(2px) rotate(8deg); }

/* --- Responsive --- */
@media (max-width: 560px) {
  #psgh-chat { --chat-gap: 14px; right: var(--chat-gap); left: var(--chat-gap); }
  #psgh-chat .chat-panel {
    width: auto;
    left: 0;
    right: 0;
    height: min(78dvh, calc(100dvh - 110px));
  }
  #psgh-chat .chat-teaser { max-width: calc(100vw - 28px); }
  #psgh-chat .chat-launcher-label { display: none; }
  #psgh-chat .chat-launcher { padding: .5rem; }
  /* El teclado del móvil deja poco alto: el pie de contacto se va y la
     conversación se queda con el espacio. */
  #psgh-chat .chat-foot { padding-bottom: calc(.6rem + env(safe-area-inset-bottom, 0px)); font-size: .66rem; }
}

@media (prefers-reduced-motion: reduce) {
  #psgh-chat .chat-panel,
  #psgh-chat .chat-msg,
  #psgh-chat .chat-teaser,
  #psgh-chat .chat-to-bottom,
  #psgh-chat .chat-avatar img,
  #psgh-chat .chat-head-copy i { animation: none; }
  #psgh-chat .chat-launcher,
  #psgh-chat.has-nudge:not(.is-open) .chat-launcher { animation: none; opacity: 1; transform: none; }
  #psgh-chat.has-nudge:not(.is-open) .chat-launcher-icon::after { animation: none; opacity: 0; }
  #psgh-chat .chat-launcher:hover, #psgh-chat .chat-send:hover:not(:disabled) { transform: none; }
  #psgh-chat .chat-chip:hover { transform: none; }
  #psgh-chat .chat-dots i { animation: none; opacity: .6; }
}
