/* ============================================================
   The King Tech — WhatsApp Chatbot Widget
   ============================================================ */

/* ---- Variables ---- */
:root {
  --wa-green:         #25D366;
  --wa-green-dark:    #128C7E;
  --wa-green-header:  #075E54;
  --wa-bubble-out:    #D9FDD3;
  --wa-bubble-in:     #FFFFFF;
  --wa-chat-bg:       #EFE7DA;
  --wa-text:          #111B21;
  --wa-text-2:        #667781;
  --wa-border:        #E9EDEF;
  --wa-tick:          #53BDEB;
  --wa-radius:        18px;
  --wa-shadow:        0 12px 48px rgba(0,0,0,0.22);
  --wa-w:             375px;
  --wa-h:             610px;
}

/* ---- Floating bubble ---- */
#wa-cb-bubble {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 62px;
  height: 62px;
  background: var(--wa-green);
  border-radius: 50%;
  cursor: pointer;
  z-index: 99990;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 28px rgba(37,211,102,0.50);
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.2s;
  animation: wa-bubble-pop 0.55s cubic-bezier(.34,1.56,.64,1) both;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* Anillo de pulso (ondas) — solo visible cuando está cerrado */
#wa-cb-bubble::before,
#wa-cb-bubble::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--wa-green);
  animation: wa-pulse-ring 2.4s ease-out infinite;
  z-index: -1;
}
#wa-cb-bubble::after { animation-delay: 1.2s; }
#wa-cb-bubble.is-open::before,
#wa-cb-bubble.is-open::after { animation: none; opacity: 0; }

@keyframes wa-pulse-ring {
  0%   { transform: scale(1);   opacity: 0.55; }
  80%  { transform: scale(1.65); opacity: 0; }
  100% { transform: scale(1.65); opacity: 0; }
}

@keyframes wa-bubble-pop {
  0%   { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
#wa-cb-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 32px rgba(37,211,102,0.60);
}
#wa-cb-bubble:active { transform: scale(0.95); }

/* Ícono WA y X — posicionados encima, transición cruzada */
.wa-cb-wa-icon,
.wa-cb-close-icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.32s cubic-bezier(.34,1.56,.64,1), opacity 0.22s ease;
}

/* Ícono WhatsApp SVG */
.wa-cb-wa-icon {
  width: 34px;
  height: 34px;
  fill: #fff;
  transform: scale(1) rotate(0deg);
  opacity: 1;
}
#wa-cb-bubble.is-open .wa-cb-wa-icon {
  transform: scale(0) rotate(-90deg);
  opacity: 0;
}

/* Ícono X (cerrar) */
.wa-cb-close-icon {
  color: #fff;
  font-size: 22px;
  line-height: 1;
  transform: scale(0) rotate(90deg);
  opacity: 0;
}
#wa-cb-bubble.is-open .wa-cb-close-icon {
  transform: scale(1) rotate(0deg);
  opacity: 1;
}

/* badge */
#wa-cb-badge {
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 20px;
  background: #FF3B30;
  border-radius: 50%;
  border: 2px solid #fff;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: wa-badge-pulse 2s infinite;
  pointer-events: none;
}
#wa-cb-badge.hidden { display: none; }
@keyframes wa-badge-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,59,48,0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(255,59,48,0); }
}

/* ---- Chat window ---- */
#wa-cb-window {
  position: fixed;
  bottom: 104px;
  right: 28px;
  width: var(--wa-w);
  height: var(--wa-h);
  background: var(--wa-chat-bg);
  border-radius: 20px;
  box-shadow: var(--wa-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99989;
  transform: scale(0.85) translateY(30px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), opacity 0.25s ease;
}
#wa-cb-window.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ---- Header ---- */
#wa-cb-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--wa-green-header);
  flex-shrink: 0;
}
#wa-cb-close-btn {
  display: none; /* desktop: X está en el bubble */
  order: -1;
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  font-size: 20px;
  padding: 4px 8px 4px 0;
  cursor: pointer;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
