/* box-sizing SOLO dentro de nuestros componentes (antes era global y alteraba
   el layout de todo el sitio anfitrion, incluidos sus popups). */
#norma-launcher,
#norma-launcher *,
#norma-launcher *::before,
#norma-launcher *::after,
#norma-chat,
#norma-chat *,
#norma-chat *::before,
#norma-chat *::after {
  box-sizing: border-box;
}

/* Capa de Norma: alta, pero por DEBAJO de los popups/modales del sitio
   (Elementor, Popup Maker, Bootstrap, SweetAlert, etc. usan 1050-999999).
   Antes era 2147483647 !important y tapaba cualquier popup. */
:root {
  --norma-z: 9990;
}

/*--- CHAT LAUNCHER ---*/
#norma-launcher {
  z-index: var(--norma-z);
  font-family: 'Chivo', 'sans-serif';
  position: fixed !important;
  bottom: 32px;
  right: 32px;
  color: #fbfcfd;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  transform-origin: bottom right;
}

#norma-launcher .text {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #005e9d;
  border: solid 4px #a6ea4a;
  border-radius: 24px 0 0 24px;
  padding: 8px 28px 8px 12px;
  margin-right: -20px;
  transform-origin: right center;
  transition: clip-path 0.6s ease;
  clip-path: inset(0 0 0 0);
  z-index: 0;
}

#norma-launcher .text.fade-right {
  clip-path: inset(0 100% 0 0);
  animation: fadeOutText 0.6s forwards;
}

@keyframes fadeOutText {
  99% {
    transform: translateX(100%);
  }

  100% {
    transform: translateX(100%);
    display: none;
  }
}

#norma-launcher .text span {
  background-color: #a6ea4a;
  color: #005e9d;
  height: 32px;
  width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border-radius: 10px;
  margin-right: 12px;
}

#norma-launcher .text p {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 300;
  letter-spacing: 0.01rem;
}

#norma-launcher .image-cont,
#norma-chat .image-cont {
  background-color: #a6ea4a;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  z-index: 10;
  transition: border 0.3s ease, transform 0.3s ease;
}

#norma-launcher .image-cont.border-blue {
  border: solid 4px #005e9d;
  transform: translate(2px, 2px);
}

#norma-launcher .image-cont .image-cutter,
#norma-chat .image-cont .image-cutter {
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 0 0 50% 50%;
}

#norma-launcher .image-cont .image-cutter img,
#norma-chat .image-cont .image-cutter img {
  height: 100%;
}

/*--- CHAT WINDOW ---*/
#norma-chat {
  z-index: var(--norma-z);
  position: fixed !important;
  bottom: 32px;
  right: 32px;
  width: 400px;
  max-height: calc(100dvh - 64px);
  height: auto;
  background: #f3f5f9;
  box-shadow: 0 20px 40px rgba(0, 0, 0, .2);
  display: flex;
  flex-direction: column;
  font-family: 'Chivo', sans-serif;
  transform-origin: bottom right;
}

#norma-chat *::-webkit-scrollbar {
  display: none;
}

/* HEADER */
#norma-chat .chat-header {
  height: 120px;
  background: #005e9d;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  margin-bottom: 32px;
}

#norma-chat .image-cont {
  margin-top: 40px;
}

#norma-chat .chat-header .title {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 1.2rem;
  font-weight: 300;
  letter-spacing: 0.01rem;
}

#norma-chat .chat-header #close-chat {
  cursor: pointer;
}

/* BODY */
#chat-body {
  flex: 1;
  min-height: 0;
  padding: 0 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  font-size: 1.1rem;
}

/* MENSAJES */
#chat-body .message {
  max-width: 80%;
  padding: 16px;
  border-radius: 20px 20px 20px 0;
  line-height: 1.3;
  margin-top: 12px;
  color: #333 !important;
  /* Corte de línea: NUNCA partir palabras normales a la mitad; solo envolver por
     espacios. overflow-wrap:break-word solo rompe un token si NO entra completo
     (p. ej. una URL muy larga). word-break:normal anula cualquier break-all
     heredado; hyphens:none evita cortes por guion. */
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
}

#chat-body .message.bot {
  background: #fff;
  align-self: flex-start;
}

#chat-body .message.user {
  background: #005e9d;
  color: #fff !important;
  align-self: flex-end;
  border-radius: 20px 20px 0 20px;
}

/* TYPING INDICATOR */
#chat-body .typing {
  align-self: flex-start;
  height: 48px;
  margin: 12px 0 4px;
  padding: 12px 16px 16px;
  background-color: #fff;
  border-radius: 20px 20px 20px 0;
}

#chat-body .typing.hide {
  visibility: hidden;
  height: 0;
  margin: -18px 0 0;
  padding: 0;
}

#chat-body .typing span {
  display: inline-block;
  margin: 0 2px;
  background-color: #333;
  height: 4px;
  width: 4px;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}

#chat-body .typing span:nth-child(1) {
  animation-delay: -0.3s;
}

#chat-body .typing span:nth-child(2) {
  animation-delay: -0.15s;
}

@keyframes typing {

  0%,
  80%,
  100% {
    transform: scale(0);
  }

  40% {
    transform: scale(1.0);
  }
}

