/*
 * Weavelinx Chatbot — standalone client bubble
 * Self-contained: no Tailwind, no external dependencies.
 * All colours driven by CSS custom properties set at runtime by chatbot.js.
 */

/* ── CSS Variables (defaults; overridden per-install) ───────────────────── */
:root {
  --wlx-accent:        #6366f1;
  --wlx-accent-dark:   #4f46e5;
  --wlx-accent-light:  rgba(99,102,241,0.15);
  --wlx-accent-border: rgba(99,102,241,0.30);
  --wlx-bg:            #0f1117;
  --wlx-bg2:           #1a1d27;
  --wlx-surface:       rgba(255,255,255,0.04);
  --wlx-border:        rgba(255,255,255,0.08);
  --wlx-text:          rgba(255,255,255,0.85);
  --wlx-text-muted:    rgba(255,255,255,0.50);
  --wlx-radius:        16px;
  --wlx-z:             9999;
  --wlx-offset-x:      24px;
  --wlx-offset-y:      24px;
}

/* ── Wrapper ────────────────────────────────────────────────────────────── */
#wlx-chat-root *,
#wlx-chat-root *::before,
#wlx-chat-root *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

#wlx-chat-root {
  position: fixed;
  bottom: var(--wlx-offset-y);
  right: var(--wlx-offset-x);
  z-index: var(--wlx-z);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

#wlx-chat-root.wlx-pos-left {
  right: auto;
  left: var(--wlx-offset-x);
}

/* ── Bubble button ──────────────────────────────────────────────────────── */
#wlx-bubble {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--wlx-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(99,102,241,0.35);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  outline: none;
}
#wlx-bubble:hover {
  transform: scale(1.07);
  box-shadow: 0 6px 28px rgba(99,102,241,0.5);
}
#wlx-bubble svg { color: #fff; width: 24px; height: 24px; }
#wlx-bubble .wlx-icon-close { display: none; }
#wlx-bubble.wlx-open .wlx-icon-open  { display: none; }
#wlx-bubble.wlx-open .wlx-icon-close { display: block; }

/* Pulse animation when idle */
@keyframes wlx-pulse {
  0%,100% { box-shadow: 0 4px 20px rgba(99,102,241,0.35); }
  50%      { box-shadow: 0 4px 32px rgba(99,102,241,0.7); }
}
#wlx-bubble.wlx-pulse { animation: wlx-pulse 2s ease-in-out 3; }

/* ── Chat window ────────────────────────────────────────────────────────── */
#wlx-window {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 360px;
  max-height: 520px;
  background: var(--wlx-bg);
  border: 1px solid var(--wlx-border);
  border-radius: var(--wlx-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  transform-origin: bottom right;
  transform: scale(0.92) translateY(10px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(.34,1.56,.64,1), opacity 0.18s ease;
}
#wlx-chat-root.wlx-pos-left #wlx-window {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}
#wlx-window.wlx-visible {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 420px) {
  #wlx-window {
    width: calc(100vw - 32px);
    right: -8px;
    bottom: 66px;
  }
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#wlx-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--wlx-accent), var(--wlx-accent-dark));
  flex-shrink: 0;
}
#wlx-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}
#wlx-header-info { flex: 1; min-width: 0; }
#wlx-bot-name {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#wlx-status {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  gap: 4px;
}
#wlx-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
}
#wlx-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  transition: background 0.15s;
}
#wlx-close:hover { background: rgba(255,255,255,0.15); color: #fff; }
#wlx-close svg { width: 16px; height: 16px; }

/* ── Messages area ──────────────────────────────────────────────────────── */
#wlx-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
#wlx-messages::-webkit-scrollbar { width: 4px; }
#wlx-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ── Message bubbles ────────────────────────────────────────────────────── */
.wlx-msg-bot,
.wlx-msg-user { display: flex; align-items: flex-start; gap: 8px; }
.wlx-msg-user { flex-direction: row-reverse; }

.wlx-msg-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--wlx-accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.wlx-msg-icon svg { width: 12px; height: 12px; color: var(--wlx-accent); }

.wlx-bubble-text {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Markdown rendering inside bot bubbles */
.wlx-bubble-text .wlx-list {
  margin: 6px 0 4px 18px;
  padding: 0;
  list-style: disc;
}
.wlx-bubble-text .wlx-list li {
  margin: 3px 0;
  padding-left: 2px;
}
.wlx-bubble-text strong {
  color: var(--wlx-text);
  font-weight: 600;
}
.wlx-bubble-text code {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 11.5px;
}
.wlx-msg-bot  .wlx-bubble-text {
  background: var(--wlx-surface);
  border: 1px solid var(--wlx-border);
  border-top-left-radius: 4px;
  color: var(--wlx-text);
}
.wlx-msg-user .wlx-bubble-text {
  background: var(--wlx-accent-light);
  border: 1px solid var(--wlx-accent-border);
  border-top-right-radius: 4px;
  color: var(--wlx-text);
}

/* CTA buttons inside bot messages */
.wlx-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.wlx-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 8px;
  background: var(--wlx-accent-light);
  border: 1px solid var(--wlx-accent-border);
  color: var(--wlx-accent);
  text-decoration: none;
  transition: background 0.15s;
}
.wlx-cta-btn:hover { background: rgba(99,102,241,0.25); }

/* Typing indicator */
.wlx-typing {
  display: flex;
  gap: 4px;
  padding: 10px 13px;
  background: var(--wlx-surface);
  border: 1px solid var(--wlx-border);
  border-radius: 14px;
  border-top-left-radius: 4px;
  align-items: center;
}
.wlx-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--wlx-text-muted);
  animation: wlx-bounce 1.2s ease infinite;
}
.wlx-dot:nth-child(2) { animation-delay: 0.2s; }
.wlx-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes wlx-bounce {
  0%,60%,100% { transform: translateY(0); }
  30%          { transform: translateY(-5px); }
}

/* ── Suggestion chips ───────────────────────────────────────────────────── */
#wlx-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 8px;
}
.wlx-chip {
  padding: 5px 12px;
  font-size: 12px;
  border: 1px solid var(--wlx-border);
  border-radius: 20px;
  background: var(--wlx-surface);
  color: var(--wlx-text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.wlx-chip:hover {
  border-color: var(--wlx-accent-border);
  color: var(--wlx-accent);
}

/* ── Input bar ──────────────────────────────────────────────────────────── */
#wlx-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--wlx-border);
  background: var(--wlx-bg2);
  flex-shrink: 0;
}
#wlx-input {
  flex: 1;
  background: var(--wlx-surface);
  border: 1px solid var(--wlx-border);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--wlx-text);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color 0.15s;
}
#wlx-input::placeholder { color: var(--wlx-text-muted); }
#wlx-input:focus { border-color: var(--wlx-accent-border); }
#wlx-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--wlx-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
#wlx-send:hover  { background: var(--wlx-accent-dark); }
#wlx-send:active { transform: scale(0.92); }
#wlx-send svg { width: 16px; height: 16px; color: #fff; }
#wlx-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Powered-by footer ──────────────────────────────────────────────────── */
#wlx-powered {
  text-align: center;
  padding: 5px;
  font-size: 10px;
  color: var(--wlx-text-muted);
  border-top: 1px solid var(--wlx-border);
}
#wlx-powered a { color: var(--wlx-text-muted); text-decoration: none; }
#wlx-powered a:hover { color: var(--wlx-accent); }
