:root{
  --mary-navy:#0E2A3D;
  --mary-blue:#1E7FB8;
  --mary-lightblue:#EAF4FA;
  --mary-gray:#5B6770;
}

.mary-widget{
  position:fixed;
  right:20px;
  bottom:20px;
  z-index:2147483000; /* al tope: por encima de popups, formularios y overlays del tema/Elementor */
  font-family:"Kelson",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Calibri,sans-serif;
}

/* ---------- Burbuja cerrada (ícono flotante) ---------- */
.mary-bubble-toggle{
  width:76px;
  height:76px;
  border-radius:50%;
  border:3px solid #fff;
  box-shadow:0 6px 18px rgba(14,42,61,.28);
  background:var(--mary-lightblue);
  overflow:hidden;
  cursor:pointer;
  padding:0;
  animation:mary-idle-bounce 3.2s ease-in-out infinite;
  position:relative;
}
.mary-bubble-toggle img{
  width:100%;
  height:100%;
  object-fit:cover;
  object-position:top center;
}
@keyframes mary-idle-bounce{
  0%,100%{ transform:translateY(0); }
  50%{ transform:translateY(-6px); }
}

.mary-hidden{ display:none !important; }

/* Cierra TODO el asistente (círculo + charla) por el resto de la sesión */
.mary-hide-widget{
  position:absolute;
  top:-6px;
  right:-6px;
  width:22px;
  height:22px;
  border-radius:50%;
  background:var(--mary-navy);
  color:#fff;
  border:2px solid #fff;
  font-size:11px;
  line-height:1;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  box-shadow:0 2px 6px rgba(14,42,61,.35);
  z-index:3;
}
.mary-hide-widget:hover{ opacity:.85; }

/* ---------- Globito "teaser" del círculo cerrado ---------- */
.mary-teaser{
  position:absolute;
  right:92px;
  bottom:14px;
  width:380px;
  max-width:82vw;
  background:#fff;
  border:2px solid var(--mary-navy);
  border-radius:14px;
  padding:14px 36px 14px 18px;
  font-size:12.5px;
  line-height:1.4;
  color:var(--mary-navy);
  box-shadow:0 6px 18px rgba(14,42,61,.18);
  animation:mary-teaser-in 320ms cubic-bezier(.34,1.56,.64,1);
  cursor:pointer;
}
.mary-teaser::after{
  content:"";
  position:absolute;
  right:-9px;
  bottom:20px;
  width:0; height:0;
  border-top:7px solid transparent;
  border-bottom:7px solid transparent;
  border-left:8px solid var(--mary-navy);
}
.mary-teaser::before{
  content:"";
  position:absolute;
  right:-6px;
  bottom:20px;
  width:0; height:0;
  border-top:7px solid transparent;
  border-bottom:7px solid transparent;
  border-left:8px solid #fff;
  z-index:1;
}
.mary-teaser-close{
  position:absolute;
  top:6px;
  right:8px;
  background:transparent;
  border:none;
  color:var(--mary-navy);
  font-size:14px;
  font-weight:700;
  line-height:1;
  cursor:pointer;
  padding:4px;
}
.mary-teaser-close:hover{ opacity:.65; }
@keyframes mary-teaser-in{
  0%{ transform:scale(.7) translateY(6px); opacity:0; }
  60%{ transform:scale(1.05) translateY(-2px); opacity:1; }
  100%{ transform:scale(1) translateY(0); }
}

@media (max-width:480px){
  .mary-teaser{ right:80px; width:260px; max-width:78vw; }
}

/* ---------- Panel abierto ---------- */
.mary-panel{
  position:absolute;
  right:0;
  bottom:0;
  width:340px;
  max-width:calc(100vw - 24px);
  background:#fff;
  border-radius:16px;
  box-shadow:0 10px 40px rgba(14,42,61,.28);
  overflow:hidden;
  display:flex;
  flex-direction:column;
  max-height:78vh;
  z-index:2;
}

