/* ══════════════════════════════════════════════
   POP-UP DE BIENVENIDA · "ESCÁNER"
   Se abre en cada carga de página (ver popup.js).
   Paleta: navy / cyan / verde de marca (sin rosa).
══════════════════════════════════════════════ */

@property --pop-angle {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}

.cpd-pop {
  --pop-navy: #007E9A;
  --pop-cyan: #00B3BD;
  --pop-cyan-soft: #5fd4db;
  --pop-green: #83bf4c;
  --pop-ink: #03161e;
  --pop-radius: 28px;

  position: fixed;
  inset: 0;
  z-index: 100000;
  display: grid;
  place-items: center;
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  color: #fff;
}

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

/* ── Fondo ─────────────────────────────────── */
.cpd-pop__backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(0, 126, 154, 0.35), transparent 60%),
    rgba(2, 12, 18, 0.78);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  opacity: 0;
  transition: opacity 0.6s ease;
}

.cpd-pop.is-open .cpd-pop__backdrop {
  opacity: 1;
}

.cpd-pop.is-closing .cpd-pop__backdrop {
  opacity: 0;
  transition-delay: 0.35s;
}

/* ── Haz de luz que "despliega" la tarjeta ── */
.cpd-pop__beam {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(940px, calc(100vw - 32px));
  height: 2px;
  transform: translate(-50%, -50%) scaleX(0);
  background: linear-gradient(90deg, transparent, var(--pop-cyan) 20%, #fff 50%, var(--pop-green) 80%, transparent);
  box-shadow: 0 0 18px 3px rgba(0, 179, 189, 0.8), 0 0 60px 8px rgba(0, 179, 189, 0.35);
  border-radius: 2px;
  pointer-events: none;
  opacity: 0;
}

.cpd-pop.is-open .cpd-pop__beam {
  animation: popBeam 1.1s cubic-bezier(.7, 0, .2, 1) both;
}

.cpd-pop.is-closing .cpd-pop__beam {
  animation: popBeamOut 0.7s cubic-bezier(.7, 0, .2, 1) both;
}

@keyframes popBeam {
  0% { transform: translate(-50%, -50%) scaleX(0); opacity: 1; }
  40% { transform: translate(-50%, -50%) scaleX(1); opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scaleX(1); opacity: 0; }
}

@keyframes popBeamOut {
  0%, 45% { transform: translate(-50%, -50%) scaleX(1); opacity: 0; }
  55% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scaleX(0); opacity: 1; }
}

/* ── Escenario + tarjeta ───────────────────── */
.cpd-pop__stage {
  position: relative;
  width: 100%;
  max-width: 940px;
  padding: 16px;
  perspective: 1400px;
}

