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

:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface2: #f0efe9;
  --border: #e4e2d8;
  --text: #18180f;
  --muted: #72726a;
  --accent: #18180f;
  --accent-inv: #f7f6f2;
  --winner: #0a6647;
  --winner-bg: #dff4ec;
  --winner-border: #1a9e72;
  --danger: #991f1f;
  --danger-bg: #fde8e8;
  --sidebar-w: 260px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  font-size: 15px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1c1c1a;
    --surface2: #232320;
    --border: #2c2c28;
    --text: #ededea;
    --muted: #888880;
    --accent: #ededea;
    --accent-inv: #111110;
    --winner-bg: #052e1e;
    --winner-border: #1a9e72;
    --danger-bg: #2a0d0d;
  }
}

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

/* ── Login ── */
.login-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.login-logo { font-size: 32px; }
.login-title { font-size: 22px; font-weight: 600; letter-spacing: -0.5px; }
.login-sub { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.login-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 15px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  outline: none;
  text-align: center;
  letter-spacing: 0.2em;
}

.login-input:focus { border-color: var(--muted); }

.login-btn {
  width: 100%;
  background: var(--accent);
  color: var(--accent-inv);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  font-family: 'Inter', sans-serif;
}
.login-btn:hover { opacity: 0.85; }

.login-error { font-size: 13px; color: var(--danger); }

/* ── Layout ── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px;
}
.logo-icon { font-size: 18px; }
.logo-text { font-size: 16px; font-weight: 600; letter-spacing: -0.3px; }

.new-btn {
  width: 100%;
  background: var(--accent);
  color: var(--accent-inv);
  border: none;
  border-radius: var(--radius-xs);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  font-family: 'Inter', sans-serif;
}
.new-btn:hover { opacity: 0.8; }

.history-section { flex: 1; overflow-y: auto; padding: 0.75rem 0.75rem; }
.history-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 8px; padding: 0 0.25rem; }
.history-list { display: flex; flex-direction: column; gap: 2px; }
.history-empty { font-size: 13px; color: var(--muted); padding: 0.25rem; }

.history-item {
  background: none;
  border: none;
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
  width: 100%;
}
.history-item:hover { background: var(--surface2); }
.history-item.active { background: var(--surface2); }
.history-item-q {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.history-item-date {
  font-size: 11px;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.settings-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 7px 12px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  width: 100%;
  font-family: 'Inter', sans-serif;
  transition: background 0.1s;
}
.settings-toggle:hover { background: var(--surface2); }

/* ── Main ── */
.main {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
}

/* ── Settings Panel ── */
.settings-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem;
}
.settings-inner { max-width: 700px; margin: 0 auto; }
.settings-title { font-size: 16px; font-weight: 600; margin-bottom: 1.25rem; }

.setting-group { margin-bottom: 1rem; }
.setting-label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.05em; }
.setting-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.setting-input:focus { border-color: var(--muted); }
.mono { font-family: 'JetBrains Mono', monospace; }

.setting-divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

.prompts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.prompt-field textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.5;
}
.prompt-field textarea:focus { border-color: var(--muted); }

.save-settings-btn {
  margin-top: 1rem;
  background: var(--accent);
  color: var(--accent-inv);
  border: none;
  border-radius: var(--radius-xs);
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: opacity 0.15s;
}
.save-settings-btn:hover { opacity: 0.85; }

/* ── Query Area ── */
.query-area {
  flex: 0 0 auto;
  padding: 2rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.query-inner { max-width: 700px; margin: 0 auto; }
.query-title { font-size: 20px; font-weight: 600; letter-spacing: -0.3px; margin-bottom: 1rem; }

.question-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.6;
  margin-bottom: 10px;
}
.question-input:focus { border-color: var(--muted); }

