:root {
  --bg0: #0e1210;
  --bg1: #161c18;
  --bg2: #1e2820;
  --line: #2d3a30;
  --text: #e8efe6;
  --muted: #8fa094;
  --accent: #c4a35a;
  --accent2: #6fbf8a;
  --danger: #d96b6b;
  --warn: #d4a017;
  --ok: #5fbf7a;
  --font-display: "Segoe UI Semibold", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #243028 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #2a2214 0%, transparent 50%),
    var(--bg0);
  color: var(--text);
  font: 14px/1.45 var(--font-display);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.04;
  background-image: linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 28px 28px;
}

.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

nav {
  border-right: 1px solid var(--line);
  background: rgba(14, 18, 16, 0.92);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-size: 1.35rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 4px;
}
.brand span { color: var(--muted); font-size: 0.7rem; display: block; letter-spacing: 0.14em; }

.killswitch-box {
  margin-bottom: 14px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg2);
}
.btn-kill {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 6px;
  background: #ef4444;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.btn-kill:hover { background: #dc2626; }
.btn-kill.triggered { background: #16a34a; }
.btn-kill.triggered:hover { background: #15803d; }
.killswitch-status {
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
}
.killswitch-status.triggered { color: #ef4444; font-weight: 600; }

nav button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 10px 12px;
  margin: 4px 0;
  border-radius: 8px;
  cursor: pointer;
}
nav button.active, nav button:hover {
  color: var(--text);
  border-color: var(--line);
  background: var(--bg2);
}

main { padding: 24px 28px 48px; }
h1 { margin: 0 0 6px; font-size: 1.6rem; }
.sub { color: var(--muted); margin-bottom: 20px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.card {
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}

.card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.meta { color: var(--muted); font-size: 0.85rem; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent2);
}
.badge.ver { color: var(--accent); }

.badge-pending {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin-left: 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }

button.btn, .btn {
  background: var(--accent);
  color: #15120a;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
}
button.btn.secondary { background: var(--bg2); color: var(--text); border: 1px solid var(--line); }
button.btn.danger { background: var(--danger); color: #1a0a0a; }
button.btn.ok { background: var(--ok); }

input, select, textarea {
  width: 100%;
  background: var(--bg0);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0 12px;
  font: inherit;
}
textarea { min-height: 90px; font-family: var(--font-mono); font-size: 12px; }

label { color: var(--muted); font-size: 0.85rem; }
.panel { display: none; }
.panel.active { display: block; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px;
  background: var(--muted);
}
.status-dot.ok { background: var(--ok); }
.status-dot.bad { background: var(--danger); }
.status-dot.warn { background: var(--warn); }

.mono { font-family: var(--font-mono); font-size: 12px; white-space: pre-wrap; }
.flash { margin-top: 10px; color: var(--accent2); }

.chat-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 14px;
  min-height: 70vh;
}
.chat-sidebar { max-height: 75vh; overflow: auto; }
.chat-session-list { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.chat-session-item {
  text-align: left;
  width: 100%;
  background: var(--bg0);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
.chat-session-item.active, .chat-session-item:hover {
  border-color: var(--accent);
}
.chat-session-item .meta { display: block; margin-top: 4px; }
.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 70vh;
  max-height: 75vh;
}
.chat-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
.chat-messages {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px 12px;
}
.chat-bubble {
  max-width: 92%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--bg0);
  white-space: pre-wrap;
}
.chat-bubble.user { align-self: flex-end; border-color: #3a4a38; }
.chat-bubble.assistant { align-self: flex-start; border-color: #4a3f28; }
.chat-bubble.tool { align-self: stretch; max-width: 100%; background: transparent; padding: 0; border: none; }
.chat-bubble .role {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tool-trace {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 4px 0;
  font-family: var(--font-mono);
  font-size: 12px;
}
.tool-trace summary { cursor: pointer; color: var(--accent2); }
.tool-trace pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  color: var(--muted);
  max-height: 180px;
  overflow: auto;
}
.chat-composer { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }
.chat-composer textarea { margin-bottom: 8px; min-height: 70px; }

/* Overview analytics */
.overview-filter {
  width: auto;
  min-width: 140px;
  padding: 6px 10px;
}
.overview-stats { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.stat-card h3 { font-size: 1.8rem; margin: 0; color: var(--accent); }
.stat-row { display: flex; gap: 18px; flex-wrap: wrap; }
.insights-list { margin-top: 10px; }
.insight-item {
  padding: 8px 10px;
  margin: 4px 0;
  border-left: 3px solid var(--accent2);
  background: rgba(111, 191, 138, 0.06);
  font-size: 0.9rem;
}
.activity-timeline {
  max-height: 320px;
  overflow-y: auto;
  margin-top: 8px;
}
.activity-row {
  display: grid;
  grid-template-columns: 100px 100px 80px 1fr 12px;
  gap: 8px;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}
.activity-time { color: var(--muted); font-family: var(--font-mono); font-size: 0.78rem; }
.activity-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-kind { color: var(--muted); font-size: 0.78rem; }
.agent-metrics {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--accent2);
}
.integrations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.integration-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg0);
}
.integration-card.active { border-color: var(--accent2); }
.integration-status.ok { color: var(--ok); }
.integration-status.warn { color: var(--warn); }
.integration-status.muted { color: var(--muted); }
.integration-card a { color: var(--accent); text-decoration: none; }
.integration-card a:hover { text-decoration: underline; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  nav { position: relative; height: auto; display: flex; flex-wrap: wrap; gap: 4px; }
  nav button { width: auto; }
  .chat-layout { grid-template-columns: 1fr; }
}
