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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #222633;
  --border: #2a2e3d;
  --text: #e0e0e6;
  --text-dim: #8888a0;
  --accent: #6c8cff;
  --accent-dim: #3d5099;
  --green: #4caf7c;
  --yellow: #e0a830;
  --red: #d45050;
  --orange: #d48040;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- Header ---- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.header-link {
  color: inherit;
  text-decoration: none;
}

.header-link:hover {
  color: var(--accent);
}

#header-stats {
  display: flex;
  gap: 12px;
  align-items: center;
}

.stat-badge {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.stat-badge.dim {
  color: var(--text-dim);
}

/* ---- Pages ---- */

.page {
  min-height: calc(100vh - 57px);
}

.page.hidden {
  display: none;
}

/* ---- Homepage ---- */

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  padding: 40px 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.home-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, transform 0.15s;
}

.home-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.home-card-icon {
  font-size: 32px;
  margin-bottom: 16px;
  line-height: 1;
}

.home-card-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.home-card-desc {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 16px;
  flex: 1;
}

.home-card-stats {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
}

.home-card-stats span {
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
}

/* ---- Activity page ---- */

main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 16px;
  padding: 20px 24px;
  max-width: 1600px;
  margin: 0 auto;
  height: calc(100vh - 57px);
}

#instances-panel {
  grid-column: 1;
  grid-row: 1 / 3;
  overflow-y: auto;
}

#concerns-panel {
  grid-column: 2;
  grid-row: 1;
  overflow-y: auto;
}

#history-panel {
  grid-column: 2;
  grid-row: 2;
  overflow-y: auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.panel h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
}

/* ---- Instance cards ---- */

.instance-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s;
}

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

.instance-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.instance-name {
  font-weight: 600;
  font-size: 14px;
}

.instance-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.status-connected {
  background: rgba(76, 175, 124, 0.15);
  color: var(--green);
}

.status-disconnected {
  background: rgba(212, 80, 80, 0.15);
  color: var(--red);
}

.instance-meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.persona-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.persona-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-dim);
  border-radius: 6px;
  padding: 10px 12px;
}

.persona-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 4px;
}

.persona-description {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.4;
}

.persona-background {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
  line-height: 1.4;
}

.persona-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.expertise-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--border);
  color: var(--text-dim);
}

/* ---- Activity section ---- */

.activity-section {
  margin-top: 8px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.activity-line {
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.6;
  transition: opacity 0.3s;
}

.activity-line.stale {
  opacity: 0.4;
}

.activity-icon {
  margin-right: 4px;
}

.activity-tool {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(108, 140, 255, 0.12);
  color: var(--accent);
  font-weight: 500;
  margin-right: 4px;
}

.load-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.load-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

/* ---- Concern cards ---- */

.concern-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s;
}

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

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

.concern-id {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-dim);
}

.persona-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(108, 140, 255, 0.12);
  color: var(--accent);
  font-weight: 500;
  margin-left: 4px;
}

.concern-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.status-pending { background: rgba(224, 168, 48, 0.15); color: var(--yellow); }
.status-assigned { background: rgba(108, 140, 255, 0.15); color: var(--accent); }
.status-in_progress { background: rgba(212, 128, 64, 0.15); color: var(--orange); }
.status-responded { background: rgba(76, 175, 124, 0.15); color: var(--green); }
.status-closed { background: rgba(76, 175, 124, 0.1); color: var(--green); }
.status-failed { background: rgba(212, 80, 80, 0.15); color: var(--red); }
.status-timeout { background: rgba(212, 80, 80, 0.1); color: var(--red); }

.concern-task {
  font-size: 13px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.concern-meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  gap: 12px;
}

.concern-tags {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}

/* ---- Buttons ---- */

.btn {
  font-size: 13px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent-dim);
}

.btn-sm {
  font-size: 12px;
  padding: 4px 10px;
}

.btn-xs {
  font-size: 11px;
  padding: 2px 8px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: #5a7ae6;
  border-color: #5a7ae6;
}

.btn-warning {
  background: var(--yellow);
  border-color: var(--yellow);
  color: #000;
}

.btn-danger {
  background: transparent;
  border-color: var(--red);
  color: var(--red);
}

.btn-danger:hover {
  background: rgba(212, 80, 80, 0.15);
}

/* ---- Swarm layout ---- */

.swarm-layout {
  display: flex;
  height: calc(100vh - 57px);
}

#swarm-sidebar {
  width: 280px;
  min-width: 280px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#swarm-project-list,
#swarm-swarm-list {
  border-bottom: 1px solid var(--border);
  padding: 0;
}

