:root {
  --bg: #07090d;
  --surface: #0d1117;
  --surface-2: #121822;
  --line: #1f2733;
  --line-2: #2b3544;
  --text: #e8edf3;
  --muted: #8a96a8;
  --dim: #5b6677;
  --lime: #ccff00;
  --lime-2: #a8d400;
  --lime-glow: rgba(204, 255, 0, 0.35);
  --docs: #4fc3ff;
  --news: #ff8a4c;
  --ok: #7ddc3a;
  --warn: #ffc24a;
  --bad: #ff5d6c;
  --radius: 6px;
  --font: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
.mono { font-family: var(--mono); }
.dim { color: var(--dim); }
.lime { color: var(--lime); }

.grid-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(204, 255, 0, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(204, 255, 0, 0.035) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 30%, #000 30%, transparent 100%);
}
body.is-login .grid-bg::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 18%;
  width: 720px;
  height: 720px;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(204, 255, 0, 0.12), transparent 60%);
}

/* brand mark: Kong-style lime block */
.mark {
  display: inline-block;
  width: 14px;
  height: 14px;
  background: var(--lime);
  clip-path: polygon(0 0, 70% 0, 100% 30%, 100% 100%, 30% 100%, 0 70%);
  box-shadow: 0 0 14px var(--lime-glow);
}
.brandline { display: flex; align-items: center; gap: 0.6rem; }
.brandline .mono { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }

/* ---------- buttons ---------- */
.btn-primary {
  background: var(--lime);
  color: #0a0d05;
  border: 0;
  border-radius: var(--radius);
  font-weight: 700;
  padding: 0.7rem 1.1rem;
  transition: transform 120ms ease, box-shadow 160ms ease, background 160ms ease;
}
.btn-primary:hover { box-shadow: 0 0 0 3px rgba(204, 255, 0, 0.18), 0 0 22px var(--lime-glow); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { background: var(--line-2); color: var(--muted); box-shadow: none; cursor: progress; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.error { color: var(--bad); font-size: 0.85rem; margin: 0.4rem 0 0; font-family: var(--mono); }

/* ---------- login ---------- */
.login {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-card {
  width: min(460px, 100%);
  background: rgba(13, 17, 23, 0.88);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 2rem;
  backdrop-filter: blur(8px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.03);
  animation: rise 500ms ease-out;
}
.login-card h1 { font-size: 2.8rem; letter-spacing: -0.03em; margin: 1rem 0 0.4rem; font-weight: 700; }
.lede { color: var(--muted); line-height: 1.55; margin: 0 0 1.4rem; }
.stack {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.75rem;
  margin-bottom: 1.4rem;
}
.stack div { display: flex; justify-content: space-between; padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--line); }
.stack div:last-child { border-bottom: 0; }
.stack .k { color: var(--dim); }
.stack .v { color: var(--lime); }
.login-form { display: grid; gap: 0.8rem; }
.login-form label { display: grid; gap: 0.3rem; }
.login-form label span { font-size: 0.7rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
input {
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  padding: 0.7rem 0.8rem;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
input:focus { border-color: var(--lime); box-shadow: 0 0 0 3px rgba(204, 255, 0, 0.12); }

/* ---------- app shell ---------- */
.app {
  position: relative;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 13, 0.85);
  backdrop-filter: blur(6px);
}
.topbar .title { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.topbar .sep { margin: 0 0.1rem; }
.top-right { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; justify-content: flex-end; }
.roster { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.pill, .roster .agent {
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
}
.roster .agent .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 0.4rem; background: var(--dim); vertical-align: middle; }
.roster .agent.up .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.roster .agent.down .dot { background: var(--bad); }
.roster .agent b { color: var(--text); font-weight: 500; }

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) minmax(360px, 30%);
  gap: 1px;
  background: var(--line);
  min-height: 0;
}
.panel {
  background: var(--surface);
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  min-height: 42px;
}
.label {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--lime);
}
.panel-head .mono { font-size: 0.72rem; }

/* ---------- topology ---------- */
.topo svg { width: 100%; padding: 0.8rem 0.6rem 0; }
#edges path {
  fill: none;
  stroke: var(--line-2);
  stroke-width: 1.5;
  marker-end: url(#arrow);
  transition: stroke 300ms ease;
}
.arrowhead { fill: var(--line-2); }
#edges path.on {
  stroke: var(--lime);
  stroke-dasharray: 5 4;
  animation: flow 900ms linear infinite;
  filter: drop-shadow(0 0 3px var(--lime-glow));
}
#edges path.on.docs { stroke: var(--docs); filter: drop-shadow(0 0 3px rgba(79, 195, 255, 0.5)); }
#edges path.on.news { stroke: var(--news); filter: drop-shadow(0 0 3px rgba(255, 138, 76, 0.5)); }
#edges path.err { stroke: var(--bad); stroke-dasharray: none; animation: none; }
@keyframes flow { to { stroke-dashoffset: -18; } }

