/* Agents flow view + agent side panel (SPEC §13). Owned by frontend-agents.
 * Uses base.css's dark-theme variables (--bg, --panel, --border, --text,
 * --muted, --accent) with fallbacks so this stays self-sufficient if
 * base.css hasn't landed yet. LF line endings. */

.agents-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  color: var(--text, #e5e7eb);
  font-family: inherit;
}

/* ---- toolbar ---------------------------------------------------------- */

.agents-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border, #262b33);
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.agents-filters {
  display: flex;
  gap: 6px;
}

.agent-chip {
  background: var(--panel, #161a20);
  border: 1px solid var(--border, #262b33);
  color: var(--muted, #9aa4b2);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.agent-chip:hover {
  color: var(--text, #e5e7eb);
  border-color: var(--muted, #9aa4b2);
}

.agent-chip.is-active {
  background: var(--accent, #60a5fa);
  color: #0b0e14;
  border-color: var(--accent, #60a5fa);
  font-weight: 600;
}

.agents-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
  font-size: 11px;
  color: var(--muted, #9aa4b2);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.agents-fit-btn {
  background: var(--panel, #161a20);
  border: 1px solid var(--border, #262b33);
  color: var(--text, #e5e7eb);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.agents-fit-btn:hover {
  border-color: var(--accent, #60a5fa);
}

/* ---- graph canvas ------------------------------------------------------ */

.agents-canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, var(--border, #262b33) 1px, transparent 0) 0 0 / 24px 24px,
    var(--bg, #0b0e14);
}

.agents-svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  outline: none;
}

.agents-svg.is-dragging {
  cursor: grabbing;
}

.agents-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted, #9aa4b2);
  font-size: 13px;
  pointer-events: none;
}

.agents-empty[hidden] {
  display: none;
}

/* edges */

.agent-edge {
  fill: none;
  stroke: var(--border, #383f4a);
  stroke-width: 1.6;
  transition: stroke 0.2s ease;
}

.agent-edge.is-active {
  stroke: var(--accent, #60a5fa);
  stroke-width: 2;
  stroke-dasharray: 6 5;
  animation: agents-edge-flow 0.9s linear infinite;
}

@keyframes agents-edge-flow {
  to {
    stroke-dashoffset: -22;
  }
}

.agent-arrow-head {
  fill: var(--border, #383f4a);
}

.agent-arrow-head.is-active {
  fill: var(--accent, #60a5fa);
}

/* nodes */

.agent-node {
  cursor: pointer;
}

.agent-node:focus {
  outline: none;
}

.agent-glow {
  fill: none;
  opacity: 0;
}

.agent-node.is-active .agent-glow {
  fill: var(--role-color, var(--accent, #60a5fa));
  opacity: 0.28;
  animation: agents-pulse 1.6s ease-in-out infinite;
}

@keyframes agents-pulse {
  0%, 100% {
    opacity: 0.18;
    r: 30px;
  }
  50% {
    opacity: 0.4;
    r: 37px;
  }
}

.agent-circle {
  fill: var(--role-color, #33383f);
  stroke: var(--role-color, #545b66);
  stroke-width: 2;
  transition: fill 0.2s ease, stroke 0.2s ease;
}

.agent-node:not(.is-active):not(.is-holding) .agent-circle {
  fill: #262b33;
  stroke: #3b4250;
}

.agent-node:focus-visible .agent-circle,
.agent-node.is-selected .agent-circle {
  stroke: #ffffff;
  stroke-width: 2.5;
}

.agent-ring {
  fill: none;
  pointer-events: none;
  opacity: 0;
}

.agent-node.ring-waiting .agent-ring {
  stroke: var(--muted, #9aa4b2);
  stroke-width: 1.5;
  stroke-dasharray: 2 5;
  opacity: 0.8;
}

.agent-node.ring-blocked .agent-ring {
  stroke: #f87171;
  stroke-width: 2.5;
  opacity: 0.95;
}

.agent-letter {
  font-size: 16px;
  font-weight: 700;
  fill: var(--muted, #9aa4b2);
  pointer-events: none;
  user-select: none;
}

/* .is-holding (waiting for its working agents): filled like .is-active, but no glow/pulse */
.agent-node.is-active .agent-letter,
.agent-node.is-holding .agent-letter {
  fill: #0b0e14;
}

.agent-id {
  font-size: 11px;
  font-weight: 600;
  fill: var(--text, #e5e7eb);
  pointer-events: none;
  user-select: none;
}

.agent-title {
  font-size: 10px;
  fill: var(--muted, #9aa4b2);
  pointer-events: none;
  user-select: none;
}

.agent-badge-bg {
  stroke: var(--bg, #0b0e14);
  stroke-width: 1.5;
}

.agent-badge-text {
  font-size: 9px;
  font-weight: 700;
  fill: #0b0e14;
  pointer-events: none;
  user-select: none;
}

.badge-blocked,
.badge-failed {
  fill: #f87171;
}

.badge-stale {
  fill: #fbbf24;
}

.badge-done {
  fill: #4ade80;
}

/* a model the runner can't use as-is (SPEC §12): yellow "!" on the node, tooltip and panel */
.badge-model {
  fill: #fbbf24;
}

.model-warn {
  color: #fbbf24;
  font-weight: 600;
}

/* ---- activity strip ---------------------------------------------------- */

.agents-activity {
  flex: 0 0 auto;
  max-height: 140px;
  overflow-y: auto;
  border-top: 1px solid var(--border, #262b33);
  padding: 6px 12px;
}

.agents-activity-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted, #9aa4b2);
  margin-bottom: 4px;
}

.agents-activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}

.agents-activity-list li {
  display: flex;
  gap: 8px;
}

.act-time {
  color: var(--muted, #9aa4b2);
  flex: 0 0 auto;
  width: 56px;
}

.act-text {
  color: var(--text, #e5e7eb);
}

/* ---- tooltip ------------------------------------------------------------ */

.agents-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 280px;
  background: var(--panel, #161a20);
  border: 1px solid var(--border, #262b33);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.tt-title {
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tt-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.tt-row {
  color: var(--muted, #9aa4b2);
}

.tt-row b {
  color: var(--text, #e5e7eb);
  font-weight: 600;
  margin-right: 4px;
}

.tt-detail {
  font-style: italic;
}

.tt-composing {
  color: #93c5fd;
  font-style: italic;
}

.tt-muted {
  opacity: 0.8;
}

.tt-status {
  font-weight: 600;
  text-transform: capitalize;
}

.status-spawning,
.status-working {
  color: #4ade80;
}

.status-waiting {
  color: #9aa4b2;
}

.status-blocked,
.status-failed {
  color: #f87171;
}

.status-stale {
  color: #fbbf24;
}

.status-done {
  color: #60a5fa;
}

.status-killed {
  color: #f87171;
}

/* ======================================================================
 * Agent window content (agent_panel.js)
 * ==================================================================== */

.sp-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  color: var(--text, #e5e7eb);
}

.sp-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, #262b33);
  position: relative;
}

.sp-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #0b0e14;
  flex: 0 0 auto;
}

.sp-heading {
  min-width: 0;
}

.sp-id-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sp-id {
  font-weight: 700;
  font-size: 15px;
}

.sp-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  text-transform: capitalize;
}

.sp-role {
  color: var(--muted, #9aa4b2);
  font-size: 12px;
  margin-top: 2px;
}

.sp-meta {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border, #262b33);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  flex: 0 0 auto;
}

.sp-meta-row {
  display: flex;
  gap: 8px;
}

.sp-meta-label {
  color: var(--muted, #9aa4b2);
  width: 70px;
  flex: 0 0 auto;
}

.sp-meta-row a {
  color: var(--accent, #60a5fa);
  text-decoration: none;
  margin-right: 6px;
}

.sp-meta-row a:hover {
  text-decoration: underline;
}

.sp-older-toggle {
  background: none;
  border: 1px solid var(--border, #262b33);
  color: var(--muted, #9aa4b2);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
  cursor: pointer;
}

.sp-older-toggle:hover {
  color: var(--text, #e5e7eb);
  border-color: var(--muted, #9aa4b2);
}

.sp-older a {
  opacity: 0.65;
}

.sp-actions {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border, #262b33);
  flex: 0 0 auto;
}

.sp-kill {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid #f87171;
  color: #f87171;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

.sp-kill:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.22);
}

.sp-kill:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sp-log {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sp-log-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border, #262b33);
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.sp-log-filter {
  background: var(--bg, #0b0e14);
  color: var(--text, #e5e7eb);
  border: 1px solid var(--border, #262b33);
  border-radius: 6px;
  font-size: 12px;
  padding: 2px 6px;
}

.sp-follow-label {
  font-size: 12px;
  color: var(--muted, #9aa4b2);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sp-load-older {
  background: none;
  border: 1px solid var(--border, #262b33);
  color: var(--muted, #9aa4b2);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  margin-left: auto;
}

.sp-log-status {
  padding: 4px 16px;
  font-size: 11px;
  color: var(--muted, #9aa4b2);
  border-bottom: 1px solid var(--border, #262b33);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 0 auto;
}

.sp-log-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 16px 20px;
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sp-composing {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-top: 1px solid var(--border, #262b33);
  color: #93c5fd;
  font-size: 12px;
  font-style: italic;
}

.sp-composing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #60a5fa;
  animation: sp-composing-pulse 1.2s ease-in-out infinite;
}

@keyframes sp-composing-pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

.log-entry {
  border-radius: 6px;
}

.log-entry.log-flash {
  outline: 2px solid var(--accent, #58a6ff);
  outline-offset: 1px;
}

.log-time {
  color: var(--muted, #9aa4b2);
  font-size: 10.5px;
  margin-right: 6px;
}

.log-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.log-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 4px 0 0;
}

.log-prompt {
  background: rgba(96, 165, 250, 0.08);
  border: 1px solid rgba(96, 165, 250, 0.35);
  padding: 4px 8px;
}

.log-prompt summary {
  cursor: pointer;
  color: #60a5fa;
  font-size: 11.5px;
}

.log-prompt pre {
  margin: 6px 0 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-reasoning {
  color: var(--muted, #9aa4b2);
  font-style: italic;
  padding: 2px 4px;
}

.log-message {
  padding: 2px 4px;
}

.log-tool_call,
.log-tool_result {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border, #262b33);
  padding: 4px 8px;
}

.log-tool_call summary,
.log-tool_result summary {
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--text, #e5e7eb);
}

.log-tool_call summary {
  color: #93c5fd;
}

.log-tool-kind {
  margin-right: 6px;
  opacity: 0.7;
}

.log-tool-badge {
  margin-right: 6px;
  font-weight: 600;
}

.log-tool-badge.ok { color: #4ade80; }
.log-tool-badge.fail { color: #f87171; }

.log-tool-preview {
  white-space: pre-wrap;
  word-break: break-word;
}

.log-tool_call pre,
.log-tool_result pre {
  margin: 6px 0 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.log-stdout .log-mono {
  color: var(--text, #e5e7eb);
}

.log-stderr .log-mono {
  color: #f87171;
}

.log-system {
  color: var(--muted, #9aa4b2);
  padding: 2px 4px;
}

.md-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 8px;
  border-radius: 6px;
  white-space: pre-wrap;
}

.sp-error {
  padding: 16px;
  color: #f87171;
  font-size: 12px;
}

/* ---- shell tool rows: one <details> per command, with a terminal block inside (terminal.js, #129) ---- */

.log-tool {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border, #262b33);
  padding: 4px 8px;
}

.log-tool > summary {
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--text, #e5e7eb);
}

.log-tool > summary {
  list-style: none;
}

.log-tool > summary::-webkit-details-marker {
  display: none;
}

.log-tool > summary::before {
  content: '▸';
  flex: 0 0 auto;
  color: var(--muted, #9aa4b2);
}

.log-tool[open] > summary::before {
  content: '▾';
}

.log-tool > summary .log-time {
  margin-right: 0;
  flex: 0 0 auto;
}

.log-tool-name {
  flex: 0 0 auto;
  color: #93c5fd;
}

.log-tool > summary .log-tool-preview {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-status {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  white-space: nowrap;
}

.tool-status.running { color: #93c5fd; }
.tool-status.ok { color: #4ade80; }
.tool-status.fail { color: #f87171; }
.tool-status.ended { color: var(--muted, #9aa4b2); font-weight: 400; }

.tool-spin {
  width: 9px;
  height: 9px;
  border: 2px solid rgba(147, 197, 253, 0.3);
  border-top-color: #93c5fd;
  border-radius: 50%;
  animation: tool-spin 0.8s linear infinite;
}

@keyframes tool-spin {
  to { transform: rotate(360deg); }
}

.term {
  margin: 6px 0 2px;
  border: 1px solid #1f2430;
  border-radius: 6px;
  background: #0a0d12;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.45;
  color: #d4d9e1;
  overflow: hidden;
}

.term pre {
  margin: 0;
  font: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}

.term-head {
  padding: 6px 10px;
  border-bottom: 1px solid #1f2430;
  color: #93c5fd;
  max-height: 8em;
  overflow: auto;
}

.term-out {
  padding: 6px 10px;
  max-height: 50vh;
  overflow: auto;
}

.term-out.term-empty {
  color: var(--muted, #9aa4b2);
  font-style: italic;
}

.term-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px;
  border-top: 1px solid #1f2430;
  color: var(--muted, #9aa4b2);
  font-size: 11px;
}

.term-meta {
  flex: 1 1 auto;
  min-width: 0;
}

.term-copy {
  flex: 0 0 auto;
  background: none;
  border: 1px solid var(--border, #262b33);
  border-radius: 5px;
  color: var(--muted, #9aa4b2);
  font-size: 11px;
  padding: 1px 8px;
  cursor: pointer;
}

.term-copy:hover {
  color: var(--text, #e5e7eb);
}

.ansi-bold { font-weight: 700; }
.ansi-dim { opacity: 0.65; }
.ansi-italic { font-style: italic; }
.ansi-underline { text-decoration: underline; }

.ansi-fg-0 { color: #6b7280; }
.ansi-fg-1 { color: #f87171; }
.ansi-fg-2 { color: #4ade80; }
.ansi-fg-3 { color: #facc15; }
.ansi-fg-4 { color: #60a5fa; }
.ansi-fg-5 { color: #c084fc; }
.ansi-fg-6 { color: #22d3ee; }
.ansi-fg-7 { color: #d4d9e1; }
.ansi-fg-8 { color: #9ca3af; }
.ansi-fg-9 { color: #fca5a5; }
.ansi-fg-10 { color: #86efac; }
.ansi-fg-11 { color: #fde047; }
.ansi-fg-12 { color: #93c5fd; }
.ansi-fg-13 { color: #d8b4fe; }
.ansi-fg-14 { color: #67e8f9; }
.ansi-fg-15 { color: #f9fafb; }

.ansi-bg-0 { background-color: #374151; }
.ansi-bg-1 { background-color: #b91c1c; }
.ansi-bg-2 { background-color: #15803d; }
.ansi-bg-3 { background-color: #a16207; }
.ansi-bg-4 { background-color: #1d4ed8; }
.ansi-bg-5 { background-color: #7e22ce; }
.ansi-bg-6 { background-color: #0e7490; }
.ansi-bg-7 { background-color: #9ca3af; }
.ansi-bg-8 { background-color: #4b5563; }
.ansi-bg-9 { background-color: #dc2626; }
.ansi-bg-10 { background-color: #16a34a; }
.ansi-bg-11 { background-color: #ca8a04; }
.ansi-bg-12 { background-color: #2563eb; }
.ansi-bg-13 { background-color: #9333ea; }
.ansi-bg-14 { background-color: #0891b2; }
.ansi-bg-15 { background-color: #e5e7eb; }
