/* ═══════════════════════════════════════════════════════════════
   GeminiRAG — Design System
   Dark Minimalism + Glassmorphism
   Palette : #0A0A0F bg · #6366F1 accent · #F1F5F9 text
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  /* Backgrounds */
  --bg-base:       #0A0A0F;
  --bg-surface:    rgba(255,255,255,0.03);
  --bg-surface-2:  rgba(255,255,255,0.06);
  --bg-hover:      rgba(255,255,255,0.08);

  /* Borders */
  --border:        rgba(255,255,255,0.08);
  --border-focus:  rgba(99,102,241,0.5);

  /* Accent (Indigo) */
  --accent:        #6366F1;
  --accent-light:  rgba(99,102,241,0.15);
  --accent-glow:   rgba(99,102,241,0.3);

  /* Text */
  --text-primary:  #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted:    #475569;

  /* Semantic */
  --success:       #10B981;
  --warning:       #F59E0B;
  --error:         #EF4444;
  --video-color:   #8B5CF6;
  --image-color:   #06B6D4;
  --text-color:    #10B981;
  --pdf-color:     #F59E0B;

  /* Sidebar */
  --sidebar-width: 280px;
  --sources-width: 320px;

  /* Spacing */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  18px;

  /* Font */
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ─── Layout ────────────────────────────────────────────────────── */
body {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr 0px;
  grid-template-rows: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.3s ease;
}

body.sources-open {
  grid-template-columns: var(--sidebar-width) 1fr var(--sources-width);
}

/* ─── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  grid-column: 1;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: linear-gradient(180deg, rgba(99,102,241,0.03) 0%, transparent 40%);
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.logo-icon {
  font-size: 20px;
  color: var(--accent);
  line-height: 1;
}

.logo-accent { color: var(--accent); }

.stats-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--text-secondary);
}

.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s ease infinite;
}

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

/* ─── Upload Section ────────────────────────────────────────────── */
.upload-section {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.drop-zone {
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  transition: all 0.2s ease;
  background: var(--bg-surface);
  position: relative;
  overflow: hidden;
}

.drop-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.drop-zone[data-type="video"]::before { background: radial-gradient(ellipse at center, rgba(139,92,246,0.08), transparent 70%); }
.drop-zone[data-type="image"]::before { background: radial-gradient(ellipse at center, rgba(6,182,212,0.08), transparent 70%); }
.drop-zone[data-type="text"]::before  { background: radial-gradient(ellipse at center, rgba(16,185,129,0.08), transparent 70%); }

.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-1px);
}

.drop-zone:hover::before, .drop-zone.drag-over::before { opacity: 1; }

.drop-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.drop-zone[data-type="video"] .drop-icon { background: rgba(139,92,246,0.15); color: var(--video-color); }
.drop-zone[data-type="image"] .drop-icon { background: rgba(6,182,212,0.15); color: var(--image-color); }
.drop-zone[data-type="text"]  .drop-icon { background: rgba(16,185,129,0.15); color: var(--text-color); }

.drop-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
}

.drop-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ─── Progress ──────────────────────────────────────────────────── */
.upload-progress {
  padding: 0 16px 12px;
  flex-shrink: 0;
}

.progress-bar-wrap {
  height: 3px;
  background: var(--bg-surface-2);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #8B5CF6);
  border-radius: 2px;
  transition: width 0.3s ease;
  animation: shimmer 1.5s ease infinite;
}

@keyframes shimmer {
  0%   { filter: brightness(1); }
  50%  { filter: brightness(1.3); }
  100% { filter: brightness(1); }
}

.progress-label {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ─── Documents Section ─────────────────────────────────────────── */
.documents-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 16px 16px;
  min-height: 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.refresh-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.refresh-btn:hover { color: var(--text-primary); }

.doc-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.empty-state {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 12px;
}
.empty-sub { margin-top: 4px; font-size: 11px; }

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  gap: 8px;
  transition: background 0.15s;
}

.doc-item:hover { background: var(--bg-hover); }

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

.doc-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}

.type-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.type-badge.video  { background: rgba(139,92,246,0.15); color: var(--video-color); }
.type-badge.image  { background: rgba(6,182,212,0.15);  color: var(--image-color); }
.type-badge.text   { background: rgba(16,185,129,0.15); color: var(--text-color); }
.type-badge.pdf    { background: rgba(245,158,11,0.15); color: var(--pdf-color); }

