:root {
  --bg: #0f1117;
  --bg-panel: #161b27;
  --bg-card: #1e2536;
  --bg-hover: #242d42;
  --border: #2a3348;
  --text: #e4e8f0;
  --text-muted: #7b8aa0;
  --accent: #4f8ef7;
  --accent-dim: #1e3460;
  --success: #22c55e;
  --warn: #f59e0b;
  --error: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
}
.header-actions { display: flex; align-items: center; gap: 14px; }

.branch-link {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: color .15s, border-color .15s;
}
.branch-link:hover { color: var(--text); border-color: var(--accent); }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%,100% { opacity: 1; } 50% { opacity: 0.4; }
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
button:hover { opacity: .88; }
button:active { transform: scale(.97); }
button.icon-btn {
  background: transparent;
  color: var(--text-muted);
  padding: 4px 8px;
  font-size: 16px;
}
button.icon-btn:hover { color: var(--text); }

/* Layout */
main {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 24px;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

/* Panel shared */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.panel-header h2 { font-size: 15px; font-weight: 600; }

.badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Job list */
.job-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.job-card:hover { border-color: var(--accent); background: var(--bg-hover); }
.job-card.active { border-color: var(--accent); background: var(--accent-dim); }

.job-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.job-card-id {
  font-size: 12px;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}
.job-card-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Status pill */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.pill.QUERYING   { background: #1c2d52; color: #7eb5ff; }
.pill.CHUNKING   { background: #2a2215; color: var(--warn); }
.pill.CONFIRMING { background: #1a2840; color: #60c4f8; }
.pill.COMPLETE   { background: #152318; color: var(--success); }
.pill.ERROR      { background: #2d1414; color: var(--error); }
.pill.active::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

/* Detail panel */
#job-detail-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.job-id-label {
  font-size: 11px;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--text-muted);
}

/* Pipeline */
.pipeline-section {
  margin: 20px 0;
  overflow-x: auto;
}
.pipeline {
  display: flex;
  align-items: center;
  min-width: 480px;
}
.pipeline-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: .3;
  transition: opacity .3s;
}
.pipeline-stage.done   { opacity: .7; }
.pipeline-stage.active { opacity: 1; }
.pipeline-stage.error  { opacity: 1; }

.stage-node {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: border-color .3s, box-shadow .3s;
}
.pipeline-stage.done  .stage-node { border-color: var(--success); }
.pipeline-stage.active .stage-node {
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(79,142,247,.4);
  animation: pulse-ring 1.5s ease-in-out infinite;
}
.pipeline-stage.error .stage-node { border-color: var(--error); }

@keyframes pulse-ring {
  0%,100% { box-shadow: 0 0 12px rgba(79,142,247,.3); }
  50%      { box-shadow: 0 0 28px rgba(79,142,247,.7); }
}

.stage-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
.pipeline-stage.active .stage-label { color: var(--text); }
.pipeline-stage.done   .stage-label { color: var(--success); }
.pipeline-stage.error  .stage-label { color: var(--error); }

.stage-duration {
  font-size: 11px;
  color: var(--text-muted);
  font-family: "SF Mono", "Fira Code", monospace;
  min-height: 16px;
}

.pipeline-arrow {
  color: var(--border);
  font-size: 18px;
  padding: 0 4px;
  margin-bottom: 26px;
  flex-shrink: 0;
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 2px;
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* Progress bar */
#progress-section { margin-bottom: 20px; }
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.progress-bar {
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #7cc4ff);
  border-radius: 3px;
  transition: width .4s ease;
  width: 0%;
}

/* Chunks table */
.chunks-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
}
.chunks-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.chunks-table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.chunks-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.chunks-table tr:last-child td { border-bottom: none; }
.chunks-table tr:hover td { background: var(--bg-hover); }
.chunks-table .path-cell {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 11px;
  color: var(--text-muted);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Empty / loading */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 13px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  z-index: 999;
  transition: opacity .2s;
}
.toast.hidden { opacity: 0; pointer-events: none; }
.toast.error { border-color: var(--error); color: var(--error); }

/* Tab bar */
.tab-bar {
  display: flex;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 56px;
  z-index: 90;
}
.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); opacity: 1; transform: none; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Tab panes */
.tab-pane { display: block; }

/* Scheduler panel */
.scheduler-panel {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}
.text-muted { color: var(--text-muted); font-size: 12px; }

/* Scheduler state colors */
.state-enabled { color: var(--success); font-weight: 600; }
.state-disabled { color: var(--text-muted); }

.hidden { display: none !important; }
