/* ── Branded AI Chatbot ── chat.css ─────────────────────────── */

:root {
  --baicb-primary:  #1a1a2e;
  --baicb-accent:   #e94560;
  --baicb-radius:   16px;
  --baicb-shadow:   0 24px 64px rgba(0,0,0,.22), 0 4px 16px rgba(0,0,0,.12);
  --baicb-font:     'Segoe UI', system-ui, -apple-system, sans-serif;
  --baicb-w:        360px;
  --baicb-h:        900px;
  --baicb-w-expand: 520px;
  --baicb-h-expand: 900px;
  --baicb-bubble-size: 60px;
}

/* ── Root ────────────────────────────────────────────────────── */
.baicb-root {
  position: fixed;
  z-index: 999999;
  font-family: var(--baicb-font);
  font-size: 15px;
  line-height: 1.5;
}

/* Right-side positions */
.baicb-root.baicb--bottom-right     { bottom: 24px;  right: 24px; }
.baicb-root.baicb--mid-bottom-right { bottom: 25%;   right: 24px; }
.baicb-root.baicb--middle-right     { top: 50%;      right: 24px; transform: translateY(-50%); }
.baicb-root.baicb--mid-upper-right  { top: 25%;      right: 24px; }

/* Left-side positions */
.baicb-root.baicb--bottom-left      { bottom: 24px;  left: 24px; }
.baicb-root.baicb--mid-bottom-left  { bottom: 25%;   left: 24px; }
.baicb-root.baicb--middle-left      { top: 50%;      left: 24px; transform: translateY(-50%); }
.baicb-root.baicb--mid-upper-left   { top: 25%;      left: 24px; }

/* Chat window — anchors to bottom of bubble for bottom positions, top for upper positions */
.baicb-root.baicb--bottom-right .baicb-window,
.baicb-root.baicb--mid-bottom-right .baicb-window,
.baicb-root.baicb--bottom-left .baicb-window,
.baicb-root.baicb--mid-bottom-left .baicb-window { bottom: 76px; top: auto; }

.baicb-root.baicb--middle-right .baicb-window,
.baicb-root.baicb--mid-upper-right .baicb-window,
.baicb-root.baicb--middle-left .baicb-window,
.baicb-root.baicb--mid-upper-left .baicb-window { top: 0; bottom: auto; }

/* Window left/right alignment */
.baicb-root.baicb--bottom-right .baicb-window,
.baicb-root.baicb--mid-bottom-right .baicb-window,
.baicb-root.baicb--middle-right .baicb-window,
.baicb-root.baicb--mid-upper-right .baicb-window { right: 0; left: auto; }

.baicb-root.baicb--bottom-left .baicb-window,
.baicb-root.baicb--mid-bottom-left .baicb-window,
.baicb-root.baicb--middle-left .baicb-window,
.baicb-root.baicb--mid-upper-left .baicb-window { left: 0; right: auto; }

/* Legacy aliases */
.baicb-root.baicb--right { bottom: 24px; right: 24px; }
.baicb-root.baicb--left  { bottom: 24px; left:  24px; }
.baicb-root.baicb--right .baicb-window { right: 0; }
.baicb-root.baicb--left  .baicb-window { left:  0; }

/* ── Bubble ─────────────────────────────────────────────────── */
.baicb-bubble {
  width:  var(--baicb-bubble-size); height: var(--baicb-bubble-size);
  border-radius: 50%;
  background: var(--baicb-accent);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
  position: relative;
  margin-left: auto;
  /* touch target */
  min-width: var(--baicb-bubble-size); min-height: var(--baicb-bubble-size);
}
.baicb-bubble:hover  { transform: scale(1.1); box-shadow: 0 8px 28px rgba(0,0,0,.3); }
.baicb-bubble:active { transform: scale(.95); }
.baicb-bubble--img {
  background: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  width: var(--baicb-bubble-size); height: var(--baicb-bubble-size);
  padding: 0;
}
.baicb-bubble--img:hover  { box-shadow: none !important; }
.baicb-bubble--img .baicb-bubble-img,
.baicb-bubble--img .baicb-bubble-img-close {
  width: var(--baicb-bubble-size); height: var(--baicb-bubble-size);
  object-fit: contain;
  display: block;
  position: absolute;
  top: 0; left: 0;
  transition: opacity .2s, transform .2s;
}
.baicb-bubble--img .baicb-bubble-img-close {
  opacity: 0;
  transform: rotate(-90deg) scale(.7);
}
.baicb-root.baicb--open .baicb-bubble--img .baicb-bubble-img       { opacity: 0; transform: scale(.7); }
.baicb-root.baicb--open .baicb-bubble--img .baicb-bubble-img-close { opacity: 1; transform: rotate(0) scale(1); }
.baicb-bubble--img .baicb-notif-dot { border-color: transparent; }

