/* ══════════════════════════════════════════════════════════════════════
   Research Assistant chat panel

   All chat styling lives here. The Python in
   pages/components/chat_panel.py only emits structure and class names, so
   restyling the chat should not require touching Python.

   Open/closed state is the `.is-open` class on `.chat-panel`, toggled by a
   callback in app.py. Change the transition here, not there.
   ══════════════════════════════════════════════════════════════════════ */

:root {
  --chat-accent: #1565C0;
  --chat-accent-contrast: #ffffff;
  --chat-panel-width: 400px;
  --chat-panel-bg: #fafafa;
  --chat-surface: #ffffff;
  --chat-border: #e0e0e0;
  --chat-text: #333333;
  --chat-text-muted: #aaaaaa;
  --chat-radius: 12px;
  --chat-font-size: 0.85rem;
}

/* ── Floating action button ──────────────────────────────────────────── */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background-color: var(--chat-accent);
  color: var(--chat-accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  user-select: none;
}

/* ── Panel shell ─────────────────────────────────────────────────────── */
.chat-panel {
  position: fixed;
  top: 0;
  /* Parked just off-screen; the extra 20px hides the box-shadow. */
  right: calc(-1 * (var(--chat-panel-width) + 20px));
  width: var(--chat-panel-width);
  height: 100vh;
  background-color: var(--chat-panel-bg);
  border-left: 1px solid var(--chat-border);
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
  transition: right 0.3s ease;
  z-index: 999;
  display: flex;
  flex-direction: column;
}

.chat-panel.is-open {
  right: 0;
}

/* The launcher sits over the composer's send button; the panel has its own
   close control, so hide the launcher while the panel is open. */
body:has(.chat-panel.is-open) .chat-fab {
  opacity: 0;
  pointer-events: none;
}

/* ── Header ──────────────────────────────────────────────────────────── */
.chat-panel__header {
  padding: 16px;
  background-color: var(--chat-accent);
  color: var(--chat-accent-contrast);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-panel__title    { font-weight: 600; font-size: 0.95rem; }
.chat-panel__subtitle { font-size: 0.72rem; opacity: 0.8; margin-top: 2px; }

.chat-panel__close {
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 8px;
}

/* ── Message list ────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Composer ────────────────────────────────────────────────────────── */
.chat-composer {
  padding: 12px;
  border-top: 1px solid var(--chat-border);
  background-color: var(--chat-surface);
  flex-shrink: 0;
}

.chat-composer__row { display: flex; gap: 8px; }

.chat-composer__input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 20px;
  font-size: var(--chat-font-size);
  outline: none;
  font-family: inherit;
}

.chat-composer__send {
  padding: 10px 14px;
  background-color: var(--chat-accent);
  color: var(--chat-accent-contrast);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
}

.chat-composer__hint {
  font-size: 0.65rem;
  color: var(--chat-text-muted);
  margin-top: 6px;
  text-align: center;
}

/* ── Message bubbles ─────────────────────────────────────────────────── */
.chat-msg-row {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 8px;
}
.chat-msg-row--user { justify-content: flex-end; }

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--chat-radius);
  font-size: var(--chat-font-size);
  line-height: 1.45;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.chat-bubble--assistant {
  background-color: var(--chat-surface);
  color: var(--chat-text);
  border: 1px solid #e8e8e8;
}

.chat-bubble--user {
  background-color: var(--chat-accent);
  color: var(--chat-accent-contrast);
  border: none;
}

/* Wrapper used only when a layer badge sits beside the text. */
.chat-bubble__body {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 4px;
}

.chat-bubble .dash-markdown { margin: 0; }

/* ── Retrieval-layer badge ───────────────────────────────────────────── */
.chat-layer-badge {
  font-size: 0.6rem;
  color: #ffffff;
  border-radius: 3px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
  background-color: #9E9E9E;      /* default + `fallback` */
}
.chat-layer-badge--schema   { background-color: #4CAF50; }
.chat-layer-badge--episodic { background-color: #FF9800; }
.chat-layer-badge--semantic { background-color: #2196F3; }
.chat-layer-badge--fallback { background-color: #9E9E9E; }

/* ── Node-ID citation row ────────────────────────────────────────────── */
.chat-citations { margin-top: 4px; }

.chat-citation {
  font-size: 0.62rem;
  color: var(--chat-text-muted);
  font-family: monospace;
  margin-right: 4px;
}

/* ── Suggested-question chips (welcome message) ──────────────────────── */
.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 8px 8px 8px;
}

.chat-suggestion {
  background: none;
  border: 1px solid var(--chat-accent);
  color: var(--chat-accent);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 0.75rem;
  cursor: pointer;
  text-align: left;
  line-height: 1.3;
  transition: all 0.15s;
  font-family: inherit;
}
.chat-suggestion:hover {
  background: var(--chat-accent);
  color: var(--chat-accent-contrast);
}

/* ── Markdown inside bubbles ─────────────────────────────────────────── */
#chat-messages .dash-markdown p { margin: 0 0 0.4em 0; }
#chat-messages .dash-markdown p:last-child { margin-bottom: 0; }
#chat-messages .dash-markdown ul,
#chat-messages .dash-markdown ol { margin: 0.3em 0 0.3em 1.2em; padding: 0; }
#chat-messages .dash-markdown li { margin: 0.1em 0; }
#chat-messages .dash-markdown h1,
#chat-messages .dash-markdown h2,
#chat-messages .dash-markdown h3 { margin: 0.4em 0 0.2em; font-size: 0.9rem; }
#chat-messages .dash-markdown code { font-size: 0.78rem; background: #f0f0f0; padding: 1px 4px; border-radius: 3px; }
#chat-messages .dash-markdown pre  { margin: 0.3em 0; overflow-x: auto; }
#chat-messages .dash-markdown strong { font-weight: 600; }

/* ── Entity chip row ─────────────────────────────────────────────────── */
.entity-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.entity-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 9px;
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  font-family: inherit;
  background-color: #455A64;      /* default for unrecognised node types */
}
.entity-chip:hover  { opacity: 0.85; transform: translateY(-1px); }
.entity-chip:active { transform: translateY(0); opacity: 1; }

.entity-chip--dataset  { background-color: #1565C0; }
.entity-chip--concept  { background-color: #2E7D32; }
.entity-chip--notebook { background-color: #6A1B9A; }
.entity-chip--station  { background-color: #E65100; }

/* ── Action bar ──────────────────────────────────────────────────────── */
.action-bar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #f0f0f0;
}

.action-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #f6f8fa;
  color: #444;
  font-size: 0.73rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.action-bar-btn:hover  { background: #eaf0fb; border-color: #1565C0; color: #1565C0; }
.action-bar-btn:active { background: #dce8f9; }
