/**
 * Chatbot UI — Quiet Intelligence Design System
 * Lottie "Surprised Boy" as the AI Research Assistant character
 */

/* ═══════════════════════════════════════════════════════════════
   CONTAINER
   ═══════════════════════════════════════════════════════════════ */

#gmr-chatbot {
  position: fixed;
  bottom: 24px;
  right: 24px;
  font-family: var(--font-ui);
  z-index: 1000;
}

/* ═══════════════════════════════════════════════════════════════
   TOGGLE BUTTON
   ═══════════════════════════════════════════════════════════════ */

.chatbot-toggle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--color-ink);
  border: 2px solid rgba(200, 164, 94, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  overflow: hidden;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.28);
  z-index: 1001;
}

.chatbot-toggle:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35), 0 0 0 4px rgba(200, 164, 94, 0.18);
  border-color: rgba(200, 164, 94, 0.65);
}

.chatbot-toggle.open {
  opacity: 0;
  transform: scale(0.82);
  pointer-events: none;
}

/* ── Lottie container inside toggle ── */
.chatbot-toggle__lottie {
  display: none;         /* hidden until loaded */
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  /* Gold tint to unify with brand palette */
  filter: sepia(0.2) saturate(1.8) hue-rotate(5deg) brightness(1.1);
}

.chatbot-toggle__lottie.lottie-loaded {
  display: block;
}

/* ── Fallback dot + label ── */
.chatbot-toggle__dot {
  display: none;
  width: 10px;
  height: 10px;
  background: var(--color-accent);
  border-radius: 50%;
  animation: chatbot-pulse 2s ease infinite;
}

.chatbot-toggle__label {
  display: none;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--color-surface);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

@keyframes chatbot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(1.35); }
}

/* ═══════════════════════════════════════════════════════════════
   CHAT WINDOW
   ═══════════════════════════════════════════════════════════════ */

.chatbot-window {
  position: absolute;
  bottom: 88px;
  right: 0;
  width: min(420px, 100vw);
  max-height: 630px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(18px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.chatbot-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

@media (max-width: 480px) {
  .chatbot-window {
    position: fixed;
    inset: 0;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    bottom: 0;
    right: 0;
  }
  .chatbot-window.open { z-index: 1002; }
}

/* ═══════════════════════════════════════════════════════════════
   CHARACTER HEADER
   ═══════════════════════════════════════════════════════════════ */

.chatbot-character {
  width: 100%;
  height: 160px;
  background: linear-gradient(150deg, #0d0d0d 0%, #1c1a18 100%);
  border-bottom: 1px solid rgba(200, 164, 94, 0.15);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

/* Warm glow behind character */
.chatbot-character::before {
  content: '';
  position: absolute;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(200, 164, 94, 0.1) 0%, transparent 70%);
  left: -30px;
  top: -40px;
  border-radius: 50%;
  pointer-events: none;
}

/* ── Lottie in chat window header ── */
.chatbot-character__lottie {
  display: none;
  width: 140px;
  height: 140px;
  flex-shrink: 0;
  margin-left: 12px;
  filter: sepia(0.15) saturate(1.6) hue-rotate(5deg) brightness(1.1);
}

.chatbot-character__lottie.lottie-loaded {
  display: block;
}

.chatbot-character__overlay {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0 16px;
  position: relative;
  z-index: 1;
}

.chatbot-character__name {
  font-family: var(--font-editorial);
  font-size: 1rem;
  font-weight: 500;
  color: #ffffff;
  line-height: 1.2;
}

.chatbot-character__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.02em;
}

.chatbot-status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  animation: chatbot-pulse 3s ease infinite;
}

.chatbot-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: rgba(255,255,255,0.65);
  transition: background 0.15s, color 0.15s;
  z-index: 2;
}

.chatbot-close:hover {
  background: rgba(255,255,255,0.14);
  color: #fff;
}

/* ═══════════════════════════════════════════════════════════════
   MESSAGES
   ═══════════════════════════════════════════════════════════════ */

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--color-surface);
}

.chatbot-messages::-webkit-scrollbar        { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track  { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb  { background: var(--color-border); border-radius: 2px; }

.chatbot-message { display: flex; animation: chatbot-slideUp 0.25s ease-out; }
.chatbot-message.user { justify-content: flex-end; }
.chatbot-message.bot  { justify-content: flex-start; }

.message-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  word-wrap: break-word;
}

.chatbot-message.user .message-bubble {
  background: var(--color-ink);
  color: var(--color-surface);
  border-radius: var(--radius) var(--radius-sm) var(--radius-sm) var(--radius);
}

.chatbot-message.bot .message-bubble {
  background: var(--color-surface-warm);
  color: var(--color-ink);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm) var(--radius) var(--radius) var(--radius-sm);
}

.message-bubble p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.55;
  color: inherit;
}

/* Typing */
.chatbot-message.typing .message-bubble {
  padding: 12px 14px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-ink-muted);
  animation: chatbot-typing 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-5px); }
}

@keyframes chatbot-slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════
   INPUT
   ═══════════════════════════════════════════════════════════════ */

.chatbot-input-area {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.chatbot-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  background: var(--color-surface-warm);
  color: var(--color-ink);
  outline: none;
  transition: border-color 0.15s;
}

.chatbot-input::placeholder { color: var(--color-ink-muted); }
.chatbot-input:focus         { border-color: var(--color-accent); }

.chatbot-send {
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--color-ink);
  color: var(--color-surface);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.12s;
}

.chatbot-send:hover  { opacity: 0.8; }
.chatbot-send:active { transform: scale(0.92); }

/* ═══════════════════════════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════════════════════════ */

.chatbot-footer {
  padding: 8px 14px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-warm);
  text-align: center;
  font-size: 0.68rem;
  color: var(--color-ink-muted);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  #gmr-chatbot   { bottom: 16px; right: 16px; }
  .chatbot-toggle { width: 64px; height: 64px; }
  .message-bubble { max-width: 88%; }
  .chatbot-messages { padding: 12px; }
  .chatbot-input-area { padding: 10px; gap: 6px; }
  .chatbot-send { width: 32px; height: 32px; }
  .chatbot-character { height: 140px; }
  .chatbot-character__lottie { width: 120px; height: 120px; }
}

@media print { #gmr-chatbot { display: none !important; } }
