/* AI Chatbot Widget — Front-end styles
   Design language matches the admin UI:
   - Primary #2451b0 / hover #1a3d8c (same as admin accent)
   - Tailwind-style neutrals (#111827, #374151, #6b7280, #f7f8fa, #e5e7eb)
   - Border-radius 12-16px, clean box-shadows, smooth transitions
   - Animations: panel slide-up, bubble fade-in, typing bounce, toggle scale
   All selectors scoped to .ai-chatbot. !important used only where needed to
   beat WooCommerce / Elementor theme resets on button/input elements. */


/* ── Root container (fixed bottom-right / bottom-left via inline style) ── */

.ai-chatbot {
  position: fixed !important;
  bottom: 24px !important;
  right: 24px !important;
  z-index: 999999 !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
  color: #111827 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
  gap: 12px !important;
}


/* ── Keyframe animations ─────────────────────────────────────────────────── */

@keyframes aica-slide-up {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

@keyframes aica-bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* WhatsApp-style dot bounce — each dot gets a different delay */
@keyframes aica-dot-bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%            { transform: translateY(-6px); opacity: 1;   }
}

@keyframes aica-toggle-pop {
  0%   { transform: scale(0.85); }
  65%  { transform: scale(1.06); }
  100% { transform: scale(1);    }
}

@media (prefers-reduced-motion: reduce) {
  @keyframes aica-slide-up    { from { opacity: 0; } to { opacity: 1; } }
  @keyframes aica-bubble-in   { from { opacity: 0; } to { opacity: 1; } }
  @keyframes aica-dot-bounce  { 0%, 100% { opacity: 0.4; } 30% { opacity: 1; } }
  @keyframes aica-toggle-pop  { from { opacity: 0; } to { opacity: 1; } }
}


/* ── Toggle button ───────────────────────────────────────────────────────── */

