/**
 * Beatsy AI Chat Widget — Core Styles v2
 * File: assets/css/ai-widget.css
 */

/* ─── Widget Root ────────────────────────────────────── */
#beatsy-widget-root {
  position: relative;
  z-index: 2147483647 !important;
}

#beatsy-ai-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2147483647 !important;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 14px;
  isolation: isolate;
}

/* ─── Launcher Bubble ────────────────────────────────── */
#bai-launcher {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), background .25s, box-shadow .25s, width .25s, height .25s;
  position: relative;
  outline: none;
  animation: bai-breathing 3s infinite ease-in-out;
}
@keyframes bai-breathing {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
#bai-launcher:hover { transform: scale(1.1); animation-play-state: paused; }

#bai-launcher .bai-icon-chat,
#bai-launcher .bai-icon-close { position: absolute; transition: all .25s; }

#bai-launcher .bai-icon-chat {
  opacity: 1;
  transform: rotate(0) scale(1);
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#bai-launcher .bai-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
  font-size: 24px;
  color: #fff;
}

#beatsy-ai-widget.open #bai-launcher {
  width: 58px;
  height: 58px;
  background: linear-gradient(135deg, #2C58BC, #1e3f8a);
  box-shadow: 0 6px 24px rgba(44,88,188,.5);
  animation: none;
}

#beatsy-ai-widget.open #bai-launcher .bai-icon-chat  { opacity: 0; transform: rotate(90deg) scale(0.5); box-shadow: none; }
#beatsy-ai-widget.open #bai-launcher .bai-icon-close { opacity: 1; transform: rotate(0) scale(1); }

/* Notification badge */
#bai-unread-badge {
  position: absolute;
  top: -2px; right: -2px;
  background: #FF6D3B;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  animation: bai-pulse 2s infinite;
}
@keyframes bai-pulse {
  0%,100% { transform: scale(1); } 50% { transform: scale(1.15); }
}

/* Tooltip on launcher */
#bai-tooltip {
  position: absolute;
  bottom: 68px; right: 0;
  background: #041527;
  color: #fff;
  padding: 8px 14px;
  border-radius: 12px 12px 4px 12px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: all .3s;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
#bai-tooltip::after {
  content: '';
  position: absolute;
  bottom: -6px; right: 14px;
  border: 6px solid transparent;
  border-top-color: #041527;
  border-bottom: none;
}
#beatsy-ai-widget:not(.open) #bai-launcher:hover + #bai-tooltip,
#beatsy-ai-widget:not(.open) #bai-tooltip.visible { opacity: 1; transform: translateY(0); }

/* ─── Attention Grabber ──────────────────────────────── */
#bai-attention-grabber {
  position: absolute;
  bottom: 80px;
  right: 0;
  background: #fff;
  color: #1a2638;
  padding: 12px 16px;
  padding-right: 36px;
  border-radius: 12px 12px 0 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 1;
  transform: translateY(0);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: bottom right;
  z-index: 9999;
  animation: bai-bounce-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 1.5s both;
}

#bai-attention-grabber::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 20px;
  border-width: 8px 8px 0 0;
  border-style: solid;
  border-color: #fff transparent transparent transparent;
}

