/* ============================================================
   MedRAG — Medical Q&A Chatbot
   Dark-mode premium design with glassmorphism accents
   ============================================================ */

/* ── CSS Variables ────────────────────────────────────────── */
:root {
  --bg-base:        #0d0f14;
  --bg-surface:     #13161e;
  --bg-elevated:    #1a1e2a;
  --bg-hover:       #1e2330;
  --bg-active:      #232838;

  --border:         rgba(255,255,255,0.07);
  --border-accent:  rgba(99,102,241,0.35);

  --text-primary:   #e8eaf0;
  --text-secondary: #8b90a7;
  --text-muted:     #555c78;
  --text-link:      #818cf8;

  --accent:         #6366f1;          /* indigo */
  --accent-glow:    rgba(99,102,241,0.25);
  --accent-hover:   #4f52d4;

  --research-color:  #34d399;         /* emerald */
  --research-bg:     rgba(52,211,153,0.1);
  --research-border: rgba(52,211,153,0.3);

  --guideline-color:  #60a5fa;        /* blue */
  --guideline-bg:     rgba(96,165,250,0.1);
  --guideline-border: rgba(96,165,250,0.3);

  --danger:         #f87171;
  --danger-bg:      rgba(248,113,113,0.1);
  --warn-color:     #fbbf24;
  --warn-bg:        rgba(251,191,36,0.08);
  --warn-border:    rgba(251,191,36,0.3);

  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-xl:   20px;

  --sidebar-w:   280px;
  --topbar-h:    56px;
  --panel-w:     380px;

  --font-main:   'Inter', system-ui, sans-serif;
  --font-mono:   'JetBrains Mono', monospace;

  --transition:  0.2s ease;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family:      var(--font-main);
  background-color: var(--bg-base);
  color:            var(--text-primary);
  display:          flex;
  font-size:        14px;
  line-height:      1.6;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* ══════════════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════════════ */
.sidebar {
  width:      var(--sidebar-w);
  min-width:  var(--sidebar-w);
  height:     100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display:    flex;
  flex-direction: column;
  position:   relative;
  z-index:    100;
  flex-shrink: 0;
  transition: transform var(--transition);
}

.sidebar-header {
  display:     flex;
  align-items: center;
  justify-content: space-between;
  padding:     18px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display:     flex;
  align-items: center;
  gap:         10px;
}

.logo-icon {
  width:       34px;
  height:      34px;
  background:  linear-gradient(135deg, var(--accent), #818cf8);
  border-radius: var(--radius-md);
  display:     flex;
  align-items: center;
  justify-content: center;
  color:       #fff;
  box-shadow:  0 0 16px var(--accent-glow);
}

.logo-text {
  font-size:   17px;
  font-weight: 700;
  background:  linear-gradient(135deg, #c7d2fe, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.new-chat-btn {
  width:       32px;
  height:      32px;
  border:      1px solid var(--border);
  border-radius: var(--radius-sm);
  background:  transparent;
  color:       var(--text-secondary);
  cursor:      pointer;
  display:     flex;
  align-items: center;
  justify-content: center;
  transition:  all var(--transition);
}
.new-chat-btn:hover {
  background: var(--bg-hover);
  color:      var(--text-primary);
  border-color: var(--border-accent);
}

.sidebar-section-label {
  font-size:   11px;
  font-weight: 600;
  color:       var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding:     14px 16px 6px;
}

.session-list {
  flex:     1;
  overflow-y: auto;
  padding:  6px 8px;
}

.session-empty {
  padding:    24px 16px;
  color:      var(--text-muted);
  font-size:  13px;
  text-align: center;
}

.session-item {
  padding:       10px 12px;
  border-radius: var(--radius-md);
  cursor:        pointer;
  display:       flex;
  align-items:   center;
  gap:           10px;
  transition:    all var(--transition);
  border:        1px solid transparent;
  margin-bottom: 2px;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active {
  background:  var(--bg-active);
  border-color: var(--border-accent);
}

.session-item-icon {
  width:        28px;
  height:       28px;
  border-radius: 6px;
  background:   var(--bg-elevated);
  display:      flex;
  align-items:  center;
  justify-content: center;
  color:        var(--text-secondary);
  flex-shrink:  0;
  font-size:    12px;
}

.session-item-info { flex: 1; min-width: 0; }
.session-item-preview {
  font-size:     13px;
  color:         var(--text-primary);
  white-space:   nowrap;
  overflow:      hidden;
  text-overflow: ellipsis;
}
.session-item-meta {
  font-size:  11px;
  color:      var(--text-muted);
  margin-top: 2px;
}

.session-item-delete {
  width:      24px;
  height:     24px;
  border:     none;
  background: transparent;
  color:      var(--text-muted);
  cursor:     pointer;
  border-radius: 4px;
  display:    flex;
  align-items: center;
  justify-content: center;
  opacity:    0;
  transition: all var(--transition);
  flex-shrink: 0;
}
.session-item:hover .session-item-delete { opacity: 1; }
.session-item-delete:hover {
  background: var(--danger-bg);
  color:      var(--danger);
}

.sidebar-footer {
  padding:       16px;
  border-top:    1px solid var(--border);
  display:       flex;
  flex-direction: column;
  gap:           8px;
}

.sidebar-user {
  display:     flex;
  align-items: center;
  gap:         8px;
  padding:     8px 4px 4px;
  font-size:   12px;
  color:       var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.sidebar-username {
  font-weight: 500;
  color:       var(--text-secondary);
  overflow:    hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sources-badge {
  display:     flex;
  align-items: center;
  gap:         8px;
  font-size:   12px;
  color:       var(--text-muted);
}

.source-dot {
  width:         8px;
  height:        8px;
  border-radius: 50%;
  flex-shrink:   0;
}
.source-dot.research  { background: var(--research-color); }
.source-dot.guideline { background: var(--guideline-color); }

/* ── Database Stats button ─────────────────────────────────── */
.db-stats-btn {
  display:       flex;
  align-items:   center;
  gap:           9px;
  width:         100%;
  padding:       10px 14px;
  background:    var(--bg-elevated);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  color:         var(--text-secondary);
  font-family:   var(--font-main);
  font-size:     13px;
  font-weight:   500;
  cursor:        pointer;
  transition:    all var(--transition);
}
.db-stats-btn:hover {
  background:   var(--bg-hover);
  border-color: var(--border-accent);
  color:        var(--text-primary);
  box-shadow:   0 0 12px var(--accent-glow);
}
.db-stats-btn svg { flex-shrink: 0; }

/* ── Stats Modal ───────────────────────────────────────────── */
.stats-modal-overlay {
  position:        fixed;
  inset:           0;
  background:      rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index:         300;
  opacity:         0;
  visibility:      hidden;
  pointer-events:  none;
  transition:      opacity 0.2s ease, visibility 0.2s ease;
}
.stats-modal-overlay.open {
  opacity:        1;
  visibility:     visible;
  pointer-events: auto;
}

.stats-modal {
  display:        flex;
  flex-direction: column;
  position:       fixed;
  top:            50%;
  left:           50%;
  transform:      translate(-50%, -50%) scale(0.95);
  width:          min(560px, 92vw);
  max-height:     80vh;
  background:     var(--bg-surface);
  border:         1px solid var(--border-accent);
  border-radius:  var(--radius-xl);
  box-shadow:     0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(99,102,241,0.1);
  z-index:        301;
  overflow:       hidden;
  opacity:        0;
  visibility:     hidden;
  pointer-events: none;
  transition:     opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}
.stats-modal.open {
  opacity:        1;
  visibility:     visible;
  pointer-events: auto;
  transform:      translate(-50%, -50%) scale(1);
}

.stats-modal-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         18px 20px;
  border-bottom:   1px solid var(--border);
  flex-shrink:     0;
}
.stats-modal-title-row {
  display:     flex;
  align-items: center;
  gap:         10px;
  color:       var(--accent);
}
.stats-modal-title-row h2 {
  font-size:   16px;
  font-weight: 600;
  color:       var(--text-primary);
}

.stats-modal-close {
  width:         32px;
  height:        32px;
  border:        1px solid var(--border);
  border-radius: var(--radius-sm);
  background:    transparent;
  color:         var(--text-secondary);
  cursor:        pointer;
  display:       flex;
  align-items:   center;
  justify-content: center;
  transition:    all var(--transition);
}
.stats-modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.stats-modal-body {
  overflow-y: auto;
  padding:    20px;
  display:    flex;
  flex-direction: column;
  gap:        20px;
}

/* Loading state */
.stats-loading {
  display:         flex;
  align-items:     center;
  justify-content: center;
  gap:             12px;
  padding:         40px 0;
  color:           var(--text-muted);
  font-size:       14px;
}
.stats-spinner {
  width:        20px;
  height:       20px;
  border:       2px solid var(--border);
  border-top:   2px solid var(--accent);
  border-radius: 50%;
  animation:    spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Stats summary row */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.stat-card {
  background:    var(--bg-elevated);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  padding:       16px;
  text-align:    center;
  transition:    border-color var(--transition);
}
.stat-card:hover { border-color: var(--border-accent); }
.stat-card-value {
  font-size:   26px;
  font-weight: 700;
  background:  linear-gradient(135deg, #e8eaf0, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}
.stat-card-label {
  font-size:  11px;
  color:      var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Breakdown section */
.stats-section-title {
  font-size:     12px;
  font-weight:   600;
  color:         var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.stats-breakdown {
  display:        flex;
  flex-direction: column;
  gap:            8px;
}
.stats-row {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  background:      var(--bg-elevated);
  border:          1px solid var(--border);
  border-radius:   var(--radius-md);
  padding:         10px 14px;
  font-size:       13px;
}
.stats-row-label {
  display:     flex;
  align-items: center;
  gap:         8px;
  color:       var(--text-secondary);
}
.stats-row-dot {
  width:         8px;
  height:        8px;
  border-radius: 50%;
  flex-shrink:   0;
}
.stats-row-value {
  font-weight:  600;
  color:        var(--text-primary);
  font-family:  var(--font-mono);
  font-size:    13px;
}
.stats-bar-wrap {
  height:        4px;
  background:    var(--bg-hover);
  border-radius: 99px;
  margin-top:    6px;
  overflow:      hidden;
}
.stats-bar-fill {
  height:        100%;
  border-radius: 99px;
  transition:    width 0.6s ease;
}

/* Error state */
.stats-error {
  text-align:  center;
  color:       var(--danger);
  font-size:   13px;
  padding:     32px 0;
}

/* ── Sidebar overlay (mobile) ──────────────────────────────── */
.sidebar-overlay {
  display:  none;
  position: fixed;
  inset:    0;
  background: rgba(0,0,0,0.6);
  z-index:  90;
}

/* ══════════════════════════════════════════════════════════
   MAIN PANEL
══════════════════════════════════════════════════════════ */
.main {
  flex:     1;
  display:  flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  height:        var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display:       flex;
  align-items:   center;
  gap:           12px;
  padding:       0 20px;
  background:    rgba(13,15,20,0.85);
  backdrop-filter: blur(12px);
  position:      relative;
  z-index:       10;
  flex-shrink:   0;
}

.menu-btn {
  display:       none;
  width:         36px;
  height:        36px;
  border:        1px solid var(--border);
  border-radius: var(--radius-sm);
  background:    transparent;
  color:         var(--text-secondary);
  cursor:        pointer;
  align-items:   center;
  justify-content: center;
  transition:    all var(--transition);
}
.menu-btn:hover {
  background:   var(--bg-hover);
  color:        var(--text-primary);
}

.topbar-title {
  font-size:   15px;
  font-weight: 600;
  color:       var(--text-primary);
  flex:        1;
}

.topbar-badges { display: flex; gap: 8px; }

/* ── Chat area ──────────────────────────────────────────────── */
.chat-area {
  flex:       1;
  overflow-y: auto;
  padding:    0;
  position:   relative;
}

/* ── Welcome ────────────────────────────────────────────────── */
.welcome {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  min-height:      100%;
  padding:         60px 24px 40px;
  text-align:      center;
}

.welcome-icon {
  width:         72px;
  height:        72px;
  border-radius: var(--radius-xl);
  background:    linear-gradient(135deg, rgba(99,102,241,0.15), rgba(129,140,248,0.08));
  border:        1px solid var(--border-accent);
  display:       flex;
  align-items:   center;
  justify-content: center;
  color:         var(--accent);
  margin-bottom: 24px;
  box-shadow:    0 0 40px var(--accent-glow);
}

.welcome-title {
  font-size:     28px;
  font-weight:   700;
  margin-bottom: 12px;
  background:    linear-gradient(135deg, #e8eaf0, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-subtitle {
  color:         var(--text-secondary);
  max-width:     500px;
  margin-bottom: 40px;
  line-height:   1.7;
  font-size:     15px;
}

.suggestion-grid {
  display:               grid;
  grid-template-columns: repeat(2, 1fr);
  gap:                   12px;
  max-width:             560px;
  width:                 100%;
  margin-bottom:         32px;
}

.suggestion-card {
  background:    var(--bg-surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       16px;
  cursor:        pointer;
  text-align:    left;
  display:       flex;
  flex-direction: column;
  gap:           10px;
  transition:    all var(--transition);
}
.suggestion-card:hover {
  background:   var(--bg-hover);
  border-color: var(--border-accent);
  transform:    translateY(-2px);
  box-shadow:   0 8px 24px rgba(0,0,0,0.3);
}

.suggestion-icon { font-size: 22px; }

.suggestion-text {
  font-size:  13px;
  color:      var(--text-secondary);
  line-height: 1.5;
}

.disclaimer {
  display:     flex;
  align-items: center;
  gap:         8px;
  font-size:   12px;
  color:       var(--text-muted);
  background:  var(--bg-surface);
  border:      1px solid var(--border);
  border-radius: var(--radius-md);
  padding:     10px 14px;
}

/* ── Messages ──────────────────────────────────────────────── */
.messages {
  padding:   0;
  max-width: 800px;
  margin:    0 auto;
  width:     100%;
  padding:   24px 24px 16px;
}

.message-group {
  margin-bottom: 28px;
}

/* Human message */
.message-human {
  display:       flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.message-human-bubble {
  background:    linear-gradient(135deg, var(--accent), #4f46e5);
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  padding:       12px 16px;
  max-width:     75%;
  font-size:     14px;
  line-height:   1.6;
  color:         #fff;
  box-shadow:    0 4px 16px rgba(99,102,241,0.25);
}

/* AI message */
.message-ai { display: flex; flex-direction: column; gap: 10px; }

.message-ai-header {
  display:     flex;
  align-items: center;
  gap:         10px;
}

.ai-avatar {
  width:        32px;
  height:       32px;
  border-radius: 8px;
  background:   linear-gradient(135deg, var(--accent), #818cf8);
  display:      flex;
  align-items:  center;
  justify-content: center;
  color:        #fff;
  flex-shrink:  0;
  font-size:    12px;
  font-weight:  700;
}

.ai-label {
  font-size:  13px;
  font-weight: 600;
  color:      var(--text-secondary);
}

/* Route badge */
.badge {
  font-size:     11px;
  font-weight:   600;
  padding:       3px 8px;
  border-radius: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-research {
  background:  var(--research-bg);
  color:       var(--research-color);
  border:      1px solid var(--research-border);
}
.badge-guideline {
  background:  var(--guideline-bg);
  color:       var(--guideline-color);
  border:      1px solid var(--guideline-border);
}
.badge-both {
  background:  rgba(129,140,248,0.1);
  color:       #a5b4fc;
  border:      1px solid rgba(129,140,248,0.3);
}
.badge-refused {
  background:  var(--danger-bg);
  color:       var(--danger);
  border:      1px solid rgba(248,113,113,0.3);
}

.message-ai-body {
  background:    var(--bg-surface);
  border:        1px solid var(--border);
  border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
  padding:       18px 20px;
  font-size:     14px;
  line-height:   1.75;
  color:         var(--text-primary);
}

/* Markdown-style content in answers */
.message-ai-body p { margin-bottom: 10px; }
.message-ai-body p:last-child { margin-bottom: 0; }
.message-ai-body strong { color: var(--text-primary); font-weight: 600; }
.message-ai-body em { font-style: italic; }
.message-ai-body ul, .message-ai-body ol { padding-left: 20px; margin-bottom: 10px; }
.message-ai-body li { margin-bottom: 4px; }

/* Inline citation links */
.cite-link {
  display:       inline-flex;
  align-items:   center;
  justify-content: center;
  width:         20px;
  height:        20px;
  border-radius: 50%;
  background:    var(--accent-glow);
  color:         var(--text-link);
  font-size:     11px;
  font-weight:   600;
  font-family:   var(--font-mono);
  cursor:        pointer;
  border:        1px solid var(--border-accent);
  transition:    all var(--transition);
  text-decoration: none;
  vertical-align: middle;
  margin:        0 1px;
}
.cite-link:hover {
  background:  var(--accent);
  color:       #fff;
  transform:   scale(1.15);
}

/* ── Alert banners ──────────────────────────────────────────── */
.alert-banner {
  border-radius: var(--radius-md);
  padding:       12px 16px;
  font-size:     13px;
  display:       flex;
  align-items:   flex-start;
  gap:           10px;
  margin-top:    10px;
}

.alert-banner.conflict {
  background:  var(--warn-bg);
  border:      1px solid var(--warn-border);
  color:       var(--warn-color);
}

.alert-banner.refused {
  background:  var(--danger-bg);
  border:      1px solid rgba(248,113,113,0.3);
  color:       var(--danger);
}

.alert-icon { flex-shrink: 0; margin-top: 1px; }

.alert-banner strong { display: block; margin-bottom: 2px; }

/* ── Citation cards bar ─────────────────────────────────────── */
.citation-bar {
  display:    flex;
  gap:        8px;
  flex-wrap:  wrap;
  margin-top: 12px;
}

.citation-chip {
  display:       flex;
  align-items:   center;
  gap:           6px;
  padding:       5px 10px;
  border-radius: 20px;
  font-size:     12px;
  cursor:        pointer;
  transition:    all var(--transition);
  border:        1px solid;
  font-family:   var(--font-mono);
  font-size:     11px;
}
.citation-chip.research {
  background:  var(--research-bg);
  border-color: var(--research-border);
  color:       var(--research-color);
}
.citation-chip.guideline {
  background:  var(--guideline-bg);
  border-color: var(--guideline-border);
  color:       var(--guideline-color);
}
.citation-chip:hover { filter: brightness(1.2); transform: translateY(-1px); }

.view-all-citations {
  padding:       5px 12px;
  border-radius: 20px;
  font-size:     12px;
  background:    var(--bg-elevated);
  border:        1px solid var(--border);
  color:         var(--text-secondary);
  cursor:        pointer;
  transition:    all var(--transition);
}
.view-all-citations:hover {
  background:   var(--bg-hover);
  color:        var(--text-primary);
}

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

.typing-dot {
  width:         7px;
  height:        7px;
  border-radius: 50%;
  background:    var(--text-muted);
  animation:     typingBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ══════════════════════════════════════════════════════════
   INPUT AREA
══════════════════════════════════════════════════════════ */
.input-area {
  padding:      16px 24px;
  border-top:   1px solid var(--border);
  background:   rgba(13,15,20,0.9);
  backdrop-filter: blur(12px);
  flex-shrink:  0;
}

.input-wrapper {
  display:       flex;
  align-items:   center;
  gap:           10px;
  background:    var(--bg-surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       10px 12px;
  max-width:     800px;
  margin:        0 auto;
  transition:    border-color var(--transition), box-shadow var(--transition);
}
.input-wrapper:focus-within {
  border-color: var(--border-accent);
  box-shadow:   0 0 0 3px var(--accent-glow);
}

.query-input {
  flex:           1;
  background:     transparent;
  border:         none;
  outline:        none;
  color:          var(--text-primary);
  font-family:    var(--font-main);
  font-size:      14px;
  line-height:    1.6;
  resize:         none;
  max-height:     180px;
  overflow-y:     auto;
  padding:        0;
  margin:         0;
  display:        block;
  vertical-align: middle;
  align-self:     center;
}
.query-input::placeholder { color: var(--text-muted); }

.send-btn {
  width:         38px;
  height:        38px;
  border-radius: var(--radius-sm);
  background:    var(--accent);
  border:        none;
  color:         #fff;
  cursor:        pointer;
  display:       flex;
  align-items:   center;
  justify-content: center;
  transition:    all var(--transition);
  flex-shrink:   0;
}
.send-btn:hover:not(:disabled) {
  background:  var(--accent-hover);
  transform:   scale(1.05);
}
.send-btn:disabled {
  background:  var(--bg-elevated);
  color:       var(--text-muted);
  cursor:      not-allowed;
}

.input-footer {
  text-align: center;
  font-size:  11px;
  color:      var(--text-muted);
  margin-top: 8px;
  max-width:  800px;
  margin:     8px auto 0;
}

/* ══════════════════════════════════════════════════════════
   CITATION PANEL
══════════════════════════════════════════════════════════ */
.citation-panel {
  position:   fixed;
  top:        0;
  right:      0;
  width:      var(--panel-w);
  height:     100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index:    200;
  display:    flex;
  flex-direction: column;
  transform:  translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.citation-panel.open { transform: translateX(0); }

.citation-panel-header {
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  padding:       18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink:   0;
}
.citation-panel-header h3 {
  font-size:   16px;
  font-weight: 600;
}

.close-panel-btn {
  width:         32px;
  height:        32px;
  border:        1px solid var(--border);
  border-radius: var(--radius-sm);
  background:    transparent;
  color:         var(--text-secondary);
  cursor:        pointer;
  display:       flex;
  align-items:   center;
  justify-content: center;
  transition:    all var(--transition);
}
.close-panel-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.citation-panel-body {
  flex:       1;
  overflow-y: auto;
  padding:    16px;
  display:    flex;
  flex-direction: column;
  gap:        12px;
}

.citation-card {
  background:    var(--bg-elevated);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  overflow:      hidden;
  transition:    border-color var(--transition);
}
.citation-card:hover { border-color: var(--border-accent); }

.citation-card-header {
  padding:     12px 14px;
  display:     flex;
  align-items: flex-start;
  gap:         10px;
}

.citation-number {
  width:        24px;
  height:       24px;
  border-radius: 50%;
  background:   var(--accent-glow);
  border:       1px solid var(--border-accent);
  color:        var(--text-link);
  font-size:    12px;
  font-weight:  700;
  display:      flex;
  align-items:  center;
  justify-content: center;
  flex-shrink:  0;
  font-family:  var(--font-mono);
}

.citation-card-info { flex: 1; min-width: 0; }

.citation-title {
  font-size:    13px;
  font-weight:  600;
  color:        var(--text-primary);
  margin-bottom: 4px;
  display:      -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow:     hidden;
}

.citation-meta {
  display:  flex;
  gap:      8px;
  flex-wrap: wrap;
  align-items: center;
}

.citation-meta-item {
  font-size: 11px;
  color:     var(--text-muted);
  display:   flex;
  align-items: center;
  gap:       4px;
}

.citation-snippet {
  padding:     10px 14px;
  border-top:  1px solid var(--border);
  font-size:   12px;
  color:       var(--text-secondary);
  line-height: 1.6;
  font-style:  italic;
}

.citation-footer {
  padding:       10px 14px;
  border-top:    1px solid var(--border);
  display:       flex;
  align-items:   center;
  justify-content: space-between;
}

.citation-link {
  font-size:   12px;
  color:       var(--text-link);
  text-decoration: none;
  display:     flex;
  align-items: center;
  gap:         4px;
  transition:  color var(--transition);
}
.citation-link:hover { color: #c7d2fe; }

.score-bar {
  display:     flex;
  align-items: center;
  gap:         6px;
  font-size:   11px;
  color:       var(--text-muted);
}
.score-fill {
  height:        4px;
  width:         50px;
  background:    var(--bg-base);
  border-radius: 2px;
  overflow:      hidden;
}
.score-fill-inner {
  height:        100%;
  background:    linear-gradient(90deg, var(--accent), #818cf8);
  border-radius: 2px;
  transition:    width 0.5s ease;
}

.panel-overlay {
  display:  none;
  position: fixed;
  inset:    0;
  background: rgba(0,0,0,0.4);
  z-index:  190;
}

/* ══════════════════════════════════════════════════════════
   THINKING BUBBLE  (Gemini / ChatGPT-style inline)
══════════════════════════════════════════════════════════ */

/* Container that sits in the message list */
.thinking-bubble-wrap {
  padding: 4px 0 12px 0;
  animation: fadeInUp 0.25s ease both;
}

/* Header row: avatar + label + shimmer text */
.thinking-header {
  display:     flex;
  align-items: center;
  gap:         10px;
  cursor:      pointer;
  user-select: none;
  padding:     2px 0;
}

/* Animated "Thinking…" shimmer label */
.thinking-label {
  font-size:   14px;
  font-weight: 500;
  background:  linear-gradient(
    90deg,
    var(--text-muted) 0%,
    var(--accent)     40%,
    #a78bfa           60%,
    var(--text-muted) 100%
  );
  background-size: 250% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmerText 2.2s linear infinite;
}

@keyframes shimmerText {
  0%   { background-position: 0% center; }
  100% { background-position: 250% center; }
}

/* Three animated pulse dots next to the label */
.thinking-dots {
  display:     flex;
  align-items: center;
  gap:         4px;
  margin-left: 2px;
}
.thinking-dot-pulse {
  width:         5px;
  height:        5px;
  border-radius: 50%;
  background:    var(--accent);
  animation:     pulseDot 1.4s ease-in-out infinite both;
}
.thinking-dot-pulse:nth-child(1) { animation-delay: 0s; }
.thinking-dot-pulse:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot-pulse:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulseDot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1.1); opacity: 1; }
}

/* Chevron toggle icon */
.thinking-chevron {
  margin-left:  auto;
  font-size:    11px;
  color:        var(--text-muted);
  transition:   transform 0.25s ease;
  opacity:      0.6;
}
.thinking-bubble-wrap.expanded .thinking-chevron {
  transform: rotate(180deg);
}

/* Collapsible steps list */
.thinking-steps-list {
  overflow:        hidden;
  max-height:      0;
  transition:      max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                   opacity 0.25s ease;
  opacity:         0;
  padding-left:    36px;
}
.thinking-bubble-wrap.expanded .thinking-steps-list {
  max-height:  300px;
  opacity:     1;
}

/* Individual step rows */
.ts-step {
  display:     flex;
  align-items: center;
  gap:         8px;
  padding:     5px 0;
  font-size:   13px;
  color:       var(--text-muted);
  transition:  color 0.3s ease;
}
.ts-icon {
  width:         16px;
  height:        16px;
  flex-shrink:   0;
  display:       flex;
  align-items:   center;
  justify-content: center;
  font-size:     11px;
}
/* Pending state — dim dot */
.ts-step.ts-pending .ts-icon::before {
  content:       '';
  display:       block;
  width:         6px;
  height:        6px;
  border-radius: 50%;
  background:    var(--border);
}
/* Active state — spinning ring */
.ts-step.ts-active {
  color: var(--text-primary);
}
.ts-step.ts-active .ts-icon::before {
  content:       '';
  display:       block;
  width:         12px;
  height:        12px;
  border-radius: 50%;
  border:        2px solid transparent;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  animation:     spin 0.7s linear infinite;
}
/* Done state — check */
.ts-step.ts-done {
  color: var(--research-color);
}
.ts-step.ts-done .ts-icon { color: var(--research-color); font-size: 12px; }
.ts-step.ts-done .ts-icon::before { content: '✓'; font-weight: 700; }

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

/* ══════════════════════════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════════════════════════ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-group { animation: fadeInUp 0.3s ease forwards; }

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar {
    position:  fixed;
    top:       0;
    left:      0;
    height:    100vh;
    transform: translateX(-100%);
    z-index:   110;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }

  .menu-btn { display: flex; }

  .suggestion-grid { grid-template-columns: 1fr; }

  .citation-panel { width: 100%; }

  .messages { padding: 16px; }
}

/* ══════════════════════════════════════════════════════════
   AUTH GATE
══════════════════════════════════════════════════════════ */
.auth-gate {
  position:        fixed;
  inset:           0;
  z-index:         500;
  display:         flex;
  align-items:     center;
  justify-content: center;
  background:      var(--bg-base);
  /* hidden by default — JS shows it when needed */
  visibility:      hidden;
  opacity:         0;
  transition:      opacity 0.25s ease, visibility 0.25s ease;
}
.auth-gate.visible {
  visibility: visible;
  opacity:    1;
}

.auth-card {
  width:         min(420px, 92vw);
  background:    var(--bg-surface);
  border:        1px solid var(--border-accent);
  border-radius: var(--radius-xl);
  padding:       40px 36px 32px;
  box-shadow:    0 32px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(99,102,241,0.08);
  display:       flex;
  flex-direction: column;
  gap:           20px;
  animation:     authCardIn 0.3s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes authCardIn {
  from { transform: translateY(24px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

.auth-logo {
  display:     flex;
  align-items: center;
  gap:         10px;
  margin-bottom: 4px;
}

.auth-title {
  font-size:   24px;
  font-weight: 700;
  background:  linear-gradient(135deg, #e8eaf0, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin:      0;
}

.auth-subtitle {
  font-size: 14px;
  color:     var(--text-muted);
  margin:    0;
}

.auth-error {
  background:    var(--danger-bg);
  border:        1px solid rgba(248,113,113,0.35);
  border-radius: var(--radius-md);
  color:         var(--danger);
  font-size:     13px;
  padding:       10px 14px;
}

.auth-form {
  display:        flex;
  flex-direction: column;
  gap:            14px;
}

.auth-field {
  display:        flex;
  flex-direction: column;
  gap:            6px;
}
.auth-field label {
  font-size:   12px;
  font-weight: 600;
  color:       var(--text-secondary);
  letter-spacing: 0.04em;
}
.auth-field input {
  background:    var(--bg-elevated);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  padding:       10px 14px;
  color:         var(--text-primary);
  font-family:   var(--font-main);
  font-size:     14px;
  outline:       none;
  transition:    border-color var(--transition), box-shadow var(--transition);
}
.auth-field input:focus {
  border-color: var(--border-accent);
  box-shadow:   0 0 0 3px var(--accent-glow);
}
.auth-field input::placeholder { color: var(--text-muted); }

.auth-submit-btn {
  display:         flex;
  align-items:     center;
  justify-content: center;
  gap:             8px;
  width:           100%;
  padding:         12px;
  background:      var(--accent);
  border:          none;
  border-radius:   var(--radius-md);
  color:           #fff;
  font-family:     var(--font-main);
  font-size:       14px;
  font-weight:     600;
  cursor:          pointer;
  margin-top:      4px;
  transition:      background var(--transition), transform var(--transition), box-shadow var(--transition);
}
.auth-submit-btn:hover {
  background:  var(--accent-hover);
  transform:   translateY(-1px);
  box-shadow:  0 6px 20px var(--accent-glow);
}
.auth-submit-btn:disabled {
  opacity: 0.6;
  cursor:  not-allowed;
  transform: none;
}

.auth-btn-spinner {
  width:         16px;
  height:        16px;
  border:        2px solid rgba(255,255,255,0.35);
  border-top:    2px solid #fff;
  border-radius: 50%;
  animation:     spin 0.7s linear infinite;
}

.auth-toggle {
  text-align: center;
  font-size:  13px;
  color:      var(--text-muted);
  margin:     0;
}
.auth-toggle-btn {
  background:  none;
  border:      none;
  color:       var(--text-link);
  font-size:   13px;
  cursor:      pointer;
  padding:     0;
  margin-left: 4px;
  transition:  color var(--transition);
}
.auth-toggle-btn:hover { color: var(--accent); }

/* Logout button in sidebar footer */
.logout-btn {
  display:       flex;
  align-items:   center;
  gap:           9px;
  width:         100%;
  padding:       10px 14px;
  background:    transparent;
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  color:         var(--text-muted);
  font-family:   var(--font-main);
  font-size:     13px;
  cursor:        pointer;
  transition:    all var(--transition);
  margin-top:    8px;
}
.logout-btn:hover {
  border-color: rgba(248,113,113,0.4);
  color:        var(--danger);
  background:   var(--danger-bg);
}
