:root {
  --teal: #1ea4b5;
  --teal-dark: #136f7a;
  --teal-soft: #e3f5f8;
  --blue: #1d5fd8;
  --ink: #16343a;
  --muted: #5e7a80;
  --bg: #f3f7f8;
  --card: #ffffff;
  --line: #d9e6e9;
  --pink: #ff2fb3;
  --violet: #7a3cff;
  --sky: #2bb1ff;
  --green: #30d158;
  --orange: #ffb020;
  --rainbow: linear-gradient(90deg, var(--pink), var(--violet), var(--sky), var(--green), var(--orange), var(--pink));
  --radius: 20px;
  --shadow: 0 8px 28px rgba(22, 52, 58, .08);
  --header-h: 86px;
  --foot-h: 36px;
  --gap: 18px;
  /* alto disponible para el contenido en escritorio */
  --avail-h: calc(100dvh - var(--header-h) - var(--foot-h) - var(--gap) * 2);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Poppins", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
button { font-family: inherit; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 18px;
  height: var(--header-h);
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.top::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -4px;
  height: 4px;
  background: var(--rainbow);
  background-size: 200% 100%;
  animation: slide 14s linear infinite;
}
@keyframes slide { to { background-position: 200% 0; } }
.brand img { height: 64px; width: auto; display: block; }
.top-text { flex: 1; min-width: 0; }
.top-text h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: -.01em;
  line-height: 1.1;
}
.top-text .hl { color: var(--teal); }
.top-text p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.badge {
  font-size: .72rem;
  font-weight: 700;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border: 1px solid #bfe4ea;
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
}

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 20px;
  width: min(1500px, 100%);
  height: calc(var(--avail-h) + var(--gap) * 2);
  margin: 0 auto;
  padding: var(--gap) 20px;
  align-items: stretch;
}

/* ---------- Stage (avatar) ---------- */
.stage-col {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: var(--avail-h);
}
.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  /* lo más grande posible sin salirse ni de ancho ni de alto */
  width: min(100%, calc(var(--avail-h) * 16 / 9));
  margin: 0 auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  isolation: isolate;
}
.stage::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: var(--radius);
  padding: 3px;
  background: var(--rainbow);
  background-size: 300% 100%;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: .55;
  pointer-events: none;
  z-index: 6;
  transition: opacity .4s;
}
.stage.talking::after { opacity: 1; animation: slide 6s linear infinite; }

.stage .idle,
.stage .talk {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  background: #fff;
  pointer-events: none;
  display: block;
}
.stage .idle {
  transform-origin: 50% 100%;
  animation: breathe 4.6s ease-in-out infinite;
  transition: opacity .2s ease;
}
.stage.talking .idle {
  opacity: 0;
  visibility: hidden;
  animation: none;
}
@keyframes breathe {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.012) translateY(-1px); }
}
.stage .talk {
  opacity: 0;
  transition: opacity .35s ease;
}
.stage.talking .talk { opacity: 1; }
.stage .talk::-webkit-media-controls { display: none !important; }

/* Pregunta en pantalla */
.q-card {
  position: absolute; inset: 0;
  z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  padding: 6% 8%;
  text-align: center;
  color: #fff;
  background: linear-gradient(135deg, #1ea4b5 0%, #1a8fc4 45%, #1d5fd8 100%);
  animation: fade .4s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.q-step {
  font-size: .8rem; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  opacity: .9;
  padding: 5px 12px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 999px;
}
.q-text {
  font-size: clamp(1.4rem, 3.6vw, 2.8rem);
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: -.01em;
  text-shadow: 0 4px 24px rgba(0, 40, 80, .35);
  text-wrap: balance;
  max-width: 18ch;
}
.q-sub {
  font-size: clamp(.9rem, 1.6vw, 1.1rem);
  font-weight: 500;
  max-width: 36ch;
  opacity: .95;
}
.ask-btn {
  margin-top: 6px;
  border: 0; border-radius: 999px;
  background: #fff; color: var(--teal-dark);
  font-size: clamp(1rem, 1.8vw, 1.25rem); font-weight: 900; letter-spacing: .08em;
  padding: 14px 40px;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(0, 30, 70, .35);
  animation: nudge 2.2s ease-in-out infinite;
  transition: transform .15s, background .15s;
}
.ask-btn:hover { background: #eaf7f9; transform: scale(1.04); }
.ask-btn:active { transform: scale(.98); }
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.skip {
  border: 0; background: transparent;
  color: rgba(255,255,255,.85);
  font-size: .8rem; font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer;
}
.skip:hover { color: #fff; }

.status {
  position: absolute;
  left: 14px; bottom: 14px;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.9);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem; font-weight: 700;
  backdrop-filter: blur(6px);
  z-index: 4;
}
.status .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green);
  animation: ping 2.2s infinite;
}
.stage.talking .status { color: var(--teal-dark); }
.stage.talking .status .dot { background: var(--teal); animation: ping .9s infinite; }
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(30,164,181,.55); }
  100% { box-shadow: 0 0 0 9px rgba(30,164,181,0); }
}