.doc-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  transition: color 0.15s;
  display: flex; align-items: center;
  flex-shrink: 0;
}
.doc-delete:hover { color: var(--error); }

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

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

.header-left { display: flex; align-items: center; gap: 10px; }
.page-title  { font-size: 16px; font-weight: 600; letter-spacing: -0.3px; }

.model-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 3px 8px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 4px;
  border: 1px solid rgba(99,102,241,0.2);
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: rgba(255,255,255,0.15); }

/* ─── Messages ──────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Welcome Card */
.welcome-card {
  max-width: 480px;
  margin: auto;
  text-align: center;
  padding: 40px 32px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(10px);
}

.welcome-icon {
  font-size: 40px;
  color: var(--accent);
  margin-bottom: 16px;
  display: block;
}

.welcome-card h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 10px;
  letter-spacing: -0.3px;
}

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

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
}

.chip {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-sans);
}
.chip:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--text-primary);
}

/* Message bubbles */
.message {
  display: flex;
  gap: 12px;
  max-width: 720px;
  animation: fadeUp 0.25s ease;
}

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

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.message.user .avatar {
  background: linear-gradient(135deg, var(--accent), #8B5CF6);
  color: white;
}

.message.assistant .avatar {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  color: var(--accent);
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.7;
  max-width: calc(100% - 44px);
}

.message.user .bubble {
  background: linear-gradient(135deg, var(--accent), #7C3AED);
  color: white;
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
}

.message.assistant .bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  backdrop-filter: blur(10px);
}

.bubble-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.sources-btn {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-surface-2);
  color: var(--accent);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
  display: flex; align-items: center; gap: 5px;
}
.sources-btn:hover { background: var(--accent-light); border-color: var(--accent); }

.token-count {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Thinking indicator */
.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 4px 0;
}

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

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

/* ─── Input Area ────────────────────────────────────────────────── */
.input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: linear-gradient(0deg, rgba(10,10,15,0.95), transparent);
  backdrop-filter: blur(10px);
}

.input-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  transition: border-color 0.2s;
}

.input-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.question-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
}

.question-input::placeholder { color: var(--text-muted); }

.input-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.filter-select {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  font-family: var(--font-sans);
}
.filter-select:focus { border-color: var(--border-focus); }

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

.send-btn:hover { background: #5558E8; transform: scale(1.05); }
.send-btn:active { transform: scale(0.98); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  padding-left: 2px;
}

/* ─── Sources Panel ─────────────────────────────────────────────── */
.sources-panel {
  grid-column: 3;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(99,102,241,0.02) 0%, transparent 30%);
  width: 0;
  transition: width 0.3s ease;
}

body.sources-open .sources-panel {
  width: var(--sources-width);
}

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

.sources-header h3 {
  font-size: 14px;
  font-weight: 600;
}

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

.source-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  transition: border-color 0.15s;
}

.source-card:hover { border-color: rgba(255,255,255,0.15); }

.source-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.source-score {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--accent-light);
  padding: 2px 6px;
  border-radius: 4px;
}

.source-file {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  margin-right: 6px;
}

.source-content {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── Toast ─────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  animation: slideIn 0.25s ease, fadeOut 0.3s ease 3s forwards;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 240px;
  max-width: 360px;
}

.toast.success {
  background: rgba(16,185,129,0.15);
  border-color: rgba(16,185,129,0.3);
  color: #34D399;
}

.toast.error {
  background: rgba(239,68,68,0.15);
  border-color: rgba(239,68,68,0.3);
  color: #F87171;
}

.toast.info {
  background: rgba(99,102,241,0.15);
  border-color: rgba(99,102,241,0.3);
  color: #818CF8;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

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

/* ─── Code blocks in messages ───────────────────────────────────── */
.bubble pre {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: var(--font-mono);
  font-size: 12px;
}

.bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(99,102,241,0.15);
  padding: 1px 5px;
  border-radius: 3px;
  color: #A5B4FC;
}

.bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* ─── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar { display: none; }
  .sources-panel { display: none; }
}