/* FOOTER */
#chat-footer {
  display: flex;
  position: relative;
}

#chat-footer .input-container {
  display: flex;
  align-items: stretch;
  width: 100%;
  margin: 8px 16px 12px;
  border: 1px solid #ccc;
  border-radius: 14px;
  overflow: hidden;
  background-color: #fff;
}

#chat-footer textarea {
  flex: 1;
  max-height: 100px;
  padding: 8px 16px;
  border: none;
  overflow-y: auto;
  resize: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
  transition: border-color 0.2s;
  font-size: 1.1rem;
  font-family: 'Chivo', sans-serif;
  font-weight: 300;
  letter-spacing: 0.01rem;
  line-height: 1.5;
}

#chat-footer textarea::-webkit-scrollbar {
  display: none;
}

#chat-footer textarea:focus {
  outline: none;
}

#chat-footer .input-container:focus-within {
  border-color: #005e9d;
}

#chat-footer .send-img {
  width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#chat-footer .send-img img {
  width: 24px;
  height: auto;
  transition: transform 0.2s ease;
}

#chat-footer .send-img:hover img {
  transform: rotate(-35deg);
}

/* FADE EFFECT (clases con prefijo propio: ".fade/.show" genericas chocaban
   con los modales de Bootstrap y plugins de popups del sitio) */
.norma-fade {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.35s ease, visibility 0.35s;
}

.norma-fade.norma-show {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

@media screen and (max-width: 768px) and (pointer: coarse) {

  #norma-launcher {
    transform: scale(0.75);
    bottom: 8px;
    right: 8px;
  }

  #norma-chat {
    position: fixed;
    bottom: 0;
    top: 0;
    left: 0;
    width: 100%;
    transform: none;
    max-height: none !important;
  }

  #norma-chat .chat-header {
    height: 60px;
    padding: 10px 24px;
    margin-bottom: 0;
  }

  #norma-chat .chat-header .title {
    font-size: 1rem;
  }

  #norma-chat .image-cont {
    height: 50px;
    width: 50px;
    margin-top: 0;
  }
}

@media screen and (max-height: 768px) and (pointer: coarse) and (orientation: landscape) {

  #norma-launcher {
    transform: scale(0.75);
    bottom: 8px;
    right: 8px;
  }

  #norma-chat {
    position: fixed;
    bottom: 0;
    top: 0;
    left: 0;
    width: 100%;
    transform: none;
    max-height: none !important;
  }

  #norma-chat .chat-header {
    height: 60px;
    padding: 10px 24px;
    margin-bottom: 0;
  }

  #norma-chat .chat-header .title {
    font-size: 1rem;
  }

  #norma-chat .image-cont {
    height: 50px;
    width: 50px;
    margin-top: 0;
  }
}

/* HEADER FINO PARA ZOOM x2 */
#norma-chat.thin-header .chat-header {
  height: 60px;
  padding: 10px 24px;
  margin-bottom: 0;
}

#norma-chat.thin-header .chat-header .title {
  font-size: 1rem;
}

#norma-chat.thin-header .chat-header .image-cont {
  height: 50px;
  width: 50px;
  margin-top: 0;
}

/* Ocultar completamente la UI nativa del embedding (contenedor con id propio;
   "#root" es generico y podia coincidir con elementos del sitio). */
#norma-wxo-root,
#norma-wxo-root * {
  display: none !important;
  position: fixed !important;
  top: -9999px !important;
  left: -9999px !important;
  width: 0 !important;
  height: 0 !important;
  max-width: 0 !important;
  max-height: 0 !important;
  overflow: hidden !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  z-index: -9999 !important;
}

/* Nuestros elementos visibles cuando tienen .norma-show (salvo que haya un popup del sitio abierto) */
#norma-launcher.norma-fade.norma-show {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

#norma-chat.norma-fade.norma-show {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

/* FIX SCROLL EMBEBIDO. Cuando el wxoLoader de IBM abre su chat en pantalla
   completa, agrega estas clases al <body> del sitio anfitrion y le pone
   overflow:hidden, dejando la pagina sin scroll. Forzamos que el body siga
   siendo scrolleable (nuestra regla !important gana al style inline de IBM). */
body.wxo-embed-body-temp:not(.norma-popup-open),
body.wxo-embed-fullscreen-temp:not(.norma-popup-open),
body.wxo-chat-open:not(.norma-popup-open) {
  overflow: auto !important;
  height: auto !important;
  position: static !important;
}

/* Defensa extra: si alguna version del wxoLoader tambien bloquea el <html>,
   lo neutralizamos con :has() (body es hijo directo de html). */
html:has(> body.wxo-embed-body-temp:not(.norma-popup-open)),
html:has(> body.wxo-embed-fullscreen-temp:not(.norma-popup-open)),
html:has(> body.wxo-chat-open:not(.norma-popup-open)) {
  overflow: auto !important;
  height: auto !important;
}

/* Mientras el sitio muestra un popup/modal, Norma se atenua y deja de
   interceptar clics para no competir con el popup. */
body.norma-popup-open #norma-launcher,
body.norma-popup-open #norma-chat,
body.norma-popup-open #norma-launcher.norma-fade.norma-show,
body.norma-popup-open #norma-chat.norma-fade.norma-show {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
