:root {
  --surface:     #ffffff;
  --bg:          #f8f7f4;
  --border:      #e2dfd8;
  --border-dark: #c8c4bc;
  --text:        #18181a;
  --text-muted:  #7a7872;
  --accent:      #5c7a62;
  --mono:        'IBM Plex Mono', monospace;
  --sans:        'IBM Plex Sans', sans-serif;
  --radius:      6px;
  --chat-w:      380px;
  --chat-h:      520px;
}

/* ── CHAT FAB ────────────────────────────────────────────────────── */

.chat-fab {
  position: fixed;
  bottom: 80px;
  right: 48px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  transition: transform 0.2s, background 0.2s;
  z-index: 200;
}

.chat-fab:hover { transform: scale(1.07); background: #333; }
.chat-fab.open  { background: var(--accent); }

.fab-icon { width: 20px; height: 20px; }

/* ── CHAT WIDGET ─────────────────────────────────────────────────── */

.chat-widget {
  position: fixed;
  bottom: 144px;
  right: 48px;
  width: var(--chat-w);
  height: var(--chat-h);
  background: var(--surface);
  border: 1px solid var(--border-dark);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.14);
  display: flex;
  flex-direction: column;
  z-index: 199;
  overflow: hidden;
  /* hidden state */
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.97);
  transition: opacity 0.2s, transform 0.2s;
}

.chat-widget.visible {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0) scale(1);
}

/* head */
.chat-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-head-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
}

.chat-head-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  box-shadow: 0 0 0 2px #d4edda;
  flex-shrink: 0;
}

.chat-head-hint {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

/* body */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 4px; }

/* intro */
.chat-intro p {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.suggestion {
  font-family: var(--sans);
  font-size: 0.78rem;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s;
}

.suggestion:hover { border-color: var(--accent); color: var(--accent); }

/* messages */
.msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  animation: fadeUp 0.18s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-label {
  font-family: var(--mono);
  font-size: 0.55rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.msg.user .msg-label { text-align: right; }

.msg-bubble {
  font-size: 0.84rem;
  line-height: 1.65;
  padding: 10px 13px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user             { align-items: flex-end; }
.msg.user .msg-bubble { background: var(--text); color: #fff; max-width: 88%; }
.msg.assistant .msg-bubble { background: var(--bg); border: 1px solid var(--border); }

/* source links */
.msg-sources {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.source-link {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
  transition: opacity 0.15s;
}

.source-link:hover { opacity: 0.7; }
.source-link::before { content: '↗'; flex-shrink: 0; }

/* typing indicator */
.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: fit-content;
}

.typing-dot {
  width: 5px;
  height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.1s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); }
}

/* foot */
.chat-foot {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  font-family: var(--sans);
  font-size: 0.84rem;
  line-height: 1.5;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 12px;
  border-radius: var(--radius);
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 110px;
  overflow-y: auto;
  transition: border-color 0.15s;
}

.chat-input:focus { border-color: var(--accent); }

.chat-send {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.chat-send:hover    { opacity: 0.85; }
.chat-send:disabled { opacity: 0.35; cursor: not-allowed; }

.chat-send svg { width: 14px; height: 14px; }

/* ── RESPONSIVE ──────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .chat-widget { width: calc(100vw - 32px); right: 16px; bottom: 130px; }
  .chat-fab    { right: 20px; bottom: 74px; }
}
