/* AIChat Widget v2.3 */

/* ── Botón flotante ── */
#aichat-bubble {
  position: fixed;
  bottom: 24px;
  right: var(--aic-pos-r);
  left: var(--aic-pos-l);
  width: var(--aic-bsize);
  height: var(--aic-bsize);
  border-radius: 50%;
  background: var(--aic-color);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  z-index: 999998;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--aic-bfont);
  transition: transform .2s, box-shadow .2s;
}
#aichat-bubble:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,.22); }
#aichat-bubble:focus-visible { outline: 2px solid var(--aic-color); outline-offset: 3px; }
/* Se oculta cuando el chat está abierto (gestionado por JS con clase .open) */
#aichat-bubble.open { display: none; }

/* ── Ventana del chat ── */
#aichat-win {
  position: fixed;
  bottom: var(--aic-win-bottom);
  right: var(--aic-pos-r);
  left: var(--aic-pos-l);
  width: 440px;
  max-width: calc(100vw - 32px);
  height: 620px;
  max-height: calc(100vh - 60px);
  background: var(--aic-col-bg, #fff);
  border-radius: var(--aic-radius);
  box-shadow: 0 12px 48px rgba(0,0,0,.12), 0 0 0 1px rgba(0,0,0,.04);
  z-index: 999999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--aic-font, 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
}
#aichat-win.open { display: flex; }

/* ── Header ── */
.ac-hdr {
  background: var(--aic-color);
  color: var(--aic-col-header-text, #fff);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
}
.ac-hdr-av {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,.2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.ac-hdr-info { flex: 1; min-width: 0; }
.ac-hdr h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  color: var(--aic-col-header-text, #fff);
}
.ac-hdr span {
  font-size: 11px;
  opacity: .85;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--aic-col-header-text, #fff);
}
.ac-dot {
  width: 6px;
  height: 6px;
  background: #34d399;
  border-radius: 50%;
  display: inline-block;
  animation: acdot 2s infinite;
}
@keyframes acdot { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Botón cerrar (X) en el header ── */
#aichat-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  color: var(--aic-col-header-text, #fff);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
  transition: background .2s;
}
#aichat-close:hover { background: rgba(255,255,255,.35); }
#aichat-close:focus-visible { outline: 2px solid rgba(255,255,255,.7); outline-offset: 2px; }

/* ── Handle de resize ── */
#ac-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  cursor: nw-resize;
  z-index: 10;
  border-radius: var(--aic-radius) 0 0 0;
}
#ac-resize-handle::after {
  content: '';
  position: absolute;
  top: 5px;
  left: 5px;
  width: 10px;
  height: 10px;
  border-top: 2px solid rgba(255,255,255,0.5);
  border-left: 2px solid rgba(255,255,255,0.5);
  border-radius: 2px 0 0 0;
}

