/* =========================================================
   WP AI Chatbot – Frontend Widget
   All colours/sizes driven by CSS variables.
   Override in your theme with :root { --wpaicb-primary: … }
   ========================================================= */

/* ── Variables (defaults) ──────────────────────────────── */
:root {
  --wpaicb-primary:      #0066cc;
  --wpaicb-primary-dark: #004fa3;
  --wpaicb-bg:           #ffffff;
  --wpaicb-surface:      #f5f7fa;
  --wpaicb-text:         #1a1a2e;
  --wpaicb-text-muted:   #6b7280;
  --wpaicb-border:       #e5e7eb;
  --wpaicb-bubble-user:  #0066cc;
  --wpaicb-bubble-bot:   #f0f4ff;
  --wpaicb-radius:       16px;
  --wpaicb-font:         inherit;
  --wpaicb-shadow:       0 8px 32px rgba(0,0,0,.18);
  --wpaicb-z:            99999;
  --wpaicb-btn-size:     56px;
}

/* ── Root container ─────────────────────────────────────── */
#wpaicb-root {
  position: fixed;
  bottom: 24px;
  z-index: var(--wpaicb-z);
  font-family: var(--wpaicb-font);
  line-height: 1.5;
  font-size: 15px;
}
/* Position applied by JS inline style */

/* ── Toggle button ──────────────────────────────────────── */
#wpaicb-toggle {
  width:  var(--wpaicb-btn-size);
  height: var(--wpaicb-btn-size);
  border-radius: 50%;
  background: var(--wpaicb-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--wpaicb-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
  outline-offset: 3px;
  /* Attention animation — runs on load, pauses when open */
  animation: wpaicb-attention 3s ease-in-out 2s infinite;
}
#wpaicb-toggle:hover  { background: var(--wpaicb-primary-dark); transform: scale(1.07); animation: none; }
#wpaicb-toggle:focus  { outline: 2px solid var(--wpaicb-primary); }
#wpaicb-toggle svg    { width: 24px; height: 24px; }
#wpaicb-toggle.wpaicb-open { animation: none; }

/* Ripple ring behind the button */
#wpaicb-toggle::before {
  content: '';
  position: absolute;
  width: var(--wpaicb-btn-size);
  height: var(--wpaicb-btn-size);
  border-radius: 50%;
  background: var(--wpaicb-primary);
  opacity: 0;
  animation: wpaicb-ripple 3s ease-out 2s infinite;
  pointer-events: none;
}
#wpaicb-toggle.wpaicb-open::before { animation: none; }

/* Bounce + pulse attention sequence */
@keyframes wpaicb-attention {
  0%          { transform: scale(1);    }
  6%          { transform: scale(1.18); }
  12%         { transform: scale(0.95); }
  18%         { transform: scale(1.08); }
  24%         { transform: scale(1);    }
  100%        { transform: scale(1);    }
}

/* Expanding ring ripple */
@keyframes wpaicb-ripple {
  0%   { transform: scale(1);   opacity: 0.5; }
  100% { transform: scale(2.2); opacity: 0;   }
}

/* ── Chat window ────────────────────────────────────────── */
#wpaicb-window {
  position: absolute;
  bottom: 68px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 50vh;
  max-height: 50vh;
  background: var(--wpaicb-bg);
  border: 1px solid var(--wpaicb-border);
  border-radius: var(--wpaicb-radius);
  box-shadow: var(--wpaicb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Animation */
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
#wpaicb-root.wpaicb-pos-right #wpaicb-window { right: 0; left: auto; }
#wpaicb-root.wpaicb-pos-left  #wpaicb-window { left: 0;  right: auto; }

#wpaicb-window:not([hidden]) {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
/* hidden attr still used but we animate via class */
#wpaicb-window[hidden] { display: flex !important; }

/* Mobile — full width bottom sheet, 50vh height */
@media (max-width: 600px) {
  #wpaicb-window {
    position: fixed !important;
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 16px 16px 0 0 !important;
  }
  /* 16px prevents iOS auto-zoom on input focus */
  #wpaicb-input       { font-size: 16px; }
  #wpaicb-email-input { font-size: 16px; }
  #wpaicb-send        { width: 46px; height: 46px; }
  .wpaicb-ts          { font-size: 10px; }
  #wpaicb-footer-note { display: none; }
}

/* ── Header ─────────────────────────────────────────────── */
#wpaicb-header {
  background: var(--wpaicb-primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;  /* Never shrink — always visible */
  min-height: 60px;
  position: relative;
  z-index: 1;
}
#wpaicb-header-info { display: flex; align-items: center; gap: 10px; }

#wpaicb-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; letter-spacing: .03em;
}
#wpaicb-title       { font-weight: 600; font-size: 15px; }
#wpaicb-status      { font-size: 12px; opacity: .85; display: flex; align-items: center; gap: 5px; }
.wpaicb-dot         { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; display: inline-block; }

#wpaicb-close-btn {
  background: none; border: none; color: #fff; cursor: pointer;
  padding: 4px; border-radius: 6px; opacity: .8;
  transition: opacity .15s, background .15s;
  display: flex; align-items: center;
}
#wpaicb-close-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }
#wpaicb-close-btn svg   { width: 18px; height: 18px; }