.cpd-pop__card {
  --rx: 0deg;
  --ry: 0deg;
  --mx: 50%;
  --my: 50%;

  position: relative;
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  border-radius: var(--pop-radius);
  background:
    radial-gradient(120% 90% at 0% 0%, rgba(0, 179, 189, 0.16), transparent 55%),
    radial-gradient(90% 80% at 100% 100%, rgba(131, 191, 76, 0.10), transparent 60%),
    linear-gradient(150deg, #052a36 0%, #04202a 45%, var(--pop-ink) 100%);
  box-shadow:
    0 40px 120px -20px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  overflow: hidden;
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transform-style: preserve-3d;
  transition: transform 0.25s ease-out;
  clip-path: inset(49.6% 0 49.6% 0 round var(--pop-radius));
  max-height: calc(100dvh - 32px);
}

.cpd-pop.is-open .cpd-pop__card {
  animation: popUnfold 0.9s cubic-bezier(.77, 0, .18, 1) 0.4s both;
}

.cpd-pop.is-closing .cpd-pop__card {
  animation: popFold 0.45s cubic-bezier(.7, 0, .3, 1) both;
}

@keyframes popUnfold {
  0% { clip-path: inset(49.6% 0 49.6% 0 round var(--pop-radius)); filter: brightness(2.2); }
  60% { filter: brightness(1.15); }
  100% { clip-path: inset(0 0 0 0 round var(--pop-radius)); filter: brightness(1); }
}

@keyframes popFold {
  0% { clip-path: inset(0 0 0 0 round var(--pop-radius)); filter: brightness(1); }
  100% { clip-path: inset(49.6% 0 49.6% 0 round var(--pop-radius)); filter: brightness(2.2); }
}

/* Borde de luz giratorio */
.cpd-pop__border {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.5px;
  background: conic-gradient(from var(--pop-angle),
      transparent 0 55%,
      var(--pop-cyan) 70%,
      var(--pop-green) 82%,
      transparent 95%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: popSpin 6s linear infinite;
  pointer-events: none;
  z-index: 5;
}

@keyframes popSpin {
  to { --pop-angle: 360deg; }
}

/* Luz que sigue al cursor */
.cpd-pop__spot {
  position: absolute;
  inset: 0;
  background: radial-gradient(420px circle at var(--mx) var(--my), rgba(0, 179, 189, 0.16), transparent 60%);
  pointer-events: none;
  z-index: 1;
}

/* Trama de fondo decorativa (fuera del flujo del grid) */
.cpd-pop__grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 36px 36px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

/* ── Botón cerrar ──────────────────────────── */
.cpd-pop__close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
  transition: background 0.25s, transform 0.4s cubic-bezier(.3, 1.6, .5, 1), border-color 0.25s;
}

.cpd-pop__close svg {
  width: 18px;
  height: 18px;
}

.cpd-pop__close:hover {
  background: rgba(0, 179, 189, 0.25);
  border-color: var(--pop-cyan);
  transform: rotate(90deg);
}

.cpd-pop__close:focus-visible,
.cpd-pop__btn:focus-visible {
  outline: 2px solid var(--pop-cyan-soft);
  outline-offset: 3px;
}

/* ══════════════════════════════════════════════
   PANEL VISUAL · MAMÓGRAFO
══════════════════════════════════════════════ */
.cpd-pop__visual {
  position: relative;
  min-height: 440px;
  display: grid;
  place-items: center;
  isolation: isolate;
  z-index: 2;
}

/* Equipo: silueta de rayos X + imagen real revelada por escaneo */
.cpd-pop__device {
  position: relative;
  width: min(84%, 340px);
  aspect-ratio: 377 / 321;
  animation: popFloat 6s ease-in-out infinite;
}

.cpd-pop__device img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.cpd-pop__xray {
  filter: grayscale(1) invert(1) contrast(1.8) sepia(1) hue-rotate(140deg) saturate(5) brightness(1.3) drop-shadow(0 0 1px #5fd4db) drop-shadow(0 0 8px rgba(0, 179, 189, 0.9));
  opacity: 0;
  mix-blend-mode: screen;
}

.cpd-pop__real {
  clip-path: inset(0 0 100% 0);
  filter: drop-shadow(0 24px 30px rgba(0, 0, 0, 0.55));
}

.cpd-pop__device-scan {
  position: absolute;
  left: -8%;
  right: -8%;
  top: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--pop-cyan-soft), #fff, var(--pop-cyan-soft), transparent);
  box-shadow: 0 0 16px 4px rgba(0, 179, 189, 0.7);
  border-radius: 3px;
  opacity: 0;
}

.cpd-pop.is-open .cpd-pop__xray {
  animation: popXray 2.6s ease 0.9s both;
}

.cpd-pop.is-open .cpd-pop__real {
  animation: popReveal 1.6s cubic-bezier(.6, 0, .3, 1) 1.5s both;
}

.cpd-pop.is-open .cpd-pop__device-scan {
  animation: popDeviceScan 1.6s cubic-bezier(.6, 0, .3, 1) 1.5s both;
}

@keyframes popXray {
  0% { opacity: 0; }
  20% { opacity: 0.95; }
  65% { opacity: 0.6; }
  100% { opacity: 0; }
}

@keyframes popReveal {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(0 0 0 0); }
}

@keyframes popDeviceScan {
  0% { top: 0; opacity: 1; }
  92% { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

@keyframes popFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* Sombra de "piso" holográfica */
.cpd-pop__device::after {
  content: '';
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -14px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 179, 189, 0.45), transparent 70%);
  filter: blur(4px);
  z-index: -1;
}

@keyframes popPing {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* ══════════════════════════════════════════════
   CONTENIDO
══════════════════════════════════════════════ */
.cpd-pop__content {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.15rem;
  padding: 3.25rem 3rem 4.5rem 1rem;
}

.pop-item {
  opacity: 0;
}

.cpd-pop.is-open .pop-item {
  animation: popItem 0.7s cubic-bezier(.2, .8, .2, 1) calc(1.1s + var(--i, 0) * 0.12s) both;
}

@keyframes popItem {
  from { opacity: 0; transform: translateY(16px); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}

.cpd-pop__eyebrow {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.9rem 0.4rem 0.7rem;
  border-radius: 999px;
  background: rgba(0, 179, 189, 0.12);
  border: 1px solid rgba(0, 179, 189, 0.35);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--pop-cyan-soft);
}

.cpd-pop__live {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pop-green);
}

.cpd-pop__live::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid var(--pop-green);
  animation: popPing 1.8s ease-out infinite;
}

.cpd-pop__title {
  font-size: clamp(2rem, 3.6vw, 2.9rem);
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.cpd-pop__title em {
  font-style: normal;
  background: linear-gradient(90deg, var(--pop-cyan-soft), var(--pop-green));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.cpd-pop__desc {
  font-size: 1.02rem;
  line-height: 1.6;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.78);
  max-width: 44ch;
}

.cpd-pop__desc strong {
  color: #fff;
  font-weight: 600;
}

/* Chips de características */
.cpd-pop__chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.cpd-pop__chips li {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.8rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
}

.cpd-pop__chips svg {
  width: 16px;
  height: 16px;
  color: var(--pop-cyan-soft);
  flex-shrink: 0;
}

/* Botones */
.cpd-pop__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.35rem;
}

