/* ============================================================
   Gaby, la asesora virtual — Fase 3 (interfaz visual)
   ============================================================
   Reutiliza los tokens --dg-* de design-system.css (ya cargado en
   todas las páginas públicas) para heredar automáticamente el tema
   claro/oscuro del sitio, sin lógica de tema propia.

   El botón flotante vive en la esquina inferior IZQUIERDA (a
   propósito separado de WhatsApp + carrito, que ocupan la derecha,
   para no amontonar tres botones flotantes en el mismo lado). El
   único vecino posible ahí es la barra del comparador de productos
   (index.html, y solo mientras hay 1+ productos seleccionados): el
   modificador ".dg-chatbot-toggle--sobre-comparador" lo sube para no
   superponerse, mismo patrón que ya usaba con el carrito del lado
   derecho.
   ============================================================ */

.dg-chatbot-toggle {
  position: fixed;
  left: 1.1rem;
  bottom: 1.1rem;
  z-index: 950;
  width: 58px;
  height: 58px;
  box-sizing: border-box;
  border-radius: 50%;
  /* Anillo del color de fondo de la página: separa el botón de lo que
     tenga detrás (texto o imagen) al flotar sobre contenido con
     scroll, en vez de solo la sombra — que por sí sola no basta cuando
     el fondo debajo también es oscuro. */
  border: 3px solid var(--dg-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--dg-accent-strong), var(--dg-accent-soft));
  color: var(--dg-accent-contrast);
  font-size: 1.4rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.5), var(--dg-shadow-lg);
  transition: transform var(--dg-transition-fast), box-shadow var(--dg-transition-fast);
}

.dg-chatbot-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,.55), var(--dg-shadow-lg);
}

.dg-chatbot-toggle:focus-visible {
  outline: 2px solid var(--dg-accent);
  outline-offset: 3px;
}

.dg-chatbot-toggle--sobre-comparador {
  bottom: 5.5rem;
}

.dg-chatbot-toggle__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--dg-success);
  border: 2px solid var(--dg-bg);
}

/* ---------------------------------------------------------
   Panel
   --------------------------------------------------------- */
.dg-chatbot-panel {
  position: fixed;
  left: 1.1rem;
  bottom: calc(1.1rem + 68px);
  z-index: 960;
  width: min(380px, calc(100vw - 2.2rem));
  height: min(600px, 70vh);
  display: flex;
  flex-direction: column;
  background: var(--dg-surface-elevated);
  border: 1px solid var(--dg-border);
  border-radius: var(--dg-radius-lg);
  box-shadow: var(--dg-shadow-lg);
  overflow: hidden;
  animation: dgSlideUp .25s ease both;
}

.dg-chatbot-panel[hidden] { display: none; }

.dg-chatbot-panel--sobre-comparador {
  bottom: calc(5.5rem + 68px);
}

.dg-chatbot-panel--minimizado .dg-chatbot-body,
.dg-chatbot-panel--minimizado .dg-chatbot-footer,
.dg-chatbot-panel--minimizado .dg-chatbot-chips {
  display: none;
}

.dg-chatbot-panel--minimizado {
  height: auto;
}

/* Header */
.dg-chatbot-header {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .9rem 1rem;
  background: var(--dg-surface);
  border-bottom: 1px solid var(--dg-border);
  flex: 0 0 auto;
}

.dg-chatbot-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex: 0 0 38px;
  background: linear-gradient(135deg, var(--dg-accent-strong), var(--dg-accent-soft));
  color: var(--dg-accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--dg-font-heading);
  font-weight: 700;
  font-size: 1.15rem;
}

.dg-chatbot-header-info {
  flex: 1;
  min-width: 0;
}

.dg-chatbot-header-info strong {
  display: block;
  font-family: var(--dg-font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--dg-text);
  line-height: 1.2;
}

.dg-chatbot-status {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .74rem;
  color: var(--dg-muted);
}

.dg-chatbot-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dg-success);
  flex: 0 0 7px;
}

