:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --text-soft: #64748b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.08);
  --sidebar-w: 280px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1e293b;
    --border: #263244;
    --text: #f1f5f9;
    --text-muted: #cbd5e1;
    --text-soft: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: rgba(59, 130, 246, 0.14);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, 0.12);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, 0.12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

/* Boot & Login */
.boot-screen, .login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.login-logo img { width: 40px; height: 40px; border-radius: 10px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 6px 0 20px; color: var(--text-soft); font-size: 14px; }

/* Main Shell */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 30;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
}

.brand img { width: 28px; height: 28px; border-radius: 7px; }

.sidebar-actions {
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-input {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 13px;
}

.task-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.task-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.task-item:hover { background: var(--surface-2); }
.task-item.active {
  background: var(--primary-soft);
  border-color: rgba(29, 78, 216, 0.25);
}

.task-item-title {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-soft);
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

/* Main Content */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.content {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn-danger {
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.25);
  background: var(--danger-soft);
}
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* Cards & Forms */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.banner {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.banner-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: rgba(180, 83, 9, 0.25);
}
.banner-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.25);
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.field input[type="text"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 14px;
}
.field textarea { resize: vertical; min-height: 96px; }
.field-hint { font-size: 12px; color: var(--text-soft); margin-top: 4px; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-running { background: var(--primary-soft); color: var(--primary); }
.badge-completed { background: var(--success-soft); color: var(--success); }
.badge-waiting { background: var(--warn-soft); color: var(--warn); }
.badge-failed { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--text-soft); }

/* Progress */
.progress-bar-track {
  width: 100%;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 14px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  font-size: 13px;
}
.log-row {
  display: flex;
  gap: 8px;
  color: var(--text-muted);
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}
.log-row:last-child { border-bottom: none; }
.log-time { color: var(--text-soft); font-size: 11.5px; flex-shrink: 0; font-variant-numeric: tabular-nums; }

/* Sources */
.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.source-card {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  transition: border-color 0.15s;
}
.source-card:hover { border-color: var(--primary); text-decoration: none; }
.source-card.highlight { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.source-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 4px; }
.source-num { font-weight: 700; font-size: 12px; color: var(--primary); }
.source-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.source-domain { font-size: 11.5px; color: var(--text-soft); margin-top: 4px; }

/* Report Prose */
.prose { font-size: 15px; line-height: 1.78; color: var(--text); }
.prose h1 { font-size: 24px; line-height: 1.3; margin: 0 0 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.prose h2 { font-size: 18.5px; margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 16px; margin: 20px 0 8px; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 14px; padding-left: 22px; }
.prose li { margin-bottom: 6px; }
.prose blockquote {
  margin: 12px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--primary);
  background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
}
.prose pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 13px;
}
.prose code {
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}
.prose pre code { background: none; padding: 0; }
.table-wrap { overflow-x: auto; margin: 14px 0; }
.prose table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.prose th { background: var(--surface-2); font-weight: 600; }

.cite-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 0 4px;
  margin: 0 1px;
  border-radius: 4px;
  background: var(--primary-soft);
  color: var(--primary);
  vertical-align: super;
  line-height: 1.3;
}

/* Followup */
.followup-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.followup-msg {
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.followup-user { background: var(--primary-soft); border-color: rgba(29, 78, 216, 0.2); }
.followup-assistant { background: var(--bg); }
.followup-role { font-size: 12px; font-weight: 700; color: var(--text-soft); margin-bottom: 6px; }

/* Focus & Document lists */
.focus-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  margin-bottom: 12px;
}
.doc-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.doc-pick-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
}
.doc-pick-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-weight: 500;
  cursor: pointer;
  min-width: 0;
  flex: 1;
}
.doc-pick-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-muted);
}

/* Spinner & Toast */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 60;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
}

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 25;
}

/* Mobile Responsive */
@media (max-width: 860px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: 84vw;
    max-width: 310px;
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-backdrop.open { display: block; }
  .content { padding: 16px 14px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
}
