/* ==========================================================================
   ELEVATE GROWTH - IN-PAGE CHAT WIDGET
   Self-contained. Every selector is namespaced `.egc-` so it can never
   collide with styles.css. Reads brand tokens from :root when available and
   falls back to literals so the widget also works on pages that load late.
   ========================================================================== */

.egc-root {
  /* Los nombres --egc-red* vienen del widget de Global Mattress; aquí son el
     azul de la marca. Leen los tokens de la landing si existen. */
  --egc-red: var(--accent, #1a6fb5);
  --egc-red-dark: var(--accent-600, #155e9b);
  --egc-red-hover: var(--navy, #0f2942);
  --egc-ink: var(--ink, #1d2b3a);
  --egc-ink-soft: var(--muted, #5a6673);
  --egc-ink-muted: var(--soft, #7a8794);
  --egc-surface: #FFFFFF;
  --egc-canvas: var(--bg, #f4f5f7);
  --egc-line: var(--line, #e6ebf0);
  --egc-green: #10B981;
  --egc-font-head: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --egc-font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --egc-ease: cubic-bezier(0.4, 0, 0.2, 1);

  position: fixed;
  bottom: 32px;
  right: 32px;
  z-index: 9998;
  font-family: var(--egc-font-body);
  line-height: 1.5;
}

.egc-root *,
.egc-root *::before,
.egc-root *::after {
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   LAUNCHER (replaces the old WhatsApp FAB)
   -------------------------------------------------------------------------- */

.egc-launcher {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 62px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--egc-red);
  color: #FFFFFF;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(26, 111, 181, 0.45);
  transition: transform 0.25s var(--egc-ease), background-color 0.2s ease;
}

.egc-launcher:hover {
  background: var(--egc-red-dark);
  transform: scale(1.08);
}

.egc-launcher:focus-visible {
  outline: 3px solid rgba(26, 111, 181, 0.35);
  outline-offset: 3px;
}

.egc-launcher-icon {
  font-size: 1.6rem;
  transition: transform 0.25s var(--egc-ease), opacity 0.18s ease;
}

/* Swap the bubble for a chevron while the panel is open */
.egc-root.is-open .egc-launcher-icon--open { transform: scale(0.4); opacity: 0; }
.egc-root.is-open .egc-launcher-icon--close { transform: scale(1); opacity: 1; }
.egc-launcher-icon--close { position: absolute; transform: scale(0.4); opacity: 0; }

.egc-pulse-ring {
  position: absolute;
  inset: -6px;
  border: 2px solid var(--egc-red);
  border-radius: 50%;
  pointer-events: none;
  animation: egcPulseRing 2s cubic-bezier(0.24, 0, 0.38, 1) infinite;
}

.egc-root.is-open .egc-pulse-ring { display: none; }

@keyframes egcPulseRing {
  0%   { transform: scale(0.95); opacity: 0.8; }
  50%  { transform: scale(1.3);  opacity: 0; }
  100% { transform: scale(1.3);  opacity: 0; }
}

.egc-unread {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border: 2px solid #FFFFFF;
  border-radius: 999px;
  background: var(--egc-ink);
  color: #FFFFFF;
  font-family: var(--egc-font-head);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.egc-root.is-open .egc-unread,
.egc-unread[hidden] { display: none; }

/* --------------------------------------------------------------------------
   TOOLTIP
   -------------------------------------------------------------------------- */

.egc-tooltip {
  position: absolute;
  right: calc(100% + 14px);
  top: 50%;
  transform: translate(10px, -50%);
  padding: 10px 18px;
  border-radius: 24px;
  background: #111827;
  color: #FFFFFF;
  font-family: var(--egc-font-head);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s var(--egc-ease), transform 0.25s var(--egc-ease), visibility 0.25s;
}

.egc-tooltip::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: #111827;
}

.egc-root:not(.is-open) .egc-launcher:hover ~ .egc-tooltip,
.egc-root:not(.is-open) .egc-launcher:focus-visible ~ .egc-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translate(0, -50%);
}

/* --------------------------------------------------------------------------
   PANEL
   -------------------------------------------------------------------------- */

.egc-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 18px);
  display: flex;
  flex-direction: column;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  overflow: hidden;
  border-radius: 18px;
  background: var(--egc-surface);
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.3), 0 8px 20px -8px rgba(0, 0, 0, 0.15);
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.28s var(--egc-ease), transform 0.28s var(--egc-ease), visibility 0.28s;
}

.egc-root.is-open .egc-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* --------------------------------------------------------------------------
   HEADER
   -------------------------------------------------------------------------- */

.egc-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding: 16px 16px 16px 18px;
  background: linear-gradient(135deg, var(--egc-red) 0%, var(--egc-red-dark) 100%);
  color: #FFFFFF;
}

.egc-avatar {
  position: relative;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--egc-font-head);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.egc-avatar-status {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--egc-red-dark);
  border-radius: 50%;
  background: var(--egc-green);
}

.egc-header-text {
  flex: 1;
  min-width: 0;
}

.egc-header-name {
  display: block;
  font-family: var(--egc-font-head);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.egc-header-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
}

.egc-header-sub .egc-dot {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--egc-green);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25);
}

