/* 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. */

#psgh-chat {
  --chat-w: 400px;
  --chat-h: min(640px, calc(100dvh - 130px));
  --chat-radius: 22px;
  position: fixed;
  right: 24px;
  bottom: 24px;
  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(--gradient, linear-gradient(115deg, #2f8cff, #bd5cff));
  color: #fff;
  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; }

/* --- 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 rgba(7, 17, 31, .1);
  border-radius: var(--chat-radius);
  background: #fff;
  box-shadow: 0 34px 90px rgba(7, 17, 31, .26);
  overflow: hidden;
  transform-origin: bottom right;
  animation: chat-in .28s cubic-bezier(.2, .9, .3, 1);
}
#psgh-chat .chat-panel[hidden] { display: none; }
@keyframes chat-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }

#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;
}
#psgh-chat .chat-head::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--gradient, linear-gradient(115deg, #2f8cff, #bd5cff));
}
#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);
  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; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 4px rgba(52, 211, 153, .16); }
#psgh-chat .chat-close {
  margin-left: auto;
  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-close:hover { background: rgba(255, 255, 255, .18); }
#psgh-chat .chat-close svg { width: 17px; height: 17px; }

/* --- Conversación --- */
#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(--paper, #f4f7fb);
  scrollbar-width: thin;
}
#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-msg { display: flex; max-width: 88%; animation: msg-in .22s ease-out; }
#psgh-chat .chat-msg.user { align-self: flex-end; justify-content: flex-end; }
#psgh-chat .chat-msg.bot { align-self: flex-start; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }

#psgh-chat .chat-bubble {
  margin: 0;
  padding: .7rem .95rem;
  border-radius: 16px;
  font-size: .92rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#psgh-chat .chat-msg.bot .chat-bubble {
  border: 1px solid rgba(7, 17, 31, .08);
  border-bottom-left-radius: 5px;
  background: #fff;
  color: #16273c;
  box-shadow: 0 6px 18px rgba(7, 17, 31, .05);
}
#psgh-chat .chat-msg.user .chat-bubble {
  border-bottom-right-radius: 5px;
  background: var(--gradient, linear-gradient(115deg, #2f8cff, #bd5cff));
  color: #fff;
}
#psgh-chat .chat-bubble a { color: var(--blue-deep, #004d94); font-weight: 700; text-decoration: underline; }
#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;
}

/* Indicador de escritura / acción en curso. */
#psgh-chat .chat-typing {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  color: #64748b;
  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); } }

/* --- Sugerencias --- */
#psgh-chat .chat-suggestions {
  display: flex;
  gap: .4rem;
  margin: 0;
  padding: .7rem 1.05rem 0;
  overflow-x: auto;
  scrollbar-width: none;
  background: #fff;
}
#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(--blue-deep, #004d94);
  font-size: .8rem;
  font-weight: 650;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
#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: #fff;
}
#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(--paper, #f4f7fb);
  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(--blue, #2f8cff);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(47, 140, 255, .12);
}
#psgh-chat .chat-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 13px;
  background: var(--gradient, linear-gradient(115deg, #2f8cff, #bd5cff));
  color: #fff;
  cursor: pointer;
  transition: transform .2s, opacity .2s;
}
#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; }

#psgh-chat .chat-foot {
  margin: 0;
  padding: 0 1.05rem .8rem;
  color: #8496a9;
  font-size: .7rem;
  line-height: 1.5;
  text-align: center;
}
#psgh-chat .chat-foot a { color: var(--blue-deep, #004d94); 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); } }

#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 { right: 14px; bottom: 14px; left: 14px; }
  #psgh-chat .chat-panel { width: auto; left: 0; right: 0; height: min(76dvh, calc(100dvh - 110px)); }
  #psgh-chat .chat-launcher-label { display: none; }
  #psgh-chat .chat-launcher { padding: .5rem; }
}

@media (prefers-reduced-motion: reduce) {
  #psgh-chat .chat-panel,
  #psgh-chat .chat-msg,
  #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-dots i { animation: none; opacity: .6; }
}