#wa-cb-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.25);
}
#wa-cb-header-info {
  flex: 1;
  min-width: 0;
}
#wa-cb-header-name {
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#wa-cb-header-status {
  color: rgba(255,255,255,0.75);
  font-size: 12.5px;
  margin-top: 1px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.wa-cb-online-dot {
  width: 7px;
  height: 7px;
  background: #4ADE80;
  border-radius: 50%;
  display: inline-block;
  animation: wa-online-blink 2s infinite;
}
@keyframes wa-online-blink {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* ---- Chat background pattern ---- */
#wa-cb-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  background-color: var(--wa-chat-bg);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' opacity='0.04'%3E%3Cpath d='M50 50l10-10M70 50l10-10M90 50l10-10M110 50l10-10M130 50l10-10M150 50l10-10M170 50l10-10M190 50l10-10M210 50l10-10M230 50l10-10M250 50l10-10M270 50l10-10M290 50l10-10M310 50l10-10M330 50l10-10M350 50l10-10M370 50l10-10' stroke='%23000' stroke-width='1'/%3E%3C/svg%3E");
}
#wa-cb-messages::-webkit-scrollbar { width: 5px; }
#wa-cb-messages::-webkit-scrollbar-track { background: transparent; }
#wa-cb-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

/* ---- Date chip ---- */
.wa-cb-date-chip {
  display: flex;
  justify-content: center;
  margin: 8px 0;
}
.wa-cb-date-chip span {
  background: rgba(225,245,254,0.92);
  color: var(--wa-text-2);
  font-size: 11.5px;
  padding: 4px 12px;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* ---- Message rows ---- */
.wa-cb-msg-row {
  display: flex;
  margin: 1px 0;
}
.wa-cb-msg-row.in  { justify-content: flex-start; }
.wa-cb-msg-row.out { justify-content: flex-end; }

/* ---- Bubbles ---- */
.wa-cb-bubble-msg {
  max-width: 82%;
  padding: 7px 10px 6px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--wa-text);
  word-break: break-word;
  position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,0.10);
  animation: wa-msg-in 0.18s ease both;
}
@keyframes wa-msg-in {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.wa-cb-msg-row.in  .wa-cb-bubble-msg { background: var(--wa-bubble-in); border-top-left-radius: 0; }
.wa-cb-msg-row.out .wa-cb-bubble-msg { background: var(--wa-bubble-out); border-top-right-radius: 0; }

/* tail triangles */
.wa-cb-msg-row.in .wa-cb-bubble-msg::before {
  content: '';
  position: absolute;
  top: 0; left: -7px;
  border: 7px solid transparent;
  border-top-color: var(--wa-bubble-in);
  border-right-color: var(--wa-bubble-in);
  border-top-left-radius: 2px;
}
.wa-cb-msg-row.out .wa-cb-bubble-msg::after {
  content: '';
  position: absolute;
  top: 0; right: -7px;
  border: 7px solid transparent;
  border-top-color: var(--wa-bubble-out);
  border-left-color: var(--wa-bubble-out);
  border-top-right-radius: 2px;
}

/* meta (time + ticks) */
.wa-cb-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
  float: right;
  margin-left: 8px;
}
.wa-cb-time {
  font-size: 10.5px;
  color: var(--wa-text-2);
  white-space: nowrap;
}
.wa-cb-ticks { font-size: 13px; color: var(--wa-text-2); line-height: 1; }
.wa-cb-ticks.read { color: var(--wa-tick); }

/* ---- Typing indicator ---- */
.wa-cb-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--wa-bubble-in);
  border-radius: 8px;
  border-top-left-radius: 0;
  width: fit-content;
  box-shadow: 0 1px 2px rgba(0,0,0,0.10);
  animation: wa-msg-in 0.18s ease both;
}
.wa-cb-typing::before {
  content: '';
  position: absolute;
  top: 0; left: -7px;
  border: 7px solid transparent;
  border-top-color: var(--wa-bubble-in);
  border-right-color: var(--wa-bubble-in);
}
.wa-cb-typing-dot {
  width: 7px; height: 7px;
  background: #adb5bd;
  border-radius: 50%;
  animation: wa-typing-bounce 1.2s infinite;
}
.wa-cb-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.wa-cb-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes wa-typing-bounce {
  0%,80%,100% { transform: translateY(0); }
  40%          { transform: translateY(-6px); }
}

