/* =========================================================
   MercaAI Chat v1.0.2 – Frontend Styles
   ========================================================= */

:root {
  --mercaai-primary:     #0071a1;
  --mercaai-header-txt:  #ffffff;
  --mercaai-bg:          #f4f6f8;
  --mercaai-user-bubble: #0071a1;
  --mercaai-bot-bubble:  #ffffff;
  --mercaai-icon-color:  #0071a1;
  --mercaai-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Apple Color Emoji', 'Noto Color Emoji', Roboto, sans-serif;
  /* Tamaño de burbujas — sobrescritos dinámicamente desde JS */
  --mercaai-bbl-fs:  14px;
  --mercaai-bbl-pv:  10px;
  --mercaai-bbl-ph:  14px;
  --mercaai-bbl-mw:  82%;
}

/* ── Wrapper ─────────────────────────────────────────── */
#mercaai-wrap {
  position: fixed !important;
  bottom: 20px;
  right: 20px;
  z-index: 999999;
  font-family: var(--mercaai-font);
}
#mercaai-wrap.mercaai-pos-left { right: auto; left: 20px; }

/* ── Trigger ─────────────────────────────────────────── */
#mercaai-trigger {
  width: 58px !important;
  height: 58px !important;
  border-radius: 50% !important;
  background: var(--mercaai-icon-color) !important;
  border: none !important;
  box-shadow: none !important;
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 18px rgba(0,0,0,.28) !important;
  transition: transform .2s;
  position: relative;
  padding: 0 !important;
  outline: none !important;
  color: #fff !important;
}
#mercaai-trigger:hover { transform: scale(1.07); }
.mercaai-icon-open,
.mercaai-icon-close {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.mercaai-badge {
  position: absolute;
  top: -3px; right: -3px;
  background: #e74c3c;
  color: #fff;
  border-radius: 50%;
  width: 20px; height: 20px;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  line-height: 1;
}

/* ── Ventana (oculta por defecto) ────────────────────── */
#mercaai-window {
  display: none;               /* CERRADA por defecto */
  position: absolute;
  bottom: 70px; right: 0;
  width: 370px;
  max-width: calc(100vw - 24px);
  height: 520px;
  max-height: calc(100vh - 110px);
  background: var(--mercaai-bg);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
}
#mercaai-window.mercaai-open {
  display: flex;
  animation: mercaaiIn .22s ease;
}
#mercaai-wrap.mercaai-pos-left #mercaai-window { right: auto; left: 0; transform-origin: bottom left; }

#mercaai-window.mercaai-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important; height: 100vh !important;
  max-width: 100vw !important; max-height: 100vh !important;
  border-radius: 0 !important;
}

@keyframes mercaaiIn {
  from { opacity:0; transform:translateY(10px) scale(.97); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}

/* ── Header ──────────────────────────────────────────── */
.mercaai-header {
  background: var(--mercaai-primary);
  color: #fff;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  user-select: none;
}
.mercaai-header-left {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 15px;
  color: var(--mercaai-header-txt);
}
.mercaai-status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(255,255,255,.35);
  flex-shrink: 0;
}
.mercaai-header-actions { display: flex; align-items: center; gap: 2px; }

/* ── Header buttons – iconos 100% CSS ────────────────── */
.mercaai-hbtn {
  position: relative;
  width: 30px !important;
  height: 30px !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  padding: 0 !important;
  margin: 0 !important;
  cursor: pointer;
  border-radius: 5px !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  text-decoration: none !important;
  color: transparent !important;  /* ocultar cualquier texto residual */
  font-size: 0 !important;
  overflow: hidden;
  flex-shrink: 0;
}
.mercaai-hbtn:hover { background: rgba(255,255,255,.2) !important; }

/* ── Icono Cerrar (X) ────────────────────────────────── */
#mercaai-close-btn::before,
#mercaai-close-btn::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 2.5px;
  background: rgba(255,255,255,.95);
  border-radius: 2px;
}
#mercaai-close-btn::before { transform: translate(-50%,-50%) rotate(45deg); }
#mercaai-close-btn::after  { transform: translate(-50%,-50%) rotate(-45deg); }

/* ── Icono Maximizar (rectángulo con esquinas) ─────────── */
#mercaai-maximize::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 13px; height: 11px;
  border: 2px solid rgba(255,255,255,.95);
  border-radius: 2px;
  box-sizing: border-box;
}
/* Barra de título del rectángulo */
#mercaai-maximize::after {
  content: '';
  position: absolute;
  top: calc(50% - 5.5px + 2px);
  left: 50%;
  transform: translateX(-50%);
  width: 13px; height: 2px;
  background: rgba(255,255,255,.95);
}

