@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600&family=Space+Mono:wght@400;600&display=swap");

:root {
  --bg: #0d1117;
  --panel: #141a22;
  --panel-2: #1c2430;
  --text: #e6edf3;
  --muted: #9da7b3;
  --accent: #73daca;
  --accent-2: #f4bf75;
  --danger: #f7768e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at top left, #1c2430, #0d1117 55%);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
}

.app {
  min-height: 100vh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Topbar ──────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #73daca, #7aa2f7);
}

.title { font-size: 20px; font-weight: 600; }
.subtitle { color: var(--muted); font-size: 13px; }

.topbar-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.status {
  font-family: "Space Mono", monospace;
  color: var(--accent-2);
}

/* Last task banner — shows the most recent manager task in the header */
.last-task-banner {
  font-size: 11px;
  color: #9ece6a;
  font-family: "Space Mono", monospace;
  max-width: 520px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.85;
}

/* ── Status grid ─────────────────────────────────────────────────── */

.grid {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.panel {
  background: var(--panel);
  padding: 16px;
  border-radius: 12px;
  min-height: 100px;
}

.panel h2 {
  margin: 0 0 12px 0;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.overview { display: grid; gap: 8px; }

.kv {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 280px;
  overflow: auto;
}

.card {
  background: var(--panel-2);
  padding: 12px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.row.muted { color: var(--muted); font-size: 13px; }

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: #1e293b;
  color: var(--accent);
  font-size: 12px;
}

/* ── Activity section: timeline (left) + terminal (right) ────────── */

.activity-section {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 20px;
  align-items: stretch;
}

.activity-timeline-panel {
  min-height: 600px;
  display: flex;
  flex-direction: column;
}

.activity-terminal-panel {
  min-height: 600px;
  display: flex;
  flex-direction: column;
}

/* Pulsing live dot */
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.4s;
}

.live-dot.live {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Event count badge next to "Stream" heading */
.stream-badge {
  font-size: 11px;
  font-family: "Space Mono", monospace;
  color: var(--muted);
  font-weight: 400;
}

.stream-tz {
  font-size: 10px;
  font-family: "Space Mono", monospace;
  color: var(--muted);
  opacity: 0.6;
  font-weight: 400;
  margin-left: auto;
}

/* ── Timeline column ─────────────────────────────────────────────── */

.activity-timeline {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.tl-entry {
  display: grid;
  grid-template-columns: 10px 66px 1fr;
  gap: 8px;
  align-items: start;
  padding: 7px 4px;
  border-bottom: 1px solid #1a2230;
  cursor: pointer;
  transition: background 0.12s;
  border-radius: 4px;
}

.tl-entry:hover { background: #1a2535; }

.tl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 3px;
  flex-shrink: 0;
}

.tl-time {
  font-family: "Space Mono", monospace;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1.5;
}

.tl-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tl-role {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.3;
  font-family: "Space Mono", monospace;
}

.tl-desc {
  font-size: 11px;
  color: var(--text);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ── Content terminal ────────────────────────────────────────────── */

.stream {
  background: #0a0f18;
  color: var(--text);
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  font-size: 12px;
  border-radius: 12px;
  font-family: "Space Mono", monospace;
  line-height: 1.5;
}

.event-stream details {
  margin-bottom: 6px;
  padding: 6px 10px;
  border: 1px solid #2f3b4d;
  border-radius: 8px;
  background: #0b131d;
}

.event-stream summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 11px;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.event-stream summary::before {
  content: "▶";
  font-size: 8px;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.event-stream details[open] summary::before {
  transform: rotate(90deg);
}

.event-stream pre {
  margin: 8px 0 0 0;
  white-space: pre-wrap;
  color: var(--text);
  font-size: 12px;
}

/* ── Lower section: graph + debug logs ──────────────────────────── */

.lower-section {
  display: grid;
  gap: 20px;
  grid-template-columns: 1.4fr 1fr;
}

.graph {
  height: 340px;
  border-radius: 12px;
  background: #0f1620;
  position: relative;
  overflow: hidden;
}

.edge { stroke: #2f3b4d; stroke-width: 1.5; }
.node { stroke: #0d1117; stroke-width: 2; }
.node.agent { fill: var(--accent); }
.node.task  { fill: var(--accent-2); }

.label {
  fill: var(--muted);
  font-size: 11px;
  font-family: "Space Mono", monospace;
}

/* ── Log controls ────────────────────────────────────────────────── */

.log-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.log-controls label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.log-controls select,
.log-controls input {
  background: #0f1620;
  border: 1px solid #2f3b4d;
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  font-family: "Space Mono", monospace;
  font-size: 12px;
}

.log-summary {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
  font-family: "Space Mono", monospace;
}

/* ── Status / diagnostic colors ──────────────────────────────────── */

.line-error   { color: var(--danger); }
.line-warning { color: var(--accent-2); }
.line-info    { color: var(--text); }
.line-debug   { color: #7aa2f7; }

.diag-issue { color: var(--danger);  font-size: 13px; }
.diag-ok    { color: var(--accent);  font-size: 13px; }

.raw-state { max-height: 320px; }

.status-live  { color: var(--accent); }
.status-stale { color: var(--danger); }

/* ── API Budget ──────────────────────────────────────────────────── */

.usage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.budget-bar-wrap {
  height: 6px;
  background: var(--panel-2);
  border-radius: 3px;
  overflow: hidden;
  margin: 6px 0 4px;
}

.budget-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
  min-width: 2px;
}

/* ── Footer ──────────────────────────────────────────────────────── */

.footer {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 10px 0;
}

/* ── Event type styles (terminal) ────────────────────────────────── */

.event-thinking {
  border-color: #2a3545 !important;
  background: #080d14 !important;
  opacity: 0.8;
}
.event-thinking summary { color: #7aa2f7 !important; font-style: italic; }
.event-thinking pre { color: #9da7b3; font-size: 11px; }

.event-onboarding { border-color: #5a3fa0 !important; background: #0f0a1e !important; }
.event-onboarding summary { color: #bb9af7 !important; }

.event-name-chosen { border-color: #1a6b5a !important; background: #061210 !important; }
.event-name-chosen summary { color: var(--accent) !important; font-weight: 600; }

.event-manager-context summary { color: var(--accent-2) !important; }

.event-manager-task { border-color: #4a6a30 !important; background: #080f04 !important; }
.event-manager-task summary { color: #9ece6a !important; font-weight: 600; }

.event-worker-result summary { color: var(--text) !important; }

.event-debug-report { border-color: #7aa2f7 !important; background: #080c18 !important; }
.event-debug-report summary { color: #7aa2f7 !important; font-weight: 600; }

/* ── Responsive ──────────────────────────────────────────────────── */

@media (max-width: 1100px) {
  .activity-section { grid-template-columns: 1fr; }
  .activity-timeline-panel { min-height: 300px; }
  .lower-section { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .grid { grid-template-columns: 1fr; }
  .usage-grid { grid-template-columns: 1fr; }
  .log-controls { flex-direction: column; align-items: flex-start; }
}
