/* ============================================================
 * POPUP WHATSAPP — «¿Tienes un proyecto que programar?»
 * Tarjeta en la esquina (hoja inferior en celular). wa-popup.js arma la
 * animación con clases en orden: is-spark → is-plan → is-glass + is-sweep
 * → is-content → is-alive; is-leaving al cerrar. Con movimiento reducido
 * solo se usa is-content (fundido).
 * ============================================================ */

.wa-pop {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1500; /* bajo el header (2002) y el menú lateral (2000) */
  width: min(400px, calc(100vw - 32px));
}

.wa-pop[hidden] {
  display: none;
}

.wa-pop__card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 26px 24px 22px;
  border: 1px solid transparent;
  border-radius: 22px;
  background: rgba(13, 15, 15, 0);
  color: var(--color-text-primary);
  transition: background 0.5s ease, border-color 0.5s ease, box-shadow 0.6s ease;
}

.wa-pop.is-glass .wa-pop__card {
  background: linear-gradient(160deg, rgba(26, 29, 29, 0.94), rgba(9, 11, 11, 0.96));
  border-color: rgba(255, 255, 255, 0.06);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(244, 216, 0, 0.08), 0 0 60px rgba(244, 216, 0, 0.1);
  backdrop-filter: blur(14px);
}

/* Grilla de plano técnico que queda tenue al rellenarse */
.wa-pop__card::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0;
  transition: opacity 0.5s ease;
  background:
    repeating-linear-gradient(90deg, rgba(244, 216, 0, 0.1) 0 1px, transparent 1px 22px),
    repeating-linear-gradient(0deg, rgba(244, 216, 0, 0.1) 0 1px, transparent 1px 22px);
}

.wa-pop.is-plan .wa-pop__card::before { opacity: 1; }
.wa-pop.is-glass .wa-pop__card::before { opacity: 0.18; }

/* Barrido de luz */
.wa-pop__card::after {
  content: '';
  position: absolute;
  top: -50%;
  bottom: -50%;
  left: -60%;
  z-index: -1;
  width: 40%;
  opacity: 0;
  transform: rotate(18deg);
  background: linear-gradient(90deg, transparent, rgba(244, 216, 0, 0.18), rgba(255, 255, 255, 0.1), transparent);
}

.wa-pop.is-sweep .wa-pop__card::after {
  animation: wa-pop-sweep 1s cubic-bezier(0.3, 0.6, 0.2, 1) forwards;
}

@keyframes wa-pop-sweep {
  0% { left: -60%; opacity: 1; }
  100% { left: 130%; opacity: 0; }
}

/* Contorno que se dibuja */
.wa-pop__trace {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.wa-pop__trace rect {
  fill: none;
  stroke: var(--color-accent-primary);
  stroke-width: 1.6;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: opacity 0.6s ease 0.2s;
}

.wa-pop.is-plan .wa-pop__trace rect {
  animation: wa-pop-trace 0.75s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

.wa-pop.is-glass .wa-pop__trace rect {
  opacity: 0;
}

@keyframes wa-pop-trace {
  to { stroke-dashoffset: 0; }
}

/* Punto de luz de origen */
.wa-pop__spark {
  position: absolute;
  right: -5px;
  bottom: -5px;
  z-index: 3;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-accent-primary);
  box-shadow: 0 0 18px 4px rgba(244, 216, 0, 0.7);
  transform: scale(0);
}

.wa-pop.is-spark .wa-pop__spark {
  animation: wa-pop-spark 0.9s ease forwards;
}

@keyframes wa-pop-spark {
  0% { transform: scale(0); }
  25% { transform: scale(1.6); }
  70% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.4); opacity: 0; }
}

/* Contenido escalonado */
.wa-pop__in {
  opacity: 0;
  transform: translateY(12px);
  filter: blur(4px);
  transition: opacity 0.5s ease, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.5s ease;
}

.wa-pop.is-content .wa-pop__in {
  opacity: 1;
  transform: none;
  filter: none;
}

.wa-pop.is-content .wa-pop__title { transition-delay: 0.08s; }
.wa-pop.is-content .wa-pop__text { transition-delay: 0.16s; }
.wa-pop.is-content .wa-pop__cta { transition-delay: 0.24s; }
.wa-pop.is-content .wa-pop__micro { transition-delay: 0.32s; }

.wa-pop__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: rgba(5, 7, 7, 0.6);
  color: var(--color-text-secondary);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.4s ease 0.6s, color 0.2s ease, border-color 0.2s ease;
}

.wa-pop.is-content .wa-pop__close { opacity: 1; }

.wa-pop__close:hover,
.wa-pop__close:focus-visible {
  color: var(--color-text-primary);
  border-color: var(--color-plomo-oscuro);
}

.wa-pop__prompt {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 1.2em;
  margin: 0;
  font-family: var(--font-family-mono);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--color-accent-primary);
}

.wa-pop__cursor {
  width: 7px;
  height: 14px;
  background: var(--color-accent-primary);
  animation: wa-pop-blink 1s steps(1) infinite;
}

@keyframes wa-pop-blink {
  50% { opacity: 0; }
}

.wa-pop__title {
  margin: 12px 0 8px;
  padding-right: 28px;
  font-family: var(--font-family-headings);
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.15;
}

.wa-pop__title em {
  font-style: normal;
  color: var(--color-accent-primary);
}

.wa-pop__text {
  margin: 0 0 18px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--color-text-secondary);
}

.wa-pop__cta {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--color-accent-primary);
  color: var(--color-primario);
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 10px 30px rgba(244, 216, 0, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.wa-pop__cta:hover,
.wa-pop__cta:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(244, 216, 0, 0.35);
  color: var(--color-primario);
}

.wa-pop__cta svg {
  flex: none;
  width: 20px;
  height: 20px;
}

.wa-pop__cta::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -40%;
  width: 30%;
  transform: skewX(-20deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
}

.wa-pop.is-alive .wa-pop__cta::after {
  animation: wa-pop-shine 3.2s ease-in-out 0.4s infinite;
}

@keyframes wa-pop-shine {
  0%, 70% { left: -40%; }
  100% { left: 130%; }
}

.wa-pop__micro {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 0;
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.wa-pop__micro i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #25D366; /* verde WhatsApp: solo en este punto */
}

.wa-pop.is-alive .wa-pop__micro i {
  animation: wa-pop-ping 1.8s ease-out infinite;
}

@keyframes wa-pop-ping {
  0% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.55); }
  100% { box-shadow: 0 0 0 9px rgba(37, 211, 102, 0); }
}

/* Salida: se repliega hacia la esquina */
.wa-pop.is-leaving {
  opacity: 0;
  transform: scale(0.6) translate(20%, 20%);
  transform-origin: 100% 100%;
  transition: transform 0.45s cubic-bezier(0.6, 0, 0.8, 0.2), opacity 0.45s ease;
}

@media (max-width: 640px) {
  .wa-pop {
    right: 12px;
    left: 12px;
    bottom: 12px;
    width: auto;
  }

  .wa-pop__title {
    font-size: 1.35rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wa-pop__in,
  .wa-pop__close,
  .wa-pop.is-leaving {
    transform: none;
    filter: none;
    transition: opacity 0.3s ease;
  }

  .wa-pop__card {
    background: linear-gradient(160deg, rgba(26, 29, 29, 0.94), rgba(9, 11, 11, 0.96));
    border-color: rgba(255, 255, 255, 0.06);
  }

  .wa-pop__cursor,
  .wa-pop.is-alive .wa-pop__cta::after,
  .wa-pop.is-alive .wa-pop__micro i {
    animation: none;
  }
}
