/* ============================================================
   StarSphere Visitor Chatbot — UI v4.0
   WhatsApp-style messenger theme
   SF Pro font stack
   ============================================================ */

:root {
  /* Core colours — WhatsApp palette */
  --bg-page:     #e8eaf0;          /* outer page / behind panel */
  --bg-panel:    #efe9e0;          /* chat wallpaper — warm beige like WhatsApp */
  --bg-header:   #075e54;          /* WhatsApp dark teal header */
  --bg-input:    #f0f0f0;          /* input row background */
  --bg-input-fld:#ffffff;          /* pill input field */

  /* Bubbles */
  --bbl-in:      #ffffff;          /* incoming (bot / agent) — white */
  --bbl-out:     #d9fdd3;          /* outgoing (user) — WhatsApp light green */
  --bbl-in-txt:  #111b21;          /* text inside incoming bubble */
  --bbl-out-txt: #111b21;          /* text inside outgoing bubble */

  /* Text */
  --txt-main:    #111b21;
  --txt-sub:     #8696a0;          /* muted grey — timestamps */
  --txt-header:  #ffffff;          /* text on the dark header */
  --txt-header-sub: rgba(255,255,255,.75);
  --txt-input:   #111b21;
  --txt-placeholder: #8696a0;

  /* Accents */
  --accent:      #00a884;          /* WhatsApp green accent (send button, links) */
  --accent-send: #00a884;
  --online:      #25d366;
  --border:      rgba(0,0,0,.08);
  --shadow:      0 4px 30px rgba(0,0,0,.16), 0 1px 8px rgba(0,0,0,.1);

  /* Avatar ring colour */
  --av-ring:     #e4e6ea;

  /* Geometry */
  --r:  16px;                      /* panel corner radius */
  --w:  360px;
  --h:  580px;
  --z:  999999;

  /* Font — San Francisco stack */
  --sf: -apple-system, BlinkMacSystemFont, "SF Pro Text",
        "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
}

/* ─── RESET ─────────────────────────────────── */
#cpb-wrapper, #cpb-wrapper * {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── WRAPPER ────────────────────────────────── */
#cpb-wrapper {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: var(--z);
  font-family: var(--sf);
  font-size: 14px;
  line-height: 1.45;
  color: var(--txt-main);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

/* ─── FAB BUBBLE ─────────────────────────────── */
#cpb-bubble {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--accent);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  position: relative;
  box-shadow: 0 4px 18px rgba(0,168,132,.45), 0 2px 8px rgba(0,0,0,.2);
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
  flex-shrink: 0;
  overflow: hidden;
  padding: 0;
}
.cpb-launcher-img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
#cpb-bubble:hover {
  transform: scale(1.09);
  box-shadow: 0 6px 26px rgba(0,168,132,.55), 0 2px 8px rgba(0,0,0,.2);
}
#cpb-bubble:active  { transform: scale(.95); }
#cpb-bubble:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* Hide the floating launcher while the panel is open so it never
   overlaps the input row / send button */
#cpb-wrapper:has(#cpb-panel:not([hidden])) #cpb-bubble,
#cpb-wrapper.cpb-open #cpb-bubble {
  display: none;
}

/* icon swap via JS class */
#cpb-ic-close { display: none; }

/* Notification dot */
#cpb-dot {
  position: absolute; top: 3px; right: 3px;
  width: 13px; height: 13px;
  background: #e41e3f; border-radius: 50%;
  border: 2px solid #fff;
  animation: cpb-dotpulse 2s infinite;
}
@keyframes cpb-dotpulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(228,30,63,.55); }
  50%      { box-shadow: 0 0 0 6px rgba(228,30,63,0); }
}

