/* chatbot-platform/widget/widget.css
   All classes prefixed .fg-chat- to avoid site style conflicts.
   All color tokens use CSS custom properties defined on #fg-chat-root.
   Neutral gray defaults show before /config resolves — no site branding leaks. */

/* ── CSS CUSTOM PROPERTY DEFAULTS ─────────────────────────────────────────── */
#fg-chat-root {
  --chat-primary:      #6B7280;
  --chat-accent:       #374151;
  --chat-bg:           #F9FAFB;
  --chat-panel-bg:     #ffffff;
  --chat-text:         #111827;
  --chat-muted:        #6B7280;
  --chat-font-heading: system-ui, sans-serif;
  --chat-font-body:    system-ui, sans-serif;
  --chat-radius:       12px;
  --chat-shadow:       0 8px 32px rgba(0,0,0,0.12);
}

/* ── BOX SIZING ─────────────────────────────────────────────────────────────── */
#fg-chat-root * { box-sizing: border-box; }

/* ── LAUNCHER WRAPPER ──────────────────────────────────────────────────────── */
.fg-chat-launcher-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  z-index: var(--fg-chat-z, 9999);
}

/* Spinning gradient border */
.fg-chat-launcher-wrap::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: conic-gradient(var(--chat-primary), var(--chat-accent), #8B5CF6, var(--chat-primary));
  animation: fg-chat-spin 2.5s linear infinite;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 0;
}

.fg-chat-launcher-wrap.is-open::before,
.fg-chat-launcher-wrap:hover::before {
  opacity: 1;
}

/* Hide spin for sites using launcherStyle: 'solid' */
#fg-chat-root.fg-chat-no-spin .fg-chat-launcher-wrap::before {
  display: none;
}

@keyframes fg-chat-spin {
  to { transform: rotate(360deg); }
}

/* ── LAUNCHER BUTTON ────────────────────────────────────────────────────────── */
.fg-chat-launcher {
  position: absolute;
  inset: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--chat-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px color-mix(in srgb, var(--chat-primary) 40%, transparent);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 1;
}

.fg-chat-launcher:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 30px color-mix(in srgb, var(--chat-primary) 60%, transparent);
}

.fg-chat-launcher svg {
  width: 22px;
  height: 22px;
  color: #fff;
  flex-shrink: 0;
}

/* ── UNREAD BADGE ───────────────────────────────────────────────────────────── */
.fg-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chat-accent);
  border: 2px solid #fff;
}

/* ── CHAT WINDOW ────────────────────────────────────────────────────────────── */
.fg-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 400px;
  height: 560px;
  background: var(--chat-panel-bg);
  border-radius: 16px;
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: var(--fg-chat-z, 9999);
  font-family: var(--chat-font-body);
}

.fg-chat-window.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* ── HEADER ─────────────────────────────────────────────────────────────────── */
.fg-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--chat-bg);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  flex-shrink: 0;
}

.fg-chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-text);
  color: var(--chat-primary);
  font-family: var(--chat-font-heading);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.fg-chat-header-info { flex: 1; min-width: 0; }

.fg-chat-header-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--chat-text);
  font-family: var(--chat-font-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fg-chat-header-sub {
  font-size: 12px;
  color: var(--chat-muted);
  margin-top: 1px;
}

.fg-chat-header-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  color: var(--chat-muted);
  display: flex;
  align-items: center;
  transition: color 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}

.fg-chat-header-close:hover {
  color: var(--chat-text);
  background: rgba(0,0,0,0.05);
}

.fg-chat-header-close svg { width: 16px; height: 16px; }

/* ── MESSAGE THREAD ─────────────────────────────────────────────────────────── */
.fg-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
  background: var(--chat-bg);
}

.fg-chat-messages:focus { outline: 2px solid var(--chat-primary); outline-offset: -2px; }

/* ── EMPTY / WELCOME STATE ──────────────────────────────────────────────────── */
.fg-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 12px 8px;
  gap: 8px;
}

.fg-chat-empty-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--chat-text);
  color: var(--chat-primary);
  font-family: var(--chat-font-heading);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.02em;
}

.fg-chat-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--chat-text);
  font-family: var(--chat-font-heading);
}

