:root{ --app-height: 100vh; }

/* =========================================================
   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: 14px; flex: 0 0 auto; }

.wa-icon{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  line-height:1;
}

.wa-icon i{
  font-size:18px;
}

.wa-icon svg{
  width: 22px;
  height: 22px;
  fill: #ffffff;
  opacity: 0.95;
}

.wa-icon:hover svg{ opacity: 1; }
.wa-icon:active{ transform: scale(0.92); }

/* =========================================================
   CHAT
   ========================================================= */

.wa-chat{
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background-color: #efeae2;
  background-image: url("https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png");
  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; }

  /* gana espacio en móvil */
body.whatsapp-active.keyboard-open .menu_movil{ display: none !important; }
body.whatsapp-active.keyboard-open{ padding-top: 0 !important; }

  /* aquí es donde el iPhone 11 deja de descuadrar */
  .whatsapp-wrapper{
    max-width: 350px;
    margin: 0 auto;
  }

  /* iOS Safari hace zoom con font-size < 16px; eso "ensancha" todo */
  .wa-input input{ font-size: 16px; }
  .wa-input textarea{ font-size: 16px; }
  .options button{ font-size: 16px; }

  /* teclado abierto: fijamos abajo pero manteniendo el mismo ancho */
  body.keyboard-open{ overflow: hidden; }

  body.keyboard-open .whatsapp-wrapper{
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 0;
    z-index: 9999;

    /* Evita el bug de 100vw con teclado en iOS */
    width: auto;
    max-width: 350px;
    margin: 0 auto;
    transform: none;

    border-radius: 14px;
  }

  body.keyboard-open .wa-input{
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* =========================================================
   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; }