/* ── Icono Restaurar (dos cuadrados superpuestos) ───────── */
#mercaai-restore::before {
  content: '';
  position: absolute;
  top: calc(50% - 1px); left: calc(50% - 1px);
  transform: translate(-50%,-50%);
  width: 9px; height: 8px;
  border: 2px solid rgba(255,255,255,.95);
  border-radius: 1px;
  background: var(--mercaai-primary);
  box-sizing: border-box;
}
#mercaai-restore::after {
  content: '';
  position: absolute;
  top: calc(50% + 2px); left: calc(50% + 2px);
  transform: translate(-50%,-50%);
  width: 9px; height: 8px;
  border: 2px solid rgba(255,255,255,.95);
  border-radius: 1px;
  background: transparent;
  box-sizing: border-box;
}

/* ── WhatsApp ────────────────────────────────────────── */
.mercaai-wa-btn {
  color: transparent !important;
  overflow: visible !important;
}
.mercaai-wa-btn:hover { background: rgba(37,211,102,.18) !important; }
.mercaai-wa-btn svg { flex-shrink: 0; }

/* ── Mensajes ────────────────────────────────────────── */
.mercaai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.mercaai-messages::-webkit-scrollbar { width: 4px; }
.mercaai-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.14); border-radius: 2px; }

/* ── Burbujas ────────────────────────────────────────── */
.mercaai-msg { display:flex; flex-direction:column; max-width:86%; animation:mercaaiFade .18s ease; }
.mercaai-msg.user { align-self:flex-end;   align-items:flex-end; }
.mercaai-msg.bot  { align-self:flex-start; align-items:flex-start; }

@keyframes mercaaiFade {
  from { opacity:0; transform:translateY(5px); }
  to   { opacity:1; transform:translateY(0); }
}