@keyframes bai-bounce-in {
  0% { opacity: 0; transform: scale(0.5) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

#bai-attention-grabber.bai-hidden,
#beatsy-ai-widget.open #bai-attention-grabber {
  opacity: 0;
  transform: scale(0.8) translateY(10px);
  pointer-events: none;
  visibility: hidden;
}

.bai-grabber-close {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: #999;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  line-height: 1;
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

.bai-grabber-close:hover {
  color: #1a2638;
  background: rgba(0,0,0,.06);
}

/* ─── Chat Window ────────────────────────────────────── */
#bai-window {
  position: absolute;
  bottom: 80px; right: 0;
  width: 370px;
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18), 0 4px 20px rgba(44,88,188,.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(.85) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .25s;
}
#beatsy-ai-widget.open #bai-window {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ─── Header ─────────────────────────────────────────── */
#bai-header {
  background: linear-gradient(135deg, #2C58BC 0%, #1a3a9e 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.bai-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff;
  border: 2px solid rgba(255,255,255,.3);
  flex-shrink: 0;
  overflow: hidden;
}
.bai-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.bai-header-info { flex: 1; min-width: 0; }
.bai-header-info strong { color: #fff; font-size: 14px; font-weight: 700; display: block; }
.bai-online-dot {
  display: inline-block;
  width: 7px; height: 7px;
  background: #4ade80;
  border-radius: 50%;
  margin-right: 4px;
  animation: bai-blink 2s infinite;
}
.bai-agent-dot {
  display: inline-block;
  width: 7px; height: 7px;
  background: #f59e0b;
  border-radius: 50%;
  margin-right: 4px;
}
@keyframes bai-blink { 0%,100%{opacity:1} 50%{opacity:.4} }
.bai-status { color: rgba(255,255,255,.75); font-size: 11px; }
.bai-header-actions { display: flex; gap: 6px; flex-shrink: 0; }
.bai-header-btn {
  background: rgba(255,255,255,.15);
  border: none; border-radius: 8px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; cursor: pointer; font-size: 13px;
  transition: background .2s;
}
.bai-header-btn:hover { background: rgba(255,255,255,.25); }

/* Live agent banner in header */
.bai-live-agent-bar {
  background: linear-gradient(135deg, #059669, #047857);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
  animation: bai-fadein .3s ease;
}
.bai-live-agent-bar i { font-size: 14px; }

/* ─── Messages Area ──────────────────────────────────── */
#bai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8f9fb;
  scroll-behavior: smooth;
}
#bai-messages::-webkit-scrollbar { width: 4px; }
#bai-messages::-webkit-scrollbar-track { background: transparent; }
#bai-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* ─── Message Bubbles ────────────────────────────────── */
.bai-msg { display: flex; flex-direction: column; max-width: 85%; animation: bai-fadein .25s ease; }
@keyframes bai-fadein { from { opacity:0; transform: translateY(6px); } to { opacity:1; transform:none; } }
.bai-msg.ai    { align-self: flex-start; }
.bai-msg.user  { align-self: flex-end; }
.bai-msg.agent { align-self: flex-start; }
.bai-msg.system {
  align-self: center;
  max-width: 90%;
  margin: 6px 0;
}
.bai-msg.system .bai-bubble {
  background: #e2e8f0;
  color: #475569;
  font-size: 11px;
  padding: 5px 14px;
  border-radius: 30px;
  box-shadow: none;
  font-weight: 600;
  text-align: center;
  border: none;
}
.bai-msg.system .bai-time {
  display: none;
}

.bai-bubble {
  padding: 10px 13px;
  border-radius: 16px;
  line-height: 1.5;
  font-size: 13.5px;
  word-break: break-word;
}
.bai-msg.ai .bai-bubble {
  background: #fff;
  color: #1a2638;
  border-radius: 4px 16px 16px 16px;
  box-shadow: 0 1px 6px rgba(0,0,0,.07);
}
.bai-msg.agent .bai-bubble {
  background: linear-gradient(135deg, #059669, #047857);
  color: #fff;
  border-radius: 4px 16px 16px 16px;
  box-shadow: 0 1px 6px rgba(5,150,105,.25);
}
.bai-msg.agent .bai-sender {
  font-size: 10px;
  color: #059669;
  font-weight: 600;
  margin-bottom: 2px;
  padding-left: 4px;
}
.bai-msg.user .bai-bubble {
  background: linear-gradient(135deg, #2C58BC, #1e3f8a);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}
.bai-time {
  font-size: 10px;
  color: #aaa;
  margin-top: 3px;
  padding: 0 4px;
}
.bai-msg.user .bai-time { text-align: right; }

/* System / event messages */
.bai-msg.system {
  align-self: center;
  max-width: 90%;
}
.bai-msg.system .bai-bubble {
  background: rgba(44,88,188,.08);
  color: #2C58BC;
  border-radius: 12px;
  text-align: center;
  font-size: 12px;
  padding: 6px 14px;
  box-shadow: none;
}

/* Lists inside AI responses */
.bai-bubble ul.ai-list { margin: 4px 0 4px 14px; padding: 0; }
.bai-bubble ul.ai-list li { margin-bottom: 2px; }

/* ─── Typing Indicator ───────────────────────────────── */
.bai-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}
.bai-typing-dots span {
  display: inline-block;
  width: 7px; height: 7px;
  background: #2C58BC;
  border-radius: 50%;
  animation: bai-bounce .9s infinite;
}
.bai-typing-dots span:nth-child(2) { animation-delay: .15s; }
.bai-typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bai-bounce { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-6px)} }

/* ─── Suggestion Chips ───────────────────────────────── */
#bai-starters {
  padding: 8px 14px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: #f8f9fb;
  flex-shrink: 0;
}
.bai-chip {
  background: #fff;
  border: 1.5px solid #2C58BC22;
  color: #2C58BC;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
  text-align: left;
}
.bai-chip:hover { background: #2C58BC; color: #fff; border-color: #2C58BC; }

/* ─── Lead Capture Form ──────────────────────────────── */
/* Using class selector (.bai-lead-form) since React renders with className */
.bai-lead-form {
  display: none;
  padding: 14px;
  background: #fff;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
  animation: bai-fadein .3s ease;
}
.bai-lead-form.active { display: block; }
.bai-lead-form h6 {
  font-weight: 700;
  font-size: 13px;
  color: #1a2638;
  margin: 0 0 10px;
  line-height: 1.4;
}
.bai-lead-form input {
  width: 100%;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 7px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  font-family: inherit;
  box-sizing: border-box;
  color: #1a2638;
  background: #fafafa;
}
.bai-lead-form input:focus {
  border-color: #2C58BC;
  box-shadow: 0 0 0 3px rgba(44,88,188,.12);
  background: #fff;
}
.bai-lead-form input::placeholder { color: #b0b8c9; }
.bai-lead-btns { display: flex; gap: 6px; margin-top: 4px; }
.bai-lead-btns button {
  flex: 1; border: none; border-radius: 8px;
  padding: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .2s;
}
.bai-btn-primary { background: #2C58BC; color: #fff; }
.bai-btn-secondary { background: #f3f4f6; color: #555; }
.bai-btn-primary:hover { background: #1e3f8a; transform: translateY(-1px); }
.bai-btn-secondary:hover { background: #e5e7eb; }

/* ─── Escalation Banner ──────────────────────────────── */
/* Using class selector since React renders with className */
.bai-escalation {
  display: none;
  padding: 12px 14px;
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border-top: 2px solid #fbbf24;
  flex-shrink: 0;
  animation: bai-fadein .3s ease;
}
.bai-escalation.active { display: block; }
.bai-escalation p {
  font-size: 12.5px;
  color: #78350f;
  margin: 0 0 10px;
  font-weight: 600;
  line-height: 1.4;
}
.bai-escalate-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.bai-esc-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all .2s;
  flex: 1;
  justify-content: center;
  white-space: nowrap;
}
.bai-esc-whatsapp { background: #25D366; color: #fff; }
.bai-esc-whatsapp:hover { background: #1ebe5c; }
.bai-esc-email { background: #2C58BC; color: #fff; }
.bai-esc-email:hover { background: #1e3f8a; }
.bai-esc-dismiss { background: #f3f4f6; color: #555; }
.bai-esc-dismiss:hover { background: #e5e7eb; }

/* Queue waiting animation */
.bai-queue-status {
  display: none;
  padding: 10px 14px;
  background: #f0f4ff;
  border-top: 2px solid #2C58BC;
  flex-shrink: 0;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: #1e3f8a;
  font-weight: 600;
}
.bai-queue-status.active { display: flex; }
.bai-queue-spinner {
  width: 16px; height: 16px;
  border: 2.5px solid #2C58BC33;
  border-top-color: #2C58BC;
  border-radius: 50%;
  animation: bai-spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes bai-spin { to { transform: rotate(360deg); } }

/* ─── Input Area ─────────────────────────────────────── */
#bai-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
}
#bai-input {
  flex: 1;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 9px 13px;
  font-size: 13.5px;
  outline: none;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color .2s, box-shadow .2s;
  font-family: inherit;
  color: #1a2638;
}
#bai-input:focus { border-color: #2C58BC; box-shadow: 0 0 0 3px rgba(44,88,188,.1); }
#bai-send {
  width: 38px; height: 38px;
  background: #2C58BC;
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  transition: background .2s, transform .15s;
  flex-shrink: 0;
}
#bai-send:hover { background: #1e3f8a; transform: scale(1.05); }
#bai-send:disabled { background: #c5cde8; cursor: not-allowed; transform: none; }

/* ─── Powered-by Footer ──────────────────────────────── */
#bai-powered {
  text-align: center;
  padding: 6px;
  font-size: 10px;
  color: #ccc;
  background: #fff;
  border-top: 1px solid #f5f5f5;
  flex-shrink: 0;
}
#bai-powered a { color: #2C58BC; text-decoration: none; }

/* ─── Mobile Responsive ──────────────────────────────── */
@media (max-width: 480px) {
  #beatsy-ai-widget {
    bottom: 16px;
    right: 16px;
  }
  #bai-window {
    position: fixed;
    bottom: 90px;
    right: 16px;
    left: 16px;
    width: auto;
    max-height: calc(100svh - 110px);
    border-radius: 16px;
  }
  #bai-attention-grabber {
    position: fixed;
    bottom: 90px;
    right: 16px;
    left: 16px;
    width: auto;
    white-space: normal;
    text-align: left;
  }
  #bai-input {
    font-size: 16px; /* Prevents iOS zoom */
  }
  .bai-chip { font-size: 11px; padding: 4px 10px; }
  .bai-esc-btn { flex: none; }
  .bai-escalate-btns { flex-direction: column; }
}

/* ─── Dark Mode ──────────────────────────────────────── */
[data-bs-theme="dark"] #bai-window { background: #1a2638; }
[data-bs-theme="dark"] #bai-messages { background: #111b2a; }
[data-bs-theme="dark"] .bai-msg.ai .bai-bubble { background: #1f2f45; color: #e2e8f0; }
[data-bs-theme="dark"] #bai-input-area,
[data-bs-theme="dark"] #bai-powered { background: #1a2638; border-color: #2d3f55; }
[data-bs-theme="dark"] #bai-input { background: #111b2a; border-color: #2d3f55; color: #e2e8f0; }
[data-bs-theme="dark"] .bai-chip { background: #1f2f45; border-color: #2d3f55; color: #93b4ff; }
[data-bs-theme="dark"] #bai-starters { background: #111b2a; }
[data-bs-theme="dark"] .bai-lead-form { background: #1a2638; border-color: #2d3f55; }
[data-bs-theme="dark"] .bai-lead-form input { background: #111b2a; border-color: #2d3f55; color: #e2e8f0; }
[data-bs-theme="dark"] .bai-lead-form h6 { color: #e2e8f0; }
[data-bs-theme="dark"] #bai-attention-grabber { background: #1a2638; color: #e2e8f0; box-shadow: 0 4px 20px rgba(0,0,0,0.4); }
[data-bs-theme="dark"] #bai-attention-grabber::after { border-color: #1a2638 transparent transparent transparent; }
[data-bs-theme="dark"] .bai-grabber-close { color: #888; }
[data-bs-theme="dark"] .bai-grabber-close:hover { color: #e2e8f0; }
[data-bs-theme="dark"] .bai-msg.system .bai-bubble { background: rgba(147,180,255,.1); color: #93b4ff; }
