/*
 * WhatsApp Hub · colores de la guía de marca de Celular Lab.
 * Magenta #B2147C, azul #31589B (hover #233F74), tintes #EAEEF5, texto #283236, verde #1FA855 solo para el botón de WhatsApp.
 * Todas las variables se pueden sobrescribir desde el tema.
 */
.wahub {
  --wahub-accent: var(--wahub-accent-override, #1fa855);
  --wahub-accent-text: var(--wahub-accent-text-override, #ffffff);
  --wahub-cta: var(--wahub-cta-override, #15803d);
  --wahub-brand: var(--wahub-brand-override, #31589b);
  --wahub-brand-dark: var(--wahub-brand-dark-override, #233f74);
  --wahub-magenta: var(--wahub-magenta-override, #b2147c);
  --wahub-bg: var(--wahub-bg-override, #ffffff);
  --wahub-text: var(--wahub-text-override, #283236);
  --wahub-muted: var(--wahub-muted-override, #494949);
  --wahub-bubble: var(--wahub-bubble-override, #eaeef5);
  position: fixed;
  /* Respeta la zona segura de los iPhone y sube por encima del teclado cuando se abre. */
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--wahub-kb, 0px));
  z-index: 2147483000;
  max-width: calc(100vw - 16px);
  font-family: var(--wahub-font, "Montserrat", "Heebo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  font-size: 14px;
  line-height: 1.4;
  color: var(--wahub-text);
}

/* Evita que estilos del tema (width:100%, content-box, márgenes) desborden el widget. */
.wahub,
.wahub * {
  box-sizing: border-box;
}

.wahub button,
.wahub input {
  margin: 0;
  font-family: inherit;
  touch-action: manipulation;
}

.wahub__fab {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--wahub-accent);
  color: var(--wahub-accent-text);
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  -webkit-tap-highlight-color: transparent;
}

.wahub__panel {
  position: absolute;
  right: 0;
  bottom: 68px;
  display: flex;
  flex-direction: column;
  width: min(360px, calc(100vw - 32px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  /* --wahub-vh lo fija el JS con la altura visible real (sin teclado). */
  max-height: min(520px, calc(var(--wahub-vh, 100vh) - 100px));
  background: var(--wahub-bg);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.wahub__panel[hidden] { display: none; }
.wahub__panel:focus { outline: none; }

.wahub__head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 10px 14px;
  background: linear-gradient(135deg, var(--wahub-magenta), var(--wahub-brand));
  color: #ffffff;
}

.wahub__close {
  min-width: 36px;
  min-height: 36px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.wahub__log {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.wahub__msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--wahub-bubble);
  color: var(--wahub-text);
  overflow-wrap: anywhere;
}

.wahub__msg--user {
  align-self: flex-end;
  background: var(--wahub-brand);
  color: #ffffff;
}

.wahub__chips {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 8px;
}

.wahub__chip {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--wahub-brand);
  border-radius: 18px;
  background: transparent;
  color: var(--wahub-brand);
  font-size: 13px;
  cursor: pointer;
}

.wahub__chip:hover { background: var(--wahub-bubble); }

.wahub__wa {
  flex: 0 0 auto;
  margin: 0 12px 8px;
  min-height: 40px;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--wahub-cta);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.wahub__wa[hidden] { display: none; }
.wahub__wa:disabled { opacity: 0.6; cursor: progress; }

.wahub__form {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--wahub-bubble);
}

.wahub__input {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid #c4cbd3;
  border-radius: 8px;
  background: var(--wahub-bg);
  color: var(--wahub-text);
  /* 16px evita el zoom automático de iOS al tocar el cuadro, que descuadra la página. */
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

.wahub__send {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--wahub-brand);
  color: #ffffff;
  font-size: 14px;
  cursor: pointer;
}

.wahub__send:hover { background: var(--wahub-brand-dark); }

.wahub__privacy {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 12px 10px;
  color: var(--wahub-muted);
  font-size: 12px;
}

.wahub button:focus-visible,
.wahub input:focus-visible,
.wahub a:focus-visible {
  outline: 2px solid var(--wahub-brand);
  outline-offset: 2px;
}

/* Móvil: el panel ocupa como máximo ~70 % de la altura visible y, al escribir, deja sitio al teclado. */
@media (max-width: 480px) {
  .wahub__panel {
    max-height: min(520px, calc(var(--wahub-vh, 100vh) * 0.7));
  }

  .wahub--typing .wahub__chips,
  .wahub--typing .wahub__privacy,
  .wahub--typing .wahub__wa {
    display: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .wahub__panel { animation: wahub-in 0.15s ease-out; }
  @keyframes wahub-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
}