.dg-chatbot-header-actions {
  display: flex;
  gap: .2rem;
  flex: 0 0 auto;
}

.dg-chatbot-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--dg-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  transition: background var(--dg-transition-fast), color var(--dg-transition-fast);
}

.dg-chatbot-icon-btn:hover {
  background: var(--dg-surface-soft);
  color: var(--dg-text);
}

.dg-chatbot-icon-btn:focus-visible {
  outline: 2px solid var(--dg-accent);
  outline-offset: 2px;
}

/* Body / mensajes */
.dg-chatbot-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  background: var(--dg-bg);
}

.dg-chatbot-msg {
  max-width: 82%;
  padding: .55rem .8rem;
  border-radius: 14px;
  font-size: .87rem;
  line-height: 1.45;
  white-space: pre-line;
}

.dg-chatbot-msg--bot {
  align-self: flex-start;
  background: var(--dg-surface-soft);
  color: var(--dg-text);
  border-bottom-left-radius: 4px;
}

.dg-chatbot-msg--user {
  align-self: flex-end;
  background: var(--dg-accent);
  color: var(--dg-accent-contrast);
  border-bottom-right-radius: 4px;
}

.dg-chatbot-msg--bot a {
  color: var(--dg-accent-strong);
  font-weight: 600;
}

.dg-chatbot-msg--error {
  border-left: 3px solid var(--dg-danger);
}

/* Chips inline dentro de una respuesta tipo "question" */
.dg-chatbot-chips--inline {
  padding: .5rem 0 0;
  background: transparent;
}

/* Tarjeta de producto (product_list / product_detail / comparison) */
.dg-chatbot-producto-lista {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-self: stretch;
}

.dg-chatbot-producto {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  padding: .6rem;
  background: var(--dg-surface-soft);
  border: 1px solid var(--dg-border);
  border-radius: 12px;
}

.dg-chatbot-producto--detalle {
  flex-direction: column;
}

.dg-chatbot-producto--detalle .dg-chatbot-producto-foto {
  width: 100%;
  height: 160px;
}

.dg-chatbot-producto-foto {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  flex: 0 0 64px;
}

.dg-chatbot-producto-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  font-size: .8rem;
}

.dg-chatbot-producto-info strong {
  font-size: .85rem;
  color: var(--dg-text);
}

.dg-chatbot-producto-precios {
  display: flex;
  flex-wrap: wrap;
  gap: .1rem .6rem;
  color: var(--dg-muted);
}

.dg-chatbot-producto-disponible {
  font-size: .74rem;
  color: var(--dg-success);
}

.dg-chatbot-producto-disponible--no {
  color: var(--dg-danger);
}

.dg-chatbot-producto-acciones {
  display: flex;
  gap: .4rem;
  margin-top: .3rem;
  flex-wrap: wrap;
  flex: 1 1 100%;
}

.dg-chatbot-producto-btn {
  font-size: .74rem;
  padding: .35em .75em;
  border-radius: 999px;
  border: 1px solid var(--dg-accent);
  background: transparent;
  color: var(--dg-text);
  cursor: pointer;
}

.dg-chatbot-producto-btn:hover {
  background: var(--dg-accent);
  color: var(--dg-accent-contrast);
}

.dg-chatbot-producto-btn--fantasma:disabled {
  opacity: .45;
  cursor: not-allowed;
  border-color: var(--dg-border);
}

.dg-chatbot-producto-btn--fantasma:disabled:hover {
  background: transparent;
  color: var(--dg-text);
}

/* Píldoras de estado (availability, order_status) */
.dg-chatbot-pill {
  display: inline-block;
  padding: .15em .6em;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--dg-success-bg);
  color: var(--dg-success);
}

.dg-chatbot-pill--ok {
  background: var(--dg-success-bg);
  color: var(--dg-success);
}

.dg-chatbot-pill--no {
  background: var(--dg-danger-bg);
  color: var(--dg-danger);
}

