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

:root {
  --bg: #080b14;
  --bg2: #0d1120;
  --glass: rgba(255,255,255,0.04);
  --glass-border: rgba(255,255,255,0.08);
  --glass-hover: rgba(255,255,255,0.07);
  --primary: #818cf8;
  --primary-end: #c084fc;
  --primary-glow: rgba(129,140,248,0.25);
  --text: #e2e8f0;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --success: #34d399;
  --error: #f87171;
  --warn: #fbbf24;
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-w: 220px;
  --transition: 0.22s cubic-bezier(.4,0,.2,1);
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ─── Animated BG Orbs ─────────────────────────────────────────── */
.bg-orbs {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.orb {
  position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.18;
  animation: float 14s ease-in-out infinite;
}
.orb-1 { width: 500px; height: 500px; background: #818cf8; top: -150px; left: -100px; animation-delay: 0s; }
.orb-2 { width: 400px; height: 400px; background: #c084fc; bottom: -100px; right: -80px; animation-delay: -5s; }
.orb-3 { width: 300px; height: 300px; background: #38bdf8; top: 40%; left: 40%; animation-delay: -9s; }

@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-30px) scale(1.06); }
}

/* ─── Glass ────────────────────────────────────────────────────── */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* ─── Screens ──────────────────────────────────────────────────── */
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: none; align-items: center; justify-content: center;
}
.screen.active { display: flex; }

/* ─── Auth Card ────────────────────────────────────────────────── */
.auth-card {
  width: 100%; max-width: 420px;
  border-radius: 24px;
  padding: 44px 40px;
  display: flex; flex-direction: column; gap: 20px;
  animation: slideUp 0.5s cubic-bezier(.4,0,.2,1) both;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}

.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 4px;
}
.logo-icon { width: 36px; height: 36px; flex-shrink: 0; }
.logo-icon.small { width: 28px; height: 28px; }
.logo-text {
  font-size: 16px; font-weight: 600;
  background: linear-gradient(135deg, var(--primary), var(--primary-end));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-title { font-size: 26px; font-weight: 700; line-height: 1.2; }
.auth-subtitle { font-size: 14px; color: var(--text-muted); }

/* ─── Inputs ───────────────────────────────────────────────────── */
.input-group { display: flex; flex-direction: column; gap: 7px; }
.input-group label { font-size: 13px; font-weight: 500; color: var(--text-dim); }
.input-group input, .chat-input-wrap input {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit; font-size: 15px;
  padding: 12px 16px; width: 100%;
  outline: none; transition: border-color var(--transition), box-shadow var(--transition);
}
.input-group input:focus, .chat-input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
input::placeholder { color: var(--text-muted); }

/* ─── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 22px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; font-weight: 600;
  border: none; cursor: pointer; transition: all var(--transition);
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-end));
  color: #fff;
  box-shadow: 0 4px 20px var(--primary-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 28px var(--primary-glow); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-full { width: 100%; justify-content: center; }
.btn svg { width: 16px; height: 16px; }
.btn-icon-only {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  padding: 6px; border-radius: 8px; transition: color var(--transition), background var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.btn-icon-only svg { width: 18px; height: 18px; }
.btn-icon-only:hover { color: var(--text); background: var(--glass-hover); }

/* ─── Status / Errors ──────────────────────────────────────────── */
.error-msg {
  color: var(--error); font-size: 13px;
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.2);
  border-radius: 8px; padding: 10px 14px;
}
.auth-footer {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted); margin-top: 4px;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted); transition: background 0.4s;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--error); }
.hidden { display: none !important; }

/* ─── App Layout ───────────────────────────────────────────────── */
#app-screen { display: none; align-items: stretch; }
#app-screen.active { display: flex; }

.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  height: 100vh;
  display: flex; flex-direction: column;
  border-radius: 0; border-top: none; border-bottom: none; border-left: none;
  padding: 24px 16px;
  z-index: 5;
}
.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 24px; border-bottom: 1px solid var(--glass-border);
  margin-bottom: 16px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-family: inherit; font-size: 14px; font-weight: 500;
  transition: all var(--transition); text-align: left; width: 100%;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--glass-hover); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(129,140,248,0.15), rgba(192,132,252,0.1));
  color: var(--primary);
  border: 1px solid rgba(129,140,248,0.2);
}
.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 16px; border-top: 1px solid var(--glass-border);
}
.user-badge { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-end));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; text-transform: uppercase;
}
#user-name-display { font-size: 13px; font-weight: 500; color: var(--text-dim); }

/* ─── Main Content ─────────────────────────────────────────────── */
.main-content {
  flex: 1; height: 100vh; overflow: hidden;
  display: flex; flex-direction: column; position: relative;
}
.tab-panel {
  display: none; flex-direction: column; height: 100%; padding: 32px 36px;
  overflow: hidden;
}
.tab-panel.active { display: flex; }

