/* StudioPro 360 – Asistente IA */
#sp360cb {
  --sp360-primary: #111111;
  --sp360-on-primary: #ffffff;
  --sp360-accent: #25D366;
  --sp360-on-accent: #111111;
  --sp360-bg: #ffffff;
  --sp360-surface: #f4f4f5;
  --sp360-text: #18181b;
  --sp360-muted: #71717a;
  --sp360-border: #e4e4e7;
  --sp360-radius: 18px;
  --sp360-x: 20px;
  --sp360-y: 20px;
  --sp360-x-m: 16px;
  --sp360-y-m: 16px;
  --sp360-size: 60px;
  position: fixed;
  bottom: var(--sp360-y);
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--sp360-text);
}
@media (prefers-color-scheme: dark) {
  #sp360cb {
    --sp360-bg: #18181b;
    --sp360-surface: #27272a;
    --sp360-text: #f4f4f5;
    --sp360-muted: #a1a1aa;
    --sp360-border: #3f3f46;
  }
}
#sp360cb.sp360cb--right { right: var(--sp360-x); }
#sp360cb.sp360cb--left { left: var(--sp360-x); }
#sp360cb *, #sp360cb *::before, #sp360cb *::after { box-sizing: border-box; }
#sp360cb button, #sp360cb textarea { font: inherit; color: inherit; margin: 0; }
#sp360cb svg { width: 20px; height: 20px; display: block; }

/* Botón flotante */
#sp360cb .sp360cb-launcher {
  width: var(--sp360-size); height: var(--sp360-size); border-radius: 50%; border: 0; cursor: pointer;
  position: relative; overflow: hidden;
  background: var(--sp360-primary); color: var(--sp360-on-primary);
  display: grid; place-items: center; padding: 0;
  box-shadow: 0 8px 24px rgba(0,0,0,.22);
  transition: transform .2s ease;
  margin-left: auto;
}
#sp360cb.sp360cb--left .sp360cb-launcher { margin-left: 0; }
#sp360cb .sp360cb-launcher:hover { transform: scale(1.06); }
#sp360cb .sp360cb-launcher svg { width: calc(var(--sp360-size) * .43); height: calc(var(--sp360-size) * .43); }
#sp360cb .sp360cb-ico-close { display: none; }
#sp360cb.sp360cb--open .sp360cb-ico-open { display: none; }
#sp360cb.sp360cb--open .sp360cb-ico-close { display: block; }

/* Botón con favicon o imagen propia */
#sp360cb .sp360cb-launcher--img { background: #ffffff; border: 1px solid rgba(0,0,0,.08); }
#sp360cb .sp360cb-launcher--img .sp360cb-ico-open { display: none; }
#sp360cb .sp360cb-launcher-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
#sp360cb.sp360cb--open .sp360cb-launcher--img { background: var(--sp360-primary); }
#sp360cb.sp360cb--open .sp360cb-launcher-img { display: none; }

/* Avatar con favicon o imagen propia */
#sp360cb .sp360cb-avatar--img { background: #ffffff; overflow: hidden; padding: 0; }
#sp360cb .sp360cb-avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Panel */
#sp360cb .sp360cb-panel {
  position: absolute; bottom: calc(var(--sp360-size) + 16px);
  width: 380px; max-width: calc(100vw - var(--sp360-x) - 16px);
  height: 600px; max-height: calc(100vh - var(--sp360-y) - var(--sp360-size) - 40px);
  min-height: 320px;
  background: var(--sp360-bg);
  border: 1px solid var(--sp360-border);
  border-radius: var(--sp360-radius);
  box-shadow: 0 18px 50px rgba(0,0,0,.25);
  display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(12px) scale(.98); pointer-events: none; visibility: hidden;
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
#sp360cb.sp360cb--right .sp360cb-panel { right: 0; transform-origin: bottom right; }
#sp360cb.sp360cb--left .sp360cb-panel { left: 0; transform-origin: bottom left; }
#sp360cb.sp360cb--open .sp360cb-panel { opacity: 1; transform: none; pointer-events: auto; visibility: visible; }

#sp360cb .sp360cb-header {
  display: flex; align-items: center; gap: 10px; padding: 14px 12px 14px 16px;
  background: var(--sp360-primary); color: var(--sp360-on-primary);
}
#sp360cb .sp360cb-avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: .5px;
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28);
}
#sp360cb .sp360cb-titles { flex: 1; min-width: 0; }
#sp360cb .sp360cb-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sp360cb .sp360cb-sub { font-size: 12.5px; opacity: .8; display: flex; align-items: center; gap: 6px; }
#sp360cb .sp360cb-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }
#sp360cb .sp360cb-icon-btn {
  background: transparent; border: 0; padding: 7px; border-radius: 8px; cursor: pointer; color: inherit; opacity: .85;
}
#sp360cb .sp360cb-icon-btn:hover { opacity: 1; background: rgba(255,255,255,.14); }
#sp360cb .sp360cb-icon-btn svg { width: 18px; height: 18px; }