#nodes rect {
  fill: var(--surface-2);
  stroke: var(--line-2);
  stroke-width: 1;
  transition: stroke 300ms ease, fill 300ms ease;
}
#nodes text {
  fill: var(--text);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
}
#nodes text.sub { fill: var(--dim); font-family: var(--mono); font-size: 8.5px; font-weight: 400; }
#nodes .kong rect { fill: rgba(204, 255, 0, 0.06); stroke: rgba(204, 255, 0, 0.45); }
#nodes .kong text:not(.sub) { fill: var(--lime); }
#nodes g.on rect { stroke: var(--lime); fill: rgba(204, 255, 0, 0.08); }
#nodes g.on.docs rect { stroke: var(--docs); fill: rgba(79, 195, 255, 0.08); }
#nodes g.on.news rect { stroke: var(--news); fill: rgba(255, 138, 76, 0.08); }
#nodes g.err rect { stroke: var(--bad); }
body.running #nodes .kong rect { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { stroke: var(--lime); fill: rgba(204, 255, 0, 0.14); } }

.legend { display: flex; gap: 1rem; padding: 0.4rem 1rem; font-size: 0.68rem; color: var(--dim); }
.legend .sw { display: inline-block; width: 14px; height: 2px; margin-right: 0.35rem; vertical-align: middle; background: var(--line-2); }
.legend .sw.on { background: var(--lime); box-shadow: 0 0 6px var(--lime-glow); }
.plan {
  margin: 0.4rem 1rem 1rem;
  padding: 0.7rem 0.8rem;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius);
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.5;
  overflow: auto;
}
.plan b { color: var(--lime); font-weight: 500; }
.plan .task { margin-top: 0.35rem; }
.plan .task .who { color: var(--text); }

/* ---------- chat ---------- */
.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.msg { max-width: 82ch; animation: rise 260ms ease-out; }
.msg .who {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 0.35rem;
}
.msg.user { align-self: flex-end; }
.msg.user .who { text-align: right; }
.msg.user .body {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}
.msg.agent .who { color: var(--lime); }
.msg.agent .body {
  border-left: 2px solid var(--lime);
  padding: 0.1rem 0 0.1rem 1rem;
  line-height: 1.6;
  color: #d5dce5;
}
.msg.thinking .body { color: var(--muted); font-family: var(--mono); font-size: 0.82rem; border-left-color: var(--line-2); }
.msg.thinking .body { line-height: 1.7; }
.msg.thinking .who::after { content: " · live"; color: var(--lime); }
.msg.thinking:not(.done) .body::after { content: "▍"; color: var(--lime); animation: blink 1s steps(1) infinite; }
.msg.thinking.done .who::after { content: " · run log"; color: var(--dim); }
.msg.thinking.done .body { color: var(--dim); font-size: 0.74rem; }
@keyframes blink { 50% { opacity: 0; } }