/* Eval tab scrolls as a whole (not chat — that has its own internal scroll) */
#tab-eval {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--glass-border) transparent;
}
#tab-eval::-webkit-scrollbar { width: 4px; }
#tab-eval::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 4px; }

.panel-header { margin-bottom: 28px; }
.panel-header h2 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.panel-header p { font-size: 14px; color: var(--text-muted); }

/* ─── Chat ─────────────────────────────────────────────────────── */
.chat-container {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  gap: 20px; padding-right: 8px; margin-bottom: 20px;
  scrollbar-width: thin; scrollbar-color: var(--glass-border) transparent;
}
.chat-container::-webkit-scrollbar { width: 4px; }
.chat-container::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 4px; }

.chat-welcome {
  margin: auto; text-align: center;
  color: var(--text-muted); font-size: 15px;
}
.welcome-icon {
  font-size: 36px; margin-bottom: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-end));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  animation: pulse-glow 3s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.4); }
}

.chat-message {
  display: flex; gap: 12px; animation: fadeIn 0.3s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-message.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
.chat-message.user .msg-avatar {
  background: linear-gradient(135deg, var(--primary), var(--primary-end));
  color: #fff;
}
.chat-message.assistant .msg-avatar {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--glass-border);
  color: var(--primary);
  font-size: 14px;
}

.msg-bubble {
  max-width: 70%; padding: 14px 18px; border-radius: 16px;
  font-size: 14px; line-height: 1.65;
}
.chat-message.user .msg-bubble {
  background: linear-gradient(135deg, rgba(129,140,248,0.2), rgba(192,132,252,0.15));
  border: 1px solid rgba(129,140,248,0.2);
  border-top-right-radius: 4px;
}
.chat-message.assistant .msg-bubble {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-top-left-radius: 4px;
}

.typing-indicator {
  display: flex; gap: 5px; align-items: center; padding: 4px 0;
}
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary); opacity: 0.4;
  animation: typing 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 80%, 100% { opacity: 0.4; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.2); }
}

.chat-input-row { flex-shrink: 0; }
.chat-input-wrap {
  display: flex; align-items: center; gap: 10px;
  border-radius: 14px; padding: 6px 6px 6px 16px;
}
.chat-input-wrap input {
  border: none; background: none; padding: 10px 0; flex: 1;
}
.chat-input-wrap input:focus { box-shadow: none; border-color: transparent; }
.btn-send {
  width: 42px; height: 42px; padding: 0; border-radius: 10px;
  flex-shrink: 0; justify-content: center;
}
.btn-attach {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 8px;
  border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.btn-attach svg { width: 18px; height: 18px; }
.btn-attach:hover { color: var(--primary); background: rgba(129,140,248,0.1); }
.btn-attach.uploading { color: var(--primary); animation: pulse-glow 1s infinite; }

.chat-upload-toast {
  margin-bottom: 8px; padding: 10px 16px;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  animation: fadeIn 0.25s ease;
}
.chat-upload-toast.success { background: rgba(52,211,153,0.12); border: 1px solid rgba(52,211,153,0.25); color: var(--success); }
.chat-upload-toast.error-status { background: rgba(248,113,113,0.1); border: 1px solid rgba(248,113,113,0.2); color: var(--error); }
.chat-upload-toast.loading { background: rgba(129,140,248,0.1); border: 1px solid rgba(129,140,248,0.2); color: var(--primary); }

/* ─── Upload ───────────────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--glass-border);
  border-radius: var(--radius);
  padding: 52px 32px;
  text-align: center; cursor: pointer;
  transition: all var(--transition);
  background: var(--glass);
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary);
  background: rgba(129,140,248,0.06);
}
.upload-icon { width: 64px; height: 64px; margin: 0 auto 18px; }
.upload-title { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.upload-sub { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }
.file-types { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip {
  padding: 4px 12px; border-radius: 100px;
  background: rgba(129,140,248,0.1);
  border: 1px solid rgba(129,140,248,0.2);
  font-size: 12px; font-weight: 600; color: var(--primary);
  letter-spacing: 0.5px;
}

.upload-status {
  margin-top: 16px; padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
}
.upload-status.success {
  background: rgba(52,211,153,0.1);
  border: 1px solid rgba(52,211,153,0.2);
  color: var(--success);
}
.upload-status.error-status {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.2);
  color: var(--error);
}

.file-preview {
  margin-top: 20px; border-radius: var(--radius);
  padding: 18px 22px;
  display: flex; align-items: center; gap: 16px;
}
.file-icon-wrap {
  width: 44px; height: 44px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(129,140,248,0.2), rgba(192,132,252,0.15));
  border: 1px solid rgba(129,140,248,0.2);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); flex-shrink: 0;
}
.file-icon-wrap svg { width: 22px; height: 22px; }
.file-info { flex: 1; min-width: 0; }
.file-name { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { display: block; font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ─── Evaluation ───────────────────────────────────────────────── */
.eval-trigger {
  border-radius: var(--radius);
  padding: 24px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  margin-bottom: 28px;
}
.eval-trigger-info h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.eval-trigger-info p { font-size: 13px; color: var(--text-muted); }

.eval-loading {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  padding: 48px; color: var(--text-muted); font-size: 14px;
}
.pulse-ring {
  width: 56px; height: 56px; border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--primary);
  border-right-color: var(--primary-end);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.eval-results { flex: 1; overflow-y: auto; }

.eval-summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  margin-bottom: 28px;
}
.metric-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius); padding: 22px 20px;
  text-align: center;
  animation: fadeIn 0.4s ease both;
}
.metric-card:nth-child(2) { animation-delay: 0.08s; }
.metric-card:nth-child(3) { animation-delay: 0.16s; }
.metric-label { font-size: 12px; color: var(--text-muted); font-weight: 500; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.6px; }
.metric-value {
  font-size: 36px; font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-end));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.metric-bar {
  margin-top: 12px; height: 4px; background: rgba(255,255,255,0.06);
  border-radius: 4px; overflow: hidden;
}
.metric-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-end));
  border-radius: 4px; transition: width 0.8s cubic-bezier(.4,0,.2,1);
}

