/* ==========================================================================
   Agencia Detective — Asistente de admisión

   Deliberadamente más cálido que el resto del sitio: burbujas redondeadas,
   fondo claro y ritmo de conversación. El contraste es intencional; aquí la
   persona está hablando, no leyendo un expediente.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Lanzador
   -------------------------------------------------------------------------- */

.chat-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: var(--r-pill);
  background: var(--ink-2);
  border: 1px solid var(--rule-dark);
  color: var(--white);
  box-shadow: var(--shadow-lg);
  transition:
    background-color var(--dur) var(--ease-out),
    border-color var(--dur) var(--ease-out),
    transform var(--dur) var(--ease-out);
}

.chat-launcher:hover {
  background: var(--azure-deep);
  border-color: var(--azure);
  transform: translateY(-2px);
}

.chat-launcher svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  stroke-width: 1.6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Punto ámbar: la única señal de «hay algo aquí» */
.chat-launcher__dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 12px;
  height: 12px;
  border-radius: var(--r-pill);
  background: var(--amber);
  border: 2px solid var(--ink);
}

.chat-launcher__dot::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  border: 2px solid var(--amber);
  animation: chat-pulse 2.6s var(--ease-out) infinite;
}

@keyframes chat-pulse {
  0%   { transform: scale(1);   opacity: 0.9; }
  70%  { transform: scale(2.4); opacity: 0; }
  100% { transform: scale(2.4); opacity: 0; }
}

.chat-launcher[aria-expanded="true"] .chat-launcher__dot { display: none; }

@media (prefers-reduced-motion: reduce) {
  .chat-launcher__dot::after { animation: none; }
}

/* --------------------------------------------------------------------------
   Aviso emergente
   -------------------------------------------------------------------------- */

.chat-teaser {
  position: fixed;
  right: calc(clamp(1rem, 0.5rem + 1.4vw, 1.75rem) + 74px);
  bottom: calc(clamp(1rem, 0.5rem + 1.4vw, 1.75rem) + 8px);
  z-index: var(--z-float);
  display: flex;
  align-items: center;
  gap: 0.9rem;
  max-width: 270px;
  padding: 0.85rem 1rem;
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: 14px 14px 4px 14px;
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  color: var(--text);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.96);
  transform-origin: bottom right;
  transition:
    opacity var(--dur) var(--ease-out),
    transform var(--dur) var(--ease-out),
    visibility var(--dur);
}

.chat-teaser.is-visible { opacity: 1; visibility: visible; transform: none; }

.chat-teaser__text { flex: 1; line-height: 1.45; }

.chat-teaser__close {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: var(--r-pill);
  color: var(--slate);
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}

.chat-teaser__close:hover { color: var(--text); background: var(--paper-2); }
.chat-teaser__close svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }

@media (max-width: 560px) {
  .chat-teaser { display: none; }
}

/* --------------------------------------------------------------------------
   Panel
   -------------------------------------------------------------------------- */

.chat-panel {
  position: fixed;
  right: clamp(1rem, 0.5rem + 1.4vw, 1.75rem);
  bottom: calc(clamp(1rem, 0.5rem + 1.4vw, 1.75rem) + 72px);
  z-index: calc(var(--z-float) + 5);
  display: flex;
  flex-direction: column;
  width: 384px;
  max-width: calc(100vw - 2rem);
  height: 560px;
  max-height: calc(100dvh - 8rem);
  background: var(--paper);
  border-radius: 14px;
  box-shadow: 0 32px 80px -24px rgba(10, 20, 36, 0.55);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(0.97);
  transform-origin: bottom right;
  transition:
    opacity var(--dur) var(--ease-out),
    transform var(--dur) var(--ease-out),
    visibility var(--dur);
}

.chat-panel.is-open { opacity: 1; visibility: visible; transform: none; }

/* Con el panel abierto, el resto de la pila flotante queda detrás y sin uso:
   se retira para no dejar botones a medio tapar. El acceso directo a WhatsApp
   sigue disponible en la cabecera del propio panel. */
