/* ============================================================
   GenAI Chat - Dark Theme Styles
   ============================================================ */

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #16213e;
  --bg-input: #1e1e3a;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b8;
  --text-muted: #6c6c80;
  --accent: #4a6cf7;
  --accent-hover: #5b7bf8;
  --user-bubble: #2a3a6e;
  --assistant-bubble: #1e1e32;
  --error-color: #f44336;
  --success-color: #4caf50;
  --border-color: #2a2a44;
  --scrollbar-track: #1a1a2e;
  --scrollbar-thumb: #3a3a5e;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ============================================================
   Login Screen
   ============================================================ */
.screen { height: 100vh; }

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-tertiary) 100%);
}

.login-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  margin: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-header h1 {
  font-size: 28px;
  margin-bottom: 8px;
}

.login-header p {
  color: var(--text-secondary);
  font-size: 14px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 15px;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.error-message {
  margin-top: 16px;
  padding: 10px 14px;
  background: rgba(244, 67, 54, 0.1);
  border: 1px solid rgba(244, 67, 54, 0.3);
  border-radius: 8px;
  color: var(--error-color);
  font-size: 13px;
  text-align: center;
}

/* ============================================================
   Chat Screen
   ============================================================ */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.header-left h1 {
  font-size: 18px;
  font-weight: 600;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

#model-selector {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}

#model-selector:focus { outline: none; border-color: var(--accent); }

.btn-icon {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-icon:hover { background: var(--bg-tertiary); }

/* System Prompt */
.system-prompt-container {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.system-prompt-toggle {
  width: 100%;
  padding: 8px 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
}

.system-prompt-toggle:hover { color: var(--text-secondary); }
.toggle-arrow { font-size: 10px; transition: transform 0.2s; }
.toggle-arrow.open { transform: rotate(90deg); }

.system-prompt-panel { padding: 0 20px 12px; }

#system-prompt {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  resize: vertical;
  font-family: inherit;
}

#system-prompt:focus { outline: none; border-color: var(--accent); }

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

.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}

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

.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.message.error { align-self: center; }

.message-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.message.error .message-bubble {
  background: rgba(244, 67, 54, 0.1);
  border: 1px solid rgba(244, 67, 54, 0.3);
  color: var(--error-color);
  font-size: 13px;
}

.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

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

/* Markdown content inside assistant bubbles */
.message-bubble h1, .message-bubble h2, .message-bubble h3,
.message-bubble h4, .message-bubble h5, .message-bubble h6 {
  margin: 12px 0 6px;
  color: var(--text-primary);
}

.message-bubble h1 { font-size: 1.3em; }
.message-bubble h2 { font-size: 1.2em; }
.message-bubble h3 { font-size: 1.1em; }

.message-bubble p { margin: 6px 0; }

.message-bubble ul, .message-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}

.message-bubble code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.9em;
}

.message-bubble pre {
  margin: 8px 0;
  border-radius: 8px;
  overflow-x: auto;
}

.message-bubble pre code {
  display: block;
  padding: 12px 16px;
  background: #0d1117;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.message-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.message-bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
}

.message-bubble th, .message-bubble td {
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  font-size: 13px;
}

.message-bubble th {
  background: var(--bg-tertiary);
}

/* Loading */
.loading-indicator {
  display: flex;
  gap: 6px;
  padding: 16px;
  align-self: flex-start;
}

.loading-dot {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }

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

/* Input */
.input-container {
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

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

.input-wrapper:focus-within { border-color: var(--accent); }

#chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
}

#chat-input:focus { outline: none; }

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

.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   Responsive
   ============================================================ */

/* ============================================================
   Header Tabs
   ============================================================ */
.header-tabs {
  display: flex;
  gap: 4px;
  margin-left: 16px;
}

.header-tab {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.header-tab:hover { color: var(--text-secondary); }
.header-tab.active {
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

/* ============================================================
   Evaluations View
   ============================================================ */
.eval-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.eval-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.eval-run-btn {
  width: auto;
  padding: 10px 20px;
}

.eval-status {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

.eval-status.running { border-color: var(--accent); color: var(--accent); }
.eval-status.error { border-color: var(--error-color); color: var(--error-color); }

/* Eval list */
.eval-list { display: flex; flex-direction: column; gap: 8px; }

.eval-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.eval-card:hover { border-color: var(--accent); }

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

.eval-card-id { font-weight: 600; font-size: 14px; }

.eval-card-status {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.eval-card-status.complete { background: rgba(76, 175, 80, 0.15); color: var(--success-color); }
.eval-card-status.running { background: rgba(74, 108, 247, 0.15); color: var(--accent); }
.eval-card-status.partial { background: rgba(255, 193, 7, 0.15); color: #ffc107; }

.eval-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.eval-card-scores {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.eval-model-score {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  font-size: 12px;
}

.eval-model-score .model-name { color: var(--text-secondary); }
.eval-model-score .score-val { font-weight: 600; }

/* Eval detail */
.eval-detail {
  flex: 1;
  overflow-y: auto;
}

.eval-back-btn {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 16px;
}

.eval-back-btn:hover { color: var(--text-primary); border-color: var(--accent); }

/* Score table */
.eval-score-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 13px;
}

.eval-score-table th,
.eval-score-table td {
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  text-align: center;
}

.eval-score-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.eval-score-table td:first-child {
  text-align: left;
  font-weight: 500;
}

.score-cell { font-weight: 600; border-radius: 4px; }
.score-1, .score-2 { color: #f44336; }
.score-3 { color: #ffc107; }
.score-4, .score-5 { color: #4caf50; }

/* Leaderboard */
.eval-leaderboard {
  margin-bottom: 20px;
}

.eval-section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: 6px;
}

.leaderboard-rank {
  font-size: 18px;
  font-weight: 700;
  width: 30px;
  text-align: center;
}

.leaderboard-rank.gold { color: #ffd700; }
.leaderboard-rank.silver { color: #c0c0c0; }
.leaderboard-rank.bronze { color: #cd7f32; }

.leaderboard-model { flex: 1; font-weight: 500; }

.leaderboard-score {
  font-size: 18px;
  font-weight: 700;
}

/* Performance bars */
.eval-perf-section { margin-bottom: 20px; }

.perf-bar-container {
  margin-bottom: 8px;
}

.perf-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.perf-bar-track {
  height: 20px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}

.perf-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s;
}

.perf-bar-fill.cost { background: #ff9800; }

/* Test case details */
.eval-testcase-section { margin-bottom: 20px; }

.testcase-group {
  margin-bottom: 12px;
}

.testcase-group-header {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.testcase-group-header:hover { background: var(--bg-input); }

.testcase-items {
  display: none;
  padding: 8px 0;
}

.testcase-items.open { display: block; }

.testcase-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}

.testcase-prompt {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.testcase-rubric {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-style: italic;
}

.testcase-responses {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.testcase-response {
  padding: 8px 10px;
  background: var(--bg-input);
  border-radius: 6px;
  font-size: 12px;
}

.testcase-response-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.testcase-response-model { font-weight: 600; color: var(--text-secondary); }
.testcase-response-text {
  color: var(--text-primary);
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 100px;
  overflow-y: auto;
}

.testcase-judge {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 600px) {
  .message { max-width: 90%; }
  .chat-header { padding: 10px 12px; }
  .header-left h1 { font-size: 15px; }
  #model-selector { font-size: 12px; padding: 6px 8px; }
  .messages-container { padding: 12px; }
  .input-container { padding: 10px 12px; }
  .login-container { padding: 24px; }
}