/* ── Messages area ──────────────────────────────────────── */
#wpaicb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--wpaicb-surface);
  scroll-behavior: smooth;
}

.wpaicb-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 4px;
  animation: wpaicb-pop .18s ease;
}
@keyframes wpaicb-pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.wpaicb-msg-bot  { align-self: flex-start; }
.wpaicb-msg-user { align-self: flex-end; }

.wpaicb-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  color: var(--wpaicb-text);
}
.wpaicb-msg-bot  .wpaicb-bubble {
  background: var(--wpaicb-bubble-bot);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--wpaicb-border);
}
.wpaicb-msg-user .wpaicb-bubble {
  background: var(--wpaicb-bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.wpaicb-ts {
  font-size: 11px;
  color: var(--wpaicb-text-muted);
  padding: 0 4px;
}
.wpaicb-msg-user .wpaicb-ts { text-align: right; }

/* Typing indicator */
.wpaicb-typing-dots {
  display: flex; gap: 4px; align-items: center; padding: 4px 0;
}
.wpaicb-typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--wpaicb-primary);
  opacity: .4;
  animation: wpaicb-bounce 1.2s infinite;
}
.wpaicb-typing-dots span:nth-child(2) { animation-delay: .2s; }
.wpaicb-typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes wpaicb-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .4; }
  40%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Input area ─────────────────────────────────────────── */
#wpaicb-input-area {
  border-top: 1px solid var(--wpaicb-border);
  padding: 10px 12px 8px;
  background: var(--wpaicb-bg);
  flex-shrink: 0;
}
#wpaicb-input-row {
  display: flex; gap: 8px; align-items: flex-end;
}
#wpaicb-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--wpaicb-border);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: var(--wpaicb-font);
  font-size: 14px;
  color: var(--wpaicb-text);
  background: var(--wpaicb-surface);
  outline: none;
  transition: border-color .15s;
  max-height: 120px;
  line-height: 1.5;
}
#wpaicb-input:focus { border-color: var(--wpaicb-primary); }

#wpaicb-send {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--wpaicb-primary);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, opacity .15s;
}
#wpaicb-send:disabled { opacity: .4; cursor: default; }
#wpaicb-send:not(:disabled):hover { background: var(--wpaicb-primary-dark); }
#wpaicb-send svg { width: 16px; height: 16px; }

#wpaicb-footer-note {
  font-size: 10px;
  color: var(--wpaicb-text-muted);
  text-align: center;
  margin-top: 6px;
}

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 600px) {

  /* Toggle button — larger tap target */
  #wpaicb-toggle {
    width: max(var(--wpaicb-btn-size), 52px);
    height: max(var(--wpaicb-btn-size), 52px);
  }
  #wpaicb-toggle svg { width: 28px; height: 28px; }

  /* Chat window — half screen bottom sheet */
  #wpaicb-window {
    position: fixed !important;
    top: auto !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 50vh !important;
    max-height: 50vh !important;
    border-radius: 16px 16px 0 0 !important;
    border: none !important;
  }

  /* 16px prevents iOS auto-zoom on input focus */
  #wpaicb-input       { font-size: 16px; }
  #wpaicb-email-input { font-size: 16px; }

  /* Larger send button */
  #wpaicb-send     { width: 46px; height: 46px; }
  #wpaicb-send svg { width: 20px; height: 20px; }

  .wpaicb-ts          { font-size: 10px; }
  #wpaicb-footer-note { display: none; }
}

/* ── Email capture panel ─────────────────────────────────────────────── */
/* ── Email capture panel ─────────────────────────────────────────────── */
#wpaicb-email-panel {
  background: var(--wpaicb-surface);
  border-top: 1px solid var(--wpaicb-border);
  padding: 10px 12px 8px;
  animation: wpaicb-pop .2s ease;
}
#wpaicb-email-prompt {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--wpaicb-text-muted);
}
#wpaicb-email-row {
  display: flex;
  gap: 8px;
}
#wpaicb-email-input {
  flex: 1;
  border: 1px solid var(--wpaicb-border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--wpaicb-font);
  color: var(--wpaicb-text);
  background: var(--wpaicb-bg);
  outline: none;
  transition: border-color .15s;
}
#wpaicb-email-input:focus { border-color: var(--wpaicb-primary); }
#wpaicb-email-input:disabled { opacity: .5; }

#wpaicb-email-panel #wpaicb-email-send {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--wpaicb-primary);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
#wpaicb-email-panel #wpaicb-email-send:disabled { opacity: .4; cursor: default; }
#wpaicb-email-panel #wpaicb-email-send:not(:disabled):hover { background: var(--wpaicb-primary-dark); }
#wpaicb-email-panel #wpaicb-email-send svg { width: 15px; height: 15px; }

#wpaicb-email-msg {
  font-size: 12px;
  margin-top: 6px;
  min-height: 16px;
}
.wpaicb-email-success { color: #16a34a; }
.wpaicb-email-error   { color: #dc2626; }

/* Warning bubble style (unanswered message) */
.wpaicb-bubble-warning {
  border-left: 3px solid #f59e0b !important;
  background: #fffbeb !important;
  color: #92400e !important;
}