.gate {
  position: absolute; inset: 0;
  z-index: 5;
  border: 0;
  background: linear-gradient(to top, rgba(255,255,255,.92) 0%, rgba(255,255,255,.35) 45%, rgba(255,255,255,0) 70%);
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 7%;
  cursor: pointer;
  transition: opacity .35s;
}
.gate.hidden { opacity: 0; pointer-events: none; }
.gate-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 26px;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  box-shadow: 0 12px 32px rgba(30,164,181,.45);
  animation: nudge 2.4s ease-in-out infinite;
}
.gate-title { font-weight: 900; font-size: 1.1rem; line-height: 1.1; }
.gate-sub { font-weight: 500; font-size: .82rem; opacity: .95; }

/* ---------- Panel: formulario siempre visible ---------- */
.panel {
  height: var(--avail-h);
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.panel .share { margin-top: auto; }
.panel-head h2 { margin: 0; font-size: 1.15rem; font-weight: 900; }
.panel-head p { margin: 4px 0 0; font-size: .86rem; color: var(--muted); line-height: 1.4; }

.contact { display: flex; flex-direction: column; gap: 10px; }
.contact label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: .76rem; font-weight: 700; color: var(--muted);
}
.contact input[type="text"], .contact input[type="tel"] {
  font: inherit; font-size: 1rem; font-weight: 500; color: var(--ink);
  padding: 12px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff; outline: none;
}
.contact input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(30,164,181,.18); }
.contact .consent {
  flex-direction: row; align-items: flex-start; gap: 8px;
  font-weight: 500; font-size: .76rem; line-height: 1.35;
}
.contact .consent input { margin-top: 2px; accent-color: var(--teal); width: 16px; height: 16px; }
.contact .consent a { color: var(--teal-dark); }
.contact .err { margin: 0; color: #b42318; font-size: .78rem; font-weight: 700; }
.contact button[type="submit"] {
  border: 0; border-radius: 999px;
  background: var(--teal); color: #fff;
  font-size: 1rem; font-weight: 700;
  padding: 14px 16px; cursor: pointer;
  box-shadow: 0 8px 20px rgba(30,164,181,.3);
}
.contact button[type="submit"]:hover { background: var(--teal-dark); }
.contact button:disabled { opacity: .6; cursor: default; }
.sent {
  padding: 18px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, #1ea4b5, #1d5fd8);
  color: #fff;
  display: flex; flex-direction: column; gap: 6px;
  animation: pop .3s ease-out both;
}
.sent strong { font-size: 1.1rem; font-weight: 900; }
.sent span { font-size: .88rem; opacity: .95; line-height: 1.4; }
@keyframes pop {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.panel-note { margin: 0; font-size: .72rem; color: var(--muted); line-height: 1.4; }

/* Compartir */
.share { border-top: 1px solid var(--line); padding-top: 12px; }
.share h3 { margin: 0 0 8px; font-size: .86rem; font-weight: 700; color: var(--ink); }
.share-row { display: flex; gap: 8px; flex-wrap: wrap; }
.sh {
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; cursor: pointer;
  text-decoration: none;
  transition: transform .15s, filter .15s;
}
.sh svg { width: 22px; height: 22px; }
.sh:hover { transform: translateY(-2px); filter: brightness(1.08); }
.sh.wa { background: #25d366; }
.sh.fb { background: #1877f2; }
.sh.ig { background: linear-gradient(45deg, #f9ce34, #ee2a7b 50%, #6228d7); }
.sh.x { background: #111; }
.sh.copy, .sh.more { background: var(--teal-soft); color: var(--teal-dark); }
.share-msg {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: #e6f7ec; color: #137333;
  font-size: .76rem; font-weight: 600;
}

/* ---------- Footer ---------- */
.foot {
  height: var(--foot-h);
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 0 20px;
  color: var(--muted);
  font-size: .72rem;
  white-space: nowrap; overflow: hidden;
}
.foot span { overflow: hidden; text-overflow: ellipsis; }

/* ---------- Escritorio: todo cabe en pantalla, sin scroll ---------- */
@media (min-width: 901px) {
  html, body { height: 100dvh; overflow: hidden; }
}

/* ---------- Pantallas medianas ---------- */
@media (max-width: 1200px) {
  .app { grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; padding: var(--gap) 14px; }
  .panel { padding: 14px; }
}

/* ---------- Laptops de poca altura: modo compacto ---------- */
@media (min-width: 901px) and (max-height: 760px) {
  :root { --header-h: 64px; --foot-h: 28px; --gap: 12px; }
  .brand img { height: 48px; }
  .top-text h1 { font-size: 1.15rem; }
  .top-text p { font-size: .8rem; }
  .panel { padding: 12px 14px; gap: 8px; }
  .panel-head h2 { font-size: 1rem; }
  .panel-head p { font-size: .78rem; margin-top: 2px; }
  .contact { gap: 7px; }
  .contact label { font-size: .72rem; gap: 2px; }
  .contact input[type="text"], .contact input[type="tel"] { padding: 8px 10px; font-size: .92rem; border-radius: 10px; }
  .contact .consent { font-size: .7rem; }
  .contact button[type="submit"] { padding: 10px 14px; font-size: .92rem; }
  .panel-note { display: none; }
  .share { padding-top: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
  .share h3 { margin: 0; font-size: .78rem; }
  .sh { width: 36px; height: 36px; }
  .sh svg { width: 18px; height: 18px; }
  .share-msg { flex-basis: 100%; margin-top: 4px; }
  .q-text { font-size: clamp(1.3rem, 3vw, 2.2rem); }
  .ask-btn { padding: 11px 32px; }
  .sent { padding: 12px 14px; }
}
@media (min-width: 901px) and (max-height: 620px) {
  :root { --header-h: 56px; --foot-h: 0px; --gap: 8px; }
  .foot { display: none; }
  .brand img { height: 42px; }
  .top-text p { display: none; }
  .badge { display: none; }
  .panel-head p { display: none; }
  .contact input[type="text"], .contact input[type="tel"] { padding: 7px 10px; }
}

/* Elementos exclusivos de móvil (ocultos en escritorio) */
.form-fab, .panel-close, .panel-backdrop, .end-form-btn { display: none; }
.panel-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- Mobile: video pantalla completa + burbuja flotante para formulario ---------- */
@media (max-width: 900px) {
  :root { --header-h: 58px; }
  html, body {
    height: 100dvh;
    overflow: hidden;
    background: #fff;
  }
  .top {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    gap: 10px;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(22, 52, 58, 0.08);
    z-index: 10;
  }
  .brand img { height: 42px; }
  .top-text h1 { font-size: 1.05rem; }
  .top-text p { display: none; }
  .badge { display: none; }

  .app {
    display: block;
    width: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
  }
  .stage-col {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    padding: 0;
    margin: 0;
    z-index: 1;
    background: #fff;
    display: block;
  }
  .stage {
    width: 100%;
    height: 100dvh;
    aspect-ratio: auto;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
  }
  .stage::after { display: none; }
  .stage .idle,
  .stage .talk {
    top: calc(var(--header-h) + 5dvh);
    bottom: auto;
    left: 0; right: 0;
    width: 100%;
    height: calc(100dvh - var(--header-h) - 108px - env(safe-area-inset-bottom));
    object-fit: cover;
    object-position: center 15%;
    background: #fff;
  }

  .q-card {
    gap: 12px;
    padding: calc(var(--header-h) + 24px) 22px calc(92px + env(safe-area-inset-bottom));
  }
  .q-text { font-size: clamp(1.3rem, 6vw, 1.85rem); }
  .ask-btn { padding: 14px 32px; font-size: 1rem; }
  .end-form-btn { display: inline-block; }

  .gate {
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }
  .status {
    font-size: .72rem;
    left: 12px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    z-index: 12;
  }

  /* Burbuja flotante "Enviar mis datos" */
  .form-fab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    position: fixed;
    right: 14px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 20;
    border: 0;
    border-radius: 999px;
    padding: 13px 18px;
    background: linear-gradient(135deg, var(--teal) 0%, var(--blue) 100%);
    color: #fff;
    font-size: .9rem;
    font-weight: 700;
    letter-spacing: .01em;
    box-shadow: 0 10px 28px rgba(29, 95, 216, 0.45), 0 0 0 2px rgba(255, 255, 255, 0.35);
    cursor: pointer;
    animation: nudge 2.6s ease-in-out infinite;
    transition: opacity .2s, transform .2s;
  }
  .form-fab:active { transform: scale(.96); }
  .form-fab .fab-ico { width: 18px; height: 18px; flex: none; }
  body.form-open .form-fab { opacity: 0; pointer-events: none; }

  /* Fondo oscuro y cajón deslizable del formulario */
  .panel-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(8, 22, 28, 0.58);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 25;
    animation: fade .22s ease both;
  }
  .panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    height: auto;
    max-height: 88dvh;
    overflow-y: auto;
    border-radius: 24px 24px 0 0;
    padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
    box-shadow: 0 -14px 40px rgba(0, 0, 0, 0.32);
    transform: translateY(108%);
    transition: transform .32s cubic-bezier(.22, 1, .36, 1);
  }
  .panel.is-open { transform: translateY(0); }
  .panel-close {
    display: grid;
    place-items: center;
    width: 34px; height: 34px;
    border: 0;
    border-radius: 50%;
    background: var(--bg);
    color: var(--ink);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    flex: none;
  }
  .panel-close:active { background: var(--line); }

  .foot { display: none; }
}
