/* =========================================================================
   ASISTENTE EMSI (chat que captura datos y los envía a WhatsApp)
   Usa los tokens de marca de styles.css (--accent, --text, fuentes).
   ========================================================================= */

/* El avatar existente ahora es un botón: se quita el estilo nativo */
button.chat-widget__link {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
}
button.chat-widget__link:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 16px; }
.chat-widget--chat-open { display: none; }

.ec {
  --ec-wa: #128C4A;
  --ec-line: rgba(26, 23, 20, .1);

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1001;
  width: 380px;
  height: min(620px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  background: var(--bg-white, #fff);
  border-radius: 22px;
  box-shadow: 0 28px 70px rgba(26, 23, 20, .28);
  overflow: hidden;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  animation: ec-in .22s ease-out;
}
.ec[hidden] { display: none; }
.ec *, .ec *::before, .ec *::after { box-sizing: border-box; }
.ec button, .ec input { font-family: inherit; }
.ec :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Encabezado */
.ec-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px 14px 14px;
  background: var(--text);
  color: #fff;
}
.ec-head__avatar {
  width: 46px;
  height: 46px;
  flex: none;
  object-fit: contain;
  background: rgba(255, 255, 255, .08);
  border-radius: 50%;
}
.ec-head__text { flex: 1; min-width: 0; }
.ec-head__text strong {
  display: block;
  font-family: var(--font-heading);
  font-size: 17px;
  letter-spacing: -.01em;
}
.ec-head__text span {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: rgba(255, 255, 255, .7);
}
.ec-head__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #3DD07B;
  box-shadow: 0 0 0 3px rgba(61, 208, 123, .2);
}
.ec-close {
  width: 36px; height: 36px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s ease;
}
.ec-close:hover { background: rgba(255, 255, 255, .12); }

/* Conversación */
.ec-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-cream);
}
.ec-msg {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 18px;
  white-space: pre-line;
  overflow-wrap: anywhere;
  animation: ec-in .18s ease-out;
}
.ec-msg--bot {
  align-self: flex-start;
  background: var(--bg-white, #fff);
  border-bottom-left-radius: 5px;
  box-shadow: 0 2px 8px rgba(26, 23, 20, .05);
}
.ec-msg--user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.ec-msg a { color: var(--accent); font-weight: 700; }

.ec-typing { display: flex; gap: 4px; padding: 15px; }
.ec-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: ec-dot 1s infinite ease-in-out;
}
.ec-typing span:nth-child(2) { animation-delay: .15s; }
.ec-typing span:nth-child(3) { animation-delay: .3s; }

/* Opciones */
.ec-chips { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 2px; }
.ec-chip {
  padding: 9px 15px;
  border: 1.5px solid rgba(26, 23, 20, .18);
  border-radius: 999px;
  background: var(--bg-white, #fff);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.ec-chip:hover { border-color: var(--accent); color: var(--accent); }
.ec-chip--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.ec-chip--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.ec-chip--wa { background: var(--ec-wa); border-color: var(--ec-wa); color: #fff; }
.ec-chip--wa:hover { background: #0E7A3F; border-color: #0E7A3F; color: #fff; }

/* Resumen de datos */
.ec-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 16px;
  margin: 0;
  font-size: 14px;
}
.ec-card dt {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-top: 2px;
}
.ec-card dd { margin: 0; font-weight: 600; }

/* Captura de texto */
.ec-form {
  display: flex;
  gap: 8px;
  padding: 12px 12px 10px;
  border-top: 1px solid var(--ec-line);
  background: var(--bg-white, #fff);
}
.ec-form[hidden] { display: none; }
.ec-input {
  flex: 1;
  min-width: 0;
  padding: 12px 15px;
  border: 1.5px solid var(--ec-line);
  border-radius: 999px;
  font-size: 16px; /* evita el zoom automático en iOS */
  color: var(--text);
  background: var(--bg-cream);
}
.ec-input:focus { outline: none; border-color: var(--accent); background: #fff; }
.ec-input[aria-invalid="true"] { border-color: var(--accent); }
.ec-send {
  width: 46px; height: 46px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  transition: background .15s ease;
}
.ec-send:hover { background: var(--accent-hover); }
.ec-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.ec-error {
  margin: 0;
  padding: 0 18px 8px;
  font-size: 13px;
  color: var(--accent);
  background: var(--bg-white, #fff);
}
.ec-error[hidden] { display: none; }

.ec-direct {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 16px 13px;
  border-top: 1px solid var(--ec-line);
  background: var(--bg-white, #fff);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  transition: color .15s ease;
}
.ec-direct:hover { color: var(--ec-wa); }
.ec-direct svg { font-size: 15px; color: var(--ec-wa); }
.ec-close svg, .ec-send svg { display: block; margin: auto; }
.chat-widget__close svg { display: block; }

/* Móvil: el panel ocupa la parte inferior de la pantalla */
@media (max-width: 575.98px) {
  .ec {
    left: 0; right: 0; bottom: 0;
    width: auto;
    height: 88vh;
    height: 88dvh;
    border-radius: 22px 22px 0 0;
  }
}

@keyframes ec-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ec-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

@media (prefers-reduced-motion: reduce) {
  .ec, .ec * { animation: none !important; transition: none !important; }
}