.mercaai-bubble {
  /* Forzar una cadena con fuentes de emoji para evitar cuadros vacíos en Windows/Chrome. */
  font-family: var(--mercaai-font);
  padding: var(--mercaai-bbl-pv) var(--mercaai-bbl-ph);
  max-width: var(--mercaai-bbl-mw);
  border-radius: 18px;
  font-size: var(--mercaai-bbl-fs);
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: break-word;
}
.mercaai-msg.user .mercaai-bubble {
  background: var(--mercaai-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.mercaai-msg.bot .mercaai-bubble {
  background: var(--mercaai-bot-bubble);
  color: #222;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
/* Links en azul */
.mercaai-bubble a { color:#1a73e8 !important; text-decoration:underline; font-weight:500; }
.mercaai-bubble a:hover { color:#0d47a1 !important; }
.mercaai-msg.user .mercaai-bubble a { color:#aed6f1 !important; }

.mercaai-ts { font-size:10px; color:#aaa; margin-top:3px; padding:0 4px; }

/* ── Typing ──────────────────────────────────────────── */
.mercaai-typing {
  padding: 6px 16px 8px;
  display: flex; gap: 5px; align-items: center; flex-shrink: 0;
}
.mercaai-typing span {
  width:8px; height:8px; border-radius:50%;
  background:#bbb;
  animation: mercaaiDot 1.2s infinite ease-in-out;
}
.mercaai-typing span:nth-child(2) { animation-delay:.2s; }
.mercaai-typing span:nth-child(3) { animation-delay:.4s; }
@keyframes mercaaiDot {
  0%,80%,100% { transform:scale(.6); opacity:.4; }
  40%         { transform:scale(1);  opacity:1; }
}

/* ── Input (una sola línea) ──────────────────────────── */
.mercaai-footer {
  border-top: 1px solid rgba(0,0,0,.08);
  padding: 10px 12px;
  background: #fff;
  flex-shrink: 0;
}
.mercaai-input-row { display:flex; align-items:center; gap:8px; }

#mercaai-input {
  flex: 1;
  height: 40px;
  border: 1px solid #ddd !important;
  border-radius: 22px !important;
  padding: 0 14px !important;
  font-size: 14px;
  font-family: var(--mercaai-font);
  outline: none !important;
  background: #f9f9f9 !important;
  box-shadow: none !important;
  box-sizing: border-box;
  resize: none;
  line-height: 40px;
}
#mercaai-input:focus {
  border-color: var(--mercaai-primary) !important;
  background: #fff !important;
}

#mercaai-send {
  width: 40px !important; height: 40px !important;
  min-width: 40px;
  border-radius: 50% !important;
  background: var(--mercaai-primary) !important;
  border: none !important;
  box-shadow: none !important;
  cursor: pointer;
  display: flex !important;
  align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform .15s;
  padding: 0 !important;
  outline: none !important;
}
#mercaai-send:hover  { transform:scale(1.07); }
#mercaai-send:disabled { opacity:.5; cursor:not-allowed; }

/* ── Tarjetas de producto (solo imagen + nombre) ─────── */
.mercaai-products {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: flex-start;
  width: 100%;
  max-width: 300px;
}
.mercaai-product-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 8px 10px;
  text-decoration: none !important;
  color: inherit !important;
  transition: box-shadow .18s, border-color .18s;
}
.mercaai-product-card:hover {
  box-shadow: 0 3px 12px rgba(0,0,0,.12);
  border-color: var(--mercaai-primary);
  text-decoration: none !important;
}
.mercaai-product-card img {
  width: 52px; height: 52px;
  object-fit: contain;
  border-radius: 7px;
  background: #f5f5f5;
  flex-shrink: 0;
}
.mercaai-product-name {
  font-size: 13px;
  font-weight: 600;
  color: #222;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Shortcode lupa ──────────────────────────────────── */
.mercaai-shortcode-trigger {
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--mercaai-primary, #0071a1);
  transition: transform .15s;
  vertical-align: middle;
}
.mercaai-shortcode-trigger:hover { transform:scale(1.15); }

/* ── Mobile ──────────────────────────────────────────── */
@media (max-width: 480px) {
  #mercaai-wrap { right:12px; bottom:12px; }
  #mercaai-wrap.mercaai-pos-left { left:12px; right:auto; }
  #mercaai-window {
    position: fixed !important;
    bottom:0 !important; right:0 !important; left:0 !important;
    width:100vw !important; max-width:100vw !important;
    height:88vh !important; max-height:88vh !important;
    border-radius:20px 20px 0 0 !important;
    transform-origin: bottom center !important;
  }
  #mercaai-trigger { width:52px !important; height:52px !important; }
}
@media (min-width:481px) and (max-width:768px) {
  #mercaai-window { width:340px; height:480px; }
}

/* =========================================================
   MercaAI Embed – Chat incrustado en página  [mercaai_embed]
   ========================================================= */
.mercaai-embed-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,.14);
  border: 1px solid rgba(0,0,0,.08);
  background: var(--mercaai-bg, #f4f6f8);
  font-family: var(--mercaai-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Apple Color Emoji', 'Noto Color Emoji', Roboto, sans-serif);
}
.mercaai-embed-wrap .mercaai-embed-header {
  flex-shrink: 0;
}
.mercaai-embed-wrap .mercaai-embed-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.mercaai-embed-wrap .mercaai-embed-messages::-webkit-scrollbar { width: 4px; }
.mercaai-embed-wrap .mercaai-embed-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 2px; }

.mercaai-embed-wrap .mercaai-embed-typing { flex-shrink: 0; }

.mercaai-embed-wrap .mercaai-footer { flex-shrink: 0; }

/* Botón enviar del embed */
.mercaai-embed-send {
  width: 40px !important; height: 40px !important;
  min-width: 40px;
  border-radius: 50% !important;
  background: var(--mercaai-primary, #0071a1) !important;
  border: none !important; box-shadow: none !important; outline: none !important;
  cursor: pointer;
  display: flex !important; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform .15s;
  padding: 0 !important;
}
.mercaai-embed-send:hover  { transform: scale(1.07); }
.mercaai-embed-send:disabled { opacity: .5; cursor: not-allowed; }

/* Input del embed */
.mercaai-embed-input {
  flex: 1;
  height: 40px;
  border: 1px solid #ddd !important;
  border-radius: 22px !important;
  padding: 0 14px !important;
  font-size: 14px;
  outline: none !important; box-shadow: none !important;
  background: #f9f9f9 !important;
  box-sizing: border-box;
}
.mercaai-embed-input:focus {
  border-color: var(--mercaai-primary, #0071a1) !important;
  background: #fff !important;
}

/* Link WhatsApp en respuestas */
.mercaai-wa-number {
  color: #25d366 !important;
  text-decoration: none !important;
  font-weight: 600;
  white-space: nowrap;
}
.mercaai-wa-number:hover { text-decoration: underline !important; }

/* Mobile embed: altura 100% del viewport visible */
@media (max-width: 480px) {
  .mercaai-embed-wrap { border-radius: 0 !important; height: 100svh !important; }
}

/* v1.6 Quality First: identifica la variación exacta sin ocultar el producto padre. */
.mercaai-product-variation{display:block;font-size:.82em;line-height:1.25;margin-top:3px;opacity:.82}
