:root {
  --bg: #0a0e14;
  --pane: #0f1620;
  --panel: #131c28;
  --panel-2: #162231;
  --border: #253246;
  --accent: #00d9ff;
  --ok: #7cdd7c;
  --warn: #f4c96b;
  --err: #ff6b7a;
  --text: #e6f0f7;
  --muted: #8da0b3;
  --faint: #5e6f7e;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  border-right: 1px solid var(--border);
  background: var(--pane);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brandbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: .08em;
}
.brand img { width: 28px; height: 28px; }
.beta {
  margin-left: auto;
  color: var(--faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.panel {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 10px;
}
label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}
input, select, textarea {
  width: 100%;
  color: var(--text);
  background: #0b1119;
  border: 1px solid var(--border);
  outline: none;
  padding: 8px 9px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; max-height: 220px; }

.primary, .ghost {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 10px;
}
.primary {
  border-color: var(--accent);
  color: var(--accent);
}
.primary:hover:not(:disabled), .ghost:hover:not(:disabled) {
  border-color: var(--accent);
}

.account-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.account-row > div { min-width: 0; flex: 1; }
.account-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.agents-section {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.section-head {
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.section-head .muted { margin-left: auto; }
.agent-list { overflow: auto; min-height: 0; }
.agent-item {
  width: 100%;
  border: 0;
  border-bottom: 1px solid rgba(37, 50, 70, .7);
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 14px;
  display: grid;
  gap: 3px;
}
.agent-item:hover, .agent-item.active { background: rgba(0, 217, 255, .06); }
.agent-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-meta { color: var(--faint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: linear-gradient(180deg, rgba(19, 28, 40, .55), rgba(10, 14, 20, 0) 240px), var(--bg);
}
.topbar {
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: space-between;
  padding: 10px 16px;
}
.workspace-title { color: var(--muted); font-size: 12px; }
.agent-title { font-size: 18px; font-weight: 700; }
.status-cluster { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  border: 1px solid var(--border);
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
}
.pill.online { color: var(--ok); border-color: rgba(124, 221, 124, .5); }
.pill.offline { color: var(--err); border-color: rgba(255, 107, 122, .45); }
.pill.running { color: var(--warn); border-color: rgba(244, 201, 107, .5); }
.pill.error { color: var(--err); border-color: rgba(255, 107, 122, .45); }
.pill.idle, .pill.done { color: var(--muted); }

.notice {
  margin: 12px 16px 0;
  border: 1px solid var(--border);
  background: rgba(19, 28, 40, .7);
  color: var(--muted);
  padding: 9px 10px;
}
.notice.error { border-color: rgba(255, 107, 122, .5); color: var(--err); }
.notice.ok { border-color: rgba(124, 221, 124, .5); color: var(--ok); }

.settings-panel {
  margin: 12px 16px 0;
  border: 1px solid var(--border);
  background: rgba(15, 22, 32, .9);
  padding: 10px;
  display: grid;
  gap: 10px;
}
.settings-head {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  font-weight: 650;
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: end;
  min-height: 36px;
}
.toggle-row input {
  width: auto;
}
.settings-panel textarea {
  min-height: 94px;
}
.settings-panel .ghost {
  justify-self: end;
  min-width: 140px;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.empty {
  color: var(--faint);
  border: 1px dashed var(--border);
  padding: 18px;
  text-align: center;
}
.msg {
  border: 1px solid var(--border);
  background: rgba(19, 28, 40, .72);
  padding: 10px 12px;
  max-width: 980px;
}
.msg.user { border-left: 3px solid var(--accent); }
.msg.assistant { border-left: 3px solid var(--ok); }
.msg.system, .msg.result { border-left: 3px solid var(--faint); }
.msg-head {
  color: var(--faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 6px;
}
.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--pane);
  padding: 12px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 10px;
}
.composer .primary { min-height: 72px; }

.hidden { display: none !important; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .agent-list { max-height: 220px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .settings-grid { grid-template-columns: 1fr; }
  .composer { grid-template-columns: 1fr; }
  .composer .primary { min-height: 42px; }
}
