/* ================================================================
   WP AI Chatbot — Frontend Widget
   ================================================================ */

:root {
  --wpcb-color: #2563eb;
  --wpcb-color-light: #dbeafe;
  --wpcb-radius: 16px;
  --wpcb-shadow: 0 8px 32px rgba(0,0,0,.18);
  --wpcb-font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ── Launcher bubble ─────────────────────────────────────────── */
#wpcb-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--wpcb-color);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--wpcb-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  transition: transform .2s, box-shadow .2s;
  font-size: 24px;
  overflow: hidden;
  padding: 0;
}
#wpcb-launcher:hover { transform: scale(1.08); box-shadow: 0 12px 36px rgba(0,0,0,.22); }
#wpcb-launcher.wpcb-left { right: auto; left: 24px; }

/* Avatar image inside launcher */
#wpcb-launcher .wpcb-launcher-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* Pulse ring when avatar is shown */
#wpcb-launcher:has(.wpcb-launcher-avatar)::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--wpcb-color);
  animation: wpcb-pulse-ring 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes wpcb-pulse-ring {
  0%   { transform: scale(1);    opacity: .7; }
  70%  { transform: scale(1.28); opacity: 0;  }
  100% { transform: scale(1.28); opacity: 0;  }
}

#wpcb-launcher .wpcb-badge {
  position: absolute;
  top: -4px; right: -4px;
  width: 18px; height: 18px;
  background: #ef4444;
  border-radius: 50%;
  font-size: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* ── Chat window ─────────────────────────────────────────────── */
#wpcb-window {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: var(--wpcb-radius);
  box-shadow: var(--wpcb-shadow);
  display: flex;
  flex-direction: column;
  z-index: 999998;
  overflow: hidden;
  transform: translateY(20px) scale(.97);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s;
  font-family: var(--wpcb-font);
}
#wpcb-window.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}
#wpcb-window.wpcb-left { right: auto; left: 24px; }

/* ── Header ──────────────────────────────────────────────────── */
#wpcb-header {
  background: var(--wpcb-color);
  color: #fff;
  padding: .9rem 1rem;
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-shrink: 0;
}
#wpcb-header .wpcb-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
}
#wpcb-header .wpcb-title { font-weight: 700; font-size: .95rem; line-height: 1.2; }

/* Online status row */
.wpcb-status-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.wpcb-online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  box-shadow: 0 0 0 0 rgba(74,222,128,.5);
  animation: wpcb-online-pulse 2.5s ease-in-out infinite;
}
@keyframes wpcb-online-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74,222,128,.55); }
  60%  { box-shadow: 0 0 0 5px rgba(74,222,128,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}
.wpcb-subtitle {
  font-size: .72rem;
  opacity: .88;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#wpcb-close {
  background: none; border: none; color: #fff;
  font-size: 20px; cursor: pointer; opacity: .75; line-height: 1;
  padding: 4px; flex-shrink: 0;
}
#wpcb-close:hover { opacity: 1; }

/* ── Agent picker ────────────────────────────────────────────── */
#wpcb-agent-picker {
  padding: .6rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  color: #475569;
}
#wpcb-agent-picker select {
  flex: 1;
  font-size: .82rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 3px 6px;
}

/* ── Messages ────────────────────────────────────────────────── */
#wpcb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  scroll-behavior: smooth;
}
#wpcb-messages::-webkit-scrollbar { width: 4px; }
#wpcb-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.wpcb-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: wpcb-pop .18s ease;
}
.wpcb-msg.user  { align-self: flex-end; align-items: flex-end; }
.wpcb-msg.bot   { align-self: flex-start; align-items: flex-start; }