/* Bubble chat icon */
.baicb-icon-chat {
  width: 26px; height: 26px;
  transition: opacity .2s, transform .2s;
  display: block;
  flex-shrink: 0;
}
.baicb-icon-chat svg {
  width: 26px; height: 26px;
  display: block;
}

/* Close icon — hidden by default, shown when open */
.baicb-icon-close {
  position: absolute;
  width: 20px; height: 20px;
  opacity: 0;
  transform: rotate(-90deg) scale(.7);
  transition: opacity .2s, transform .2s;
  display: block;
}

.baicb-root.baicb--open .baicb-icon-chat  { opacity: 0; transform: scale(.7); }
.baicb-root.baicb--open .baicb-icon-close { opacity: 1; transform: rotate(0) scale(1); }

.baicb-notif-dot {
  position: absolute; top: 3px; right: 3px;
  width: 12px; height: 12px;
  background: var(--baicb-notif-color, #fff); border-radius: 50%;
  border: 2px solid var(--baicb-accent);
  animation: baicb-pulse 2s infinite;
  z-index: 1;
}
.baicb-root.baicb--open .baicb-notif-dot { display: none; }

@keyframes baicb-pulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%       { transform: scale(1.3); opacity: .7; }
}

/* ── Chat window ─────────────────────────────────────────────── */
.baicb-window {
  position: absolute;
  width: var(--baicb-w);
  max-height: var(--baicb-h);
  background: #fff;
  border-radius: var(--baicb-radius);
  box-shadow: var(--baicb-shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  opacity: 0; pointer-events: none;
  transform: translateY(16px) scale(.96);
  transition: opacity .25s ease, transform .25s cubic-bezier(.34,1.36,.64,1),
              width .3s ease, max-height .3s ease;
}

.baicb-root.baicb--open .baicb-window {
  opacity: 1; pointer-events: all;
  transform: translateY(0) scale(1);
  visibility: visible;
}

/* Expanded state */
.baicb-root.baicb--expanded .baicb-window {
  width:      var(--baicb-w-expand);
  max-height: var(--baicb-h-expand);
}

/* ── Header ─────────────────────────────────────────────────── */
.baicb-header {
  background: var(--baicb-primary);
  color: #fff;
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.baicb-header-info { display: flex; align-items: center; gap: 10px; min-width: 0; }

.baicb-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--baicb-accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.baicb-avatar-img {
  width: 36px; height: 36px;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.baicb-bot-name {
  font-weight: 700; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 160px;
}
.baicb-status {
  font-size: 11px; opacity: .75;
  display: flex; align-items: center; gap: 4px; margin-top: 1px;
}
.baicb-status-dot {
  width: 6px; height: 6px; background: #4ade80;
  border-radius: 50%; display: inline-block; flex-shrink: 0;
}

.baicb-header-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.baicb-header-btn {
  background: none; border: none; color: rgba(255,255,255,.7);
  cursor: pointer; padding: 6px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
  /* minimum touch target */
  min-width: 32px; min-height: 32px;
}
.baicb-header-btn:hover { color: #fff; background: rgba(255,255,255,.15); }
.baicb-header-btn svg   { width: 15px; height: 15px; }

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

.baicb-msg {
  display: flex; flex-direction: column;
  animation: baicb-fadein .2s ease both;
}
@keyframes baicb-fadein { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

.baicb-msg-bot  { align-self: flex-start; width: 90%; }
.baicb-msg-user { align-self: flex-end;   max-width: 82%; }

.baicb-msg-bubble {
  padding: 10px 14px; border-radius: 18px;
  font-size: 14px; line-height: 1.5;
  word-break: break-word;
}
.baicb-msg-bot  .baicb-msg-bubble { background: #f4f5f7; color: #222; border-bottom-left-radius: 4px; }
.baicb-msg-user .baicb-msg-bubble { background: var(--baicb-accent); color: #fff; border-bottom-right-radius: 4px; }

.baicb-msg-time { font-size: 10px; color: #aaa; margin-top: 3px; padding: 0 4px; }
.baicb-msg-user .baicb-msg-time { text-align: right; }

/* Bullet lists inside bot messages */
.baicb-msg-bubble .baicb-list {
  margin: 4px 0 2px 0;
  padding-left: 16px;
  list-style: disc;
}
.baicb-msg-bubble .baicb-list li {
  margin-bottom: 3px;
  line-height: 1.45;
}

/* Typing indicator */
.baicb-typing .baicb-msg-bubble { display: flex; align-items: center; gap: 4px; padding: 12px 16px; }
.baicb-typing-dot {
  width: 7px; height: 7px; background: #aaa; border-radius: 50%;
  animation: baicb-typing 1.2s infinite;
}
.baicb-typing-dot:nth-child(2) { animation-delay: .2s; }
.baicb-typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes baicb-typing {
  0%, 60%, 100% { transform: translateY(0);    background: #ccc; }
  30%            { transform: translateY(-5px); background: var(--baicb-accent); }
}

/* ── Input area ──────────────────────────────────────────────── */
.baicb-input-area {
  padding: 10px 12px; border-top: 1px solid #f0f0f0;
  display: flex; align-items: flex-end; gap: 8px;
  background: #fff; flex-shrink: 0;
}
.baicb-user-textarea {
  flex: 1; padding: 9px 12px;
  border: 1.5px solid #e2e2e2; border-radius: 12px;
  font-size: 14px; font-family: var(--baicb-font);
  resize: none; outline: none; line-height: 1.4;
  max-height: 100px; overflow-y: auto;
  transition: border-color .2s;
}
.baicb-user-textarea:focus { border-color: var(--baicb-accent); }
.baicb-user-textarea::placeholder { color: #bbb; }

/* Send button — text truncated, never clips */
.baicb-send-btn {
  min-width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--baicb-accent); border: none; color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .2s, transform .15s;
  /* truncation if somehow text is inside */
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  max-width: 160px;
}
.baicb-send-btn:hover  { background: var(--baicb-primary); }
.baicb-send-btn:active { transform: scale(.92); }
.baicb-send-btn svg    { width: 16px; height: 16px; flex-shrink: 0; }
.baicb-send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Consent bar ─────────────────────────────────────────────── */
.baicb-consent-bar {
  padding: 6px 14px 7px;
  border-top: 1px solid #f0f0f0;
  background: #fafafa;
  flex-shrink: 0;
}
.baicb-consent-label {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  cursor: pointer;
}
.baicb-consent-check {
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--baicb-accent);
  width: 13px; height: 13px;
  cursor: pointer;
}
.baicb-consent-text {
  font-size: 10.5px;
  color: #888;
  line-height: 1.4;
}
.baicb-consent-link {
  color: var(--baicb-accent);
  text-decoration: none;
  white-space: nowrap;
}
.baicb-consent-link:hover { text-decoration: underline; }

/* ── Footer brand ────────────────────────────────────────────── */
.baicb-footer-brand {
  text-align: center; font-size: 10px; color: #bbb;
  padding: 4px 0 6px; background: #fff; flex-shrink: 0;
}
.baicb-footer-link {
  color: #999; text-decoration: none; font-weight: 600;
  transition: color .15s;
}
.baicb-footer-link:hover { color: var(--baicb-accent); }

/* ── CTA Card ────────────────────────────────────────────────── */
.baicb-cta-card {
  background: linear-gradient(135deg, var(--baicb-primary) 0%, color-mix(in srgb, var(--baicb-primary) 80%, var(--baicb-accent)) 100%);
  border-radius: 14px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
  animation: baicb-fadein .3s ease both;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  width: 100%;
  box-sizing: border-box;
}
.baicb-cta-msg { font-size: 13px; font-weight: 600; color: rgba(255,255,255,.9); line-height: 1.4; }
.baicb-cta-btns { display: flex; flex-direction: column; gap: 7px; width: 100%; }

/* All CTA buttons — full width, text never clips */
.baicb-cta-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; box-sizing: border-box;
  color: #fff !important; text-decoration: none !important;
  padding: 10px 14px; border-radius: 10px;
  font-size: 13px; font-weight: 700; letter-spacing: .01em;
  transition: opacity .2s, transform .15s;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  min-width: 0;
}
.baicb-cta-btn:hover  { opacity: .88; transform: translateY(-1px); }
.baicb-cta-btn:active { transform: scale(.96); }

.baicb-cta-btn--link  { background: var(--baicb-accent); }
.baicb-cta-btn--phone { background: #16a34a; }
.baicb-cta-btn--sms   { background: #2563eb; }
.baicb-cta-btn--email { background: #7c3aed; }

.baicb-cta-icon { display: flex; align-items: center; flex-shrink: 0; }
.baicb-cta-icon svg { width: 14px; height: 14px; }
/* Text span inside CTA button — truncates, icon stays visible */
.baicb-cta-btn-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ── Mobile — full responsive ────────────────────────────────── */

/* Tablets (≤ 640px): full width, horizontally centered */
@media (max-width: 640px) {
  :root {
    --baicb-w:        calc(100vw - 32px);
    --baicb-w-expand: calc(100vw - 32px);
  }
  .baicb-window {
    left: 16px !important;
    right: 16px !important;
    width: auto !important;
    top: 50% !important;
    transform: translateY(-50%) translateY(16px) scale(.96) !important;
  }
  .baicb-root.baicb--open .baicb-window {
    transform: translateY(-50%) scale(1) !important;
  }
  .baicb-root.baicb--bottom-right,
  .baicb-root.baicb--mid-bottom-right,
  .baicb-root.baicb--middle-right,
  .baicb-root.baicb--mid-upper-right,
  .baicb-root.baicb--right { right: 12px; }
  .baicb-root.baicb--bottom-left,
  .baicb-root.baicb--mid-bottom-left,
  .baicb-root.baicb--middle-left,
  .baicb-root.baicb--mid-upper-left,
  .baicb-root.baicb--left  { left: 12px; }
}

/* Phones (≤ 430px) — root becomes fullscreen container, bubble floats over it */
@media (max-width: 430px) {
  /* Root: cover entire viewport — pointer-events off when closed so page is usable */
  .baicb-root {
    top: 0 !important; left: 0 !important;
    right: 0 !important; bottom: 0 !important;
    width: 100% !important; min-height: 100% !important;
    transform: none !important;
    pointer-events: none !important;
  }
  /* Re-enable pointer events on root only when open */
  .baicb-root.baicb--open {
    pointer-events: all !important;
  }
  /* Bubble always interactive regardless of open state */
  .baicb-bubble {
    pointer-events: all !important;
  }
  /* Window: JS sets position:fixed with exact visualViewport coords */
  .baicb-window {
    max-height: none !important;
    border-radius: 0 !important;
    transform: none !important;
    transition: opacity .2s ease !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: 999999 !important;
  }
  .baicb-root.baicb--open .baicb-window {
    opacity: 1 !important;
    pointer-events: all !important;
    visibility: visible !important;
  }
  /* Bubble: fixed so it floats above the root/window */
  .baicb-bubble {
    --baicb-bubble-size: 44px;
    position: fixed !important;
    bottom: 16px !important;
    right: 16px !important;
    left: auto !important;
    top: auto !important;
    margin: 0 !important;
    z-index: 1000000 !important;
  }
  .baicb-root.baicb--bottom-left .baicb-bubble,
  .baicb-root.baicb--mid-bottom-left .baicb-bubble,
  .baicb-root.baicb--middle-left .baicb-bubble,
  .baicb-root.baicb--mid-upper-left .baicb-bubble,
  .baicb-root.baicb--left .baicb-bubble { right: auto !important; left: 16px !important; }
  .baicb-notif-dot { top: 1px; right: 1px; width: 10px; height: 10px; }
  .baicb-msg-bubble { font-size: 15px; }
  .baicb-user-textarea { font-size: 16px; }
  .baicb-send-btn   { min-width: 44px; height: 44px; }
  .baicb-header-btn { min-width: 40px; min-height: 40px; }
}
