:root{ --app-height: 100vh; }
@supports (height: 100dvh){ :root{ --app-height: 100dvh; } }

/* =========================================================
   RESET MINIMAL (evita "ensanches" por box model raro)
   ========================================================= */
*,*::before,*::after{ box-sizing: border-box; }
img{ max-width: 100%; height: auto; }

/* =========================================================
   WHATSAPP CARD (base)
   ========================================================= */

.whatsapp-wrapper{
  width: 100%;
  max-width: 420px;
  height: min(630px, var(--app-height));
  margin: 20px auto;
  border-radius: 14px;
  overflow: hidden;
  background: #efeae2;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  display: flex;
  flex-direction: column;
}

/* Solo elevar por encima del menú cuando estás en el bloque WhatsApp */
body.whatsapp-active .whatsapp-wrapper{
  position: relative;
  z-index: 40;
}

/* =========================================================
   CABECERA
   ========================================================= */

.wa-header{
  background: #008069;
  color: #fff;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  min-height: 56px;
}

.wa-avatar{
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wa-avatar img{
  width: 38px;
  height: 38px;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}

.wa-title{
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.1;
  font-weight: 700;
}

.wa-title span{
  display: block;
  font-size: 11px;
  color: #d2f8f0;
  font-weight: 500;
  margin-top: 2px;
}

.wa-actions{
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}

/* Botones como WhatsApp: sin borde, fondo transparente, hit-area cómoda */
.wa-icon{
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.wa-icon svg{
  width: 22px;
  height: 22px;
  fill: currentColor;
  opacity: .95;
}

/* Efecto típico de WhatsApp al pasar/press */
.wa-icon:hover{ background: rgba(255,255,255,.12); }
.wa-icon:active{ transform: scale(.92); background: rgba(255,255,255,.18); }

/* Accesibilidad: foco visible pero discreto */
.wa-icon:focus-visible{
  outline: 2px solid rgba(255,255,255,.55);
  outline-offset: 2px;
}


/* =========================================================
   CHAT
   ========================================================= */

.wa-chat{
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background-color: #efeae2;
  background-image: url(img/fondo_whatsapp.webp);
  background-repeat: repeat;
  background-size: 400px;
}

.wa-notice{
  background: #fff5c4;
  padding: 6px 10px;
  font-size: 11px;
  text-align: center;
  border-radius: 6px;
  margin-bottom: 12px;
  border: 1px solid #ffeeb0;
}

.msg{
  max-width: 80%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 8px;
  line-height: 1.4;
  word-wrap: break-word;
}

.msg.bot{ background: #ffffff; border-top-left-radius: 0; }
.msg.user{ background: #d9fdd3; margin-left: auto; border-top-right-radius: 0; }

/* OPCIONES */
.options{ display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }

.options button{
  border: 1px solid #dcdcdc;
  background: #ffffff;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.options button:hover{ background: #d9fdd3; }

/* En móviles (iOS/Android) el :hover puede quedarse "pegado" tras un tap */
@media (hover: none){
  .options button:hover{ background: #ffffff; }
  .options button:active{ background: #d9fdd3; }
}

/* INPUT */
.wa-input{
  display: flex;
  padding: 8px;
  background: #f0f2f5;
  align-items: center;
  gap: 8px;
  min-width: 0; /* clave: evita desbordes en flex (iOS/Chrome) */
}

.wa-input input{
  flex: 1;
  min-width: 0;
  padding: 8px 14px;
  border-radius: 20px;
  border: none;
  outline: none;
  font-size: 14px;
}

/* ===== INPUT MULTILÍNEA (textarea) ===== */
.wa-input textarea{
  flex: 1;
  min-width: 0;
  width: auto;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
  line-height: 1.25;
  padding: 10px 10px;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  overflow-y: auto;
  font-family: inherit;
}

.wa-input button{
  border: none;
  background: #00a884;
  color: #fff;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: 16px;
  flex: 0 0 auto;
}

.chat-image{
  max-width: 220px;
  border-radius: 12px;
  margin-top: 4px;
  cursor: pointer;
}

/* =========================================================
   WHATSAPP HERO
   ========================================================= */

.whatsapp-hero{
  background: #f4f6f5;
  padding: 0 15px;
}

.whatsapp-hero-inner{
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.whatsapp-hero-left{ text-align: center; }
.whatsapp-hero-left p{ font-size: 16px; line-height: 1.6; margin-bottom: 14px; }
.whatsapp-cta-text{ font-weight: 600; margin-top: 20px; }
.whatsapp-hero-left h2{ font-size: 26px; margin-bottom: 12px; }
.whatsapp-sub{ font-size: 16px; margin-bottom: 15px; }
.whatsapp-benefits{ list-style: none; padding: 0; margin-bottom: 20px; }
.whatsapp-benefits li{ font-size: 15px; margin-bottom: 6px; }
.whatsapp-hero-left img{ width: 100%; max-width: 320px; margin: 0 auto; }

.whatsapp-hero-right{ border-radius: 14px; }

/* =========================================================
   MÓVIL/TABLET (hasta 991px): fixes iOS + no scroll horizontal
   ========================================================= */

@media (max-width: 991.98px){
  html, body{ overflow-x: hidden; }
  html, body{ overscroll-behavior-x: none; }

  .whatsapp-wrapper{ max-width: 350px; margin: 0 auto; }
  .wa-input input, .wa-input textarea, .options button{ font-size: 16px; }

  /* Pantalla dedicada: misma estructura antes y después de abrir el teclado. */
  html.whatsapp-page-root{ height: 100%; overflow: hidden; }
  body.whatsapp-page{
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    padding: 0 !important;
  }
  body.whatsapp-page > header,
  body.whatsapp-page > footer,
  body.whatsapp-page .footer-jdg,
  body.whatsapp-page .whatsapp-hero-left{ display: none !important; }

  body.whatsapp-page .whatsapp-wrapper{
    position: fixed;
    top: var(--app-top, 0px);
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    height: var(--app-height);
    margin: 0;
    border-radius: 0;
    z-index: 40;
    box-shadow: none;
  }
  body.whatsapp-page .wa-back{ display: inline-flex; }
  body.whatsapp-page .wa-input{
    padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
    min-height: 84px;
  }
  body.whatsapp-page .wa-header{
    height: auto;
    flex-shrink: 0;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .options button{ min-height: 44px; }

}

/* =========================================================
   DESKTOP (>= 992px): se queda como siempre
   ========================================================= */

@media (min-width: 992px){
  .whatsapp-hero{ padding: 50px 20px; }

  .whatsapp-hero-inner{
    max-width: 1100px;
    flex-direction: row;
    align-items: stretch;
    gap: 5px;
  }

  .whatsapp-hero-left,
  .whatsapp-hero-right{ width: 50%; }

  .whatsapp-hero-left{
    text-align: left;
    display: flex;
    flex-direction: column;
  }

  .whatsapp-hero-left h2{ font-size: 36px; }
  .whatsapp-hero-left img{ max-width: 380px; margin: 0; }
  .whatsapp-hero-right{ padding: 25px; }

  .whatsapp-wrapper{
    max-width: 420px;
    margin: 20px auto;
    border-radius: 14px;
  }
}
/* Alineación cuando el textarea crece */
.wa-input{ align-items: flex-end; }

/* Controles y desplazamiento del chat */
.wa-chat{ min-height: 0; overscroll-behavior-y: contain; }
.wa-input{ flex-shrink: 0; }
.wa-input[hidden], .wa-input [hidden]{ display: none !important; }
.wa-input-hint{ width: 100%; padding: 10px; text-align: center; font-size: 14px; color: #52635e; }
.wa-back{ display: none; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; color: #fff; text-decoration: none; font-size: 24px; }

/* Pausa visual entre la respuesta del usuario y la siguiente pregunta. */
.wa-typing span{ display: inline-flex; gap: 5px; padding: 5px 2px; }
.wa-typing i{ width: 7px; height: 7px; border-radius: 50%; background: #71857c; animation: waTyping 1s infinite ease-in-out; }
.wa-typing i:nth-child(2){ animation-delay: .15s; }
.wa-typing i:nth-child(3){ animation-delay: .3s; }
@keyframes waTyping{ 0%, 60%, 100%{ opacity: .4; transform: translateY(0); } 30%{ opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce){ .wa-typing i{ animation: none; } }