.swarm-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
}

.swarm-list-header h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
}

.swarm-list-item {
  padding: 10px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}

.swarm-list-item:hover {
  background: var(--surface-hover);
}

.swarm-list-item.active {
  background: var(--bg);
  border-left-color: var(--accent);
}

.swarm-list-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.swarm-list-item-name {
  font-size: 13px;
  font-weight: 600;
}

.swarm-list-item-desc {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#swarm-main {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.swarm-empty-main {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

/* ---- Swarm status badges ---- */

.swarm-status-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.status-swarm-draft { background: rgba(136, 136, 160, 0.15); color: var(--text-dim); }
.status-swarm-decomposing { background: rgba(108, 140, 255, 0.15); color: var(--accent); }
.status-swarm-ready { background: rgba(224, 168, 48, 0.15); color: var(--yellow); }
.status-swarm-running { background: rgba(108, 140, 255, 0.15); color: var(--accent); }
.status-swarm-paused { background: rgba(224, 168, 48, 0.15); color: var(--yellow); }
.status-swarm-completed { background: rgba(76, 175, 124, 0.15); color: var(--green); }
.status-swarm-failed { background: rgba(212, 80, 80, 0.15); color: var(--red); }
.status-swarm-cancelled { background: rgba(136, 136, 160, 0.15); color: var(--text-dim); }

.status-task-queued { background: rgba(136, 136, 160, 0.15); color: var(--text-dim); }
.status-task-waiting { background: rgba(224, 168, 48, 0.15); color: var(--yellow); }
.status-task-running { background: rgba(108, 140, 255, 0.15); color: var(--accent); }
.status-task-completed { background: rgba(76, 175, 124, 0.15); color: var(--green); }
.status-task-failed { background: rgba(212, 80, 80, 0.15); color: var(--red); }
.status-task-retrying { background: rgba(212, 128, 64, 0.15); color: var(--orange); }
.status-task-paused { background: rgba(224, 168, 48, 0.15); color: var(--yellow); }
.status-task-skipped { background: rgba(136, 136, 160, 0.1); color: var(--text-dim); }

/* ---- Swarm detail ---- */

.swarm-detail {
  padding: 20px 24px;
}

/* ---- Swarm header row ---- */

.swarm-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.swarm-detail-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.swarm-detail-info h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

/* ---- Command centre (actions + prompt side by side) ---- */

.swarm-command-centre {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  min-height: 120px;
  max-height: 45vh;
}

/* Left panel: actions/buttons — 30% width */
.swarm-actions-panel {
  flex: 0 0 30%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.swarm-actions-panel .action-group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin: 0 0 2px 0;
}

.swarm-actions-panel .action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  width: 100%;
  text-align: left;
}

.swarm-actions-panel .action-btn:hover:not(:disabled) {
  background: var(--hover);
  border-color: var(--accent-dim);
  transform: translateY(-1px);
}

.swarm-actions-panel .action-btn:active:not(:disabled) {
  transform: translateY(0);
}