/* Tarjeta de estado de pedido */
.dg-chatbot-pedido {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  padding: .7rem .85rem;
  background: var(--dg-surface-soft);
  border: 1px solid var(--dg-border);
  border-radius: 12px;
  font-size: .82rem;
  max-width: 82%;
}

.dg-chatbot-pedido strong {
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: .02em;
  color: var(--dg-text);
}

/* FAQ */
.dg-chatbot-faq-pregunta {
  margin: 0 0 .3rem;
  font-weight: 700;
  color: var(--dg-accent-strong);
  font-size: .82rem;
}

.dg-chatbot-typing {
  align-self: flex-start;
  display: flex;
  gap: .28rem;
  padding: .6rem .85rem;
  background: var(--dg-surface-soft);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.dg-chatbot-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dg-muted);
  animation: dgChatTyping 1.1s ease-in-out infinite;
}

.dg-chatbot-typing span:nth-child(2) { animation-delay: .15s; }
.dg-chatbot-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes dgChatTyping {
  0%, 60%, 100% { opacity: .35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .dg-chatbot-typing span { animation: none; opacity: .7; }
  .dg-chatbot-panel { animation: none; }
}

/* Respuestas rápidas (chips) */
.dg-chatbot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  padding: 0 1rem .8rem;
  background: var(--dg-bg);
  flex: 0 0 auto;
}

.dg-chatbot-chip {
  font-size: .78rem;
  padding: .4em .8em;
  border-radius: 999px;
  border: 1px solid var(--dg-border);
  background: var(--dg-surface);
  color: var(--dg-text);
  cursor: pointer;
  transition: background var(--dg-transition-fast), border-color var(--dg-transition-fast);
}

.dg-chatbot-chip:hover {
  background: var(--dg-surface-soft);
  border-color: var(--dg-accent);
}

.dg-chatbot-chip:focus-visible {
  outline: 2px solid var(--dg-accent);
  outline-offset: 2px;
}

/* Acción "Hablar con un asesor" dentro de un mensaje */
.dg-chatbot-msg-accion {
  display: inline-flex;
  align-items: center;
  gap: .4em;
  margin-top: .5rem;
  padding: .4em .85em;
  border-radius: 999px;
  background: var(--dg-success);
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
  text-decoration: none;
}

/* Footer / entrada de texto */
.dg-chatbot-footer {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .7rem .8rem;
  background: var(--dg-surface);
  border-top: 1px solid var(--dg-border);
  flex: 0 0 auto;
}

.dg-chatbot-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--dg-border);
  background: var(--dg-surface-soft);
  color: var(--dg-text);
  border-radius: 999px;
  padding: .55em 1em;
  font-size: .87rem;
  font-family: var(--dg-font-body);
}

.dg-chatbot-input:focus-visible {
  outline: 2px solid var(--dg-accent);
  outline-offset: 1px;
}

.dg-chatbot-footer .dg-chatbot-icon-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.dg-chatbot-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  flex: 0 0 36px;
  background: linear-gradient(135deg, var(--dg-accent-strong), var(--dg-accent-soft));
  color: var(--dg-accent-contrast);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dg-transition-fast);
}

.dg-chatbot-send:hover { transform: scale(1.06); }
.dg-chatbot-send:focus-visible { outline: 2px solid var(--dg-accent); outline-offset: 2px; }

/* ---------------------------------------------------------
   Responsive — pantalla completa en móvil (spec: "casi toda la
   pantalla"), panel flotante desde tablet hacia arriba.
   --------------------------------------------------------- */
@media (max-width: 640px) {
  .dg-chatbot-panel,
  .dg-chatbot-panel--sobre-comparador {
    right: .5rem;
    left: .5rem;
    bottom: .5rem;
    top: 3.5rem;
    width: auto;
    height: auto;
  }

  .dg-chatbot-toggle,
  .dg-chatbot-toggle--sobre-comparador {
    bottom: 1.1rem;
  }
}