/* ---- Quick replies ---- */
.wa-cb-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 10px;
}
.wa-cb-qr-btn {
  background: #fff;
  border: 1.5px solid var(--wa-green);
  color: var(--wa-green-dark);
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.wa-cb-qr-btn:hover {
  background: var(--wa-green);
  color: #fff;
}
.wa-cb-qr-btn:active { transform: scale(0.95); }

/* ---- Product cards ---- */
.wa-cb-products {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 280px;
}
.wa-cb-product-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 10px;
  padding: 9px 11px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.10);
  text-decoration: none;
  color: var(--wa-text);
  transition: background 0.15s;
  cursor: pointer;
}
.wa-cb-product-card:hover { background: #F0F9F0; }
.wa-cb-product-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: #f5f5f5;
}
.wa-cb-product-info { flex: 1; min-width: 0; }
.wa-cb-product-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--wa-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.wa-cb-product-price {
  font-size: 13px;
  font-weight: 700;
  color: var(--wa-green-dark);
}
.wa-cb-product-arrow {
  color: var(--wa-green);
  font-size: 16px;
  flex-shrink: 0;
}

/* "Ver en tienda" link after cards */
.wa-cb-see-all {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--wa-green-dark);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  margin-top: 2px;
  transition: color 0.15s;
}
.wa-cb-see-all:hover { color: var(--wa-green); }

/* ---- Advisor button ---- */
.wa-cb-advisor-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--wa-green);
  color: #fff;
  border: none;
  border-radius: 22px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  margin-top: 4px;
  box-shadow: 0 3px 12px rgba(37,211,102,0.35);
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.wa-cb-advisor-btn:hover  { background: var(--wa-green-dark); color: #fff; }
.wa-cb-advisor-btn:active { transform: scale(0.96); }
.wa-cb-advisor-btn svg { width: 18px; height: 18px; fill: #fff; flex-shrink: 0; }

/* ---- Input area ---- */
#wa-cb-footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px 14px;
  background: #F0F2F5;
  flex-shrink: 0;
}
#wa-cb-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 24px;
  padding: 8px 14px;
  min-height: 44px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
#wa-cb-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  background: transparent;
  color: var(--wa-text);
  resize: none;
  min-height: 22px;
  max-height: 96px;
  line-height: 1.4;
  font-family: inherit;
}
#wa-cb-input::placeholder { color: #9AA3AF; }
#wa-cb-send-btn {
  width: 44px;
  height: 44px;
  background: var(--wa-green);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(37,211,102,0.30);
  -webkit-tap-highlight-color: transparent;
}
#wa-cb-send-btn:hover  { background: var(--wa-green-dark); }
#wa-cb-send-btn:active { transform: scale(0.92); }
#wa-cb-send-btn svg { width: 22px; height: 22px; fill: #fff; margin-left: 2px; }

/* ---- "Powered by" ---- */
#wa-cb-powered {
  text-align: center;
  font-size: 10.5px;
  color: #9AA3AF;
  padding: 0 0 4px;
  background: #F0F2F5;
  flex-shrink: 0;
}
#wa-cb-powered span { color: var(--wa-green-dark); font-weight: 600; }

/* ---- Bold/italic inside bubbles ---- */
.wa-cb-bubble-msg strong { font-weight: 700; }
.wa-cb-bubble-msg em     { font-style: italic; }

/* ============================================================
   RESPONSIVE — Móvil: ventana flotante compacta (no full width)
   ============================================================ */
@media (max-width: 540px) {
  #wa-cb-bubble { bottom: 18px; right: 16px; }

  /* Ventana por encima de la burbuja en móvil */
  #wa-cb-window.is-open { z-index: 99995; }

  /* Ventana fullscreen en móvil */
  #wa-cb-window {
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    transform: translateY(100%);
    transform-origin: bottom center;
  }
  #wa-cb-window.is-open { transform: translateY(0); }

  /* Botón X: visible en header móvil, alineado a la derecha */
  #wa-cb-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    order: 10;          /* empuja al extremo derecho */
    margin-left: auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    font-size: 18px;
    padding: 0;
    flex-shrink: 0;
  }
  #wa-cb-close-btn i { font-family: "Font Awesome 6 Free" !important; font-weight: 900; }

  .wa-cb-products { max-width: 100%; }
  #wa-cb-footer { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0)); }
}
