/* =========================================================
   WP AI Chatbot v3 — Dynamic branding CSS
   All colors injected via CSS variables set by JS
   ========================================================= */

:root {
  --cb-accent:      #0A84FF;
  --cb-accent-dark: #006ed4;
  --cb-header-bg:   linear-gradient(135deg,#0A84FF,#0051a8);
  --cb-bot-bubble:  #f0f7ff;
  --cb-user-bubble: #0A84FF;
  --cb-radius:      18px;
  --cb-shadow:      0 12px 48px rgba(0,0,0,.16), 0 2px 8px rgba(0,0,0,.08);
  --cb-font:        -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
}

/* ── Launcher ─────────────────────────────────────────────── */
#cb-launcher {
  position: fixed;
  bottom: 26px;
  z-index: 99998;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--cb-header-bg);
  box-shadow: 0 4px 20px rgba(0,0,0,.28);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), box-shadow .25s;
  overflow: visible;   /* allow badge to show outside the circle */
  padding: 0;
}
#cb-launcher.pos-right { right: 26px; }
#cb-launcher.pos-left  { left:  26px; }

#cb-launcher:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(0,0,0,.38);
}
#cb-launcher::before {
  content:''; position:absolute; inset:-7px; border-radius:50%;
  border:2px solid var(--cb-accent); opacity:0;
  animation: cb-pulse 2.6s ease-out infinite;
}
@keyframes cb-pulse {
  0%   { opacity:.55; transform:scale(.9); }
  70%  { opacity:0;   transform:scale(1.35); }
  100% { opacity:0; }
}

/* Logo mode vs icon mode */
#cb-launcher .cb-launch-logo {
  width: 72%;
  height: 72%;
  object-fit: contain;
  border-radius: 50%;
  transition: opacity .2s, transform .2s;
}#cb-launcher .cb-launch-icon {
  width: 26px;
  height: 26px;
  fill: #fff;
  transition: opacity .2s, transform .2s;
  position: absolute;
}

/* Default state: show open-element, hide close */
#cb-launcher .ico-open  { opacity: 1;  transform: scale(1)   rotate(0deg);   pointer-events: auto; }
#cb-launcher .ico-close { opacity: 0;  transform: scale(0.5) rotate(-90deg); pointer-events: none; }

/* Open state: hide open-element, show close */
#cb-launcher.open .ico-open  { opacity: 0;  transform: scale(0.5) rotate(90deg);  pointer-events: none; }
#cb-launcher.open .ico-close { opacity: 1;  transform: scale(1)   rotate(0deg);   pointer-events: auto; }

/* Unread badge */
#cb-badge {
  position:absolute; top:0; right:0;
  width:18px; height:18px; background:#ff3b30;
  border-radius:50%; font-size:11px; font-weight:700; color:#fff;
  display:flex; align-items:center; justify-content:center;
  border:2px solid #fff; pointer-events:none;
  opacity:0; transform:scale(0);
  transition:opacity .2s, transform .3s cubic-bezier(.34,1.56,.64,1);
}
#cb-badge.show { opacity:1; transform:scale(1); }

/* ── Window ───────────────────────────────────────────────── */
#cb-window {
  position:fixed;
  bottom:100px;
  z-index:99999;
  width:380px; max-width:calc(100vw - 36px);
  height:560px; max-height:calc(100vh - 120px);
  background:#fff;
  border-radius:var(--cb-radius);
  box-shadow:var(--cb-shadow);
  display:flex; flex-direction:column; overflow:hidden;
  font-family:var(--cb-font);
  transform:scale(.9) translateY(20px);
  opacity:0; pointer-events:none;
  transition:transform .3s cubic-bezier(.34,1.4,.64,1), opacity .22s;
}
#cb-window.pos-right { right:26px; }
#cb-window.pos-left  { left:26px;  }
#cb-window.open { transform:scale(1) translateY(0); opacity:1; pointer-events:auto; }

