:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel2: #243044;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent2: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { min-height: 100vh; }
header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
header h1 { margin: 0; font-size: 1.1rem; font-weight: 600; }
header .meta { color: var(--muted); font-size: 0.8rem; font-family: var(--mono); }
.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; background: var(--panel2); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { color: var(--accent2); border-color: #166534; }
.badge.err { color: var(--danger); border-color: #7f1d1d; }
nav.tabs {
  display: flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border); background: #121820;
}
nav.tabs button {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 0.4rem 0.85rem; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}
nav.tabs button:hover { color: var(--text); background: var(--panel); }
nav.tabs button.active { color: var(--text); background: var(--panel2); border-color: var(--border); }
main { padding: 1.25rem; max-width: 1100px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 1rem 1.15rem; margin-bottom: 1rem;
}
.card h2 { margin: 0 0 0.75rem; font-size: 1rem; }
.card h3 { margin: 1rem 0 0.5rem; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: flex-end; margin-bottom: 0.75rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; min-width: 160px; }
.field.narrow { flex: 0 0 auto; min-width: 100px; max-width: 180px; }
label { font-size: 0.75rem; color: var(--muted); }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 0.45rem 0.6rem; font-size: 0.9rem; font-family: inherit;
}
textarea { min-height: 80px; resize: vertical; font-family: var(--mono); }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
button.btn {
  background: var(--accent); color: white; border: none; border-radius: 6px;
  padding: 0.5rem 0.9rem; cursor: pointer; font-size: 0.85rem; font-weight: 500;
  white-space: nowrap;
}
button.btn:hover { filter: brightness(1.08); }
button.btn.secondary { background: var(--panel2); border: 1px solid var(--border); color: var(--text); }
button.btn.danger { background: var(--danger); }
button.btn.ok { background: var(--accent2); color: #052e16; }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.hint { font-size: 0.8rem; color: var(--muted); margin: 0.25rem 0 0.75rem; }
.status-bar {
  position: sticky; bottom: 0; background: #0a0e14; border-top: 1px solid var(--border);
  padding: 0.5rem 1.25rem; font-family: var(--mono); font-size: 0.78rem;
  display: flex; gap: 1rem; flex-wrap: wrap; align-items: center;
}
.status-bar .http { color: var(--warn); }
.status-bar .http.ok { color: var(--accent2); }
.status-bar .http.err { color: var(--danger); }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  padding: 0.55rem 0.65rem; border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 0.4rem; background: var(--bg); font-size: 0.85rem;
}
.list li.selected { border-color: var(--accent); background: #132033; }
.list .id { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); word-break: break-all; }
.list .actions { display: flex; gap: 0.35rem; flex-shrink: 0; }
.chat-log {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  min-height: 220px; max-height: 420px; overflow: auto; padding: 0.75rem;
  font-family: var(--mono); font-size: 0.82rem; white-space: pre-wrap; word-break: break-word;
}
.chat-log .user { color: #93c5fd; }
.chat-log .asst { color: #86efac; }
.chat-log .meta { color: var(--muted); }
.chat-log .err { color: var(--danger); }
details.raw {
  margin-top: 0.75rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg);
}
details.raw summary {
  cursor: pointer; padding: 0.4rem 0.65rem; color: var(--muted); font-size: 0.8rem;
}
details.raw pre {
  margin: 0; padding: 0.65rem; overflow: auto; max-height: 320px;
  font-family: var(--mono); font-size: 0.75rem; white-space: pre-wrap; word-break: break-word;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
.kind-fields { display: none; }
.kind-fields.show { display: block; }

.thread-history {
  margin-bottom: 1rem; padding: 0.75rem; border: 1px solid var(--border);
  border-radius: 8px; background: #121820;
}
.thread-history h3 { margin-top: 0; }
.thread-list { max-height: 200px; overflow: auto; margin-top: 0.35rem; }
.thread-list li { cursor: pointer; }
.thread-list li:hover { border-color: var(--accent); }
.thread-list li.selected { border-color: var(--accent); background: #132033; }
.chat-log .role-user { color: #93c5fd; }
.chat-log .role-assistant { color: #86efac; }
.chat-log .role-system { color: #fcd34d; }
.chat-log .role-tool { color: #c4b5fd; }
