:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf5;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-dim: #2563eb;
  --green: #22c55e;
  --orange: #f59e0b;
  --purple: #a855f7;
  --pink: #ec4899;
  --cyan: #06b6d4;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100dvh;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo { font-size: 28px; }

.brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--muted);
}

.stats {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.stat strong {
  color: var(--text);
  font-weight: 600;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface2);
  font-size: 0.75rem;
}

.badge.online { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.badge.offline { background: rgba(245, 158, 11, 0.15); color: var(--orange); }

/* Main layout */
.main {
  display: grid;
  grid-template-columns: 1fr 420px;
  flex: 1;
  min-height: 0;
}

@media (max-width: 960px) {
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side-panel { max-height: 45vh; border-top: 1px solid var(--border); }
}

/* Chat panel */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: linear-gradient(180deg, var(--bg) 0%, #121820 100%);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome {
  max-width: 640px;
  margin: auto;
  text-align: center;
  padding: 40px 20px;
}

.welcome h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.welcome p { color: var(--muted); margin-bottom: 20px; }

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.example-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.example-btn:hover {
  border-color: var(--accent);
  background: var(--surface2);
}

.msg {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.25s ease;
}

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

.msg.user .bubble {
  background: var(--accent);
  color: #fff;
  margin-left: auto;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  max-width: 85%;
}

.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
}

.bubble {
  padding: 14px 18px;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 6px;
  padding: 0 4px;
}

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

.loading .bubble {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
}

.dot {
  width: 7px; height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.15s; }
.dot:nth-child(3) { animation-delay: 0.3s; }

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

/* Input bar */
.input-bar {
  display: flex;
  gap: 10px;
  padding: 16px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}

.input-bar textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 12px 16px;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
}

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

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

.input-bar button:hover:not(:disabled) { background: var(--accent-dim); }
.input-bar button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Side panel */
.side-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  min-height: 0;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
}

.tab-content.active { display: flex; }

#graphContainer {
  flex: 1;
  min-height: 200px;
  background: #0d1117;
}

.graph-hint {
  padding: 8px 14px;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.exp-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.exp-list .empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 16px;
  font-size: 0.85rem;
}

.exp-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.82rem;
}

.exp-card h4 {
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--cyan);
}

.exp-card .metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
}

.metric {
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.exp-card .doi {
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
}

.verified { color: var(--green); }
.unverified { color: var(--orange); }

.filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}
