/* Brillo Urbano — Widget de chat web (DAIA).
   Burbuja flotante fija abajo a la derecha + panel de chat.
   Paleta de la tienda: verde oscuro, dorado y crema. Sin dependencias. */

.bu-chat {
  --bu-green: #1d4a2e;
  --bu-green-dark: #143521;
  --bu-gold: #c2a15a;
  --bu-cream: #f7f3ea;
  --bu-text: #2b2b2b;
  --bu-muted: #7a7a7a;
  --bu-border: #e6dfd0;
  --bu-shadow: 0 8px 28px rgba(20, 53, 33, 0.25);
  --bu-radius: 18px;
  font-family: "Jost", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--bu-text);
}

.bu-chat * { box-sizing: border-box; }

/* --- Burbuja flotante (fija, abajo a la derecha) --- */
.bu-bubble {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  width: 64px;
  height: 64px;
  padding: 0;
  border: 3px solid var(--bu-gold);
  border-radius: 50%;
  background: var(--bu-cream);
  box-shadow: var(--bu-shadow);
  cursor: pointer;
  z-index: 10050;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.bu-bubble:hover { transform: scale(1.06); }
.bu-bubble:focus-visible { outline: 3px solid var(--bu-gold); outline-offset: 2px; }

.bu-bubble-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.bu-bubble-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #fff;
}

.bu-bubble-close {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--bu-green);
  background: var(--bu-cream);
  border-radius: 50%;
}

.bu-chat.bu-abierto .bu-bubble-avatar,
.bu-chat.bu-abierto .bu-bubble-dot { display: none; }
.bu-chat.bu-abierto .bu-bubble-close { display: flex; }

/* --- Panel de chat --- */
.bu-panel {
  position: fixed;
  right: 20px;
  bottom: 96px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 130px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--bu-border);
  border-radius: var(--bu-radius);
  box-shadow: var(--bu-shadow);
  overflow: hidden;
  z-index: 10050;
}

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

.bu-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bu-green);
  color: #fff;
}

.bu-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--bu-gold);
  flex-shrink: 0;
}

.bu-header-text { flex: 1; min-width: 0; }
.bu-header-nombre { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bu-header-estado { font-size: 12px; color: #bfe3c8; }
.bu-header-estado::before { content: "● "; color: #22c55e; }

.bu-header-wa,
.bu-header-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}

.bu-header-wa svg { width: 19px; height: 19px; }
.bu-header-wa:hover,
.bu-header-close:hover { background: rgba(255, 255, 255, 0.28); }
.bu-header-close { font-size: 14px; }

.bu-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  background: var(--bu-cream);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bu-msg { display: flex; gap: 8px; align-items: flex-end; }
.bu-msg-user { justify-content: flex-end; }
.bu-msg-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.bu-msg-cuerpo { display: flex; flex-direction: column; gap: 6px; max-width: 82%; }
.bu-msg-user .bu-msg-cuerpo { align-items: flex-end; }

.bu-msg-burbuja {
  padding: 10px 13px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--bu-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  overflow-wrap: anywhere;
}

.bu-msg-user .bu-msg-burbuja {
  background: var(--bu-green);
  border-color: var(--bu-green);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bu-msg-assistant .bu-msg-burbuja { border-bottom-left-radius: 4px; }

/* Tarjetas de producto con foto */
.bu-img-card {
  width: 210px;
  max-width: 100%;
  background: #fff;
  border: 1px solid var(--bu-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.bu-img-foto { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; background: var(--bu-cream); }
.bu-img-info { padding: 8px 10px; }
.bu-img-nombre { font-weight: 600; font-size: 13.5px; }
.bu-img-desc { font-size: 12.5px; color: var(--bu-muted); margin-top: 2px; }

/* Derivación a una persona */
.bu-handoff {
  background: #fff8e6;
  border: 1px solid #ecd9a0;
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bu-handoff-texto { font-size: 13.5px; }

.bu-handoff-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 12px;
  border-radius: 999px;
  background: #25d366;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}

.bu-handoff-btn svg { width: 17px; height: 17px; }
.bu-handoff-btn:hover { background: #1fb857; }

/* Indicador "escribiendo" */
.bu-typing .bu-msg-burbuja { display: flex; gap: 4px; align-items: center; padding: 13px 14px; }
.bu-typing .bu-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bu-muted);
  animation: bu-bounce 1.2s infinite ease-in-out;
}
.bu-typing .bu-dot:nth-child(2) { animation-delay: 0.15s; }
.bu-typing .bu-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bu-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Respuestas rápidas */
.bu-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 0;
  overflow-x: hidden;
  background: var(--bu-cream);
}

.bu-quick-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--bu-gold);
  background: #fff;
  color: var(--bu-green);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.bu-quick-btn:hover { background: var(--bu-gold); color: #fff; }

/* Entrada de texto */
.bu-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  background: var(--bu-cream);
}

.bu-input {
  flex: 1;
  min-width: 0;
  padding: 10px 13px;
  border: 1px solid var(--bu-border);
  border-radius: 999px;
  font-size: 14.5px;
  font-family: inherit;
  background: #fff;
  color: var(--bu-text);
}

.bu-input:focus { outline: 2px solid var(--bu-gold); outline-offset: 0; border-color: var(--bu-gold); }

.bu-send {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--bu-green);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
}

.bu-send:hover:not(:disabled) { background: var(--bu-green-dark); }
.bu-send:disabled { opacity: 0.5; cursor: default; }

/* Móvil: el panel ocupa casi toda la pantalla */
@media (max-width: 480px) {
  .bu-bubble { right: max(12px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); width: 58px; height: 58px; }
  .bu-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: min(620px, calc(100dvh - 20px));
    max-height: calc(100dvh - 20px);
    border-radius: 20px 20px 0 0;
  }
}