/* ── Header ───────────────────────────────────────────────── */
#cb-header {
  background: var(--cb-header-bg);
  padding:14px 16px;
  display:flex; align-items:center; gap:11px;
  flex-shrink:0;
}
.cb-hd-avatar {
  width:40px; height:40px; border-radius:50%;
  background:rgba(255,255,255,.2);
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0; overflow:hidden;
}
.cb-hd-avatar img { width:100%; height:100%; object-fit:cover; }
.cb-hd-avatar svg { width:22px; height:22px; fill:#fff; }
#cb-hd-info { flex:1; min-width:0; }
#cb-hd-name { color:#fff; font-weight:700; font-size:15px; line-height:1.2; }
#cb-hd-page {
  display:flex; align-items:center; gap:4px; margin-top:3px;
  background:rgba(255,255,255,.15); border-radius:20px;
  padding:2px 8px; max-width:210px; width:fit-content;
}
#cb-hd-page svg { width:11px; height:11px; fill:rgba(255,255,255,.8); flex-shrink:0; }
#cb-hd-page-text {
  color:rgba(255,255,255,.9); font-size:11px;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:175px;
}

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

.cb-msg { display:flex; gap:7px; align-items:flex-end; animation:cb-in .2s ease; }
@keyframes cb-in { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }
.cb-msg.user { flex-direction:row-reverse; }

.cb-avatar {
  width:28px; height:28px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0; overflow:hidden;
}
.cb-msg.bot  .cb-avatar { background:rgba(var(--cb-accent-rgb),.13); }
.cb-msg.user .cb-avatar { background:var(--cb-accent); }
.cb-avatar img { width:100%; height:100%; object-fit:cover; }
.cb-avatar svg { width:15px; height:15px; }
.cb-msg.bot  .cb-avatar svg { fill:var(--cb-accent); }
.cb-msg.user .cb-avatar svg { fill:#fff; }

.cb-bubble {
  max-width:80%; padding:9px 13px;
  border-radius:16px; font-size:14px; line-height:1.55; word-break:break-word;
}
.cb-msg.bot  .cb-bubble { background:var(--cb-bot-bubble); color:#1c1c1e; border-bottom-left-radius:4px; }
.cb-msg.user .cb-bubble { background:var(--cb-user-bubble); color:#fff; border-bottom-right-radius:4px; }
.cb-bubble a { color:inherit; text-decoration:underline; text-underline-offset:2px; }

/* Typing */
.cb-typing { display:flex; gap:4px; padding:4px 2px; align-items:center; }
.cb-typing span { width:7px; height:7px; background:#bbb; border-radius:50%; animation:cb-bounce .9s ease infinite; }
.cb-typing span:nth-child(2){ animation-delay:.18s; }
.cb-typing span:nth-child(3){ animation-delay:.36s; }
@keyframes cb-bounce { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-6px)} }

/* ── Contact Card ─────────────────────────────────────────── */
.cb-contact-card {
  background:#fff; border:1.5px solid #e5e5ea; border-radius:14px;
  padding:14px; max-width:88%; animation:cb-in .2s ease;
}
.cb-contact-card h4 { margin:0 0 10px; font-size:14px; font-weight:700; color:#1c1c1e; display:flex; align-items:center; gap:6px; }
.cb-cf-field {
  width:100%; box-sizing:border-box; border:1.5px solid #e5e5ea;
  border-radius:9px; padding:8px 11px; font-size:13px; font-family:var(--cb-font);
  color:#1c1c1e; background:#fafafa; outline:none; margin-bottom:8px; transition:border-color .2s;
}
.cb-cf-field:focus { border-color:var(--cb-accent); background:#fff; }
.cb-cf-field::placeholder { color:#aaa; }
textarea.cb-cf-field { resize:none; }
.cb-cf-submit {
  width:100%; background:var(--cb-accent); color:#fff; border:none;
  border-radius:9px; padding:9px; font-size:13px; font-weight:600;
  font-family:var(--cb-font); cursor:pointer; transition:background .2s, transform .15s;
}
.cb-cf-submit:hover  { background:var(--cb-accent-dark); }
.cb-cf-submit:active { transform:scale(.97); }
.cb-cf-submit:disabled { opacity:.55; cursor:not-allowed; }
.cb-cf-success { text-align:center; padding:8px 0 2px; font-size:13px; color:#34c759; font-weight:600; }
.cb-cf-error { color:#ff3b30; font-size:12px; margin:-4px 0 6px; }

/* Hide input bar while pre-chat form is visible */
#cb-messages:has(#cb-prechat) ~ #cb-input-row {
  display: none;
}

/* ── Input row ────────────────────────────────────────────── */
#cb-input-row {
  padding:10px 12px; border-top:1px solid #f0f0f5;
  display:flex; gap:8px; align-items:flex-end;
  flex-shrink:0; background:#fff;
}
#cb-input {
  flex:1; resize:none; border:1.5px solid #e5e5ea; border-radius:12px;
  padding:9px 13px; font-size:14px; font-family:var(--cb-font);
  line-height:1.5; min-height:40px; max-height:110px;
  outline:none; background:#fafafa; color:#1c1c1e;
  transition:border-color .2s, background .2s; overflow-y:auto;
}
#cb-input:focus { border-color:var(--cb-accent); background:#fff; }
#cb-input::placeholder { color:#aaa; }
#cb-send {
  width:40px; height:40px; border-radius:11px;
  background:var(--cb-accent); border:none; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0; transition:background .2s, transform .15s;
}
#cb-send:hover  { background:var(--cb-accent-dark); }
#cb-send:active { transform:scale(.92); }
#cb-send:disabled { opacity:.45; cursor:not-allowed; }
#cb-send svg { width:17px; height:17px; fill:#fff; }

/* ── Footer ───────────────────────────────────────────────── */
#cb-footer { text-align:center; font-size:11px; color:#c7c7cc; padding:4px 0 9px; flex-shrink:0; }

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width:480px) {
  #cb-window.open {
    position: fixed;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
  }
  #cb-launcher { bottom: 18px; }
  #cb-launcher.pos-right { right: 18px; }
  #cb-launcher.pos-left  { left:  18px; }
}

/* ── Header close button ──────────────────────────────────── */
#cb-header-close {
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 50%;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  margin-left: auto;
  flex-shrink: 0;
  transition: background .2s, transform .15s;
}
#cb-header-close:hover  { background: rgba(255,255,255,.3); }
#cb-header-close:active { transform: scale(.9); }
#cb-header-close svg    { width: 16px; height: 16px; fill: #fff; }