.wpcb-bubble {
  padding: .6rem .85rem;
  border-radius: 18px;
  font-size: .88rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.wpcb-msg.user .wpcb-bubble {
  background: var(--wpcb-color);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.wpcb-msg.bot .wpcb-bubble {
  background: #f1f5f9;
  color: #1e293b;
  border-bottom-left-radius: 5px;
}
.wpcb-msg.bot.error .wpcb-bubble { background: #fef2f2; color: #dc2626; }
.wpcb-meta { font-size: .7rem; color: #94a3b8; margin-top: 2px; }

/* ── Typing indicator ────────────────────────────────────────── */
.wpcb-typing .wpcb-bubble {
  display: flex; gap: 4px; align-items: center; padding: .55rem .85rem;
}
.wpcb-dot {
  width: 7px; height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: wpcb-bounce .9s infinite ease-in-out;
}
.wpcb-dot:nth-child(2) { animation-delay: .15s; }
.wpcb-dot:nth-child(3) { animation-delay: .3s; }

/* ── Quick reply chips ───────────────────────────────────────── */
#wpcb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: .55rem 1rem .6rem;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
  transition: opacity .25s ease, max-height .25s ease;
  max-height: 120px;
  overflow: hidden;
}
#wpcb-chips.wpcb-chips-hidden {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-top-color: transparent;
}
.wpcb-chip {
  background: #fff;
  border: 1px solid var(--wpcb-color);
  color: var(--wpcb-color);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .8rem;
  cursor: pointer;
  font-family: var(--wpcb-font);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.wpcb-chip:hover {
  background: var(--wpcb-color);
  color: #fff;
}

/* ── Input area — pill style ─────────────────────────────────── */
#wpcb-input-area {
  padding: .6rem .75rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: .4rem;
  align-items: flex-end;
  background: #fff;
  flex-shrink: 0;
}

/* Attachment button */
#wpcb-attach {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #64748b;
  cursor: pointer;
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s;
  padding: 0;
}
#wpcb-attach:hover { background: #e2e8f0; color: #334155; }

/* Pill input */
#wpcb-input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 22px;
  padding: .52rem 1rem;
  font-size: .88rem;
  resize: none;
  max-height: 100px;
  min-height: 36px;
  font-family: var(--wpcb-font);
  line-height: 1.45;
  outline: none;
  transition: border-color .15s;
  overflow-y: auto;
  background: #f8fafc;
}
#wpcb-input:focus {
  border-color: var(--wpcb-color);
  background: #fff;
}

/* Send button */
#wpcb-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--wpcb-color);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  transition: background .15s, transform .1s;
  padding: 0;
}
#wpcb-send:hover  { background: #1d4ed8; }
#wpcb-send:active { transform: scale(.92); }
#wpcb-send:disabled { background: #94a3b8; cursor: not-allowed; }

/* ── Markdown rendering inside bot bubbles ───────────────────── */
.wpcb-msg.bot .wpcb-bubble p {
  margin: 0 0 .45em;
}
.wpcb-msg.bot .wpcb-bubble p:last-child { margin-bottom: 0; }

.wpcb-msg.bot .wpcb-bubble strong { font-weight: 700; }
.wpcb-msg.bot .wpcb-bubble em     { font-style: italic; }

.wpcb-msg.bot .wpcb-bubble h3,
.wpcb-msg.bot .wpcb-bubble h4,
.wpcb-msg.bot .wpcb-bubble h5 {
  font-size: .88rem;
  font-weight: 700;
  margin: .55em 0 .2em;
  color: #0f172a;
}

.wpcb-msg.bot .wpcb-bubble ul,
.wpcb-msg.bot .wpcb-bubble ol {
  margin: .3em 0 .45em 1.1em;
  padding: 0;
}
.wpcb-msg.bot .wpcb-bubble li { margin: .15em 0; }

.wpcb-msg.bot .wpcb-bubble blockquote {
  border-left: 3px solid #cbd5e1;
  border-radius: 0;
  margin: .4em 0;
  padding: .25em .7em;
  color: #475569;
  font-style: italic;
}

.wpcb-msg.bot .wpcb-bubble code {
  background: #e2e8f0;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, "SF Mono", "Fira Code", monospace;
  font-size: .82em;
  color: #0f172a;
}

.wpcb-msg.bot .wpcb-bubble pre {
  background: #0f172a;
  border-radius: 8px;
  padding: .65rem .85rem;
  margin: .4em 0;
  overflow-x: auto;
  font-size: .8rem;
  line-height: 1.6;
}
.wpcb-msg.bot .wpcb-bubble pre code {
  background: none;
  padding: 0;
  color: #e2e8f0;
  font-size: inherit;
  border-radius: 0;
}

.wpcb-msg.bot .wpcb-bubble a {
  color: #2563eb;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.wpcb-msg.bot .wpcb-bubble a:hover { color: #1d4ed8; }

.wpcb-msg.bot .wpcb-bubble hr {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: .5em 0;
}

/* ── Greeting bubble (pre-open) ──────────────────────────────── */
#wpcb-greeting {
  position: fixed;
  bottom: 92px;
  right: 90px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: .6rem 1rem;
  font-size: .85rem;
  color: #334155;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 999997;
  max-width: 220px;
  animation: wpcb-pop .3s ease;
}
#wpcb-greeting.wpcb-left { right: auto; left: 90px; }

/* ── Animations ──────────────────────────────────────────────── */
@keyframes wpcb-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%            { transform: translateY(-6px); }
}
@keyframes wpcb-pop {
  from { transform: scale(.9); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #wpcb-window {
    right: 0; left: 0; bottom: 0;
    width: 100%; max-width: 100%;
    height: 100vh; max-height: 100vh;
    border-radius: 0;
  }
  #wpcb-launcher { bottom: 16px; right: 16px; }
}