.egc-mode-badge {
  flex-shrink: 0;
  padding: 3px 9px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-family: var(--egc-font-head);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Phase 3 flips this to the human-agent state */
.egc-mode-badge.is-human {
  border-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.28);
}

.egc-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.egc-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.3s var(--egc-ease);
}

.egc-icon-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
}

.egc-icon-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 1px;
}

.egc-icon-btn.is-spinning { transform: rotate(-360deg); }

/* Escritorio minimiza a la esquina (chevron); móvil cierra (X). */
.egc-close-mobile { display: none; }

@media (max-width: 767px) {
  .egc-close-desktop { display: none; }
  .egc-close-mobile { display: inline-block; }
}

/* --------------------------------------------------------------------------
   MESSAGE LIST
   -------------------------------------------------------------------------- */

.egc-body {
  flex: 1;
  min-height: 0;
  padding: 18px 16px 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--egc-canvas);
  scrollbar-width: thin;
  scrollbar-color: #D1D5DB transparent;
}

.egc-body::-webkit-scrollbar { width: 6px; }
.egc-body::-webkit-scrollbar-track { background: transparent; }
.egc-body::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }
.egc-body::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

.egc-daysep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 18px;
  color: var(--egc-ink-muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.egc-daysep::before,
.egc-daysep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--egc-line);
}

.egc-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 4px;
  animation: egcRowIn 0.32s var(--egc-ease) both;
}

.egc-row:last-child { margin-bottom: 0; }

/* Una fila que se repinta porque cambió su hora ya estaba en pantalla:
   animarla otra vez es exactamente el parpadeo que queríamos quitar. */
.egc-row.is-settled { animation: none; }

/* Extra breathing room between speakers */
.egc-row.is-group-start { margin-top: 14px; }
.egc-row.is-group-start:first-child { margin-top: 0; }

@keyframes egcRowIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.egc-row--customer { flex-direction: row-reverse; }

.egc-row-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--egc-red);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--egc-font-head);
  font-size: 0.68rem;
  font-weight: 700;
}

.egc-row-avatar.is-spacer { background: transparent; }

/* The timestamp lives inside the stack, so on rows that show one the avatar
   would sink to the timestamp's baseline. Lift it back to the bubble. */
.egc-row.has-meta .egc-row-avatar { margin-bottom: 21px; }

.egc-row-stack {
  display: flex;
  flex-direction: column;
  max-width: 76%;
}

.egc-row--customer .egc-row-stack { align-items: flex-end; }

