/* ============================================
   BRANDXB — AI CHAT WIDGET
   ============================================ */

#bex-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C9A84C 0%, #F5D98C 50%, #C9A84C 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(201,168,76,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}

#bex-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(201,168,76,0.6);
}

#bex-chat-btn svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

#bex-chat-btn .bex-close-icon { display: none; }
#bex-chat-btn.open .bex-chat-icon  { display: none; }
#bex-chat-btn.open .bex-close-icon { display: block; }

/* Unread badge */
#bex-chat-btn .bex-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #0d0d0d;
  display: none;
}
#bex-chat-btn .bex-badge.visible { display: block; }

/* ── Window ──────────────────────────────── */
#bex-chat-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 9998;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100dvh - 120px);
  background: #111111;
  border: 1px solid rgba(201,168,76,0.25);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
  overflow: hidden;
  transform: scale(0.92) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s ease;
  font-family: 'Inter', 'DM Sans', system-ui, sans-serif;
}

#bex-chat-window.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Header */
#bex-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: #0d0d0d;
  border-bottom: 1px solid rgba(201,168,76,0.15);
  flex-shrink: 0;
}

.bex-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C9A84C, #F5D98C);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #0d0d0d;
  flex-shrink: 0;
}

.bex-header-info { flex: 1; min-width: 0; }
.bex-header-name {
  font-size: 14px;
  font-weight: 600;
  color: #f5f5f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bex-header-status {
  font-size: 11px;
  color: #22c55e;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}
.bex-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

#bex-chat-header button {
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  transition: color 0.15s;
}
#bex-chat-header button:hover { color: #f5f5f5; }

/* Messages area */
#bex-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

#bex-messages::-webkit-scrollbar { width: 4px; }
#bex-messages::-webkit-scrollbar-track { background: transparent; }
#bex-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

.bex-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
  animation: bexFadeUp 0.2s ease both;
}

@keyframes bexFadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bex-msg--bot {
  background: #1e1e1e;
  color: #e5e5e5;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.bex-msg--user {
  background: linear-gradient(135deg, #C9A84C, #b8953e);
  color: #0d0d0d;
  font-weight: 500;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

/* Typing indicator */
.bex-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
  background: #1e1e1e;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  animation: bexFadeUp 0.2s ease both;
}
.bex-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #888;
  animation: bexBounce 1.2s ease infinite;
}
.bex-typing span:nth-child(2) { animation-delay: 0.2s; }
.bex-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bexBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Quick replies */
#bex-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 16px 10px;
}
.bex-qr {
  background: transparent;
  border: 1px solid rgba(201,168,76,0.4);
  color: #C9A84C;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
.bex-qr:hover {
  background: rgba(201,168,76,0.12);
  border-color: #C9A84C;
}

/* Input */
#bex-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  background: #0d0d0d;
}

#bex-input {
  flex: 1;
  background: #1e1e1e;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  color: #f5f5f5;
  font-family: inherit;
  font-size: 13.5px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: 100px;
  transition: border-color 0.15s;
}
#bex-input::placeholder { color: #555; }
#bex-input:focus { border-color: rgba(201,168,76,0.5); }

#bex-send {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #C9A84C, #b8953e);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}
#bex-send:hover { opacity: 0.9; transform: scale(1.05); }
#bex-send:disabled { opacity: 0.4; cursor: default; transform: none; }
#bex-send svg { width: 18px; height: 18px; }

/* Branding footer */
#bex-footer {
  text-align: center;
  font-size: 10.5px;
  color: #444;
  padding: 6px 14px 10px;
  background: #0d0d0d;
}
#bex-footer a { color: #666; text-decoration: none; }
#bex-footer a:hover { color: #C9A84C; }

/* Mobile */
@media (max-width: 480px) {
  #bex-chat-window {
    right: 12px;
    bottom: 90px;
    width: calc(100vw - 24px);
    height: calc(100dvh - 110px);
    max-height: none;
  }
  #bex-chat-btn { bottom: 20px; right: 16px; }
}
