/* © 2026 Juan Pazmino B — chatbot de pre-venta (widget).
   Autocontenido: define sus propias vars --cb-* para funcionar igual en
   homepage, artículos y pills (las pills no cargan style.css). */

#cb-widget {
  /* Tema oscuro (por defecto) */
  --cb-bg:          #0A0A0B;
  --cb-surface:     rgba(13, 13, 15, 0.97);
  --cb-gold:        rgba(184, 147, 80, 0.90);
  --cb-gold-hi:     rgba(212, 176, 104, 0.90);
  --cb-gold-dim:    rgba(184, 147, 80, 0.45);
  --cb-border:      rgba(184, 147, 80, 0.30);
  --cb-border-soft: rgba(184, 147, 80, 0.16);
  --cb-text:        rgba(245, 240, 232, 0.90);
  --cb-muted:       rgba(245, 240, 232, 0.55);
  --cb-user-bg:     rgba(184, 147, 80, 0.10);
  --cb-shadow:      rgba(6, 5, 4, 0.55);
}

[data-theme="light"] #cb-widget {
  --cb-bg:          #F4EDE1;
  --cb-surface:     rgba(251, 246, 234, 0.98);
  --cb-gold:        rgba(122, 88, 24, 0.90);
  --cb-gold-hi:     rgba(92, 66, 18, 0.90);
  --cb-gold-dim:    rgba(122, 88, 24, 0.50);
  --cb-border:      rgba(122, 88, 24, 0.35);
  --cb-border-soft: rgba(122, 88, 24, 0.18);
  --cb-text:        rgba(26, 26, 26, 0.85);
  --cb-muted:       rgba(26, 26, 26, 0.55);
  --cb-user-bg:     rgba(122, 88, 24, 0.08);
  --cb-shadow:      rgba(60, 50, 30, 0.25);
}

/* ── Burbuja ─────────────────────────────────────────────
   Siempre oscura con la espiral en oro — el look del favicon,
   constante en ambos temas. */
.cb-bubble {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #0A0A0B;
  border: 1px solid rgba(184, 147, 80, 0.30);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 18;
  padding: 0;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.9s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.9s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.4s ease;
}
.cb-bubble.cb-in { opacity: 1; transform: translateY(0); }
.cb-bubble:hover { border-color: rgba(212, 176, 104, 0.75); }
.cb-bubble:focus-visible { outline: 1px solid var(--cb-gold); outline-offset: 3px; }
.cb-bubble svg { width: 32px; height: 32px; display: block; }
.cb-bubble.cb-hidden { display: none; }

/* ── Panel ─────────────────────────────────────────────── */
.cb-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 360px;
  height: min(560px, calc(100vh - 48px));
  background: var(--cb-surface);
  border: 1px solid var(--cb-border-soft);
  border-radius: 14px;
  box-shadow: 0 24px 64px var(--cb-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 19;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.cb-panel.cb-open { display: flex; }
.cb-panel.cb-in { opacity: 1; transform: translateY(0); }

/* ── Cabecera (etiqueta Art. 50 + nombre) ───────────────── */
.cb-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 18px 12px 20px;
  border-bottom: 1px solid var(--cb-border-soft);
  flex-shrink: 0; /* nunca se comprime cuando el teclado encoge el panel */
}
.cb-chips, .cb-inputrow, .cb-footer { flex-shrink: 0; }
.cb-ai-label {
  display: block;
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--cb-gold-dim);
}
.cb-name {
  display: block;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 18px;
  font-weight: 200;
  color: var(--cb-text);
  margin-top: 2px;
}
.cb-close {
  background: transparent;
  border: none;
  color: var(--cb-muted);
  font-family: 'Jost', sans-serif;
  font-size: 22px;
  font-weight: 100;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  transition: color 0.3s ease;
}
.cb-close:hover { color: var(--cb-gold); }
.cb-close:focus-visible { outline: 1px solid var(--cb-gold); outline-offset: 2px; }

