/**
 * Built Africa Chatbot — Stylesheet v2.0.0
 * Free-text AI-style chatbot with keyword scoring engine.
 * Author: ProspenTech (https://www.prospentech.co.za)
 */

/* ── CSS Custom Properties ──────────────────────────────── */
:root {
  --bac-red:        #BE1E2E;
  --bac-red-dark:   #961824;
  --bac-red-light:  #fbeced;
  --bac-amber:      #f4a825;
  --bac-white:      #ffffff;
  --bac-bg:         #f4f7f5;
  --bac-text:       #1a1a1a;
  --bac-muted:      #6b7280;
  --bac-border:     #e2e8f0;
  --bac-shadow:     0 12px 40px rgba(190,30,46,0.18);
  --bac-shadow-sm:  0 4px 16px rgba(0,0,0,0.10);
  --bac-radius:     18px;
  --bac-font:       'Segoe UI','Helvetica Neue',Arial,sans-serif;
  --bac-ease:       cubic-bezier(0.4,0,0.2,1);
  --bac-spring:     cubic-bezier(0.34,1.56,0.64,1);
  --bac-w:          370px;
  --bac-h:          560px;
}

/* ── Wrapper — bottom left ─────────────────────────────── */
#bac-chatbot-wrapper {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 999999;
  font-family: var(--bac-font);
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-start;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
  transition: opacity 0.4s var(--bac-ease), transform 0.4s var(--bac-ease);
}

#bac-chatbot-wrapper.bac-ready {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

/* ── "Need Help?" label ─────────────────────────────────── */
#bac-attention-label {
  background: var(--bac-amber);
  color: #1a1a1a;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 5px 14px;
  border-radius: 20px;
  box-shadow: var(--bac-shadow-sm);
  cursor: pointer;
  white-space: nowrap;
  animation: bac-bounce 2.8s ease-in-out infinite;
  transition: transform 0.2s;
  user-select: none;
}
#bac-attention-label:hover { transform: scale(1.06); }
#bac-attention-label:focus-visible {
  outline: 2px solid var(--bac-red);
  outline-offset: 2px;
}
@keyframes bac-bounce {
  0%,100% { transform: translateY(0);  }
  40%      { transform: translateY(-7px); }
  55%      { transform: translateY(-4px); }
}

/* ── Launcher button ────────────────────────────────────── */
#bac-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--bac-red);
  border: 3px solid #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--bac-shadow), 0 0 0 3px var(--bac-red);
  transition: background 0.25s var(--bac-ease), transform 0.22s var(--bac-spring);
  outline: none;
  padding: 0;
}
#bac-launcher:hover  { background: var(--bac-red-dark); transform: scale(1.08); }
#bac-launcher:focus-visible { outline: 3px solid var(--bac-red-dark); outline-offset: 3px; }
#bac-launcher svg { width: 26px; height: 26px; fill: #fff; display: block; pointer-events: none; }

/* ── Chat window ────────────────────────────────────────── */
#bac-chat-window {
  width: var(--bac-w);
  height: var(--bac-h);
  background: var(--bac-white);
  border-radius: var(--bac-radius);
  box-shadow: var(--bac-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.88) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s var(--bac-spring), opacity 0.28s var(--bac-ease);
  transform-origin: bottom left;
}
#bac-chat-window.bac-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────── */
#bac-chat-header {
  background: var(--bac-red);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 11px;
  flex-shrink: 0;
}
#bac-header-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  border: 2px solid rgba(255,255,255,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}
#bac-header-info { flex: 1; min-width: 0; }
#bac-chat-header-title {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin: 0;
}
#bac-chat-header-sub {
  font-size: 11.5px;
  color: rgba(255,255,255,0.78);
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 2px 0 0;
}
.bac-status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  animation: bac-pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes bac-pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
#bac-close-btn {
  background: rgba(255,255,255,0.18);
  border: none;
  border-radius: 50%;
  width: 30px; height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
  padding: 0;
}
#bac-close-btn:hover { background: rgba(255,255,255,0.32); }
#bac-close-btn:focus-visible { outline: 2px solid rgba(255,255,255,0.8); }
#bac-close-btn svg { width: 16px; height: 16px; fill: #fff; display: block; pointer-events: none; }