body.chat-open .float-btn,
body.chat-open .to-top {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 560px) {
  .chat-panel {
    right: 0.75rem;
    left: 0.75rem;
    bottom: 0.75rem;
    width: auto;
    max-width: none;
    height: min(78dvh, 620px);
    max-height: none;
  }
}

/* ---- Cabecera ---- */

.chat-head {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 1rem;
  background: var(--ink);
  color: var(--white);
  flex: none;
}

.chat-head__mark {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.08);
  color: var(--white);
}

.chat-head__mark svg { width: 22px; height: auto; }

.chat-head__id { flex: 1; min-width: 0; line-height: 1.25; }

.chat-head__name {
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.chat-head__state {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-invert-soft);
  margin-top: 2px;
}

.chat-head__state::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: #3FBF7F;
  flex: none;
}

.chat-head__action {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--r-pill);
  color: rgba(255, 255, 255, 0.75);
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}

.chat-head__action:hover { color: var(--white); background: rgba(255, 255, 255, 0.1); }
.chat-head__action svg { width: 17px; height: 17px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Hilo ---- */

.chat-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}

.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: var(--r-pill); }

.chat-msg {
  max-width: 86%;
  padding: 0.7rem 0.95rem;
  font-size: var(--fs-sm);
  line-height: 1.55;
  animation: chat-in 280ms var(--ease-out) both;
}

@keyframes chat-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-msg { animation: none; }
}

.chat-msg--bot {
  align-self: flex-start;
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: 14px 14px 14px 4px;
  color: var(--text);
}

.chat-msg--user {
  align-self: flex-end;
  background: var(--azure-deep);
  border-radius: 14px 14px 4px 14px;
  color: var(--white);
}

.chat-msg strong { font-weight: 600; }

/* Resumen del caso */
.chat-summary {
  align-self: stretch;
  max-width: none;
  background: var(--white);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--amber);
  border-radius: 4px 10px 10px 4px;
  padding: 0.85rem 1rem;
  animation: chat-in 280ms var(--ease-out) both;
}

.chat-summary__title {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--slate);
  margin-bottom: 0.6rem;
}

.chat-summary dl { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 0.75rem; }

.chat-summary dt {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--slate);
  white-space: nowrap;
  padding-top: 1px;
}

.chat-summary dd { font-size: var(--fs-sm); color: var(--text); font-weight: 500; }

/* Indicador de escritura */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.85rem 0.95rem;
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: 14px 14px 14px 4px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--slate);
  animation: chat-bounce 1.2s var(--ease-in-out) infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-typing span { animation: none; opacity: 0.6; }
}

/* ---- Zona de respuesta ---- */

.chat-composer {
  flex: none;
  padding: 0.75rem 1rem 0.9rem;
  background: var(--paper);
  border-top: 1px solid var(--rule);
}

.chat-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.chat-chip {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--azure);
  border-radius: var(--r-pill);
  background: var(--white);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--azure-deep);
  text-align: left;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.chat-chip:hover { background: var(--azure); color: var(--white); }
.chat-chip:active { transform: translateY(1px); }

/* Acciones de cierre: llevan a un canal real */
.chat-chip--primary {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--ink);
  font-weight: 600;
}
.chat-chip--primary:hover { background: var(--amber-deep); border-color: var(--amber-deep); color: var(--ink); }

.chat-chip--quiet {
  border-color: var(--rule-strong);
  color: var(--text-soft);
}
.chat-chip--quiet:hover { background: var(--ink); border-color: var(--ink); color: var(--white); }

/* Entrada de texto libre */
.chat-input-row { display: flex; gap: 0.5rem; }

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-pill);
  background: var(--white);
  font-size: 0.875rem;
  color: var(--text);
}

.chat-input:focus {
  outline: none;
  border-color: var(--azure);
  box-shadow: 0 0 0 3px rgba(44, 111, 209, 0.16);
}

.chat-send {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--white);
  transition: background-color var(--dur-fast) var(--ease-out);
}

.chat-send:hover { background: var(--azure-deep); }
.chat-send svg { width: 17px; height: 17px; stroke: currentColor; stroke-width: 1.9; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* Nota de privacidad */
.chat-note {
  margin-top: 0.65rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.06em;
  color: var(--slate);
  text-align: center;
}
