/* Widget aislado: no modifica estilos de la página ni del panel. */

.mk-webchat {
  --mkw-teal: #0b948b;
  --mkw-dark: #125b59;
  --mkw-ink: #152237;
  --mkw-muted: #64748b;
  --mkw-bg: #f5f8fa;
  --mkw-line: #e3eaf0;

  position: fixed;
  right: 26px;
  bottom: 24px;
  z-index: 1100;
  max-width: calc(100vw - 32px);
  color: var(--mkw-ink);
  font-family: 'Plus Jakarta Sans', Inter, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  text-align: left;
}

.mk-webchat *,
.mk-webchat *::before,
.mk-webchat *::after {
  box-sizing: border-box;
}

.mk-webchat [hidden] {
  display: none !important;
}

.mk-webchat button,
.mk-webchat input {
  font: inherit;
}

.mk-webchat button {
  cursor: pointer;
}

.mk-webchat button:disabled,
.mk-webchat input:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.mk-webchat button:focus-visible,
.mk-webchat a:focus-visible,
.mk-webchat input:focus-visible {
  outline: 2px solid #14b8a6;
  outline-offset: 3px;
}

.mk-webchat svg {
  display: block;
  width: 24px;
  height: 24px;
}

/* Fila de lanzamiento y botón flotante */

.mkw-launch-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.mkw-launch {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 62px;
  height: 62px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: var(--mkw-teal);
  color: white;
  box-shadow: 0 0 0 5px #bdeae5, 0 12px 30px #0b736e2e;
  transition: transform 0.2s, background 0.2s;
}

.mkw-launch:hover {
  transform: translateY(-2px);
  background: #087f78;
}

.mkw-launch svg {
  width: 38px;
  height: 38px;
}

.mkw-launch .mkw-cross {
  display: none;
}

.mkw-online-dot,
.mkw-avatar i {
  position: absolute;
  top: 2px;
  right: 1px;
  width: 17px;
  height: 17px;
  border: 1px solid white;
  border-radius: 50%;
  background: #29cf99;
}

/* Teaser */

.mkw-teaser {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 70px;
  padding: 10px 12px 10px 18px;
  border: 1px solid var(--mkw-line);
  border-radius: 21px;
  background: white;
  box-shadow: 0 16px 40px #162d3e20;
  transition: border-color 0.2s;
}

.mkw-teaser:hover {
  border-color: #17b6a5;
}

.mkw-teaser-main {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--mkw-ink);
  text-align: left;
}

.mkw-teaser-main strong,
.mkw-teaser-main small {
  display: block;
  white-space: nowrap;
}

.mkw-teaser-main strong {
  font-size: 14px;
  font-weight: 800;
}

.mkw-teaser-main small {
  color: var(--mkw-muted);
  font-size: 12px;
}

.mkw-teaser-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 43px;
  height: 43px;
  border-radius: 50%;
  background: #e6f8f5;
  color: var(--mkw-teal);
}

.mkw-icon-btn {
  padding: 4px;
  border: 0;
  background: none;
  color: #94a3b8;
  font-size: 23px !important;
  line-height: 1;
}

.mkw-teaser-close {
  margin-left: 4px;
}

/* Estado abierto */

.mk-webchat.is-open .mkw-teaser {
  display: none;
}

.mk-webchat.is-open .mkw-steth {
  display: none;
}

.mk-webchat.is-open .mkw-cross {
  display: block;
}

/* Ventana principal */

.mkw-window {
  position: absolute;
  right: 0;
  bottom: 98px;
  display: flex;
  flex-direction: column;
  width: min(510px, calc(100vw - 32px));
  height: min(724px, calc(100dvh - 148px));
  min-height: 300px;
  border: 1px solid #dce5ea;
  border-radius: 28px;
  background: var(--mkw-bg);
  box-shadow: 0 25px 75px #10253638;
  overflow: hidden;
  animation: mkw-appear 0.2s ease-out;
}