.fg-chat-empty-sub {
  font-size: 13px;
  color: var(--chat-muted);
  line-height: 1.5;
  max-width: 260px;
}

.fg-chat-empty-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}

/* ── MESSAGE BUBBLES ────────────────────────────────────────────────────────── */
.fg-chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 4px;
}

.fg-chat-msg--user { flex-direction: row-reverse; }

.fg-chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--chat-text);
  color: var(--chat-primary);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--chat-font-heading);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.fg-chat-msg:not(.has-avatar) .fg-chat-msg-avatar { visibility: hidden; }

.fg-chat-bubble {
  max-width: 76%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.fg-chat-msg--bot .fg-chat-bubble {
  background: var(--chat-panel-bg);
  color: var(--chat-text);
  border: 1px solid rgba(0,0,0,0.07);
  border-bottom-left-radius: 4px;
}

.fg-chat-msg--user .fg-chat-bubble {
  background: var(--chat-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ── TYPING INDICATOR ───────────────────────────────────────────────────────── */
.fg-chat-typing {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 4px;
}

.fg-chat-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--chat-panel-bg);
  border: 1px solid rgba(0,0,0,0.07);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 12px 14px;
}

.fg-chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-muted);
  animation: fg-chat-bounce 1.2s ease-in-out infinite;
}

.fg-chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.fg-chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes fg-chat-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-6px); }
}

/* ── QUICK REPLY CHIPS ──────────────────────────────────────────────────────── */
.fg-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  margin-bottom: 4px;
}

.fg-chat-chip {
  background: var(--chat-panel-bg);
  border: 1.5px solid var(--chat-primary);
  color: var(--chat-primary);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  font-family: var(--chat-font-body);
}

.fg-chat-chip:hover {
  background: var(--chat-primary);
  color: #fff;
}

/* ── CTA BUTTONS ────────────────────────────────────────────────────────────── */
.fg-chat-cta-row {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.fg-chat-btn {
  display: inline-flex;
  align-items: center;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  font-family: var(--chat-font-body);
}

.fg-chat-btn--primary {
  background: var(--chat-primary);
  color: #fff;
}

.fg-chat-btn--secondary {
  background: transparent;
  color: var(--chat-primary);
  border: 1.5px solid var(--chat-primary);
}

.fg-chat-btn:hover { opacity: 0.88; transform: translateY(-1px); }

/* ── INPUT AREA ─────────────────────────────────────────────────────────────── */
.fg-chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--chat-panel-bg);
  border-top: 1px solid rgba(0,0,0,0.06);
  flex-shrink: 0;
}

.fg-chat-input {
  flex: 1;
  border: 1.5px solid rgba(0,0,0,0.12);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  background: var(--chat-bg);
  color: var(--chat-text);
  font-family: var(--chat-font-body);
  transition: border-color 0.15s ease;
}

.fg-chat-input:focus { border-color: var(--chat-primary); }
.fg-chat-input::placeholder { color: var(--chat-muted); }

.fg-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.fg-chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }
.fg-chat-send:not(:disabled):hover { opacity: 0.88; transform: scale(1.05); }
.fg-chat-send svg { width: 16px; height: 16px; color: #fff; }

/* ── FOCUS VISIBLE ──────────────────────────────────────────────────────────── */
.fg-chat-launcher:focus-visible,
.fg-chat-header-close:focus-visible,
.fg-chat-chip:focus-visible,
.fg-chat-send:focus-visible {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

/* ── MOBILE ─────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .fg-chat-window {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .fg-chat-launcher-wrap { bottom: 16px; right: 16px; }
}

/* ── REDUCED MOTION ─────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .fg-chat-launcher-wrap::before { animation: none; }
  .fg-chat-typing-dot            { animation: none; }
  .fg-chat-window                { transition: none; }
  .fg-chat-launcher              { transition: none; }
}

/* ── DESKTOP HIDE (when showOnDesktop: false) ───────────────────────────────── */
@media (min-width: 481px) {
  #fg-chat-root.fg-chat-hide-desktop { display: none; }
}

/* ── MOBILE HIDE (when showOnMobile: false) ─────────────────────────────────── */
@media (max-width: 480px) {
  #fg-chat-root.fg-chat-hide-mobile { display: none; }
}