.egc-bubble {
  padding: 10px 14px;
  font-size: 0.875rem;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.egc-row--agent .egc-bubble {
  border-radius: 16px;
  background: var(--egc-surface);
  color: var(--egc-ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 12px -6px rgba(0, 0, 0, 0.12);
}

.egc-row--customer .egc-bubble {
  border-radius: 16px;
  background: var(--egc-red);
  color: #FFFFFF;
}

/* The tail belongs to the last bubble of a run, not to every one of them. */
.egc-row--agent.has-meta .egc-bubble { border-bottom-left-radius: 4px; }
.egc-row--customer.has-meta .egc-bubble { border-bottom-right-radius: 4px; }

.egc-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 4px 2px 0;
  color: var(--egc-ink-muted);
  font-size: 0.69rem;
}

.egc-meta .egc-check { color: #34B7F1; font-size: 0.7rem; }

/* --------------------------------------------------------------------------
   QUOTE CARD (estimados de la calculadora, dentro de un mensaje del agente)
   -------------------------------------------------------------------------- */

.egc-quote {
  margin-top: 8px;
  width: min(300px, 100%);
  background: var(--egc-surface);
  border: 1px solid var(--egc-line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 4px 14px rgba(15, 41, 66, 0.06);
}
.egc-quote-top { font-size: 12.5px; font-weight: 600; color: var(--egc-ink-soft); margin-bottom: 8px; }
.egc-quote-top i { color: var(--egc-red); margin-right: 4px; }
.egc-plans { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.egc-plan { border: 1px solid var(--egc-line); border-radius: 10px; padding: 8px 9px; }
.egc-plan.is-featured { border-color: var(--egc-red); background: #eef5fb; }
.egc-plan-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.egc-plan-name { font-size: 12.5px; font-weight: 700; color: #0f2942; }
.egc-plan-tag {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: #FFFFFF; background: var(--egc-red); border-radius: 999px; padding: 1px 6px; white-space: nowrap;
}
.egc-plan-price { font-size: 18px; font-weight: 700; color: var(--egc-ink); margin-top: 2px; }
.egc-plan-price small { font-size: 11px; font-weight: 500; color: var(--egc-ink-muted); }
.egc-plan-meta { font-size: 10.5px; color: var(--egc-ink-muted); line-height: 1.35; }
.egc-plan-buy {
  display: block; margin-top: 6px; text-align: center;
  font-size: 11.5px; font-weight: 700; color: #FFFFFF; background: var(--egc-red);
  border-radius: 7px; padding: 5px 0; text-decoration: none;
}
.egc-plan-buy:hover { background: var(--egc-red-hover); color: #FFFFFF; }
.egc-plan:not(.is-featured) .egc-plan-buy {
  background: transparent; color: var(--egc-red); border: 1px solid var(--egc-line);
}
.egc-plan:not(.is-featured) .egc-plan-buy:hover { border-color: var(--egc-red); }
.egc-quote-note { font-size: 10.5px; color: var(--egc-ink-muted); margin: 8px 0 6px; line-height: 1.4; }
.egc-quote-cta {
  display: inline-flex; gap: 6px; align-items: center;
  font-size: 12.5px; font-weight: 600; color: var(--egc-red); text-decoration: none;
}
.egc-quote-cta:hover { color: var(--egc-red-hover); }

/* --------------------------------------------------------------------------
   TYPING INDICATOR
   -------------------------------------------------------------------------- */

.egc-typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 13px 14px;
  border-radius: 16px 16px 16px 4px;
  background: var(--egc-surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 12px -6px rgba(0, 0, 0, 0.12);
}

.egc-typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9CA3AF;
  animation: egcTypingDot 1.3s infinite ease-in-out;
}

.egc-typing-bubble span:nth-child(2) { animation-delay: 0.18s; }
.egc-typing-bubble span:nth-child(3) { animation-delay: 0.36s; }

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

/* --------------------------------------------------------------------------
   COMPOSER
   -------------------------------------------------------------------------- */

.egc-composer-wrap {
  flex-shrink: 0;
  padding: 12px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--egc-line);
  background: var(--egc-surface);
}

.egc-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--egc-line);
  border-radius: 24px;
  background: var(--egc-canvas);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.egc-composer:focus-within {
  border-color: var(--egc-red);
  box-shadow: 0 0 0 3px rgba(26, 111, 181, 0.12);
}

.egc-input {
  flex: 1;
  max-height: 88px;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--egc-ink);
  font-family: var(--egc-font-body);
  font-size: 0.875rem;
  line-height: 1.45;
  resize: none;
  outline: none;
  scrollbar-width: none;
}

.egc-input::-webkit-scrollbar { display: none; }
.egc-input::placeholder { color: var(--color-text-light, #9CA3AF); }

.egc-send {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--egc-red);
  color: #FFFFFF;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background-color 0.18s ease, transform 0.18s var(--egc-ease), opacity 0.18s ease;
}

.egc-send:hover:not(:disabled) { background: var(--egc-red-hover); transform: scale(1.06); }
.egc-send:disabled { opacity: 0.4; cursor: not-allowed; }
.egc-send:focus-visible { outline: 2px solid rgba(26, 111, 181, 0.4); outline-offset: 2px; }

.egc-disclaimer {
  margin-top: 8px;
  color: var(--color-text-light, #9CA3AF);
  font-size: 0.66rem;
  text-align: center;
}

/* --------------------------------------------------------------------------
   RESPONSIVE - full screen below 768px
   -------------------------------------------------------------------------- */

@media (max-width: 767px) {
  .egc-root {
    bottom: 20px;
    right: 20px;
  }

  .egc-launcher { width: 56px; height: 56px; }
  .egc-launcher-icon { font-size: 1.45rem; }
  .egc-tooltip { display: none; }

  /*
   * Pantalla completa, siguiendo el VIEWPORT VISUAL.
   *
   * En un móvil no basta con inset:0. Cuando se abre el teclado, iOS encoge el
   * viewport visual pero deja igual el de layout, así que un panel anclado al
   * layout queda por detrás del teclado: el cuerpo se ve vacío y el composer
   * flota en mitad de la nada.
   *
   * Por eso el alto y la posición salen de dos variables que chat-widget.js
   * mantiene al día desde window.visualViewport. El 100dvh es el respaldo para
   * navegadores sin esa API.
   */
  .egc-panel {
    position: fixed;
    top: var(--egc-vv-top, 0px);
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    height: var(--egc-vv-height, 100dvh);
    max-height: none;
    border-radius: 0;
    transform: translateY(16px);
    transform-origin: center;
  }

  .egc-root.is-open .egc-panel { transform: translateY(0); }

  /* The sheet covers the launcher's corner, so hide it while open.
     The chevron in the panel header closes it. */
  .egc-root.is-open .egc-launcher,
  .egc-root.is-open .egc-pulse-ring { display: none; }
  .egc-row-stack { max-width: 82%; }
  .egc-quote { width: 100%; }

  /* Con el teclado abierto cada píxel del cuerpo cuenta. */
  .egc-header { padding: 12px 8px 12px 14px; }
  .egc-avatar { width: 36px; height: 36px; font-size: 0.85rem; }
  .egc-body { padding: 14px 12px 6px; }
  .egc-composer-wrap { padding: 10px 12px; }
  .egc-disclaimer { display: none; }

  /* La X de cerrar, más grande de lo que pide el diseño: en un móvil es el
     único modo de salir y fallar el toque es frustrante. */
  .egc-icon-btn { width: 38px; height: 38px; font-size: 1rem; }

  /* The panel already clears the home indicator, so don't inset twice */
  .egc-composer-wrap { padding-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .egc-root *,
  .egc-root *::before,
  .egc-root *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