/* Mensajes */
#sp360cb .sp360cb-log { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
#sp360cb .sp360cb-msg { display: flex; }
#sp360cb .sp360cb-msg--user { justify-content: flex-end; }
#sp360cb .sp360cb-bubble {
  max-width: 85%; padding: 10px 13px; border-radius: 16px; word-wrap: break-word; overflow-wrap: anywhere;
}
#sp360cb .sp360cb-msg--assistant .sp360cb-bubble { background: var(--sp360-surface); border-bottom-left-radius: 5px; }
#sp360cb .sp360cb-msg--user .sp360cb-bubble {
  background: var(--sp360-primary); color: var(--sp360-on-primary); border-bottom-right-radius: 5px; white-space: pre-wrap;
}
#sp360cb .sp360cb-msg--error .sp360cb-bubble { background: #fef2f2; color: #991b1b; }
#sp360cb .sp360cb-bubble p { margin: 0 0 6px; }
#sp360cb .sp360cb-bubble p:last-child { margin-bottom: 0; }
#sp360cb .sp360cb-bubble ul { margin: 4px 0 6px; padding-left: 18px; }
#sp360cb .sp360cb-bubble li { margin: 2px 0; }
#sp360cb .sp360cb-bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; font-weight: 600; }

#sp360cb .sp360cb-typing .sp360cb-bubble { display: flex; gap: 4px; padding: 13px 14px; }
#sp360cb .sp360cb-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--sp360-muted);
  animation: sp360cb-bounce 1.2s infinite ease-in-out;
}
#sp360cb .sp360cb-typing span:nth-child(2) { animation-delay: .15s; }
#sp360cb .sp360cb-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes sp360cb-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }

/* Sugerencias */
#sp360cb .sp360cb-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 14px 10px; }
#sp360cb .sp360cb-chips[hidden] { display: none; }
#sp360cb .sp360cb-chip {
  background: var(--sp360-bg); border: 1px solid var(--sp360-border); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; text-align: left;
}
#sp360cb .sp360cb-chip:hover { border-color: var(--sp360-primary); }

/* Entrada */
#sp360cb .sp360cb-form {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--sp360-border);
}
#sp360cb .sp360cb-input {
  flex: 1; resize: none; border: 1px solid var(--sp360-border); border-radius: 12px;
  padding: 9px 12px; background: var(--sp360-bg); max-height: 120px; outline: none; font-size: 15px;
}
#sp360cb .sp360cb-input:focus { border-color: var(--sp360-primary); }
#sp360cb .sp360cb-send {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--sp360-primary); color: var(--sp360-on-primary); display: grid; place-items: center; padding: 0;
}
#sp360cb .sp360cb-send:disabled { opacity: .5; cursor: default; }
#sp360cb .sp360cb-send svg { width: 18px; height: 18px; }
#sp360cb .sp360cb-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }

/* Pie */
#sp360cb .sp360cb-footer { padding: 0 12px 10px; display: flex; flex-direction: column; gap: 6px; }
#sp360cb .sp360cb-wa {
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 9px; border-radius: 12px;
  background: var(--sp360-accent); color: var(--sp360-on-accent); text-decoration: none; font-weight: 600; font-size: 14px;
}
#sp360cb .sp360cb-wa:hover { filter: brightness(.95); }
#sp360cb .sp360cb-wa svg { width: 18px; height: 18px; }
#sp360cb .sp360cb-legal { font-size: 11px; color: var(--sp360-muted); text-align: center; }
#sp360cb .sp360cb-legal a { color: inherit; }

#sp360cb :focus-visible { outline: 2px solid var(--sp360-primary); outline-offset: 2px; }

/* Móvil: pantalla completa */
@media (max-width: 520px) {
  #sp360cb { bottom: var(--sp360-y-m); }
  #sp360cb.sp360cb--right { right: var(--sp360-x-m); }
  #sp360cb.sp360cb--left { left: var(--sp360-x-m); }
  #sp360cb .sp360cb-panel {
    position: fixed; inset: 0; width: 100%; max-width: none; height: 100%; max-height: none; border-radius: 0; border: 0;
  }
  #sp360cb.sp360cb--open .sp360cb-launcher { display: none; }
  #sp360cb .sp360cb-input { font-size: 16px; } /* evita zoom en iOS */
}
@media (prefers-reduced-motion: reduce) {
  #sp360cb .sp360cb-panel, #sp360cb .sp360cb-launcher { transition: none; }
  #sp360cb .sp360cb-typing span { animation: none; }
}