.mary-panel-header{
  background:var(--mary-navy);
  color:#fff;
  padding:10px 14px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  font-weight:600;
  font-size:14px;
}
.mary-panel-title{
  flex:1;
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.mary-panel-actions{ display:flex; align-items:center; gap:10px; flex-shrink:0; }
.mary-panel-close{
  background:transparent;
  border:none;
  color:#fff;
  font-size:16px;
  cursor:pointer;
  opacity:.8;
  padding:0 2px;
}
.mary-panel-clear{
  background:transparent;
  border:none;
  color:#fff;
  font-size:11px;
  font-weight:500;
  text-decoration:underline;
  white-space:nowrap;
  cursor:pointer;
  opacity:.85;
  padding:0;
}
.mary-panel-close:hover, .mary-panel-clear:hover{ opacity:1; }

/* ---------- Resumen: última pregunta del visitante + toggle historial ---------- */
.mary-last-user{
  margin:8px 14px 0;
  padding:8px 10px;
  border-radius:10px;
  background:var(--mary-navy);
  color:#fff;
  font-size:13px;
  line-height:1.4;
  align-self:flex-end;
  max-width:85%;
  margin-left:auto;
  flex-shrink:0;
}
.mary-toggle-history{
  background:transparent;
  border:none;
  color:var(--mary-gray);
  font-size:12px;
  text-align:center;
  padding:6px 14px;
  cursor:pointer;
  text-decoration:underline;
  flex-shrink:0;
}
.mary-toggle-history:hover{ color:var(--mary-blue); }

/* ---------- Escenario del personaje + globo ---------- */
.mary-stage{
  background:var(--mary-lightblue);
  padding:14px 14px 10px;
  display:flex;
  align-items:flex-end;
  gap:10px;
  flex-shrink:0;
  max-height:260px; /* red de seguridad: nunca deja crecer el panel sin límite */
}

.mary-stage-text{
  flex:1;
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:6px;
  max-height:232px;
  overflow-y:auto;
  padding-left:10px; /* deja lugar para que la colita del globo no se recorte con el scroll */
  margin-left:-10px; /* compensa el padding para no correr el globo del lugar original */
}

.mary-character{
  width:120px;
  height:auto;
  display:block;
  flex-shrink:0;
  transform-origin:bottom center;
  animation:mary-pop-in 420ms cubic-bezier(.34,1.56,.64,1);
}

/* Transición "hacia atrás y hacia adelante" con rebote al cambiar de expresión */
.mary-character.mary-swap-out{
  animation:mary-swap-out 150ms ease-in forwards;
}
.mary-character.mary-swap-in{
  animation:mary-swap-in 300ms cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes mary-swap-out{
  0%{ transform:scale(1) translateY(0); opacity:1; }
  100%{ transform:scale(.85) translateY(8px); opacity:.4; }
}
@keyframes mary-swap-in{
  0%{ transform:scale(.85) translateY(8px); opacity:.4; }
  60%{ transform:scale(1.08) translateY(-4px); opacity:1; }
  100%{ transform:scale(1) translateY(0); opacity:1; }
}
@keyframes mary-pop-in{
  0%{ transform:scale(.6); opacity:0; }
  60%{ transform:scale(1.08); opacity:1; }
  100%{ transform:scale(1); }
}

.mary-speech-bubble{
  background:#fff;
  border:2px solid var(--mary-navy);
  border-radius:8px;
  padding:10px 12px;
  font-size:13px;
  line-height:1.4;
  color:var(--mary-navy);
  position:relative;
  flex-shrink:0;
}
.mary-speech-bubble::after{
  content:"";
  position:absolute;
  left:-9px;
  bottom:14px;
  width:0; height:0;
  border-top:7px solid transparent;
  border-bottom:7px solid transparent;
  border-right:8px solid var(--mary-navy);
}
.mary-speech-bubble::before{
  content:"";
  position:absolute;
  left:-6px;
  bottom:14px;
  width:0; height:0;
  border-top:7px solid transparent;
  border-bottom:7px solid transparent;
  border-right:8px solid #fff;
  z-index:1;
}

/* Link clickeable que Andrés/Mary puede ofrecer junto a su respuesta visible */
.mary-bubble-link{
  display:inline-block;
  align-self:flex-start;
  background:var(--mary-blue);
  color:#fff !important;
  font-size:12px;
  font-weight:600;
  padding:6px 12px;
  border-radius:20px;
  text-decoration:none;
  flex-shrink:0;
}
.mary-bubble-link:hover{ background:var(--mary-navy); }

/* ---------- Botones prediseñados de inicio ---------- */
.mary-starters{
  display:flex;
  flex-wrap:wrap;
  gap:3px;
  padding:6px 14px;
  border-bottom:1px solid #eef1f3;
  flex-shrink:0;
  max-height:104px;
  overflow-y:auto;
}
.mary-starters button{
  background:var(--mary-lightblue);
  border:1px solid #cfe4f0;
  color:var(--mary-navy);
  border-radius:11px;
  padding:2px 6px;
  font-size:10px;
  line-height:1.5;
  white-space:nowrap;
  cursor:pointer;
  transition:background .15s ease;
}
.mary-starters button:hover{ background:#d9edf7; }

/* ---------- Mensajes ---------- */
.mary-messages{
  padding:10px 14px;
  overflow-y:auto;
  flex:1 1 auto;
  min-height:60px;
  display:flex;
  flex-direction:column;
  gap:8px;
  font-size:13px;
}
.mary-msg{ max-width:85%; padding:8px 10px; border-radius:10px; line-height:1.4; }
.mary-msg-mary{ background:var(--mary-lightblue); color:var(--mary-navy); align-self:flex-start; }
.mary-msg-user{ background:var(--mary-navy); color:#fff; align-self:flex-end; }
.mary-msg-link{
  display:inline-block;
  margin-top:6px;
  font-size:12px;
  font-weight:600;
  color:var(--mary-blue);
  text-decoration:underline;
}
.mary-msg-link:hover{ color:var(--mary-navy); }

/* ---------- Formulario ---------- */
.mary-form{
  position:relative;
  border-top:1px solid #eef1f3;
  padding:8px;
  flex-shrink:0;
  box-sizing:border-box;
}
.mary-form input{
  width:100%;
  border:1px solid #dfe4e8;
  border-radius:20px;
  padding:8px 42px 8px 14px; /* espacio a la derecha para que no tape el botón */
  font-size:13px;
  outline:none;
  box-sizing:border-box;
  -webkit-appearance:none;
  appearance:none;
}
.mary-form input:focus{ border-color:var(--mary-blue); }
.mary-form button{
  position:absolute;
  top:50%;
  right:13px;
  transform:translateY(-50%);
  background:var(--mary-blue);
  color:#fff;
  border:none;
  border-radius:50%;
  width:26px;
  height:26px;
  padding:0;
  margin:0;
  line-height:1;
  box-sizing:border-box;
  -webkit-appearance:none;
  appearance:none;
  cursor:pointer;
  font-size:11px;
  display:flex;
  align-items:center;
  justify-content:center;
}

/* ---------- Botón fijo "Hablar con [vendedor]" ---------- */
.mary-talk-seller{
  display:block;
  text-align:center;
  background:#fff;
  color:var(--mary-navy);
  border-top:1px solid #eef1f3;
  padding:10px;
  font-size:13px;
  font-weight:600;
  text-decoration:none;
  flex-shrink:0;
}
.mary-talk-seller:hover{ background:var(--mary-lightblue); }

@media (max-width:480px){
  .mary-panel{ width:calc(100vw - 24px); }
}