/* ── System / warning messages ────────────────────────────── */
.cb-system-msg {
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  margin: 2px 4px;
  animation: cb-in .2s ease;
}

/* ── Conversation divider ─────────────────────────────────── */
.cb-divider {
  text-align: center;
  font-size: 11px;
  color: #aaa;
  padding: 4px 16px;
  position: relative;
  margin: 4px 0;
  flex-shrink: 0;
}

#cb-invite {
  position: fixed;
  bottom: 100px;
  z-index: 99997;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,.16);
  padding: 12px 14px 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 240px;
  font-family: var(--cb-font);
  font-size: 13px;
  color: #1c1c1e;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px) scale(.95);
  transition: opacity .3s, transform .3s;
  border-left: 4px solid var(--cb-accent);
}
#cb-invite.pos-right { right: 26px; }
#cb-invite.pos-left  { left:  26px; }
#cb-invite.show      { opacity:1; transform:translateY(0) scale(1); }
#cb-invite-msg       { flex:1; line-height:1.4; font-weight:500; }
#cb-invite-close {
  background: none; border: none; cursor: pointer;
  font-size: 14px; color: #aaa; padding: 2px 4px; flex-shrink:0;
  transition: color .15s;
}
#cb-invite-close:hover { color: #555; }

/* ── Pre-chat Form ────────────────────────────────────────── */
#cb-prechat {
  padding: 6px 4px 2px;
  animation: cb-in .25s ease;
}
.cb-prechat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid #f0f0f5;
}
.cb-pf-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  margin-bottom: 4px;
}
.cb-pf-field {
  width: 100%;
  box-sizing: border-box;
  border: 1.5px solid #e5e5ea;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 13px;
  font-family: var(--cb-font);
  color: #1c1c1e;
  background: #fafafa;
  outline: none;
  margin-bottom: 10px;
  transition: border-color .2s, background .2s;
}
.cb-pf-field:focus { border-color: var(--cb-accent); background: #fff; }
.cb-pf-field::placeholder { color: #bbb; }
.cb-pf-submit {
  width: 100%;
  background: var(--cb-accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--cb-font);
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.cb-pf-submit:hover  { background: var(--cb-accent-dark); }
.cb-pf-submit:active { transform: scale(.97); }
.cb-pf-submit:disabled { opacity: .55; cursor: not-allowed; }

/* Error message styling */
#pf-error {
  background: #fff0f0;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: #dc2626;
  margin-bottom: 10px;
  line-height: 1.5;
}