/* ─── TEASER TOOLTIP ─────────────────────────── */
.cpb-tooltip {
  position: absolute; bottom: 66px; right: 4px;
  background: #fff;
  color: var(--txt-main);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.4;
  padding: 12px 16px;
  border-radius: 16px;
  max-width: 230px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14), 0 2px 6px rgba(0,0,0,.08);
  opacity: 0; transform: translateY(8px) scale(.96);
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: auto; cursor: pointer;
}
.cpb-tooltip::after {
  content: '';
  position: absolute;
  bottom: -7px; right: 22px;
  width: 14px; height: 14px;
  background: #fff;
  transform: rotate(45deg);
  border-radius: 0 0 3px 0;
  box-shadow: 3px 3px 6px rgba(0,0,0,.05);
}
.cpb-tooltip--on { opacity: 1; transform: translateY(0) scale(1); }

/* ─── PANEL ──────────────────────────────────── */
#cpb-panel {
  width: var(--w);
  height: var(--h);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 100vw;
  animation: cpb-pop .22s ease-out;
  transform-origin: bottom right;
}
#cpb-panel[hidden] { display: none; }

@keyframes cpb-pop {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

/* ─── HEADER — white bar, reference style ────── */
#cpb-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Back / close chevron — left side of header */
#cpb-back-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--txt-header); font-size: 18px; font-weight: 700;
  flex-shrink: 0;
  transition: background .15s;
  line-height: 1;
}
#cpb-back-btn:hover { background: rgba(255,255,255,.22); }

/* Unread badge on back button */
#cpb-back-badge {
  position: absolute;
  top: -3px; right: -4px;
  background: #e41e3f;
  color: #fff; font-size: 9px; font-weight: 700;
  width: 15px; height: 15px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--bg-header);
}

#cpb-av-wrap {
  position: relative;
  width: 38px; height: 38px;
  flex-shrink: 0;
}
#cpb-av {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  border: 2px solid var(--av-ring);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1;
  overflow: hidden;
}
#cpb-av-ring {
  position: absolute; bottom: 1px; right: 1px;
  width: 10px; height: 10px;
  background: var(--online);
  border-radius: 50%;
  border: 2px solid var(--bg-header);
}

#cpb-hdr-info { flex: 1; min-width: 0; }
#cpb-hdr-name {
  display: block;
  font-size: 15px; font-weight: 700;
  color: var(--txt-header);
  letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#cpb-hdr-status {
  display: block;
  font-size: 11px;
  color: var(--txt-header-sub);
  margin-top: 1px;
}

/* Three-dot menu button — right of header */
#cpb-menu-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: transparent;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--txt-header); font-size: 20px; letter-spacing: 1px;
  flex-shrink: 0;
  transition: background .15s;
}
#cpb-menu-btn:hover { background: rgba(255,255,255,.12); }

/* New chat button */
#cpb-new-chat {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.35);
  background: transparent; color: var(--txt-header);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s;
  font-size: 18px; line-height: 1;
}
#cpb-new-chat:hover { background: rgba(255,255,255,.15); }
#cpb-new-chat[hidden] { display: none; }

/* ─── MESSAGES FEED ──────────────────────────── */
#cpb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-panel);
  scroll-behavior: smooth;
}
#cpb-messages::-webkit-scrollbar { width: 3px; }
#cpb-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ── Date / time separators — centred grey text ── */
.cpb-date-sep {
  text-align: center;
  font-size: 11px;
  color: var(--txt-sub);
  margin: 10px 0 4px;
  letter-spacing: .02em;
}

/* ── Message row ── */
.cpb-msg {
  display: flex !important;
  align-items: flex-end;
  gap: 6px;
  max-width: 85%;
  margin-bottom: 2px !important;
}
.cpb-msg--bot  { align-self: flex-start; }
.cpb-msg--user { align-self: flex-end;   flex-direction: row-reverse; }
.cpb-msg:not(.cpb-msg--first) { margin-top: -1px; }
.cpb-msg--first { margin-top: 8px !important; }