.ai-chatbot .ai-chatbot__toggle,
.ai-chatbot .ai-chatbot__toggle:not(.button) {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  background: var(--aica-accent, #2451b0) !important;
  background-color: var(--aica-accent, #2451b0) !important;
  color: #fff !important;
  border: none !important;
  border-radius: var(--aica-border-radius, 50px) !important;
  padding: 13px 22px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
  cursor: pointer !important;
  box-shadow:
    0 4px 14px rgba(36, 81, 176, 0.40),
    0 1px 3px  rgba(0, 0, 0, 0.12) !important;
  transition:
    background 0.18s ease,
    box-shadow 0.18s ease,
    transform  0.15s ease !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  animation: aica-toggle-pop 0.35s cubic-bezier(0.34,1.56,0.64,1) both !important;
}

.ai-chatbot .ai-chatbot__toggle:hover {
  background: #1a3d8c !important;
  background-color: #1a3d8c !important;
  box-shadow:
    0 6px 20px rgba(36, 81, 176, 0.50),
    0 2px 6px  rgba(0, 0, 0, 0.14) !important;
  transform: translateY(-2px) !important;
}

.ai-chatbot .ai-chatbot__toggle:active {
  transform: translateY(0) scale(0.97) !important;
}

.ai-chatbot .ai-chatbot__toggle svg {
  flex-shrink: 0 !important;
  pointer-events: none !important;
}

/* Hide the toggle button when the panel is open (data-open set by JS) */
.ai-chatbot[data-open] .ai-chatbot__toggle,
.ai-chatbot[data-open] .ai-chatbot__toggle:not(.button) {
  display: none !important;
}


/* ── Chat panel ──────────────────────────────────────────────────────────── */

.ai-chatbot .ai-chatbot__panel {
  width: 360px !important;
  max-width: calc(100vw - 32px) !important;
  height: 500px !important;
  max-height: calc(100vh - 100px) !important;
  background: #fff !important;
  border-radius: var(--aica-border-radius, 16px) !important;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.18),
    0  4px 16px rgba(0, 0, 0, 0.08),
    0  0   0 1px rgba(0, 0, 0, 0.04) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  animation: aica-slide-up 0.28s cubic-bezier(0.22,1,0.36,1) both !important;
}

/* Honour the HTML `hidden` attribute — overrides the display:flex above. */
.ai-chatbot .ai-chatbot__panel[hidden] {
  display: none !important;
}


/* ── Panel header ────────────────────────────────────────────────────────── */

.ai-chatbot .ai-chatbot__header {
  background: var(--aica-accent, #2451b0) !important;
  background-color: var(--aica-accent, #2451b0) !important;
  color: #fff !important;
  padding: 14px 16px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em !important;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  flex-shrink: 0 !important;
  gap: 10px !important;
}

/* Online status dot beside the title */
.ai-chatbot .ai-chatbot__header span:first-child {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}

.ai-chatbot .ai-chatbot__header span:first-child::before {
  content: "" !important;
  display: inline-block !important;
  width: 8px !important;
  height: 8px !important;
  border-radius: 50% !important;
  background: #10b981 !important;
  box-shadow: 0 0 0 2px rgba(16,185,129,0.30) !important;
  flex-shrink: 0 !important;
}


/* ── Close button ────────────────────────────────────────────────────────── */

.ai-chatbot .ai-chatbot__close {
  background: rgba(255,255,255,0.15) !important;
  background-color: rgba(255,255,255,0.15) !important;
  border: none !important;
  color: #fff !important;
  font-size: 20px !important;
  line-height: 1 !important;
  cursor: pointer !important;
  padding: 0 !important;
  width: 30px !important;
  height: 30px !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: none !important;
  transition: background 0.15s ease !important;
  flex-shrink: 0 !important;
  /* Critical: ensure clicks always fire — some themes block pointer events on
     child buttons inside containers. */
  pointer-events: all !important;
  position: relative !important;
  z-index: 10 !important;
}

.ai-chatbot .ai-chatbot__close:hover {
  background: rgba(255,255,255,0.30) !important;
  background-color: rgba(255,255,255,0.30) !important;
  color: #fff !important;
}

.ai-chatbot .ai-chatbot__close:active {
  transform: scale(0.92) !important;
}


/* ── Messages area ───────────────────────────────────────────────────────── */

.ai-chatbot .ai-chatbot__messages {
  flex: 1 !important;
  padding: 16px 14px !important;
  overflow-y: auto !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 10px !important;
  background: #f7f8fa !important;
  scroll-behavior: smooth !important;
}

/* Subtle scrollbar */
.ai-chatbot .ai-chatbot__messages::-webkit-scrollbar {
  width: 4px !important;
}
.ai-chatbot .ai-chatbot__messages::-webkit-scrollbar-track {
  background: transparent !important;
}
.ai-chatbot .ai-chatbot__messages::-webkit-scrollbar-thumb {
  background: #d1d5db !important;
  border-radius: 4px !important;
}


/* ── Message bubbles ─────────────────────────────────────────────────────── */

.ai-chatbot .ai-chatbot__msg {
  max-width: 82% !important;
  padding: 10px 14px !important;
  border-radius: var(--aica-border-radius, 14px) !important;
  font-size: var(--aica-font-size, 14px) !important;
  line-height: 1.5 !important;
  word-wrap: break-word !important;
  word-break: break-word !important;
  animation: aica-bubble-in 0.22s ease both !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07) !important;
}

/* Visitor bubble */
.ai-chatbot .ai-chatbot__msg--user {
  align-self: flex-end !important;
  background: var(--aica-user-bubble, var(--aica-accent, #2451b0)) !important;
  background-color: var(--aica-user-bubble, var(--aica-accent, #2451b0)) !important;
  color: #fff !important;
  border-bottom-right-radius: 4px !important;
}

/* Bot bubble */
.ai-chatbot .ai-chatbot__msg--bot {
  align-self: flex-start !important;
  background: var(--aica-bot-bubble, #e9edf5) !important;
  background-color: var(--aica-bot-bubble, #e9edf5) !important;
  color: #1b2430 !important;
  border-bottom-left-radius: 4px !important;
}


/* ── WhatsApp-style typing bubble ────────────────────────────────────────── */
/* JS creates: <div class="ai-chatbot__msg ai-chatbot__msg--bot ai-chatbot__msg--typing">
                 <span class="ai-chatbot__dot"></span> × 3
               </div>                                                          */

.ai-chatbot .ai-chatbot__msg--typing {
  display: flex !important;
  align-items: center !important;
  gap: 5px !important;
  padding: 12px 16px !important;
  min-width: 60px !important;
  min-height: 40px !important;
}

.ai-chatbot .ai-chatbot__dot {
  display: inline-block !important;
  width: 8px !important;
  height: 8px !important;
  border-radius: 50% !important;
  background: #6b7280 !important;
  animation: aica-dot-bounce 1.2s infinite ease-in-out !important;
  flex-shrink: 0 !important;
}

/* Stagger each dot: dot 1 = 0s, dot 2 = 0.2s, dot 3 = 0.4s */
.ai-chatbot .ai-chatbot__dot:nth-child(1) { animation-delay: 0s    !important; }
.ai-chatbot .ai-chatbot__dot:nth-child(2) { animation-delay: 0.2s  !important; }
.ai-chatbot .ai-chatbot__dot:nth-child(3) { animation-delay: 0.4s  !important; }


/* ── Input row ───────────────────────────────────────────────────────────── */

.ai-chatbot .ai-chatbot__form {
  display: flex !important;
  border-top: 1px solid #e5e7eb !important;
  margin: 0 !important;
  padding: 0 !important;
  background: #fff !important;
  flex-shrink: 0 !important;
}

.ai-chatbot .ai-chatbot__input {
  flex: 1 !important;
  border: none !important;
  padding: 13px 14px !important;
  font-size: var(--aica-font-size, 14px) !important;
  font-family: inherit !important;
  outline: none !important;
  background: #fff !important;
  color: #111827 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  min-width: 0 !important;
}

.ai-chatbot .ai-chatbot__input::placeholder {
  color: #9ca3af !important;
}

.ai-chatbot .ai-chatbot__input:focus {
  background: #fff !important;
  outline: none !important;
  box-shadow: none !important;
}


/* ── Send button ─────────────────────────────────────────────────────────── */

.ai-chatbot .ai-chatbot__send {
  background: var(--aica-accent, #2451b0) !important;
  background-color: var(--aica-accent, #2451b0) !important;
  color: #fff !important;
  border: none !important;
  padding: 0 18px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  font-family: inherit !important;
  cursor: pointer !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  width: auto !important;
  height: auto !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  transition: background 0.15s ease, transform 0.1s ease !important;
  flex-shrink: 0 !important;
}

.ai-chatbot .ai-chatbot__send:hover {
  background: #1a3d8c !important;
  background-color: #1a3d8c !important;
}

.ai-chatbot .ai-chatbot__send:active {
  transform: scale(0.94) !important;
}


/* ── Header actions: "New chat" + close (v1.0.6) ─────────────────────────── */

.ai-chatbot .ai-chatbot__actions {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}

.ai-chatbot .ai-chatbot__new {
  background: rgba(255,255,255,0.15) !important;
  background-color: rgba(255,255,255,0.15) !important;
  border: none !important;
  color: #fff !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  font-family: inherit !important;
  line-height: 1 !important;
  padding: 8px 10px !important;
  border-radius: 999px !important;
  cursor: pointer !important;
  box-shadow: none !important;
  text-transform: none !important;
  pointer-events: all !important;
  transition: background 0.15s ease !important;
}

.ai-chatbot .ai-chatbot__new:hover {
  background: rgba(255,255,255,0.30) !important;
  background-color: rgba(255,255,255,0.30) !important;
}


/* Divider shown when the server started a fresh conversation (idle expiry). */
.ai-chatbot .ai-chatbot__divider {
  align-self: center !important;
  font-size: 11px !important;
  color: #8a90a2 !important;
  padding: 2px 10px !important;
}


/* Send button while a reply is on its way. */
.ai-chatbot .ai-chatbot__send:disabled,
.ai-chatbot .ai-chatbot__input:disabled {
  opacity: 0.6 !important;
  cursor: wait !important;
}


/* ── Adaptive-card tray (Layer 0 categories + Layer 1 sub-options) ───────── */

/* Tray container — a column of buttons flushed left, matching bot-bubble position. */
.ai-chatbot .ai-chatbot__cards {
  display: flex !important;
  flex-direction: column !important;
  gap: 8px !important;
  align-self: flex-start !important;
  width: 100% !important;
  max-width: 88% !important;
  animation: aica-bubble-in 0.22s ease both !important;
}

/* Category card button (Layer 0). */
.ai-chatbot .ai-chatbot__card-btn {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  background: #fff !important;
  background-color: #fff !important;
  border: 1.5px solid var(--aica-accent, #2451b0) !important;
  color: var(--aica-accent, #2451b0) !important;
  border-radius: var(--aica-border-radius, 12px) !important;
  padding: 10px 14px !important;
  font-size: var(--aica-font-size, 14px) !important;
  font-family: inherit !important;
  font-weight: 600 !important;
  line-height: 1.3 !important;
  cursor: pointer !important;
  text-align: left !important;
  width: 100% !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07) !important;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease !important;
  pointer-events: all !important;
}

.ai-chatbot .ai-chatbot__card-btn:hover {
  background: var(--aica-accent, #2451b0) !important;
  background-color: var(--aica-accent, #2451b0) !important;
  color: #fff !important;
}

.ai-chatbot .ai-chatbot__card-btn:active {
  transform: scale(0.97) !important;
}

/* Emoji icon inside the category button. */
.ai-chatbot .ai-chatbot__card-icon {
  font-size: 18px !important;
  line-height: 1 !important;
  flex-shrink: 0 !important;
}

/* Sub-option buttons (Layer 1) — slightly smaller, pill-shaped. */
.ai-chatbot .ai-chatbot__card-btn--sub {
  padding: 8px 14px !important;
  border-radius: 999px !important;
  font-weight: 500 !important;
  font-size: calc(var(--aica-font-size, 14px) - 1px) !important;
}
