/* ================================================================
   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;
}

/* Bubble launcher */
#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;
}
#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; }
#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: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
#wpcb-header .wpcb-title { flex: 1; font-weight: 700; font-size: .95rem; }
#wpcb-header .wpcb-subtitle { font-size: .72rem; opacity: .82; }
#wpcb-close {
  background: none; border: none; color: #fff;
  font-size: 20px; cursor: pointer; opacity: .75; line-height: 1;
  padding: 4px;
}
#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: 14px;
  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: 4px;
}
.wpcb-msg.bot .wpcb-bubble {
  background: #f1f5f9;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}
.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; }

/* Input area */
#wpcb-input-area {
  padding: .75rem 1rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: .5rem;
  align-items: flex-end;
  background: #fff;
  flex-shrink: 0;
}
#wpcb-input {
  flex: 1;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: .55rem .8rem;
  font-size: .88rem;
  resize: none;
  max-height: 100px;
  min-height: 38px;
  font-family: var(--wpcb-font);
  line-height: 1.5;
  outline: none;
  transition: border-color .15s;
  overflow-y: auto;
}
#wpcb-input:focus { border-color: var(--wpcb-color); }

#wpcb-send {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--wpcb-color);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  transition: background .15s, transform .1s;
}
#wpcb-send:hover  { background: #1d4ed8; }
#wpcb-send:active { transform: scale(.93); }
#wpcb-send:disabled { background: #94a3b8; cursor: not-allowed; }

/* 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; }

@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; }
}