/* Bot avatar — small circle, only visible on tail message */
.cpb-msg-av {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  border: none;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  visibility: hidden;   /* hidden unless .cpb-msg--tail */
  align-self: flex-end;
  overflow: hidden;
}
.cpb-msg-av img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.cpb-msg--tail .cpb-msg-av { visibility: visible; }
.cpb-msg--user .cpb-msg-av { display: none; }

/* Column holding bubble + timestamp */
.cpb-msg-col {
  display: flex !important;
  flex-direction: column !important;
  gap: 3px; min-width: 0; max-width: 100%;
}
.cpb-msg--user .cpb-msg-col { align-items: flex-end !important; }
.cpb-msg--bot  .cpb-msg-col { align-items: flex-start !important; }

/* ── BUBBLE — hugs its text with generous breathing room ──
   Forced with !important because some host sites load global
   CSS resets (e.g. Tailwind's CDN preflight) that redefine
   display/box-sizing/border on generic elements and can
   otherwise override this widget's bubble sizing. */
.cpb-bbl {
  display: table !important;
  width: auto !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  border: none !important;
  padding: 10px 14px !important;
  margin: 0 !important;
  font-size: 13.5px;
  line-height: 1.4;
  text-align: left;
  word-break: break-word;
  white-space: normal;
}
.cpb-bbl p { margin: 0 0 8px !important; }
.cpb-bbl p:last-child { margin-bottom: 0 !important; }

/* Incoming (bot/agent) — WHITE, rounded, left tail on last */
.cpb-msg--bot .cpb-bbl {
  background: var(--bbl-in);
  color: var(--bbl-in-txt);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
/* Tail shape — bottom-left corner flattened */
.cpb-msg--bot.cpb-msg--tail .cpb-bbl {
  border-bottom-left-radius: 4px;
}
/* Non-tail (grouped) — remove top-left radius */
.cpb-msg--bot:not(.cpb-msg--first) .cpb-bbl {
  border-top-left-radius: 6px;
}

/* Outgoing (user) — WhatsApp light green, right tail on last */
.cpb-msg--user .cpb-bbl {
  background: var(--bbl-out);
  color: var(--bbl-out-txt);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.cpb-msg--user.cpb-msg--tail .cpb-bbl {
  border-bottom-right-radius: 4px;
}
.cpb-msg--user:not(.cpb-msg--first) .cpb-bbl {
  border-top-right-radius: 6px;
}

/* Timestamp — only on tail */
.cpb-ts {
  font-size: 10px;
  color: var(--txt-sub);
  padding: 0 4px;
  display: none;
}
.cpb-msg--tail .cpb-ts { display: block; }
.cpb-msg--user .cpb-ts { text-align: right; }

/* ─── TYPING INDICATOR ───────────────────────── */
#cpb-typing {
  align-self: flex-start;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
#cpb-typing .cpb-msg-av {
  visibility: visible;
}
#cpb-typing .cpb-typing-bbl {
  background: var(--bbl-in);
  border-radius: 18px 18px 18px 4px;
  padding: 11px 14px;
  display: flex; align-items: center; gap: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
#cpb-typing .cpb-typing-bbl span {
  display: block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #b0b3b8;
  animation: cpb-bounce 1.3s ease-in-out infinite;
}
#cpb-typing .cpb-typing-bbl span:nth-child(2) { animation-delay: .17s; }
#cpb-typing .cpb-typing-bbl span:nth-child(3) { animation-delay: .34s; }
@keyframes cpb-bounce {
  0%,60%,100% { transform: translateY(0);   opacity: .5; }
  30%          { transform: translateY(-5px); opacity: 1; }
}

/* ─── HANDOVER BANNER ────────────────────────── */
#cpb-handover-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(49,162,76,.08);
  border-top: 1px solid rgba(49,162,76,.2);
  color: #1a7a32;
  font-size: 12px; text-align: center;
  padding: 7px 12px; flex-shrink: 0;
}
#cpb-handover-banner svg { flex-shrink: 0; }

