:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1c2128;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --ok: #1a8a4a;
  --warn: #b7791f;
  --err: #c53030;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --side: #111827;
  --side-text: #d1d5db;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --panel: #171b23; --text: #e5e7eb; --muted: #9ca3af; --line: #2a3140;
    --accent: #4c8dff; --code-bg: #0b0f16; --side: #0b0e14; --side-text: #c7cdd6; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 16px 0 6px; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
pre { background: var(--code-bg); color: var(--code-text); padding: 12px 14px; border-radius: var(--radius); overflow: auto; margin: 0; white-space: pre-wrap; word-break: break-word; }
code.inline { background: var(--line); padding: 1px 5px; border-radius: 4px; }
small, .muted { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.side { width: 210px; flex: 0 0 210px; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side a { color: var(--side-text); padding: 9px 12px; border-radius: 8px; display: block; }
.side a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.side a.active { background: var(--accent); color: #fff; }
.side .brand { font-weight: 700; font-size: 18px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; color: #fff; }
.side .brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); display: inline-block; box-shadow: 0 0 0 4px rgba(76,141,255,.25); }
.side-foot { margin-top: auto; font-size: 13px; padding: 0 12px; display: flex; flex-direction: column; gap: 4px; }
.side-foot small { color: #6b7280; }
.main { flex: 1; padding: 28px 32px 60px; max-width: 1400px; min-width: 0; }
body.login-page .main { display: flex; align-items: center; justify-content: center; padding: 20px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.grid.agents { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) {
  .grid.two { grid-template-columns: 1fr; }
  body { flex-direction: column; }
  .side { width: auto; flex: none; height: auto; position: static; flex-direction: row; flex-wrap: wrap; gap: 2px; padding: 10px 8px; align-items: center; }
  .side a { padding: 6px 10px; font-size: 14px; }
  .side .brand { width: 100%; margin-bottom: 6px; }
  .side-foot { margin-top: 0; margin-left: auto; flex-direction: row; gap: 10px; align-items: center; }
  .side-foot small { display: none; }
  .main { padding: 16px; }
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.agent-card { display: flex; flex-direction: column; gap: 8px; }
.agent-card .title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.agent-card .title a { font-weight: 600; font-size: 16px; color: var(--text); }
.agent-card .desc { color: var(--muted); font-size: 14px; min-height: 20px; }
.agent-card .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.agent-card .actions { display: flex; gap: 8px; margin-top: 4px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--text); white-space: nowrap; }
.badge.ok { background: rgba(26,138,74,.15); color: var(--ok); }
.badge.error, .badge.timeout, .badge.killed { background: rgba(197,48,48,.15); color: var(--err); }
.badge.running { background: rgba(31,111,235,.15); color: var(--accent); }
.badge.queued { background: rgba(183,121,31,.15); color: var(--warn); }
.badge.off { background: var(--line); color: var(--muted); }
.badge.llm { background: rgba(124,58,237,.15); color: #7c3aed; }
.badge.python { background: rgba(31,111,235,.12); color: var(--accent); }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 13px; border-radius: 8px; cursor: pointer; }
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--err); }
button.danger:hover { border-color: var(--err); }
button.link { border: 0; background: none; color: inherit; padding: 0; cursor: pointer; text-align: left; }
button.link:hover { text-decoration: underline; }
button.small, .btn.small { padding: 4px 9px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { width: auto; flex: 1; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: rgba(127,127,127,.05); }
td.num { text-align: right; white-space: nowrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 14px 0 18px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

.status-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.status-bar .stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; min-width: 130px; }
.status-bar .stat b { display: block; font-size: 20px; }
.status-bar .stat span { font-size: 12px; color: var(--muted); }
.status-bar .stat.bad { border-color: var(--err); }

.log { background: var(--code-bg); color: var(--code-text); border-radius: var(--radius); padding: 12px 14px; height: 480px; overflow: auto; font-family: ui-monospace, Consolas, monospace; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.log.small { height: 240px; }

.files { display: grid; grid-template-columns: 240px 1fr; gap: 14px; min-height: 480px; }
@media (max-width: 900px) { .files { grid-template-columns: 1fr; } }
.file-list { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; overflow: auto; max-height: 560px; }
.file-list a { display: block; padding: 4px 8px; border-radius: 6px; color: var(--text); font-size: 13px; font-family: ui-monospace, Consolas, monospace; }
.file-list a.active { background: var(--accent); color: #fff; }
.file-list a.dir { color: var(--muted); }
.editor-wrap { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.editor-wrap textarea { font-family: ui-monospace, Consolas, monospace; font-size: 13px; min-height: 480px; white-space: pre; }
.CodeMirror { border: 1px solid var(--line); border-radius: var(--radius); height: 520px; font-size: 13px; }

.chat { display: grid; grid-template-columns: 240px 1fr; gap: 14px; }
@media (max-width: 900px) { .chat { grid-template-columns: 1fr; } }
.chat-list a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--text); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list a.active { background: var(--accent); color: #fff; }
.chat-messages { height: 480px; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 6px; }
.msg { max-width: 85%; padding: 9px 13px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--line); }
.msg.tool { align-self: flex-start; font-size: 12px; color: var(--muted); padding: 2px 8px; }
.msg.error { align-self: flex-start; background: rgba(197,48,48,.12); color: var(--err); }
.chat-input { display: flex; gap: 8px; margin-top: 8px; }
.chat-input textarea { min-height: 44px; height: 60px; }

.toast { position: fixed; right: 20px; bottom: 20px; background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,.25); z-index: 50; max-width: 420px; }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

.login-box { width: 360px; }
.login-box h1 { text-align: center; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.alert.error { background: rgba(197,48,48,.12); color: var(--err); }
.alert.warn { background: rgba(183,121,31,.15); color: var(--warn); }
.alert.ok { background: rgba(26,138,74,.12); color: var(--ok); }
.alert.info { background: rgba(31,111,235,.1); color: var(--accent); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
details summary { cursor: pointer; color: var(--muted); }
.help h2 { margin-top: 26px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.help pre { margin: 8px 0 14px; }
.help table { margin: 8px 0 14px; }
.wrap { word-break: break-all; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.switch input { width: auto; }