/* ── Área de mensajes ── */
.ac-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: var(--aic-col-bg, #fff);
}
.ac-msgs::-webkit-scrollbar { width: 4px; }
.ac-msgs::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ── Mensajes ── */
.ac-m { max-width: 88%; animation: acin .3s ease; }
@keyframes acin { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }
.ac-mb {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.ac-m.bot { align-self: flex-start; }
.ac-m.bot .ac-mb {
  background: var(--aic-col-bot-bubble, #f1f5f9);
  color: var(--aic-col-bot-text, #1e293b);
  border-bottom-left-radius: 4px;
}
.ac-m.usr { align-self: flex-end; }
.ac-m.usr .ac-mb {
  background: var(--aic-col-usr-bubble, var(--aic-color));
  color: var(--aic-col-usr-text, #fff);
  border-bottom-right-radius: 4px;
}

/* ── Tarjetas de enlace ── */
.ac-lnk-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1.5px solid var(--aic-color);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 6px 0 2px 0;
  text-decoration: none !important;
  color: var(--aic-color) !important;
  font-size: 12.5px;
  font-weight: 600;
  transition: all .2s;
  max-width: 100%;
  box-sizing: border-box;
  word-break: break-word;
}
.ac-lnk-card:hover {
  background: var(--aic-color);
  color: #fff !important;
  box-shadow: 0 3px 12px rgba(0,0,0,.12);
  transform: translateY(-1px);
}
.ac-lnk-icon { font-size: 14px; flex-shrink: 0; }
.ac-lnk-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-lnk-arrow { font-size: 14px; flex-shrink: 0; transition: transform .2s; }
.ac-lnk-card:hover .ac-lnk-arrow { transform: translateX(3px); }

/* ── Typing indicator ── */
.ac-typ { display: flex; gap: 4px; padding: 12px 16px; align-self: flex-start; }
.ac-typ span {
  width: 7px; height: 7px;
  background: #94a3b8; border-radius: 50%;
  animation: acb 1.4s ease-in-out infinite;
}
.ac-typ span:nth-child(2) { animation-delay: .2s; }
.ac-typ span:nth-child(3) { animation-delay: .4s; }
@keyframes acb { 0%,80%,100%{transform:scale(.6);opacity:.4} 40%{transform:scale(1);opacity:1} }

/* ── Quick Actions ── */
.ac-qa { display: flex; flex-wrap: wrap; gap: 6px; max-width: 88%; }
.ac-qb {
  background: #fff;
  border: 1.5px solid var(--aic-color);
  color: var(--aic-color);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 100px;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
  white-space: nowrap;
}
.ac-qb:hover, .ac-qb:focus-visible { background: var(--aic-color); color: #fff; }

/* ── Product Cards ── */
.ac-prods {
  display: flex; gap: 10px; overflow-x: auto;
  padding: 4px 2px 8px; max-width: 100%;
  scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
}
.ac-prods::-webkit-scrollbar { height: 3px; }
.ac-prods::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.ac-pc {
  min-width: 170px; max-width: 170px;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  overflow: hidden; flex-shrink: 0; scroll-snap-align: start;
  transition: border-color .2s, box-shadow .2s; cursor: pointer;
}
.ac-pc:hover { border-color: var(--aic-color); box-shadow: 0 4px 12px rgba(0,0,0,.06); }
.ac-pimg { width: 100%; height: 110px; background: #f8fafc; display: flex; align-items: center; justify-content: center; font-size: 40px; overflow: hidden; }
.ac-pimg img { width: 100%; height: 100%; object-fit: cover; }
.ac-pi { padding: 10px 12px; }
.ac-pn { font-size: 12px; font-weight: 600; color: #1e293b; line-height: 1.3; margin-bottom: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ac-pp { font-size: 15px; font-weight: 700; color: var(--aic-color); }
.ac-pold { font-size: 11px; color: #94a3b8; text-decoration: line-through; margin-left: 4px; }
.ac-pbdg { font-size: 9px; font-weight: 700; background: #fef2f2; color: #ef4444; padding: 2px 6px; border-radius: 4px; margin-left: 6px; }
.ac-pstk { font-size: 10px; color: #10b981; margin-top: 3px; display: flex; align-items: center; gap: 3px; }
.ac-pstk .d { width: 5px; height: 5px; background: #10b981; border-radius: 50%; }
.ac-pbuy { width: 100%; margin-top: 8px; background: var(--aic-color); color: #fff; border: none; padding: 8px; border-radius: 8px; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; transition: opacity .2s; }
.ac-pbuy:hover { opacity: .9; }

/* ── Content Suggestions ── */
.ac-sug { display: flex; flex-direction: column; gap: 6px; max-width: 88%; }
.ac-sc { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px 12px; cursor: pointer; transition: all .2s; }
.ac-sc:hover { border-color: var(--aic-color); background: rgba(79,70,229,.04); }
.ac-sci { width: 36px; height: 36px; background: rgba(79,70,229,.07); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.ac-sct h4 { font-size: 12.5px; font-weight: 600; color: #1e293b; margin: 0; line-height: 1.3; }
.ac-sct span { font-size: 11px; color: #64748b; }

/* ── Lead Form ── */
.ac-lf { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 16px; max-width: 88%; }
.ac-lf h4 { font-size: 13px; font-weight: 700; margin: 0 0 4px; }
.ac-lf > p { font-size: 11.5px; color: #64748b; margin: 0 0 12px; line-height: 1.5; }
.ac-lf input, .ac-lf textarea { width: 100%; border: 1px solid #e2e8f0; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; font-family: inherit; outline: none; margin-bottom: 8px; transition: border-color .2s; background: #fff; box-sizing: border-box; }
.ac-lf input:focus, .ac-lf textarea:focus { border-color: var(--aic-color); }
.ac-lf textarea { resize: none; min-height: 56px; }
.ac-lfsub { width: 100%; background: var(--aic-color); color: #fff; border: none; padding: 9px; border-radius: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: inherit; transition: opacity .2s; }
.ac-lfsub:hover { opacity: .9; }
.ac-lfok { text-align: center; padding: 16px; }
.ac-lfok .ck { font-size: 32px; margin-bottom: 8px; }
.ac-lfok h4 { color: #10b981; font-size: 14px; margin: 0 0 4px; }
.ac-lfok p { font-size: 12px; color: #64748b; margin: 0; }

/* ── Input area ── */
#aichat-in {
  padding: 12px 16px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: var(--aic-col-input-bg, #fff);
}
#aichat-ta {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: inherit;
  resize: none;
  max-height: 80px;
  min-height: 40px;
  outline: none;
  transition: border-color .2s;
  line-height: 1.4;
  background: var(--aic-col-input-bg, #fff);
  color: var(--aic-col-input-text, #1e293b);
}
#aichat-ta:focus { border-color: var(--aic-color); }
#aichat-ta::placeholder { color: #94a3b8; }
#aichat-send {
  width: 40px; height: 40px;
  border-radius: 50%; border: none;
  background: var(--aic-color); color: #fff;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  flex-shrink: 0; transition: all .2s;
}
#aichat-send:disabled { opacity: .4; cursor: not-allowed; }
#aichat-send:hover:not(:disabled) { opacity: .9; transform: scale(1.05); }
#aichat-send:focus-visible { outline: 2px solid var(--aic-color); outline-offset: 2px; }

/* ── Footer ── */
.ac-pw { text-align: center; padding: 6px; font-size: 10px; color: var(--aic-col-footer-text, #94a3b8); flex-shrink: 0; }

/* ══════════════════════════════════════
   RESPONSIVE — sin media queries aquí,
   los overrides van en class-aichat-widget.php
   como CSS inline para ganar a --aic-win-bottom
   ══════════════════════════════════════ */
#ac-resize-handle { display: none; }