/* ═══════════════════════════════════════════════════════
   BuyReal AI Chat — Frontend Styles
   ═══════════════════════════════════════════════════════ */

:root {
  --brac-primary:    #ff4d1c;
  --brac-secondary:  #0b0d0f;
  --brac-bg:         #ffffff;
  --brac-surface:    #f8f9fa;
  --brac-border:     #e8eaed;
  --brac-text:       #1a1a2e;
  --brac-muted:      #6b7280;
  --brac-user-bg:    var(--brac-primary);
  --brac-ai-bg:      #f0f2f5;
  --brac-ai-text:    #1a1a2e;
  --brac-radius:     18px;
  --brac-shadow:     0 12px 48px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.08);
  --brac-shadow-sm:  0 2px 12px rgba(0,0,0,.1);
  --brac-trans:      .24s cubic-bezier(.4,0,.2,1);
  --brac-z:          999999;
  --brac-font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Widget wrapper ──────────────────────────────────── */
#brac-widget {
  position: fixed;
  z-index: var(--brac-z);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--brac-font);
}

/* ── Launcher button ─────────────────────────────────── */
#brac-launcher {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--brac-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(255,77,28,.45);
  transition: transform var(--brac-trans), box-shadow var(--brac-trans);
  outline: none;
  flex-shrink: 0;
  animation: brac-pop-in .5s cubic-bezier(.34,1.56,.64,1) both;
}
#brac-launcher:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 32px rgba(255,77,28,.5);
}
#brac-launcher:active { transform: scale(.96); }

@keyframes brac-pop-in {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* Pulse ring */
#brac-launcher::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--brac-primary);
  opacity: 0;
  animation: brac-pulse 2.5s ease infinite;
}
@keyframes brac-pulse {
  0%   { transform: scale(1);   opacity: .6; }
  100% { transform: scale(1.5); opacity: 0;  }
}

.brac-launcher-icon svg {
  width: 26px; height: 26px;
  stroke: #fff;
  display: block;
}

.brac-unread-badge {
  position: absolute;
  top: -2px; right: -2px;
  min-width: 20px; height: 20px;
  background: #ef4444;
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  border: 2px solid #fff;
  animation: brac-bounce .5s cubic-bezier(.34,1.56,.64,1);
}
@keyframes brac-bounce {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* ── Chat window ─────────────────────────────────────── */
#brac-chat-window {
  width: 380px;
  max-height: 600px;
  background: var(--brac-bg);
  border-radius: 20px;
  box-shadow: var(--brac-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: brac-slide-up .3s cubic-bezier(.34,1.2,.64,1) both;
  border: 1px solid rgba(0,0,0,.06);
}
#brac-chat-window.brac-open {
  display: flex;
}
@keyframes brac-slide-up {
  from { opacity: 0; transform: scale(.92) translateY(16px); }
  to   { opacity: 1; transform: scale(1)  translateY(0); }
}

/* ── Header ──────────────────────────────────────────── */
.brac-header {
  background: linear-gradient(135deg, var(--brac-secondary) 0%, #1c2333 100%);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.brac-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brac-avatar {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  display: flex; align-items: center; justify-content: center;
  overflow: visible;
  flex-shrink: 0;
}
.brac-avatar img {
  width: 42px; height: 42px; border-radius: 50%; object-fit: cover;
}
.brac-avatar-icon { font-size: 22px; }
.brac-status-dot {
  position: absolute;
  bottom: 0; right: 0;
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--brac-secondary);
  background: #6b7280;
  transition: background var(--brac-trans);
}
.brac-status-dot.online  { background: #22c55e; }
.brac-status-dot.offline { background: #ef4444; }

.brac-header-name {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.01em;
}
.brac-header-status {
  color: rgba(255,255,255,.6);
  font-size: 12px;
  margin-top: 2px;
}

.brac-header-actions {
  display: flex;
  gap: 4px;
}
.brac-btn-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--brac-trans);
}
.brac-btn-icon:hover { background: rgba(255,255,255,.16); }
.brac-btn-icon svg { width: 16px; height: 16px; stroke: rgba(255,255,255,.8); }

/* ── Messages area ───────────────────────────────────── */
.brac-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.brac-messages::-webkit-scrollbar { width: 4px; }
.brac-messages::-webkit-scrollbar-track { background: transparent; }
.brac-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.1); border-radius: 4px; }