.send-btn {
  background: var(--accent);
  color: var(--accent-inv);
  border: none;
  border-radius: var(--radius-xs);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: opacity 0.15s, transform 0.1s;
}
.send-btn:hover { opacity: 0.85; }
.send-btn:active { transform: scale(0.99); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Progress ── */
.progress-bar {
  height: 2px;
  background: var(--border);
  overflow: hidden;
  flex-shrink: 0;
}
.progress-fill {
  height: 100%;
  background: var(--winner-border);
  width: 0%;
  transition: width 0.4s ease;
}

/* ── Results ── */
.results {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  transition: border-color 0.3s, border-width 0.3s;
}
.result-card.winner { border-color: var(--winner-border); border-width: 2px; }

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

.model-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 500;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%; flex-shrink: 0;
}
.dot.gpt    { background: #10a37f; }
.dot.gemini { background: #4285F4; }
.dot.claude { background: #c9824a; }
.dot.arbiter { background: #7c6fd4; }

.status-chip {
  font-size: 11px; padding: 3px 9px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.status-chip.done { background: var(--winner-bg); color: var(--winner); border-color: var(--winner-border); }
.status-chip.error { background: var(--danger-bg); color: var(--danger); border-color: #f09595; }

.winner-badge {
  font-size: 11px;
  background: var(--winner-bg); color: var(--winner);
  padding: 3px 9px; border-radius: 20px;
  border: 1px solid var(--winner-border);
}

.result-text {
  font-size: 13px; color: var(--muted);
  line-height: 1.7; max-height: 200px;
  overflow-y: auto; white-space: pre-wrap;
}

.arbiter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.arbiter-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px; font-size: 14px;
}
.arbiter-sub { font-size: 12px; color: var(--muted); }
.arbiter-text { font-size: 13px; color: var(--muted); line-height: 1.7; white-space: pre-wrap; }

/* ── Utilities ── */
.hidden { display: none !important; }

/* ── Mobile ── */
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .results-grid { grid-template-columns: 1fr; }
  .query-area, .results { padding: 1rem; }
}

/* ── Sidebar Tabs ── */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 0.5rem;
  gap: 2px;
}
.sidebar-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}
.sidebar-tab:hover { color: var(--text); }
.sidebar-tab.active { color: var(--text); border-bottom-color: var(--text); }

.sidebar-panel {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

/* ── Profile Form ── */
.profile-form { display: flex; flex-direction: column; gap: 10px; }
.profile-field label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.profile-field input,
.profile-field textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color 0.15s;
  resize: vertical;
  line-height: 1.5;
}
.profile-field input:focus,
.profile-field textarea:focus { border-color: var(--muted); }

.profile-save-btn {
  background: var(--accent);
  color: var(--accent-inv);
  border: none;
  border-radius: var(--radius-xs);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: opacity 0.15s;
  width: 100%;
}
.profile-save-btn:hover { opacity: 0.85; }
.profile-saved {
  font-size: 12px;
  color: var(--winner);
  text-align: center;
  margin-top: 2px;
}

/* ── Documents ── */
.docs-form { display: flex; flex-direction: column; gap: 10px; }
.docs-hint { font-size: 12px; color: var(--muted); line-height: 1.5; }

.doc-add-form { display: flex; flex-direction: column; gap: 8px; }
.doc-title-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  outline: none;
}
.doc-title-input:focus { border-color: var(--muted); }
.doc-add-form textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 7px 10px;
  font-size: 12px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  resize: vertical;
  outline: none;
  line-height: 1.5;
}
.doc-add-form textarea:focus { border-color: var(--muted); }

.doc-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  margin-bottom: 6px;
}
.doc-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.doc-item-title { font-size: 13px; font-weight: 500; color: var(--text); }
.doc-delete-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
}
.doc-delete-btn:hover { color: var(--danger); }
.doc-item-preview { font-size: 11px; color: var(--muted); line-height: 1.5; }

/* ── Memory Banner ── */
.memory-banner {
  background: var(--winner-bg);
  border-bottom: 1px solid var(--winner-border);
  padding: 8px 1.5rem;
  font-size: 13px;
  color: var(--winner);
  display: flex;
  align-items: center;
  gap: 8px;
}
.memory-icon { font-size: 14px; }