/* ── Mensajes ────────────────────────────────────────────── */
.cb-msgs {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain; /* el scroll no se encadena a la página de fondo */
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--cb-border) transparent;
}
.cb-msg {
  max-width: 88%;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 16px;
  font-weight: 200;
  line-height: 1.55;
  color: var(--cb-text);
  white-space: pre-wrap;
  word-break: break-word;
}
.cb-msg-user {
  align-self: flex-end;
  background: var(--cb-user-bg);
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
}
.cb-msg-bot { align-self: flex-start; }

/* Hipervínculos inline en las respuestas del bot */
.cb-link {
  color: var(--cb-gold);
  text-decoration: underline;
  text-decoration-color: var(--cb-gold-dim);
  text-underline-offset: 3px;
  transition: color 0.3s ease, text-decoration-color 0.3s ease;
}
.cb-link:hover { color: var(--cb-gold-hi); text-decoration-color: var(--cb-gold-hi); }

/* Indicador de escritura */
.cb-typing { display: flex; gap: 5px; align-self: flex-start; padding: 8px 2px; }
.cb-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--cb-gold-dim);
  animation: cb-pulse 1.2s ease-in-out infinite;
}
.cb-typing span:nth-child(2) { animation-delay: 0.2s; }
.cb-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cb-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 0.9; } }

/* ── Chips y salidas (patrón botón pill de BRAND.md) ────── */
.cb-chips, .cb-exits {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cb-chips { padding: 2px 0 6px; } /* vive dentro de .cb-msgs, que ya trae padding */
.cb-exits { align-self: flex-start; margin-top: -4px; }
.cb-chip {
  border-radius: 50px;
  border: 1px solid var(--cb-border);
  background: transparent;
  color: var(--cb-gold);
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  font-weight: 200;
  font-variation-settings: "wght" 200;
  letter-spacing: 0.04em;
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.4s ease, color 0.4s ease, border-color 0.4s ease,
              font-variation-settings 0.3s ease;
}
.cb-chip:hover {
  background: var(--cb-gold);
  color: var(--cb-bg);
  font-variation-settings: "wght" 400;
}
.cb-chip:focus-visible { outline: 1px solid var(--cb-gold); outline-offset: 2px; }

/* ── Input ───────────────────────────────────────────────── */
.cb-inputrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 10px 20px;
  border-top: 1px solid var(--cb-border-soft);
}
.cb-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 16px;
  font-weight: 200;
  color: var(--cb-text);
  min-width: 0;
}
.cb-input::placeholder { color: var(--cb-muted); }
.cb-input:disabled { opacity: 0.45; }
.cb-send {
  background: transparent;
  border: none;
  color: var(--cb-gold);
  font-family: 'Jost', sans-serif;
  font-size: 20px;
  font-weight: 200;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.3s ease;
}
.cb-send:hover { color: var(--cb-gold-hi); }
.cb-send:disabled { opacity: 0.35; cursor: default; }
.cb-send:focus-visible { outline: 1px solid var(--cb-gold); outline-offset: 2px; }

/* ── Pie ─────────────────────────────────────────────────── */
.cb-footer {
  display: flex;
  justify-content: space-between;
  padding: 8px 20px calc(10px + env(safe-area-inset-bottom, 0px));
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--cb-gold-dim);
}
.cb-footer a { color: inherit; text-decoration: none; transition: color 0.3s ease; }
.cb-footer a:hover { color: var(--cb-gold); }

/* ── Móvil: panel a pantalla completa ───────────────────── */
@media (max-width: 600px) {
  .cb-bubble { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .cb-panel {
    inset: 0;
    width: auto;
    /* 100dvh sigue al viewport dinámico (barra de URL); el JS lo afina
       con visualViewport cuando se abre el teclado */
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: none;
    padding-top: env(safe-area-inset-top, 0px);
    overscroll-behavior: contain;
  }
}

/* Página de fondo congelada mientras el chat está abierto en móvil.
   position:fixed en el body es lo único que iOS respeta para el scroll táctil;
   el JS guarda el scroll en top y lo restaura al cerrar. */
html.cb-lock { overflow: hidden; }
body.cb-lock { position: fixed; width: 100%; overflow: hidden; }

/* ── Accesibilidad: sin movimiento si el usuario lo pide ── */
@media (prefers-reduced-motion: reduce) {
  .cb-bubble, .cb-panel { transition: none; }
  .cb-typing span { animation: none; opacity: 0.6; }
}
