/* ── Reset & Variables ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0a0d14;
  --bg2:         #0f1420;
  --bg3:         #151c2c;
  --sidebar-w:   240px;
  --border:      rgba(255,255,255,0.07);
  --border2:     rgba(255,255,255,0.12);
  --text:        #e8edf5;
  --text-muted:  #6b7a99;
  --text-dim:    #3d4d6b;
  --accent:      #3b8cff;
  --accent2:     #00d4aa;
  --accent3:     #f0a500;
  --danger:      #ff4d6a;
  --user-bg:     #1a2540;
  --ai-bg:       #111827;
  --font-main:   'DM Sans', sans-serif;
  --font-serif:  'DM Serif Display', serif;
  --font-mono:   'DM Mono', monospace;
  --radius:      12px;
  --radius-lg:   18px;
  --shadow:      0 8px 32px rgba(0,0,0,0.4);
}

/* ── Base ────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Background grid ─────────────────────────────────────────────── */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(59,140,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,140,255,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ──────────────────────────────────────────────────────── */
body {
  display: flex;
  position: relative;
  z-index: 1;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 20px 24px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white;
  flex-shrink: 0;
}

.logo-text {
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--text);
  letter-spacing: -0.3px;
}
.logo-text em {
  font-style: italic;
  color: var(--accent);
}

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  color: var(--text-dim);
  padding: 0 8px;
  margin-bottom: 6px;
  margin-top: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 400;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text);
}

.nav-item.active {
  background: rgba(59,140,255,0.12);
  color: var(--accent);
  font-weight: 500;
}

.sidebar-status {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online { background: var(--accent2); box-shadow: 0 0 6px var(--accent2); }

.status-detail {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Main ────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,13,20,0.8);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.topbar h1 {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.3px;
}

.topbar-sub {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 2px;
  display: block;
}

.topbar-right {
  display: flex;
  gap: 10px;
}

.badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 20px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent2);
  box-shadow: 0 0 5px var(--accent2);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Chat area ───────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  scroll-behavior: smooth;
}

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

/* ── Welcome ─────────────────────────────────────────────────────── */
.welcome {
  max-width: 640px;
  margin: 40px auto;
  text-align: center;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 20px;
  filter: drop-shadow(0 0 20px rgba(59,140,255,0.3));
}

.welcome h2 {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 400;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome p {
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 28px;
}

.example-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.chip {
  padding: 9px 16px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-main);
  transition: all 0.2s;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(59,140,255,0.08);
}

/* ── Messages ────────────────────────────────────────────────────── */
.message {
  display: flex;
  gap: 14px;
  margin-bottom: 24px;
  max-width: 820px;
  animation: fadeUp 0.3s ease;
}

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

.message-user { flex-direction: row-reverse; margin-left: auto; }

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

.user-avatar { background: var(--accent); color: white; }
.ai-avatar   { background: linear-gradient(135deg, #1e3a5f, #0d2137); color: var(--accent); border: 1px solid rgba(59,140,255,0.3); }
.err-avatar  { background: var(--danger); color: white; }

.msg-bubble {
  padding: 18px 22px;
  border-radius: var(--radius-lg);
  font-size: 16px;
  line-height: 1.65;
  max-width: 100%;
}

.user-bubble {
  background: var(--user-bg);
  border: 1px solid rgba(59,140,255,0.2);
  color: var(--text);
  border-top-right-radius: 4px;
  font-size: 16px;
}

.ai-bubble {
  background: var(--ai-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-top-left-radius: 4px;
  flex: 1;
}

.err-bubble {
  background: rgba(255,77,106,0.1);
  border: 1px solid rgba(255,77,106,0.3);
  color: var(--danger);
}

/* ── Loading bubble ──────────────────────────────────────────────── */
.loading-bubble {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
}

.thinking {
  display: flex;
  gap: 5px;
}

.thinking span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.thinking-label {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Answer text ─────────────────────────────────────────────────── */
.answer-text {
  white-space: pre-wrap;
  line-height: 1.8;
  margin-bottom: 16px;
  font-size: 16px;
}

/* ── Meta row ────────────────────────────────────────────────────── */
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg3);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.meta-item strong { color: var(--text); }
.conf-high { border-color: rgba(0,212,170,0.4); color: var(--accent2); }
.conf-high strong { color: var(--accent2); }
.conf-mid  { border-color: rgba(240,165,0,0.4); color: var(--accent3); }
.conf-mid strong { color: var(--accent3); }
.conf-low  { border-color: rgba(255,77,106,0.4); color: var(--danger); }
.conf-low strong { color: var(--danger); }

/* ── Citations ───────────────────────────────────────────────────── */
.citations-block {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.citations-block summary {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  padding: 4px 0;
  user-select: none;
}

.citations-block summary:hover { color: var(--text); }
.citations-block[open] summary { color: var(--accent); }

.citations-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.citation {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.citation-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.citation-rank {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(59,140,255,0.1);
  padding: 2px 8px;
  border-radius: 10px;
}

.citation-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.citation-score {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.citation-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-muted);
}

/* ── Input area ──────────────────────────────────────────────────── */
.input-area {
  padding: 16px 28px 20px;
  border-top: 1px solid var(--border);
  background: rgba(10,13,20,0.9);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,140,255,0.1);
}

textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-main);
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
}

textarea::placeholder { color: var(--text-dim); }

.send-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.send-btn:hover { background: #5aa0ff; transform: scale(1.05); }
.send-btn:disabled { background: var(--text-dim); cursor: not-allowed; transform: none; }

.input-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  padding: 0 4px;
}

kbd {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
}

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Scrollbar ───────────────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }

/* ── Disclaimer bar ──────────────────────────────────────────────── */
.disclaimer-bar {
  background: rgba(240,165,0,0.1);
  border-bottom: 1px solid rgba(240,165,0,0.3);
  color: var(--accent3);
  font-size: 12px;
  padding: 8px 28px;
  text-align: center;
  flex-shrink: 0;
}

/* ── Page content ────────────────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

/* ── Stats grid ──────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}

.stat-value {
  font-size: 36px;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-mono);
  margin-bottom: 8px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Section title ───────────────────────────────────────────────── */
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 16px;
}

/* ── Query list ──────────────────────────────────────────────────── */
.query-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.query-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}

.qi-query {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 8px;
}

.qi-meta {
  display: flex;
  gap: 16px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ── Evaluation grid ─────────────────────────────────────────────── */
.eval-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.eval-section {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 20px;
}

.eval-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 16px;
}

.eval-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.eval-row:last-child { border-bottom: none; }
.eval-row span:first-child { color: var(--text-muted); }
.eval-row span:last-child {
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 500;
}

/* ── About cards ─────────────────────────────────────────────────── */
.about-card {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

.about-card h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--text);
}

.about-card p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-muted);
}

/* ── Architecture list ───────────────────────────────────────────── */
.arch-list { display: flex; flex-direction: column; gap: 10px; }
.arch-item {
  display: flex;
  gap: 16px;
  font-size: 13px;
}
.arch-label {
  min-width: 120px;
  color: var(--accent);
  font-weight: 500;
}

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px;
  font-size: 14px;
}

/* ── Refresh button ──────────────────────────────────────────────── */
.refresh-btn {
  padding: 8px 16px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.refresh-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Confidence colors in query list ─────────────────────────────── */
.conf-high { color: var(--accent2) !important; }
.conf-mid  { color: var(--accent3) !important; }
.conf-low  { color: var(--danger)  !important; }

/* ── Fix input always visible at bottom ─────────────────────────── */
#page-chat {
  display: flex !important;
  flex-direction: column !important;
  height: 100vh !important;
  overflow: hidden !important;
}

.chat-area {
  flex: 1 !important;
  overflow-y: auto !important;
  min-height: 0 !important;
}

.input-area {
  flex-shrink: 0 !important;
  position: relative !important;
  bottom: auto !important;
  z-index: 10 !important;
  background: rgba(10,13,20,0.95) !important;
}

.disclaimer-bar {
  flex-shrink: 0 !important;
}

/* ── Medical icons ───────────────────────────────────────────────── */
.medical-icons {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 24px;
}

.med-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px;
  background: var(--bg3);
  border: 1px solid;
  border-radius: 14px;
  width: 72px;
  transition: transform 0.2s;
  cursor: default;
}

.med-icon:hover {
  transform: translateY(-3px);
}

.med-icon span {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── EKG Animation ───────────────────────────────────────────────── */
.ekg-container {
  width: 100%;
  max-width: 500px;
  margin: 0 auto 20px;
  height: 50px;
  overflow: hidden;
  position: relative;
}

.ekg-svg {
  width: 200%;
  height: 100%;
  animation: ekg-scroll 3s linear infinite;
}

@keyframes ekg-scroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

@keyframes ekg-fade {
  0%, 100% { opacity: 0.3; }
  50%       { opacity: 1; }
}

.ekg-line {
  animation: ekg-fade 3s ease-in-out infinite;
}