/* Cabecera */

.mkw-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: none;
  padding: 19px 20px;
  background: linear-gradient(110deg, var(--mkw-dark), #0c8e85);
  color: white;
}

.mkw-avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 49px;
  height: 49px;
  border: 1px solid #ffffff30;
  border-radius: 50%;
  background: #ffffff20;
}

.mkw-avatar svg {
  width: 29px;
  height: 29px;
  color: #cbffef;
}

.mkw-avatar i {
  top: auto;
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
}

.mkw-heading {
  flex: 1;
  min-width: 0;
}

.mkw-heading strong {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.4px;
}

.mkw-heading small {
  display: block;
  color: #d2efeb;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mkw-live {
  padding: 3px 6px;
  border-radius: 5px;
  background: #ffffff20;
  color: #e4fff7;
  font-size: 10px;
  white-space: nowrap;
}

.mkw-collapse {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: #ffffff18;
  color: #fff;
}

/* Aviso */

.mkw-notice {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex: none;
  padding: 8px 16px;
  border-bottom: 1px solid #f7e7ba;
  background: #fffbeb;
  color: #9a4a12;
  font-size: 11px;
}

.mkw-notice #mkw-count {
  color: #8b500d;
  font-weight: 700;
  white-space: nowrap;
}

/* Área de mensajes */

.mkw-scroll {
  flex: 1;
  min-height: 0;
  padding: 20px 18px 22px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.mkw-messages {
  display: grid;
  gap: 15px;
}

.mkw-message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.mkw-message-badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  background: var(--mkw-teal);
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.mkw-bubble {
  max-width: calc(100% - 48px);
  padding: 13px 16px;
  border: 1px solid var(--mkw-line);
  border-radius: 18px;
  background: white;
  box-shadow: 0 2px 3px #112a3710;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mkw-message.user {
  justify-content: flex-end;
}

.mkw-message.user .mkw-bubble {
  border-color: #b3e5dc;
  border-bottom-right-radius: 5px;
  background: #e0f5f1;
}

.mkw-message.assistant .mkw-bubble {
  border-top-left-radius: 6px;
}

.mkw-message.is-pending .mkw-bubble {
  opacity: 0.65;
}

.mkw-loading {
  padding: 8px 0;
  color: var(--mkw-muted);
  font-size: 12px;
}

/* Sugerencias */

.mkw-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 18px 0 0 46px;
}

.mkw-suggestions button {
  padding: 7px 11px;
  border: 1px solid #9be8dc;
  border-radius: 10px;
  background: #effdfa;
  color: #126e67;
  font-size: 12px;
}

.mkw-suggestions button:hover {
  background: #dcf8f1;
}

/* Autenticación, alertas y cierre */

.mkw-auth {
  margin: 4px 0 16px;
  padding: 24px 20px;
  border: 1px solid var(--mkw-line);
  border-radius: 22px;
  background: white;
  text-align: center;
}

.mkw-auth-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: #e7f8f5;
  color: var(--mkw-teal);
  font-size: 25px;
}

.mkw-auth h3 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.mkw-auth p {
  margin: 0 0 15px;
  color: var(--mkw-muted);
  font-size: 13px;
}

.mkw-consent {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 17px 0;
  padding: 12px;
  border: 1px solid var(--mkw-line);
  border-radius: 12px;
  color: #536579;
  font-size: 11px;
  text-align: left;
}

.mkw-consent input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 1px 0 0;
  appearance: auto;
  accent-color: var(--mkw-teal);
}

.mkw-google {
  display: flex;
  justify-content: center;
  min-height: 44px;
  margin: 12px 0;
}

.mkw-auth-help {
  font-size: 11px !important;
}

.mkw-link {
  color: var(--mkw-teal);
  font-size: 12px;
  font-weight: 700;
  text-decoration: underline;
}