/* ─── CELEBRITY SEARCH ───────────────────────── */
#cpb-celeb-search {
  padding: 8px 10px 5px;
  border-top: 1px solid var(--border);
  background: var(--bg-input);
  flex-shrink: 0;
}
#cpb-celeb-search[hidden] { display: none; }

#cpb-celeb-input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 22px;
  border: 1.5px solid var(--border);
  background: var(--bg-input-fld);
  color: var(--txt-input);
  font-size: 13px; font-family: var(--sf);
  outline: none;
  transition: border-color .2s;
}
#cpb-celeb-input::placeholder { color: var(--txt-placeholder); }
#cpb-celeb-input:focus { border-color: var(--accent); background: #fff; }

#cpb-celeb-list {
  list-style: none;
  max-height: 150px; overflow-y: auto;
  margin-top: 5px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
}
#cpb-celeb-list:empty { display: none; }
#cpb-celeb-list li {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--txt-main);
  border-bottom: 1px solid rgba(0,0,0,.05);
  transition: background .13s;
}
#cpb-celeb-list li:last-child { border-bottom: none; }
#cpb-celeb-list li:hover { background: #f0f2f5; }

/* ─── QUICK REPLY CHIPS ──────────────────────── */
#cpb-quick-wrap {
  padding: 6px 10px 6px;
  background: var(--bg-input);
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}
#cpb-quick-wrap[hidden] { display: none; }

#cpb-quick-btns {
  display: flex; flex-wrap: wrap; gap: 6px;
}

.cpb-qbtn {
  padding: 7px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--accent);
  background: #fff;
  color: var(--accent);
  font-size: 12.5px; font-family: var(--sf); font-weight: 500;
  cursor: pointer;
  white-space: normal;
  max-width: 100%;
  flex: 0 1 auto;
  text-align: left;
  transition: background .16s, color .16s, transform .12s;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.cpb-qbtn:hover {
  background: var(--accent);
  color: #fff;
  transform: translateY(-1px);
}
.cpb-qbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── INPUT ROW — white bar, reference style ─── */
#cpb-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 10px;
  background: var(--bg-input);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* + icon button left — like reference */
#cpb-plus-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none; background: transparent;
  color: var(--txt-sub); font-size: 22px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: color .15s;
}
#cpb-plus-btn:hover { color: var(--accent); }

/* Text input — pill shape, light grey fill */
#cpb-input {
  flex: 1; min-width: 0;
  padding: 9px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--bg-input-fld);
  color: var(--txt-input);
  font-size: 13.5px; font-family: var(--sf);
  outline: none;
  transition: border-color .2s, background .2s;
}
#cpb-input::placeholder { color: var(--txt-placeholder); }
#cpb-input:focus {
  border-color: rgba(0,168,132,.35);
  background: #fff;
}
#cpb-input:disabled { opacity: .4; cursor: not-allowed; }

/* Send button — green circle, right side */
#cpb-send {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent-send);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,168,132,.3);
  transition: background .17s, transform .15s;
}
#cpb-send:hover:not(:disabled) {
  background: #06906f;
  transform: scale(1.08);
}
#cpb-send:disabled { opacity: .35; cursor: not-allowed; transform: none; }
#cpb-send:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── MOBILE ─────────────────────────────────── */
@media (max-width: 480px) {
  #cpb-wrapper {
    bottom: 0; right: 0; left: 0;
    align-items: center;
  }
  #cpb-panel {
    width: 100vw; max-width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: none;
  }
  #cpb-bubble {
    position: fixed;
    bottom: 18px; right: 18px;
  }
}

/* ─── REDUCED MOTION ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #cpb-panel, #cpb-bubble, .cpb-bbl, .cpb-qbtn
    { animation: none !important; transition: none !important; }
  #cpb-typing .cpb-typing-bbl span { animation: none; opacity: .7; }
}