.cpd-pop__btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.95rem 1.6rem;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.cpd-pop__btn svg {
  width: 18px;
  height: 18px;
  transition: transform 0.25s ease;
}

.cpd-pop__btn--primary {
  color: #fff;
  background: linear-gradient(135deg, var(--pop-cyan), var(--pop-navy));
  box-shadow: 0 10px 30px -8px rgba(0, 179, 189, 0.7);
  border: none;
}

/* Destello que recorre el botón principal */
.cpd-pop__btn--primary::before {
  content: '';
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: skewX(-20deg);
  animation: popShine 3.5s ease-in-out 2.5s infinite;
}

@keyframes popShine {
  0% { left: -60%; }
  35%, 100% { left: 130%; }
}

.cpd-pop__btn--primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px -8px rgba(0, 179, 189, 0.85);
}

.cpd-pop__btn--primary:hover svg {
  transform: translateX(4px);
}

.cpd-pop__btn--ghost {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.cpd-pop__btn--ghost:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--pop-cyan-soft);
}

/* ── Línea de electrocardiograma ───────────── */
.cpd-pop__ecg {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 56px;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
}

.cpd-pop.is-open .cpd-pop__ecg {
  opacity: 0.7;
  transition: opacity 1s ease 1.6s;
}

/* ══════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════ */
@media (max-width: 780px) {
  /* El popup puede crecer más que el viewport para que el texto
     entre grande: se scrollea el overlay, no se achica la tipografía. */
  .cpd-pop {
    align-items: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 28px 0;
  }

  .cpd-pop__card {
    grid-template-columns: minmax(120px, 38%) 1fr;
    grid-template-areas:
      "visual eyebrow"
      "visual title"
      "visual desc"
      "visual chips"
      "actions actions";
    max-height: none;
    overflow: visible;
  }

  /* Deja que eyebrow/título/desc/chips/acciones participen
     directamente del grid de la tarjeta (para que las acciones
     puedan ocupar el ancho completo debajo de la imagen). */
  .cpd-pop__content {
    display: contents;
  }

  .cpd-pop__visual {
    grid-area: visual;
    min-height: 0;
    height: auto;
    align-self: stretch;
  }

  .cpd-pop__device {
    width: min(85%, 190px);
  }

  .cpd-pop__eyebrow {
    grid-area: eyebrow;
    margin: 1.5rem 1.25rem 0 0.9rem;
    padding: 0.35rem 0.8rem 0.35rem 0.6rem;
    font-size: 0.72rem;
  }

  .cpd-pop__title {
    grid-area: title;
    margin: 0 1.25rem 0 0.9rem;
    font-size: clamp(1.5rem, 6.5vw, 2rem);
  }

  .cpd-pop__desc {
    grid-area: desc;
    margin: 0 1.25rem 0 0.9rem;
    font-size: 1rem;
    line-height: 1.55;
    max-width: none;
  }

  .cpd-pop__chips {
    grid-area: chips;
    margin: 0 1.25rem 0 0.9rem;
    gap: 0.5rem;
  }

  .cpd-pop__ecg {
    display: none;
  }

  .cpd-pop__actions {
    grid-area: actions;
    flex-wrap: nowrap;
    gap: 0.6rem;
    margin: 1.35rem 1.25rem 1.5rem 0.9rem;
  }

  .cpd-pop__btn {
    flex: 1 1 0;
    padding: 0.9rem 1rem;
    font-size: 0.95rem;
    white-space: nowrap;
  }

  .cpd-pop__close {
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
  }

  .cpd-pop__close svg {
    width: 15px;
    height: 15px;
  }
}

@media (max-width: 400px) {
  .cpd-pop__btn--primary svg {
    display: none;
  }
}

@media (max-width: 360px) {
  .cpd-pop__card {
    grid-template-columns: minmax(96px, 34%) 1fr;
  }

  .cpd-pop__device {
    width: min(85%, 130px);
  }

  .cpd-pop__chips li:nth-child(3) {
    display: none;
  }

  .cpd-pop__btn {
    padding: 0.85rem 0.7rem;
    font-size: 0.88rem;
  }
}

/* ── Movimiento reducido ───────────────────── */
@media (prefers-reduced-motion: reduce) {
  .cpd-pop *,
  .cpd-pop *::before,
  .cpd-pop *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .cpd-pop.is-open .cpd-pop__card,
  .cpd-pop.is-open .cpd-pop__real {
    clip-path: none;
  }

  .cpd-pop.is-open .pop-item {
    opacity: 1;
    transform: none;
  }

  .cpd-pop__beam,
  .cpd-pop__device-scan,
  .cpd-pop__xray {
    display: none;
  }
}