.swarm-actions-panel .action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.swarm-actions-panel .action-btn .action-icon {
  font-size: 20px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.swarm-actions-panel .action-btn .action-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.swarm-actions-panel .action-btn .action-label small {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
}

.swarm-actions-panel .action-btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.swarm-actions-panel .action-btn-primary:hover:not(:disabled) {
  background: var(--accent-hover, #3b82f6);
  border-color: var(--accent-hover, #3b82f6);
}

.swarm-actions-panel .action-btn-danger {
  border-color: var(--red);
  color: var(--red);
}

.swarm-actions-panel .action-btn-danger:hover:not(:disabled) {
  background: var(--red);
  color: #fff;
}

.swarm-actions-panel .action-btn-success {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.swarm-actions-panel .action-btn-success:hover:not(:disabled) {
  filter: brightness(1.1);
}

.swarm-actions-panel .action-btn-warning {
  border-color: var(--yellow, #eab308);
  color: var(--yellow, #eab308);
}

.swarm-actions-panel .action-btn-warning:hover:not(:disabled) {
  background: var(--yellow, #eab308);
  color: #000;
}

.swarm-actions-panel .model-select-row {
  margin-top: auto;
}

.swarm-actions-panel .model-select-row select {
  width: 100%;
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

/* Right panel: prompt + rephrased — 70% width */
.swarm-prompt-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  overflow-y: auto;
}

.swarm-prompt-original {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.swarm-prompt-original .prompt-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.swarm-prompt-rephrased {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
  flex: 1;
  overflow-y: auto;
}

.swarm-prompt-rephrased .prompt-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  margin-bottom: 6px;
}

.swarm-detail-reasoning {
  font-size: 12px;
  color: var(--text-dim);
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-dim);
}

/* ---- Pipeline steps (compact horizontal) ---- */

.pipeline-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 12px;
}

.pipeline-step {
  display: flex;
  align-items: center;
  gap: 5px;
}

.pipeline-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s, color 0.3s;
}

.pipeline-step.done .pipeline-step-num {
  background: var(--green);
  color: #fff;
}

.pipeline-step.active .pipeline-step-num {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.pipeline-step-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.pipeline-step.done .pipeline-step-label {
  color: var(--text);
}

.pipeline-step.active .pipeline-step-label {
  color: var(--accent);
  font-weight: 600;
}

.pipeline-arrow {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0 6px;
  opacity: 0.5;
}

/* Legacy classes kept for backward compat */
.swarm-detail-task {
  display: none;
}

.swarm-detail-rephrased {
  display: none;
}

.swarm-detail-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.stat-pill {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.stat-completed { color: var(--green); }
.stat-running { color: var(--accent); }
.stat-failed { color: var(--red); }
.stat-queued { color: var(--text-dim); }

/* ---- Swarm tabs ---- */

.swarm-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.swarm-tab {
  font-size: 13px;
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
}

.swarm-tab:hover {
  color: var(--text);
}

.swarm-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.swarm-tab-content {
  display: none;
}

.swarm-tab-content.active {
  display: block;
}

/* ---- DAG canvas ---- */

.dag-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#dag-canvas {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---- Task list ---- */

.task-list-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}

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

.task-list-name {
  font-weight: 600;
  font-size: 14px;
}

.task-list-desc {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
}

.task-deps {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.task-persona {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 4px;
}

.task-error {
  font-size: 12px;
  color: var(--red);
  margin-bottom: 4px;
}

.task-list-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

/* ---- Task execution info ---- */

.task-exec-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin: 4px 0;
  padding: 6px 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.03);
}

.task-exec-running {
  border-left: 3px solid var(--accent);
}

.task-exec-completed {
  border-left: 3px solid var(--green);
}

.task-exec-retrying {
  border-left: 3px solid var(--orange);
}

.task-exec-failed {
  border-left: 3px solid var(--red);
}

.task-exec-pulse {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: exec-pulse 1.5s ease-in-out infinite;
}

@keyframes exec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.task-exec-instance {
  font-weight: 600;
  color: var(--text);
}

.task-exec-persona {
  color: var(--accent);
}

.task-exec-elapsed {
  color: var(--text-dim);
}

.task-exec-concern {
  color: var(--text-dim);
  font-family: monospace;
  font-size: 11px;
}

.task-exec-retry-count {
  font-weight: 600;
  color: var(--orange);
}

.task-output-preview {
  width: 100%;
  margin-top: 4px;
  padding: 6px 8px;
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 100px;
  overflow: hidden;
}

/* ---- Swarm progress bar ---- */

.swarm-progress-bar {
  display: flex;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
  margin: 4px 0 8px;
}

.swarm-progress-fill {
  height: 100%;
  transition: width 0.5s ease;
}

.swarm-progress-completed { background: var(--green); }
.swarm-progress-running { background: var(--accent); }
.swarm-progress-failed { background: var(--red); }

.task-list-item.task-status-running {
  border-color: var(--accent);
}

.task-list-item.task-status-completed {
  border-color: var(--green);
  opacity: 0.85;
}

.task-list-item.task-status-failed {
  border-color: var(--red);
}

.task-list-item.task-status-pending_approval {
  border-color: var(--orange);
  background: rgba(232, 176, 32, 0.05);
}

/* ---- Error policy badge ---- */

.error-policy-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
  text-transform: capitalize;
}

.policy-fail_fast {
  background: rgba(212, 80, 80, 0.15);
  color: var(--red);
}

.policy-continue_on_error {
  background: rgba(212, 128, 64, 0.15);
  color: var(--orange);
}

.policy-manual_review {
  background: rgba(108, 140, 255, 0.15);
  color: var(--accent);
}

.agent-mode-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.mode-connected {
  background: rgba(100, 160, 100, 0.15);
  color: var(--green);
}

.mode-designed {
  background: rgba(168, 108, 255, 0.15);
  color: #a86cff;
}

/* Agent mode toggle in actions panel */
.agent-mode-toggle-row {
  margin-top: 4px;
}

.agent-mode-toggle {
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
}

.agent-mode-opt {
  flex: 1;
  padding: 7px 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.agent-mode-opt:first-child {
  border-right: 1px solid var(--border);
}

.agent-mode-opt:hover:not(.active) {
  background: rgba(255,255,255,0.04);
  color: var(--text-primary);
}

.agent-mode-opt.active {
  background: rgba(108, 140, 255, 0.15);
  color: var(--accent);
  cursor: default;
}

.agent-mode-opt:first-child.active {
  background: rgba(100, 160, 100, 0.15);
  color: var(--green);
}

.agent-mode-opt:last-child.active {
  background: rgba(168, 108, 255, 0.15);
  color: #a86cff;
}

/* ---- Agent spec card (task detail) ---- */

.agent-spec-card {
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid #a86cff;
  border-radius: 6px;
  margin-top: 6px;
}

.agent-spec-name {
  font-weight: 600;
  font-size: 14px;
  color: #a86cff;
  margin-bottom: 4px;
}

.agent-spec-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.agent-spec-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.agent-spec-tag {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 10px;
  background: rgba(168, 108, 255, 0.12);
  color: #a86cff;
}

.agent-spec-model {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.agent-spec-model code {
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}

.agent-spec-instructions {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 4px;
  line-height: 1.4;
}

/* ---- Pending approval ---- */

.status-task-pending_approval {
  background: rgba(232, 176, 32, 0.15);
  color: #e8b020;
}

.btn-approve {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.btn-approve:hover {
  background: #3d9a6b;
}

.task-exec-pending-approval {
  border-left: 3px solid var(--orange);
}

.task-exec-approval-icon {
  font-size: 16px;
}

.task-exec-gate-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(232, 176, 32, 0.2);
  color: #e8b020;
  font-weight: 600;
}

.stat-pending-approval {
  color: #e8b020;
}

/* ---- Task detail modal ---- */

.task-detail-modal {
  max-height: 70vh;
  overflow-y: auto;
}

.task-detail-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.task-detail-section {
  margin-bottom: 10px;
  font-size: 13px;
}

.task-detail-section strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.task-detail-desc {
  white-space: pre-wrap;
  color: var(--text-dim);
  font-size: 13px;
}

.task-detail-json {
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
  padding: 8px;
  font-size: 11px;
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.task-detail-response {
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  padding: 12px;
  max-height: 400px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.6;
}

.task-detail-input-block {
  margin-bottom: 8px;
  padding: 8px;
  background: rgba(0,0,0,0.15);
  border-radius: 4px;
}

.task-detail-input-block .md-label {
  margin-bottom: 6px;
}

.task-detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.form-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* ---- Checkpoints ---- */

.checkpoint-toolbar {
  margin-bottom: 12px;
}

.checkpoint-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.02);
}

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

.checkpoint-label {
  font-weight: 600;
  font-size: 13px;
}

.checkpoint-time {
  font-size: 12px;
  color: var(--text-dim);
}

.checkpoint-info {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.checkpoint-actions {
  display: flex;
  gap: 6px;
}

/* ---- Audit log ---- */

.audit-entry {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.audit-type {
  font-weight: 600;
  color: var(--accent);
}

.audit-time {
  color: var(--text-dim);
}

.audit-task {
  font-family: monospace;
  font-size: 11px;
  color: var(--text-dim);
}

.audit-details {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audit-actor {
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
}

.audit-severity-warn {
  border-left: 3px solid var(--orange);
  padding-left: 6px;
}

.audit-severity-error {
  border-left: 3px solid var(--red);
  padding-left: 6px;
}

/* ---- Forms ---- */

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

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

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.deps-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
  padding: 6px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
}

/* ---- Modal ---- */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
}

#modal-title {
  font-size: 16px;
  margin-bottom: 16px;
}

.modal-field {
  margin-bottom: 12px;
}

.modal-field label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.modal-field .value {
  font-size: 14px;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.message-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}

.message-item.direction-request {
  border-left: 3px solid var(--accent);
}

.message-item.direction-response {
  border-left: 3px solid var(--green);
}

.message-item.direction-follow_up {
  border-left: 3px solid var(--yellow);
}

.message-direction {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.message-content {
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

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

/* ---- Gantt chart ---- */

.gantt-chart {
  overflow-x: auto;
}

.gantt-header {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 4px;
}

.gantt-label-col {
  width: 200px;
  min-width: 200px;
  font-size: 12px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gantt-task-name {
  font-weight: 600;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}

.gantt-bar-col {
  flex: 1;
  position: relative;
  height: 24px;
  min-height: 24px;
  background: rgba(255,255,255,0.02);
  border-radius: 3px;
}

.gantt-header .gantt-bar-col {
  height: 20px;
}

.gantt-marker {
  position: absolute;
  font-size: 10px;
  color: var(--text-dim);
  transform: translateX(-50%);
}

.gantt-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.gantt-row:hover {
  background: rgba(255,255,255,0.02);
}

.gantt-bar {
  position: absolute;
  height: 16px;
  top: 4px;
  border-radius: 3px;
  min-width: 4px;
  opacity: 0.85;
}

.gantt-bar-pulse {
  animation: gantt-pulse 2s ease-in-out infinite;
}

@keyframes gantt-pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0.5; }
}

/* ---- Cost dashboard ---- */

.cost-dashboard {
  max-width: 800px;
}

.cost-summary-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.cost-card {
  flex: 1;
  min-width: 120px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.cost-card-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.cost-card-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cost-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.cost-table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.cost-table-header,
.cost-table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
  gap: 0;
  padding: 8px 12px;
  font-size: 12px;
}

.cost-table-header {
  background: var(--surface);
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
}

.cost-table-row {
  border-top: 1px solid var(--border);
  color: var(--text);
}

.cost-table-row:hover {
  background: rgba(255,255,255,0.02);
}

/* ---- Swarm files ---- */

.files-dashboard {
  padding: 12px 0;
}

.files-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.files-agent-group {
  margin-bottom: 16px;
}

.files-agent-name {
  color: var(--accent);
  font-size: 13px;
  margin: 0 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.files-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}

.file-item:hover {
  border-color: var(--accent);
}

.file-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.file-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.file-name {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-name:hover {
  color: var(--accent);
  text-decoration: underline;
}

.file-meta {
  color: var(--text-dim);
  font-size: 11px;
}

/* ---- Template list ---- */

.template-list {
  max-height: 60vh;
  overflow-y: auto;
}

.template-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.02);
}

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

.template-name {
  font-weight: 600;
  font-size: 14px;
}

.template-task-count {
  font-size: 11px;
  color: var(--text-dim);
  padding: 2px 8px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.template-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.template-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.template-actions {
  display: flex;
  gap: 6px;
}

.swarm-list-btns {
  display: flex;
  gap: 4px;
}

/* ---- Markdown rendering ---- */

.md-p { margin: 2px 0; }

.md-h { margin: 8px 0 4px; color: var(--text); }
h3.md-h { font-size: 14px; }
h4.md-h { font-size: 13px; }
h5.md-h { font-size: 12px; }
h6.md-h { font-size: 11px; }

.md-code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.9em;
  color: var(--accent);
}

.md-code-block {
  background: var(--bg);
  padding: 10px 14px;
  border-radius: 6px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 12px;
  overflow-x: auto;
  margin: 6px 0;
  border: 1px solid var(--border);
}

.md-bq {
  border-left: 3px solid var(--accent-dim);
  padding: 4px 12px;
  margin: 4px 0;
  color: var(--text-dim);
}

.md-label {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.swarm-detail-task ul, .swarm-detail-rephrased ul,
.swarm-prompt-original ul, .swarm-prompt-rephrased ul,
.swarm-detail-task ol, .swarm-detail-rephrased ol,
.swarm-prompt-original ol, .swarm-prompt-rephrased ol {
  padding-left: 20px;
  margin: 4px 0;
}

.swarm-detail-task li, .swarm-detail-rephrased li,
.swarm-prompt-original li, .swarm-prompt-rephrased li {
  margin: 2px 0;
  font-size: 13px;
}

.swarm-detail-task hr, .swarm-detail-rephrased hr,
.swarm-prompt-original hr, .swarm-prompt-rephrased hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

/* ---- Markdown tables ---- */

.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}

.md-table th,
.md-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
}

.md-table th {
  background: var(--bg);
  font-weight: 600;
  font-size: 12px;
}

.md-table tr:nth-child(even) {
  background: rgba(255,255,255,0.02);
}

.md-table tr:hover {
  background: rgba(255,255,255,0.04);
}

/* ---- Model selector ---- */

.model-select-input {
  width: 200px;
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  appearance: auto;
}

.swarm-actions-panel .model-select-input {
  width: 100%;
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 6px;
}

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

/* ---- Responsive ---- */

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  #instances-panel {
    grid-column: 1;
    grid-row: auto;
  }
  #concerns-panel,
  #history-panel {
    grid-column: 1;
    grid-row: auto;
  }
  .home-grid {
    grid-template-columns: 1fr;
  }
  .swarm-layout {
    flex-direction: column;
    height: auto;
  }
  #swarm-sidebar {
    width: 100%;
    min-width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 300px;
  }
  .form-row {
    flex-direction: column;
    gap: 0;
  }
}
