:root {
  --sidebar-bg: #0f172a;
  --sidebar-text: #e2e8f0;
  --sidebar-muted: #94a3b8;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --secondary: #f1f5f9;
  --secondary-text: #334155;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --info: #0891b2;
  --info-light: #cffafe;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
  padding: 0 0.5rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: white;
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--sidebar-muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.nav a, .nav button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  color: var(--sidebar-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.2;
  background: transparent;
  border: none;
  margin: 0;
  width: 100%;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav a:hover, .nav button:hover,
.nav a.active, .nav button.active {
  background: rgba(255,255,255,0.08);
  color: var(--sidebar-text);
}

.nav .icon {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.sidebar-footer {
  padding: 0 0.5rem;
  font-size: 0.75rem;
  color: var(--sidebar-muted);
}

/* Main content */
.main {
  flex: 1;
  margin-left: 260px;
  padding: 2rem;
  max-width: calc(100% - 260px);
}

.container { max-width: 1100px; margin: 0 auto; }

.page-header {
  margin-bottom: 1.75rem;
}

.page-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
}

.page-header p {
  margin: 0;
  color: var(--muted);
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.card-header .actions { display: flex; gap: 0.5rem; }

/* Buttons */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

button:disabled, .button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--secondary); }

/* Forms */
.form-group { margin-bottom: 1.1rem; }

label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
  color: var(--text);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.hint {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

/* Layout utilities */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
@media (max-width: 768px) {
  .sidebar { width: 100%; position: relative; }
  .main { margin-left: 0; max-width: 100%; padding: 1rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .app { flex-direction: column; }
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.badge.running { background: var(--primary-light); color: var(--primary); }
.badge.starting { background: var(--info-light); color: var(--info); }
.badge.waiting_review { background: var(--warning-light); color: var(--warning); }
.badge.completed { background: var(--success-light); color: var(--success); }
.badge.partial { background: var(--purple-light); color: var(--purple); }
.badge.failed { background: var(--danger-light); color: var(--danger); }
.badge.interrupted, .badge.interrupting { background: #ffedd5; color: #ea580c; }

.badge.pulse::before { animation: pulse 1.4s infinite; }
@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
  100% { opacity: 1; transform: scale(1); }
}

/* Alerts */
.alert {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: var(--info-light); color: #155e75; border: 1px solid #a5f3fc; }

.hidden { display: none !important; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.dropzone .icon { font-size: 2rem; margin-bottom: 0.5rem; }

/* Document list */
.doc-list { list-style: none; padding: 0; margin: 0; }
.doc-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.doc-list li:last-child { border-bottom: none; }
.doc-list .doc-meta { color: var(--muted); font-size: 0.8rem; }

/* Timeline */
.timeline {
  display: flex;
  justify-content: space-between;
  position: relative;
  padding: 0;
  margin: 0 0 1.5rem;
  list-style: none;
}
.timeline::before {
  content: "";
  position: absolute;
  top: 14px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border);
  z-index: 0;
}
.timeline-step {
  position: relative;
  z-index: 1;
  text-align: center;
  flex: 1;
  min-width: 80px;
}
.timeline-step .dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--border);
  margin: 0 auto 0.4rem;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  color: var(--muted);
  transition: all 0.3s;
}
.timeline-step.completed .dot {
  background: var(--success);
  border-color: var(--success);
  color: white;
}
.timeline-step.current .dot {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  animation: pulse-dot 1.5s infinite;
}
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(37,99,235,0.4); }
  70% { box-shadow: 0 0 0 8px rgba(37,99,235,0); }
  100% { box-shadow: 0 0 0 0 rgba(37,99,235,0); }
}
.timeline-step .label {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}
.timeline-step.completed .label { color: var(--success); }
.timeline-step.current .label { color: var(--primary); }

/* Parallel research branch count shown under the single research step */
.timeline-step .branch-count {
  font-size: 0.62rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.timeline-step.current .branch-count,
.timeline-step.completed .branch-count {
  color: inherit;
}

/* Claims */
.claims-list { list-style: none; padding: 0; margin: 0; }
.claims-list li {
  padding: 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #fafafa;
}
.claims-list li.fact { border-left-color: var(--success); }
.claims-list li.inference { border-left-color: var(--info); }
.claims-list li.conflict { border-left-color: var(--danger); }
.claims-list li.insufficient_evidence { border-left-color: var(--warning); }
.claim-type {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--secondary);
  margin-bottom: 0.4rem;
}
.claim-statement { margin: 0 0 0.5rem; font-weight: 500; }
.citation {
  margin: 0.35rem 0 0;
  padding: 0.6rem;
  background: white;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  border: 1px solid var(--border);
}
.citation .excerpt { color: var(--text); font-style: italic; }

/* Markdown body */
.markdown-body {
  background: #f8fafc;
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92rem;
  border: 1px solid var(--border);
}

pre {
  background: #f8fafc;
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
  border: 1px solid var(--border);
}

code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.55);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 1rem;
}
.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}
.close-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
}

/* Trace list */
.trace-list { list-style: none; padding: 0; margin: 0; }
.trace-list li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.trace-list li:last-child { border-bottom: none; }
.trace-status { font-weight: 600; font-size: 0.85rem; }
.trace-status.ok { color: var(--success); }
.trace-status.error { color: var(--danger); }

/* Recent runs */
.recent-list { list-style: none; padding: 0; margin: 0; }
.recent-list li {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}
.recent-list li:last-child { border-bottom: none; }
.recent-list a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.recent-list a:hover { text-decoration: underline; }
.recent-list small { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }

/* Section tabs on run page */
.tabs { display: flex; gap: 0.5rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.tab {
  padding: 0.6rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel.hidden { display: none; }