.mkw-alert {
  margin-top: 12px;
  padding: 11px 13px;
  border: 1px solid #f1bdac;
  border-radius: 13px;
  background: #fff4ee;
  color: #9a3412;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.mkw-finish {
  margin-top: 18px;
  padding: 17px;
  border: 1px solid #bee8df;
  border-radius: 18px;
  background: #e9f9f6;
  text-align: center;
}

.mkw-finish strong {
  color: #136963;
  font-size: 16px;
}

.mkw-finish p {
  margin: 5px 0 13px;
  color: #426d69;
  font-size: 12px;
}

.mkw-finish a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Pie y formulario */

.mkw-footer {
  flex: none;
  padding: 13px 15px 10px;
  border-top: 1px solid var(--mkw-line);
  background: white;
}

.mkw-form {
  display: flex;
  gap: 9px;
}

.mkw-form input {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border: 1px solid #b6cbd4;
  border-radius: 15px;
  background: #f6f9fa;
  color: var(--mkw-ink);
  outline: none;
}

.mkw-form input:focus {
  border-color: var(--mkw-teal);
  box-shadow: 0 0 0 3px #0b948b25;
}

.mkw-form input::placeholder {
  color: #8495aa;
}

.mkw-form button,
.mkw-finish a {
  padding: 11px 18px;
  border: 0;
  border-radius: 14px;
  background: var(--mkw-teal);
  color: white;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.mkw-form button:not(:disabled):hover,
.mkw-finish a:hover {
  background: #077970;
}

.mkw-footer small {
  display: block;
  margin-top: 8px;
  color: #64748b;
  font-size: 10px;
  line-height: 1.4;
}

/* Animaciones */

@keyframes mkw-appear {
  from {
    opacity: 0;
    transform: translateY(9px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive */

@media (max-width: 600px) {
  .mk-webchat {
    right: 16px;
    bottom: 16px;
  }

  .mkw-launch {
    width: 60px;
    height: 60px;
  }

  .mkw-launch svg {
    width: 29px;
    height: 29px;
  }

  .mkw-window {
    bottom: 76px;
    height: min(700px, calc(100dvh - 106px));
    border-radius: 21px;
  }

  .mkw-header {
    gap: 10px;
    padding: 13px 12px;
  }

  .mkw-heading strong {
    font-size: 15px;
  }

  .mkw-avatar {
    width: 40px;
    height: 40px;
  }

  .mkw-notice {
    padding: 7px 10px;
    font-size: 10px;
  }

  .mkw-scroll {
    padding: 15px 12px;
  }

  .mkw-teaser {
    min-height: 58px;
    padding: 8px 8px 8px 10px;
    border-radius: 16px;
  }

  .mkw-teaser-main {
    gap: 8px;
  }

  .mkw-teaser-main strong {
    font-size: 11px;
  }

  .mkw-teaser-main small {
    font-size: 10px;
  }

  .mkw-teaser-icon {
    width: 32px;
    height: 32px;
  }

  .mkw-teaser-icon svg {
    width: 18px;
    height: 18px;
  }

  .mkw-form button {
    padding: 10px 12px;
  }

  .mkw-form input {
    padding: 9px 10px;
    font-size: 16px;
  }

  .mkw-suggestions {
    margin-left: 0;
  }

  .mkw-bubble {
    font-size: 13px;
  }

  .mkw-footer {
    padding: 10px;
  }

  .mkw-auth {
    padding: 18px 13px;
  }
}

@media (max-width: 350px) {
  .mkw-teaser,
  .mkw-live {
    display: none;
  }
}

@media (max-height: 420px) {
  .mkw-window {
    min-height: 0;
    height: calc(100dvh - 110px);
  }

  .mkw-header {
    padding: 8px 12px;
  }

  .mkw-footer small {
    display: none;
  }
}

/* Accesibilidad */

@media (prefers-reduced-motion: reduce) {
  .mk-webchat * {
    animation: none !important;
    transition: none !important;
  }
}

/* Atención visual: únicamente mientras el chat esté cerrado. */
.mk-webchat .mkw-launch::before,
.mk-webchat .mkw-launch::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 2px solid #14b8a6;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .mk-webchat:not(.is-open) .mkw-launch::before {
    animation: mkw-wave 2.2s ease-out infinite;
  }
  .mk-webchat:not(.is-open) .mkw-launch::after {
    animation: mkw-wave 2.2s ease-out .65s infinite;
  }
  .mk-webchat:not(.is-open) .mkw-launch .mkw-steth {
    animation: mkw-heartbeat-v2 2.2s ease-in-out infinite;
    transform-origin: center;
  }
  .mk-webchat:not(.is-open) .mkw-teaser:not([hidden]) {
    animation: mkw-teaser-cycle 10s ease-in-out infinite;
  }
  /* Al interactuar con el aviso, se mantiene visible y utilizable. */
  .mk-webchat:not(.is-open) .mkw-teaser:hover,
  .mk-webchat:not(.is-open) .mkw-teaser:focus-within {
    animation: none;
    opacity: 1;
    visibility: visible;
    transform: none;
  }
}

@keyframes mkw-wave {
  0% { transform: scale(1); opacity: .85; }
  80%, 100% { transform: scale(var(--mkw-wave-scale, 1.50)); opacity: 0; }
}

@keyframes mkw-heartbeat-v2 {
  0%, 32%, 61%, 100% { transform: scale(1); }
  15% { transform: scale(1.18) rotate(-6deg); }
  46% { transform: scale(1.10) rotate(4deg); }
}

/* Visible unos segundos, se retira suavemente y vuelve a aparecer. */
@keyframes mkw-teaser-cycle {
  0% { opacity: 0; visibility: hidden; transform: translate(10px, 5px) scale(.97); }
  7%, 19%, 49%, 63% { opacity: 1; visibility: visible; transform: translate(0, 0) scale(1); }
  25%, 42% { opacity: 1; visibility: visible; transform: translate(0, -3px) scale(1); }
  72%, 100% { opacity: 0; visibility: hidden; transform: translate(10px, 5px) scale(.97); }
}

/* Ajustes responsive aislados del resto de la página. */
.mk-webchat .mkw-teaser { min-width: 0; }
.mk-webchat .mkw-teaser-main { min-width: 0; }
.mk-webchat .mkw-teaser-main > span:last-child { min-width: 0; }
.mk-webchat .mkw-teaser-main strong,
.mk-webchat .mkw-teaser-main small { white-space: normal; overflow-wrap: anywhere; }
.mk-webchat .mkw-teaser-close { flex: none; }

@media (max-width: 600px) {
  .mk-webchat {
    --mkw-right: max(20px, env(safe-area-inset-right, 0px));
    --mkw-left: max(12px, env(safe-area-inset-left, 0px));
    --mkw-bottom: max(20px, env(safe-area-inset-bottom, 0px));
    --mkw-wave-scale: 1.40;
    right: var(--mkw-right);
    bottom: var(--mkw-bottom);
    max-width: calc(100vw - var(--mkw-right) - var(--mkw-left));
  }
  .mk-webchat .mkw-window {
    width: min(510px, calc(100vw - var(--mkw-right) - var(--mkw-left)));
    height: min(700px, calc(100dvh - var(--mkw-bottom) - 76px - 12px));
    min-height: 0;
  }
}

/* En móviles estrechos, el aviso va encima del botón para que no se corte. */
@media (max-width: 420px) {
  .mk-webchat:not(.is-open) .mkw-teaser:not([hidden]) {
    display: flex;
    position: absolute;
    right: 0;
    bottom: calc(100% + 16px);
    width: max-content;
    max-width: min(290px, calc(100vw - var(--mkw-right) - var(--mkw-left)));
  }
}

@media (max-height: 420px) and (min-width: 601px) {
  .mk-webchat .mkw-window {
    height: calc(100dvh - 24px - 98px - 8px);
    min-height: 0;
  }
}