/* ── Messages area ──────────────────────────────────────── */
#bac-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
#bac-messages::-webkit-scrollbar { width: 4px; }
#bac-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

/* ── Message rows ───────────────────────────────────────── */
.bac-msg { display: flex; }
.bac-msg-bot  { justify-content: flex-start; }
.bac-msg-user { justify-content: flex-end;   }

.bac-msg-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}
.bac-msg-bot  .bac-msg-bubble {
  background: #f1f5f9;
  color: var(--bac-text);
  border-bottom-left-radius: 4px;
}
.bac-msg-user .bac-msg-bubble {
  background: var(--bac-red);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ── Link buttons ───────────────────────────────────────── */
.bac-link-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-left: 2px;
  margin-top: 2px;
}
.bac-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bac-red-light);
  color: var(--bac-red-dark);
  border: 1.5px solid rgba(190,30,46,0.22);
  border-radius: 10px;
  padding: 8px 13px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: var(--bac-font);
  text-decoration: none;
  transition: background 0.18s, border-color 0.18s, transform 0.15s;
  cursor: pointer;
  max-width: 90%;
  line-height: 1.3;
}
.bac-link-btn:hover {
  background: rgba(190,30,46,0.12);
  border-color: var(--bac-red);
  transform: translateX(2px);
}
.bac-link-btn:focus-visible {
  outline: 2px solid var(--bac-red);
  outline-offset: 2px;
}
.bac-ext-icon {
  font-size: 11px;
  opacity: 0.6;
  margin-left: auto;
  padding-left: 4px;
}

/* ── Typing indicator ───────────────────────────────────── */
#bac-typing {
  padding: 0 14px 8px;
  flex-shrink: 0;
}
.bac-typing-inner {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #f1f5f9;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
}
.bac-typing-inner span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  display: block;
  animation: bac-typing-dot 1.4s ease-in-out infinite;
}
.bac-typing-inner span:nth-child(2) { animation-delay: 0.18s; }
.bac-typing-inner span:nth-child(3) { animation-delay: 0.36s; }
@keyframes bac-typing-dot {
  0%,60%,100% { transform: translateY(0);    opacity: 0.45; }
  30%          { transform: translateY(-6px); opacity: 1;    }
}

/* ── Input area ─────────────────────────────────────────── */
#bac-input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--bac-border);
  padding: 10px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #fff;
}
#bac-user-input {
  flex: 1;
  border: 1.5px solid var(--bac-border);
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: var(--bac-font);
  color: var(--bac-text);
  background: #f9fafb;
  outline: none;
  resize: none;
  max-height: 80px;
  line-height: 1.45;
  transition: border-color 0.2s, background 0.2s;
  overflow-y: auto;
}
#bac-user-input:focus {
  border-color: var(--bac-red);
  background: #fff;
}
#bac-user-input::placeholder { color: #9ca3af; }

#bac-send-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--bac-red);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  outline: none;
  padding: 0;
}
#bac-send-btn:hover:not(:disabled)  { background: var(--bac-red-dark); transform: scale(1.08); }
#bac-send-btn:focus-visible { outline: 2px solid var(--bac-red-dark); outline-offset: 2px; }
#bac-send-btn:disabled { background: #d1d5db; cursor: default; transform: none; }
#bac-send-btn svg { width: 17px; height: 17px; fill: #fff; display: block; pointer-events: none; }

/* ── Footer branding ────────────────────────────────────── */
#bac-chat-footer {
  flex-shrink: 0;
  text-align: center;
  font-size: 10.5px;
  color: #9ca3af;
  padding: 5px 0 8px;
  background: #fff;
  font-family: var(--bac-font);
}
#bac-chat-footer a {
  color: var(--bac-red);
  text-decoration: none;
  font-weight: 600;
}
#bac-chat-footer a:hover { text-decoration: underline; }

/* ── Mobile responsive ──────────────────────────────────── */
@media (max-width: 420px) {
  :root {
    --bac-w: calc(100vw - 16px);
    --bac-h: 72vh;
  }
  #bac-chatbot-wrapper {
    left: 8px;
    bottom: 8px;
  }
}