.eval-rows { display: flex; flex-direction: column; gap: 12px; }
.eval-row {
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius); padding: 20px 24px;
  animation: fadeIn 0.3s ease both;
  display: flex; flex-direction: column; gap: 16px;
}

/* ── Per-field inside each eval row ──────────── */
.eval-field { display: flex; flex-direction: column; gap: 6px; }

.eval-field-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--text-muted);
}
.eval-field-label svg { width: 13px; height: 13px; }

.eval-field-value {
  font-size: 14px; line-height: 1.65; color: var(--text);
  white-space: pre-wrap; margin: 0;
}
.eval-field-value.answer-text {
  background: rgba(129,140,248,0.05);
  border: 1px solid rgba(129,140,248,0.12);
  border-radius: 8px; padding: 10px 14px;
}

/* ── Context chunks ───────────────────────────── */
.ctx-list { display: flex; flex-direction: column; gap: 8px; }

.ctx-chunk {
  display: flex; gap: 10px; align-items: flex-start;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--glass-border);
  border-radius: 8px; padding: 10px 12px;
}
.ctx-idx {
  font-size: 11px; font-weight: 700; color: var(--primary);
  font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0; padding-top: 1px;
}
.ctx-text {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; line-height: 1.6; color: var(--text-dim);
  white-space: pre-wrap; word-break: break-word; margin: 0; flex: 1;
}
.ctx-empty { font-size: 13px; color: var(--text-muted); font-style: italic; margin: 0; }
.eval-row-q { font-size: 14px; font-weight: 600; margin-bottom: 10px; color: var(--text); }
.eval-row-scores {
  display: flex; gap: 14px; flex-wrap: wrap;
}
.score-badge {
  padding: 4px 12px; border-radius: 100px;
  font-size: 12px; font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}
.score-badge.good { background: rgba(52,211,153,0.1); color: var(--success); border: 1px solid rgba(52,211,153,0.2); }
.score-badge.mid  { background: rgba(251,191,36,0.1); color: var(--warn); border: 1px solid rgba(251,191,36,0.2); }
.score-badge.bad  { background: rgba(248,113,113,0.1); color: var(--error); border: 1px solid rgba(248,113,113,0.2); }
.score-badge.null-score { background: rgba(100,116,139,0.1); color: var(--text-muted); border: 1px solid rgba(100,116,139,0.2); }

.eval-meta { font-size: 12px; color: var(--text-muted); margin-top: 20px; font-family: 'JetBrains Mono', monospace; }

/* ─── Eval History ─────────────────────────────────────────────── */
.eval-history {
  display: flex; flex-direction: column; gap: 12px;
}
.eval-history::-webkit-scrollbar { width: 4px; }
.eval-history::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 4px; }

.eval-run {
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius); overflow: hidden;
  animation: fadeIn 0.3s ease both;
}
.eval-run-latest { border-color: rgba(129,140,248,0.3); box-shadow: 0 0 0 1px rgba(129,140,248,0.1); }

.eval-run-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; cursor: pointer; transition: background var(--transition);
}
.eval-run-header:hover { background: var(--glass-hover); }
.eval-run-meta { display: flex; align-items: center; gap: 10px; }

.run-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px;
  padding: 3px 9px; border-radius: 100px;
  background: linear-gradient(135deg, rgba(129,140,248,0.2), rgba(192,132,252,0.15));
  border: 1px solid rgba(129,140,248,0.3); color: var(--primary);
}
.run-time { font-size: 13px; font-weight: 500; color: var(--text-dim); }
.run-count { font-size: 12px; color: var(--text-muted); }

.run-chevron { width: 18px; height: 18px; color: var(--text-muted); flex-shrink: 0; }
.eval-run-body { padding: 0 20px 20px; }
