/* ═══════════════════════════════════════════════════════════════════════════
   chat.css — Floating RAG chatbot
   - FAB pinned bottom-right (mobile-safe via env(safe-area-inset-*))
   - Slide-up panel: 420×640 on desktop, full-width drawer on mobile
   - Pulls colors from existing --bg-card / --gold / --text variables so
     it inherits both the dark theme (default) and light-theme overrides.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --chat-fab-size: 56px;
  --chat-panel-w:  420px;
  --chat-panel-h:  min(640px, calc(100vh - 96px));
}

/* ─── FAB (floating action button) ───────────────────────────────────────── */
.chat-fab {
  position: fixed;
  right: calc(24px + env(safe-area-inset-right, 0px));
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  width: var(--chat-fab-size);
  height: var(--chat-fab-size);
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0,0,0,.32); }
.chat-fab:active { transform: translateY(0); }
.chat-fab[data-open="1"] { background: var(--bg-card); color: var(--gold); border: 1px solid var(--border); }

/* ─── Panel ──────────────────────────────────────────────────────────────── */
.chat-panel {
  position: fixed;
  right: calc(24px + env(safe-area-inset-right, 0px));
  bottom: calc(24px + var(--chat-fab-size) + 12px + env(safe-area-inset-bottom, 0px));
  width: var(--chat-panel-w);
  height: var(--chat-panel-h);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlideUp .18s ease;
}
@keyframes chatSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
  .chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 80vh;
    border-radius: 14px 14px 0 0;
  }
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.chat-head h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--gold);
  flex: 0 0 auto;
}
.chat-head .chat-session-pick {
  flex: 1 1 auto;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: .82rem;
  max-width: 220px;
}
.chat-head-actions { display: flex; gap: 6px; }
.chat-head-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.chat-head-actions button:hover {
  color: var(--gold);
  border-color: var(--gold);
}

/* ─── Messages list ──────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
  padding: 24px 12px;
}
.chat-empty .examples {
  margin-top: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.chat-empty .examples button {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .82rem;
  cursor: pointer;
  text-align: left;
  line-height: 1.4;
}
.chat-empty .examples button:hover {
  color: var(--gold);
  border-color: var(--gold);
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 92%;
  animation: fadeIn .18s ease;
}
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.assistant { align-self: flex-start; }
.chat-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: .88rem;
  line-height: 1.55;
  color: var(--text);
  white-space: normal;
  word-break: break-word;
}
.chat-msg.user .chat-bubble {
  background: var(--accent-purple-soft);
  border-color: rgba(167,139,250,.25);
  color: var(--text);
}
.chat-bubble pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  overflow-x: auto;
  font-size: .78rem;
}
.chat-bubble code {
  background: var(--bg);
  border-radius: 4px;
  padding: 0 4px;
  font-size: .82em;
}
.chat-bubble p { margin: 0 0 6px 0; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul, .chat-bubble ol { padding-left: 20px; margin: 4px 0; }
.chat-bubble table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: .8rem;
}
.chat-bubble th, .chat-bubble td {
  border: 1px solid var(--border);
  padding: 3px 7px;
}

/* Citation chips */
.chat-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.chat-cite {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 14px;
  font-size: .72rem;
  background: var(--accent-purple-soft);
  border: 1px solid rgba(167,139,250,.25);
  color: var(--accent-purple);
  cursor: pointer;
  max-width: 100%;
}
.chat-cite:hover {
  background: var(--bg-card-hover);
}
.chat-cite .cite-num {
  font-weight: 700;
  color: var(--gold);
  flex: 0 0 auto;
}
.chat-cite .cite-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
/* In-text [#1] reference styling — applied by markdown post-processor. */
.chat-bubble .cite-ref {
  display: inline-block;
  font-size: .72em;
  color: var(--gold);
  background: rgba(199,160,42,.12);
  border-radius: 4px;
  padding: 0 4px;
  margin: 0 1px;
  cursor: pointer;
  vertical-align: super;
  line-height: 1.2;
}
.chat-bubble .cite-ref:hover { background: rgba(199,160,42,.28); }

/* Streaming cursor */
.chat-msg.streaming .chat-bubble::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: var(--gold);
  animation: chatBlink 1s steps(2, start) infinite;
}
@keyframes chatBlink { to { visibility: hidden; } }

/* ─── Input bar ──────────────────────────────────────────────────────────── */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.chat-input-bar textarea {
  flex: 1;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .88rem;
  line-height: 1.4;
  min-height: 36px;
  max-height: 120px;
  font-family: inherit;
}
.chat-input-bar textarea:focus {
  outline: none;
  border-color: var(--gold);
}
.chat-input-bar button {
  flex: 0 0 auto;
  background: var(--gold);
  color: #1a1a1a;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
}
.chat-input-bar button:disabled {
  background: var(--text-muted);
  color: var(--bg-card);
  cursor: not-allowed;
}
