:root {
  --ta: #4a90d9;
  --ta-dark: #1f4e79;
  --nta: #f0943b;
  --nta-dark: #994f00;
  --ext: #999;
  --ext-dark: #555;
  --bg: #faf8f3;
  --panel: #fff;
  --ink: #222;
  --muted: #666;
  --line: #e5e1d7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

header {
  padding: 14px 22px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
header h1 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.subtitle {
  color: var(--muted);
  font-size: 13px;
}
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  margin: 0 2px;
}
.pill.ta  { background: var(--ta);  color: #fff; }
.pill.nta { background: var(--nta); color: #fff; }
.pill.ext { background: var(--ext); color: #fff; }
code { background: #f1ede3; padding: 1px 4px; border-radius: 3px; font-size: 12px; }

.controls {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.controls input {
  flex: 1;
  max-width: 360px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}
.controls button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}
.controls button:hover { background: #f2ede1; }
.controls button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

main {
  display: grid;
  grid-template-columns: 220px 1fr 560px;
  gap: 0;
  height: calc(100vh - 104px);
}
aside, section {
  overflow-y: auto;
  padding: 14px 18px;
  border-right: 1px solid var(--line);
}
#network { border-right: none; }
#threads { background: var(--bg); }

h2 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* Tab bar */
.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
  padding-bottom: 2px;
}
.tab {
  background: none;
  border: none;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* Media cards */
.media-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.media-card img {
  width: 100%;
  border-radius: 6px;
  margin: 8px 0;
  display: block;
}
.media-prompt {
  font-style: italic;
  color: #444;
  font-size: 13px;
  padding: 8px 12px;
  background: #f6f2e8;
  border-left: 3px solid var(--ta);
  border-radius: 3px;
  margin-top: 6px;
  white-space: pre-wrap;
}
.media-reasoning {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* Codex cards */
.codex-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.codex-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.codex-content {
  white-space: pre-wrap;
  font-size: 13px;
  color: #333;
  max-height: 180px;
  overflow: hidden;
  position: relative;
}
.codex-content.expanded { max-height: 6000px; }
.codex-content:not(.expanded)::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0; height: 40px;
  background: linear-gradient(to bottom, transparent, var(--panel));
}

/* Write / bash / psyche list */
.log-entry {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.log-entry pre {
  margin: 4px 0 0;
  white-space: pre-wrap;
  word-break: break-all;
  color: #333;
  max-height: 120px;
  overflow: hidden;
  position: relative;
}
.log-entry pre.expanded { max-height: 4000px; }
.log-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.log-head .pill-agent {
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  color: #fff;
}
.log-head .pill-agent.ta  { background: var(--ta); }
.log-head .pill-agent.nta { background: var(--nta); }
.log-head .pill-agent.external { background: var(--ext); }
.log-head .t { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: auto; font-size: 11px; }
.log-head .action { color: var(--muted); }

/* Chronicle (merged stream) */
.chronicle-item {
  padding: 10px 12px;
  margin: 6px 0;
  border-left: 3px solid var(--border, #ddd);
  background: var(--card-bg, #fafaf6);
  border-radius: 0 4px 4px 0;
}
.chronicle-item.type-email  { border-left-color: #888; }
.chronicle-item.type-media  { border-left-color: #c37; }
.chronicle-item.type-codex  { border-left-color: #7b6; }
.chronicle-item.type-write  { border-left-color: #69c; }
.chronicle-item.type-bash   { border-left-color: #aa6; }
.chronicle-item.type-psyche { border-left-color: #a7a; }
.chronicle-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 6px;
  border-radius: 3px;
  color: #fff;
  background: #888;
}
.chronicle-badge.type-email  { background: #888; }
.chronicle-badge.type-media  { background: #c37; }
.chronicle-badge.type-codex  { background: #7b6; }
.chronicle-badge.type-write  { background: #69c; }
.chronicle-badge.type-bash   { background: #aa6; }
.chronicle-badge.type-psyche { background: #a7a; }
.chronicle-item img { max-width: 100%; margin-top: 8px; border-radius: 3px; }
.chronicle-item pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #f3efe6;
  padding: 8px 10px;
  border-radius: 3px;
  margin: 6px 0 0;
  white-space: pre-wrap;
  word-break: break-all;
  color: #333;
  max-height: 120px;
  overflow: hidden;
}
.chronicle-item pre.expanded { max-height: 4000px; }

/* Agent sidebar */
.agent-row {
  display: flex;
  align-items: center;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  margin-bottom: 2px;
  gap: 8px;
}
.agent-row:hover { background: #f1ede1; }
.agent-row.active { background: var(--ink); color: #fff; }
.agent-row.active .agent-stat { color: #ccc; }
.agent-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.agent-dot.ta  { background: var(--ta); }
.agent-dot.nta { background: var(--nta); }
.agent-dot.external { background: var(--ext); border-radius: 2px; }
.agent-name { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.agent-stat { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.agent-group-header {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 10px 4px 4px;
}

/* Emails */
.email {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.email-header {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 6px;
  font-size: 12px;
}
.email-from {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  color: #fff;
}
.email-from.ta  { background: var(--ta); }
.email-from.nta { background: var(--nta); }
.email-arrow { color: var(--muted); }
.email-to {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
}
.email-to .recipient {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  background: #f1ede1;
  margin-right: 3px;
  color: var(--ink);
}
.email-time {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 11px;
}
.email-subject {
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
}
.email-body {
  white-space: pre-wrap;
  font-size: 13px;
  color: #333;
  max-height: 180px;
  overflow: hidden;
  position: relative;
  transition: max-height 0.2s ease;
}
.email-body.expanded { max-height: 4000px; }
.email-body::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0; height: 40px;
  background: linear-gradient(to bottom, transparent, var(--panel));
  pointer-events: none;
}
.email-body.expanded::after { display: none; }
.email-body.short::after { display: none; }
.email-expand {
  font-size: 11px;
  color: var(--ta-dark);
  cursor: pointer;
  margin-top: 4px;
  user-select: none;
}
.email-expand:hover { text-decoration: underline; }

.empty {
  color: var(--muted);
  font-style: italic;
  padding: 40px 0;
  text-align: center;
}

/* Network */
#net-svg {
  width: 100%;
  height: auto;
  max-height: 560px;
  display: block;
}
.node text {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  fill: var(--ink);
  pointer-events: none;
}
.node circle, .node rect {
  cursor: pointer;
  transition: stroke-width 0.12s ease;
}
.node:hover circle, .node:hover rect { stroke-width: 3; }
.node.selected circle, .node.selected rect { stroke: #000; stroke-width: 3; }
.edge {
  fill: none;
  cursor: pointer;
  transition: stroke-opacity 0.12s ease, stroke-width 0.12s ease;
}
.edge:hover { stroke-opacity: 1 !important; }
.edge.dim { stroke-opacity: 0.06 !important; }
.node.dim circle, .node.dim rect { opacity: 0.25; }
.node.dim text { opacity: 0.3; }
.hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-top: 6px;
}