.md h1, .md h2, .md h3, .md h4 { font-size: 1rem; margin: 1rem 0 0.4rem; color: var(--text); letter-spacing: -0.01em; }
.md h2 { font-size: 1.08rem; }
.md p { margin: 0.45rem 0; }
.md ul, .md ol { margin: 0.4rem 0; padding-left: 1.3rem; }
.md li { margin: 0.25rem 0; }
.md li::marker { color: var(--lime-2); }
.md a { color: var(--lime); text-decoration: none; border-bottom: 1px solid rgba(204, 255, 0, 0.3); word-break: break-word; }
.md a:hover { border-bottom-color: var(--lime); }
.md strong { color: var(--text); }
.md code { font-family: var(--mono); font-size: 0.82em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 3px; padding: 0.05rem 0.3rem; }
.md pre { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8rem; overflow: auto; font-size: 0.78rem; }
.md pre code { background: none; border: 0; padding: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

.suggestions { display: flex; gap: 0.5rem; flex-wrap: wrap; padding: 0 1.4rem 0.7rem; }
.suggestions button {
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.45rem 0.7rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  transition: color 140ms ease, border-color 140ms ease;
}
.suggestions button .mono { color: var(--dim); font-size: 0.68rem; }
.suggestions button:hover { color: var(--lime); border-color: var(--lime); }
.suggestions button:hover .mono { color: var(--lime); }

.composer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 1.4rem 1rem;
  padding: 0.35rem 0.35rem 0.35rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.composer:focus-within { border-color: var(--lime); box-shadow: 0 0 0 3px rgba(204, 255, 0, 0.1); }
.composer .prompt { color: var(--lime); }
.composer input { flex: 1; border: 0; background: transparent; padding: 0.55rem 0; box-shadow: none; }
.composer input:focus { box-shadow: none; }
.chat .error { margin: -0.4rem 1.4rem 0.8rem; }

/* ---------- inspector ---------- */
.tabs { justify-content: flex-start; gap: 0.3rem; padding: 0 0.6rem; }
.tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.75rem 0.5rem 0.6rem;
}
.tab.active { color: var(--lime); border-bottom-color: var(--lime); }
.count { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 0.4rem; margin-left: 0.25rem; font-size: 0.65rem; color: var(--muted); }
.tab-body { flex: 1; min-height: 0; overflow: auto; padding: 0.6rem 0.8rem 1rem; }
.empty { color: var(--dim); font-size: 0.75rem; padding: 1rem 0.3rem; }

.trace { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.hop {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 0.2rem 0.55rem;
  padding: 0.5rem 0.55rem;
  border-radius: 4px;
  border-left: 2px solid var(--line-2);
  background: rgba(18, 24, 34, 0.5);
  animation: rise 200ms ease-out both;
}
.hop.a-smith { border-left-color: var(--lime); }
.hop.a-docs { border-left-color: var(--docs); }
.hop.a-news { border-left-color: var(--news); }
.hop .n { font-family: var(--mono); font-size: 0.65rem; color: var(--dim); padding-top: 0.15rem; }
.hop .main { min-width: 0; }
.hop .actor { font-family: var(--mono); font-size: 0.68rem; color: var(--muted); }
.hop.a-smith .actor { color: var(--lime); }
.hop.a-docs .actor { color: var(--docs); }
.hop.a-news .actor { color: var(--news); }
.hop .action { font-size: 0.84rem; font-weight: 500; }
.hop .detail { font-family: var(--mono); font-size: 0.68rem; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hop .side { text-align: right; display: grid; gap: 0.25rem; justify-items: end; }
.status {
  font-family: var(--mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  border: 1px solid currentColor;
}
.status.ok { color: var(--ok); }
.status.pending { color: var(--warn); }
.status.error, .status.denied { color: var(--bad); }
.hop .ms { font-family: var(--mono); font-size: 0.65rem; color: var(--muted); }
.bar { grid-column: 2 / 4; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--line-2); border-radius: 2px; }
.hop.a-smith .bar i { background: var(--lime-2); }
.hop.a-docs .bar i { background: var(--docs); }
.hop.a-news .bar i { background: var(--news); }

.payloads { display: grid; gap: 0.5rem; }
.payload { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.payload summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  background: var(--surface-2);
  font-size: 0.78rem;
}
.payload summary::-webkit-details-marker { display: none; }
.payload summary .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir { font-family: var(--mono); font-size: 0.6rem; text-transform: uppercase; padding: 0.1rem 0.35rem; border-radius: 3px; }
.dir.request { color: var(--docs); border: 1px solid rgba(79, 195, 255, 0.5); }
.dir.response { color: var(--lime); border: 1px solid rgba(204, 255, 0, 0.4); }
.payload pre {
  margin: 0;
  padding: 0.65rem;
  max-height: 340px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.7rem;
  line-height: 1.5;
  color: #b9c4d2;
  background: var(--bg);
  white-space: pre-wrap;
  word-break: break-word;
}

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1280px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr) minmax(320px, 34%); }
}
@media (max-width: 1050px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(300px, 40%); }
  .topo { display: none; }
}
@media (max-width: 760px) {
  .app { height: auto; }
  .layout { grid-template-columns: 1fr; }
  .chat { min-height: 70vh; }
  .roster { display: none; }
}