/* Bubbles */
.brac-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: brac-msg-in .25s ease both;
}
@keyframes brac-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.brac-bubble-wrap.brac-user { flex-direction: row-reverse; }

.brac-bubble-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--brac-surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.brac-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}

/* AI bubble */
.brac-bubble.brac-ai {
  background: var(--brac-ai-bg);
  color: var(--brac-ai-text);
  border-bottom-left-radius: 4px;
}

/* User bubble */
.brac-bubble.brac-user {
  background: var(--brac-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Agent bubble */
.brac-bubble.brac-agent {
  background: linear-gradient(135deg, #1e3a5f, #2563eb);
  color: #fff;
  border-bottom-left-radius: 4px;
}

.brac-bubble-time {
  font-size: 10px;
  color: var(--brac-muted);
  margin-top: 4px;
  padding: 0 2px;
  text-align: right;
}
.brac-bubble-wrap.brac-user .brac-bubble-time { text-align: right; }

/* bold/markdown-lite support */
.brac-bubble strong { font-weight: 700; }
.brac-bubble em     { font-style: italic; }

/* Date separator */
.brac-date-sep {
  text-align: center;
  font-size: 11px;
  color: var(--brac-muted);
  position: relative;
  margin: 4px 0;
}
.brac-date-sep::before, .brac-date-sep::after {
  content: '';
  position: absolute;
  top: 50%; width: 30%; height: 1px;
  background: var(--brac-border);
}
.brac-date-sep::before { left: 0; }
.brac-date-sep::after  { right: 0; }

/* ── Typing indicator ────────────────────────────────── */
.brac-typing-wrap {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.brac-typing-wrap small { font-size: 11px; color: var(--brac-muted); }
.brac-typing-bubble {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--brac-ai-bg);
  border-radius: 14px;
}
.brac-typing-bubble span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--brac-muted);
  animation: brac-dot-bounce 1.2s infinite ease-in-out;
}
.brac-typing-bubble span:nth-child(2) { animation-delay: .2s; }
.brac-typing-bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes brac-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-6px); }
}

/* ── Quick replies ───────────────────────────────────── */
.brac-quick-replies {
  display: flex;
  gap: 6px;
  padding: 6px 12px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
  border-top: 1px solid var(--brac-border);
}
.brac-quick-replies::-webkit-scrollbar { display: none; }
.brac-qr {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--brac-primary);
  background: transparent;
  color: var(--brac-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--brac-trans), color var(--brac-trans);
}
.brac-qr:hover {
  background: var(--brac-primary);
  color: #fff;
}

/* ── Input row ───────────────────────────────────────── */
.brac-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--brac-border);
  flex-shrink: 0;
}

#brac-input {
  flex: 1;
  border: 1.5px solid var(--brac-border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: var(--brac-font);
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color var(--brac-trans), box-shadow var(--brac-trans);
  color: var(--brac-text);
}
#brac-input:focus {
  border-color: var(--brac-primary);
  box-shadow: 0 0 0 3px rgba(255,77,28,.12);
}

#brac-send {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--brac-primary);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--brac-trans), transform var(--brac-trans);
  box-shadow: 0 2px 10px rgba(255,77,28,.3);
}
#brac-send:hover   { background: #e03d0e; transform: scale(1.08); }
#brac-send:active  { transform: scale(.94); }
#brac-send svg { width: 18px; height: 18px; stroke: #fff; }

/* ── Branding ─────────────────────────────────────────── */
.brac-branding {
  text-align: center;
  font-size: 10px;
  color: var(--brac-muted);
  padding: 4px 0 8px;
}
.brac-branding a { color: var(--brac-primary); text-decoration: none; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 480px) {
  #brac-chat-window {
    position: fixed;
    inset: 0 !important;
    width: 100% !important;
    max-height: 100% !important;
    border-radius: 0;
    margin: 0;
  }
  #brac-widget {
    inset: 0 !important;
    right: auto !important;
    left: auto !important;
    bottom: auto !important;
    width: 100%;
    height: 100%;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 16px;
  }
  #brac-launcher {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    left: auto !important;
  }
}

@media (max-width: 360px) {
  #brac-launcher { width: 52px; height: 52px; }
}
