/* ============================================
   BRANDXB — Bex AI Chat Widget  v2
   ============================================ */

/* ── Toggle button ──────────────────────────── */
#bex-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;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(201,168,76,0.45);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  outline: none;
  overflow: hidden;
}
#bex-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(201,168,76,0.65);
}
#bex-btn svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}
#bex-btn .bex-ico-close  { display: none; }
#bex-btn.open .bex-ico-chat  { display: none; }
#bex-btn.open .bex-ico-close { display: block; }

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

/* ── Chat window ────────────────────────────── */
#bex-win {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 9998;
  width: 375px;
  max-width: calc(100vw - 32px);
  height: 530px;
  max-height: calc(100dvh - 120px);
  background: #111;
  border: 1px solid rgba(201,168,76,0.22);
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 70px rgba(0,0,0,0.75), 0 0 0 0.5px rgba(201,168,76,0.08);
  overflow: hidden;
  /* closed state */
  transform: scale(0.92) translateY(14px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s ease;
  font-family: 'Inter', 'DM Sans', system-ui, sans-serif;
}
#bex-win.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

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

.bex-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(201,168,76,0.3);
}
.bex-avatar svg { display: block; width: 100%; height: 100%; }

.bex-hdr-info { flex: 1; min-width: 0; }
.bex-hdr-name {
  font-size: 13.5px;
  font-weight: 700;
  color: #f0f0f0;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bex-hdr-status {
  font-size: 11px;
  color: #4ade80;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.bex-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  animation: bex-pulse-dot 2.5s ease-in-out infinite;
}
@keyframes bex-pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

#bex-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #666;
  padding: 5px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
#bex-close-btn svg { width: 16px; height: 16px; }
#bex-close-btn:hover { color: #f0f0f0; background: rgba(255,255,255,0.07); }

/* ── Messages area ──────────────────────────── */
#bex-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
#bex-msgs::-webkit-scrollbar { width: 3px; }
#bex-msgs::-webkit-scrollbar-track { background: transparent; }
#bex-msgs::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ── Message bubbles ────────────────────────── */
.bex-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
  animation: bex-fadein 0.22s ease both;
}
@keyframes bex-fadein {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

/* ── Markdown inside bot bubbles ────────────── */
.bex-msg--bot strong { color: #f5d98c; font-weight: 650; }
.bex-msg--bot code {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
}
.bex-msg--bot ul,
.bex-msg--bot ol {
  margin: 6px 0 2px 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bex-msg--bot li { line-height: 1.5; }
.bex-msg--bot br + br { display: block; margin-top: 4px; content: ''; }

/* ── Streaming cursor ───────────────────────── */
.bex-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: #C9A84C;
  border-radius: 1px;
  margin-left: 2px;
  vertical-align: middle;
  animation: bex-blink 0.75s step-end infinite;
}
.bex-msg--done .bex-cursor { display: none; }
@keyframes bex-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Typing indicator ───────────────────────── */
.bex-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 11px 14px;
  background: #1c1c1c;
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  align-self: flex-start;
  animation: bex-fadein 0.2s ease both;
}
.bex-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #666;
  animation: bex-bounce 1.3s ease-in-out infinite;
}
.bex-typing span:nth-child(2) { animation-delay: 0.18s; }
.bex-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes bex-bounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.45; }
  30%            { transform: translateY(-6px); opacity: 1;    }
}

/* ── Suggestion chips ───────────────────────── */
#bex-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 14px 10px;
  flex-shrink: 0;
}
.bex-chip {
  background: transparent;
  border: 1px solid rgba(201,168,76,0.38);
  color: #C9A84C;
  font-size: 12px;
  font-family: inherit;
  padding: 5px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.bex-chip:hover {
  background: rgba(201,168,76,0.12);
  border-color: #C9A84C;
  color: #F5D98C;
}

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

#bex-input {
  flex: 1;
  background: #1c1c1c;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 14px;
  color: #f0f0f0;
  font-family: inherit;
  font-size: 13.5px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  line-height: 1.45;
  max-height: 110px;
  transition: border-color 0.18s;
}
#bex-input::placeholder { color: #4a4a4a; }
#bex-input:focus { border-color: rgba(201,168,76,0.45); }

#bex-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  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 svg { width: 17px; height: 17px; color: #0d0d0d; }
#bex-send:hover:not(:disabled) { opacity: 0.88; transform: scale(1.06); }
#bex-send:disabled { opacity: 0.35; cursor: default; }

/* ── Footer ─────────────────────────────────── */
#bex-footer {
  text-align: center;
  font-size: 10.5px;
  color: #3a3a3a;
  padding: 5px 14px 9px;
  background: #0d0d0d;
  flex-shrink: 0;
}
#bex-footer a { color: #555; text-decoration: none; }
#bex-footer a:hover { color: #C9A84C; }

/* ── Mobile ─────────────────────────────────── */
@media (max-width: 480px) {
  #bex-win {
    right: 10px;
    left: 10px;
    bottom: 88px;
    width: auto;
    /* Top clears the nav bar (80px) + safe gap (8px) */
    top: 88px;
    height: auto;
    max-height: none;
    border-radius: 18px;
  }
  #bex-btn { bottom: 20px; right: 16px; }
}
