/* Sofía Chat widget — Digital Media 305 brand system (Corp-Identity v1.0).
   Paleta oficial: Deep Navy #021373 · Royal #0F35A6 · Mid #415AA6
   · Cyber Cyan #05DBF2 (interactivo/glow) · Electric Magenta #EE05F2 (CTA/signal).
   Tipografía: Helvetica. Grading de marca: dark + cyan + magenta.
   Todo namespaced bajo #sofia-chat para no chocar con el sitio anfitrión. */

#sofia-chat,
#sofia-chat * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

#sofia-chat {
  /* Paleta oficial DM305 */
  --dm-navy: #021373;
  --dm-royal: #0f35a6;
  --dm-mid: #415aa6;
  --dm-cyan: #05dbf2;
  --dm-magenta: #ee05f2;

  /* Superficies derivadas (dark navy) */
  --sofia-bg: #04071a;
  --sofia-panel: #070c24;
  --sofia-elevated: #0e1740;
  --sofia-text: #f2f4fb;
  --sofia-muted: #8a93bd;
  --sofia-user: var(--dm-royal);
  --sofia-radius: 16px;
  --sofia-font: 'Helvetica Neue', Helvetica, Arial, sans-serif;

  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 2147483000;
  font-family: var(--sofia-font);
}

/* ── Launcher (anillo gradiente cyan→magenta con la cara de Sofía) ───────── */
#sofia-chat .sofia-launcher {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  padding: 3px;
  overflow: visible;
  background: linear-gradient(135deg, var(--dm-cyan), var(--dm-magenta));
  box-shadow: 0 6px 26px rgba(5, 219, 242, 0.4), 0 6px 26px rgba(238, 5, 242, 0.3);
  transition: box-shadow 0.18s ease;
  animation: sofia-heartbeat 2.8s ease-in-out infinite;
}
/* Anillo que pulsa hacia afuera (atrae la atención) */
#sofia-chat .sofia-launcher::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--dm-cyan);
  z-index: -1;
  pointer-events: none;
  animation: sofia-pulse-ring 2.8s ease-out infinite;
}
#sofia-chat .sofia-launcher:hover {
  animation-play-state: paused;
  box-shadow: 0 12px 34px rgba(5, 219, 242, 0.6), 0 12px 34px rgba(238, 5, 242, 0.5);
}
#sofia-chat .sofia-launcher:hover::after { animation-play-state: paused; opacity: 0; }

@keyframes sofia-heartbeat {
  0%, 38%, 100% { transform: scale(1); }
  10% { transform: scale(1.09); }
  20% { transform: scale(1); }
  29% { transform: scale(1.06); }
}
@keyframes sofia-pulse-ring {
  0%   { transform: scale(1);   opacity: 0.7; }
  70%  { transform: scale(1.8); opacity: 0; }
  100% { transform: scale(1.8); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #sofia-chat .sofia-launcher { animation: none; }
  #sofia-chat .sofia-launcher::after { animation: none; opacity: 0; }
}
#sofia-chat .sofia-launcher img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  display: block;
}
#sofia-chat .sofia-launcher-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--dm-magenta);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--sofia-bg);
}
#sofia-chat .sofia-launcher-badge svg { width: 13px; height: 13px; }
#sofia-chat .sofia-launcher.hidden { display: none; }

/* ── Panel ───────────────────────────────────────────────────────────────── */
#sofia-chat .sofia-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 48px);
  background: rgba(7, 12, 36, 0.62);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-radius: var(--sofia-radius);
  box-shadow: 0 24px 70px rgba(2, 19, 115, 0.6), 0 0 0 1px rgba(5, 219, 242, 0.12);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: sofia-in 0.22s ease;
}
#sofia-chat .sofia-panel.open { display: flex; }

@keyframes sofia-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Header (deep navy + divider gradiente cyan→magenta = firma de marca) ── */
#sofia-chat .sofia-header {
  position: relative;
  background: linear-gradient(135deg, rgba(4, 7, 26, 0.42), rgba(2, 19, 115, 0.34));
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
#sofia-chat .sofia-header::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--dm-cyan), var(--dm-magenta));
}
#sofia-chat .sofia-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  padding: 2px;
  background: linear-gradient(135deg, var(--dm-cyan), var(--dm-magenta));
}
#sofia-chat .sofia-avatar img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  display: block;
}
#sofia-chat .sofia-id { flex: 1; }
#sofia-chat .sofia-name {
  color: var(--sofia-text); font-weight: 700; font-size: 15px;
  display: flex; align-items: center; gap: 7px; letter-spacing: 0.2px;
}
#sofia-chat .sofia-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #2ee6a6;
  box-shadow: 0 0 0 3px rgba(46, 230, 166, 0.18);
}
#sofia-chat .sofia-sub {
  color: var(--dm-cyan); font-size: 11.5px; margin-top: 2px;
  letter-spacing: 0.4px; text-transform: uppercase; font-weight: 600;
}
#sofia-chat .sofia-close {
  background: none; border: none; color: var(--sofia-muted);
  cursor: pointer; font-size: 22px; line-height: 1; padding: 4px;
}
#sofia-chat .sofia-close:hover { color: var(--dm-cyan); }

/* ── Mensajes ────────────────────────────────────────────────────────────── */
#sofia-chat .sofia-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at 85% 12%, rgba(238, 5, 242, 0.07), transparent 38%),
    radial-gradient(circle at 12% 88%, rgba(5, 219, 242, 0.07), transparent 38%),
    transparent;
}
#sofia-chat .sofia-messages::-webkit-scrollbar { width: 6px; }
#sofia-chat .sofia-messages::-webkit-scrollbar-thumb {
  background: rgba(5, 219, 242, 0.25); border-radius: 3px;
}
/* Ancla los mensajes ABAJO (pegados al input) y deja que crezcan hacia arriba.
   Con pocos mensajes elimina el hueco grande; al llenarse, el margen colapsa y
   la lista hace scroll normal mostrando el último intercambio. */
#sofia-chat .sofia-messages > :first-child { margin-top: auto; }

/* Fila de Sofía: mini-avatar + burbuja */
#sofia-chat .sofia-row.bot {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  align-self: flex-start;
  max-width: 90%;
}
#sofia-chat .sofia-msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  flex-shrink: 0;
  padding: 1.5px;
  background: linear-gradient(135deg, var(--dm-cyan), var(--dm-magenta));
}

#sofia-chat .sofia-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
#sofia-chat .sofia-row.bot .sofia-msg { max-width: 100%; }
#sofia-chat .sofia-msg.bot {
  background: var(--sofia-elevated);
  color: var(--sofia-text);
  border: 1px solid rgba(5, 219, 242, 0.16);
  border-bottom-left-radius: 4px;
}
#sofia-chat .sofia-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--dm-royal), var(--dm-navy));
  color: #fff;
  border: 1px solid rgba(65, 90, 166, 0.5);
  border-bottom-right-radius: 4px;
}

/* typing indicator */
#sofia-chat .sofia-typing {
  display: flex; gap: 4px; padding: 12px 14px;
  background: var(--sofia-elevated);
  border: 1px solid rgba(5, 219, 242, 0.16);
  border-radius: 14px; border-bottom-left-radius: 4px;
}
#sofia-chat .sofia-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--dm-cyan);
  animation: sofia-bounce 1.2s infinite ease-in-out;
}
#sofia-chat .sofia-typing span:nth-child(2) { animation-delay: 0.15s; background: var(--dm-mid); }
#sofia-chat .sofia-typing span:nth-child(3) { animation-delay: 0.3s; background: var(--dm-magenta); }
@keyframes sofia-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Input ───────────────────────────────────────────────────────────────── */
#sofia-chat .sofia-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(5, 219, 242, 0.12);
  background: rgba(4, 7, 26, 0.32);
}
#sofia-chat .sofia-input textarea {
  flex: 1;
  resize: none;
  border: 1px solid rgba(65, 90, 166, 0.45);
  background: var(--sofia-elevated);
  color: var(--sofia-text);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  max-height: 110px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#sofia-chat .sofia-input textarea:focus {
  border-color: var(--dm-cyan);
  box-shadow: 0 0 0 3px rgba(5, 219, 242, 0.15);
}
#sofia-chat .sofia-input textarea::placeholder { color: var(--sofia-muted); }
#sofia-chat .sofia-send {
  width: 40px; height: 40px;
  border-radius: 11px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--dm-cyan), var(--dm-magenta));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: opacity 0.15s ease, transform 0.15s ease;
}
#sofia-chat .sofia-send:hover:not(:disabled) { transform: scale(1.05); }
#sofia-chat .sofia-send:disabled { opacity: 0.4; cursor: default; }
#sofia-chat .sofia-send svg { width: 19px; height: 19px; }

#sofia-chat .sofia-footer {
  text-align: center;
  font-size: 10.5px;
  color: var(--sofia-muted);
  padding: 0 12px 10px;
  background: rgba(4, 7, 26, 0.32);
  letter-spacing: 0.3px;
}
#sofia-chat .sofia-footer b { color: var(--dm-cyan); font-weight: 600; }

/* ── Móvil: el chat abre a PANTALLA COMPLETA ─────────────────────────────────
   El input queda fijo arriba del teclado y el último mensaje siempre visible.
   El alto exacto lo ajusta el JS vía visualViewport cuando aparece el teclado. */
@media (max-width: 560px) {
  #sofia-chat .sofia-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }
  #sofia-chat .sofia-launcher { width: 58px; height: 58px; }
}
