:root {
  --bg: #0b0f14;
  --panel: #121820;
  --line: #2a3544;
  --text: #e8eef5;
  --muted: #8b9cb0;
  --accent: #5eead4;
  --warn: #fbbf24;
  --bad: #f87171;
  --ok: #4ade80;
  --mono: "IBM Plex Mono", "SF Mono", Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --hdr-h: 72px;
  --bar-h: 36px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
}
.app {
  height: 100dvh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.hdr {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  max-height: 30vh;
  overflow: auto;
}
.hdr h1 { margin: 0; font-size: 1.1rem; }
.hdr-title { min-width: 0; }
.muted { color: var(--muted); font-size: 12px; }
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}
label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
input, select, textarea, button {
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #0d1218;
  color: var(--text);
  padding: 6px 8px;
  font-size: 13px;
}
select { max-width: 140px; }
input[type=number] { width: 64px; }
button {
  background: linear-gradient(180deg, #2dd4bf, #14b8a6);
  color: #042f2e;
  font-weight: 700;
  border: none;
  cursor: pointer;
  padding: 8px 12px;
}
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); font-weight: 500; }
a.link-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  text-decoration: none; font-size: 14px;
}
button.sm { padding: 2px 6px; font-size: 11px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.chk { flex-direction: row; align-items: center; gap: 4px; }

.live-bar {
  flex: 0 0 var(--bar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
  background: #0d1117;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.dot.pending { background: var(--warn); animation: pulse 1s infinite; }
.dot.ok { background: var(--ok); animation: none; }
.dot.err { background: var(--bad); animation: none; }
@keyframes pulse { 50% { opacity: 0.35; } }

.main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 38%);
  overflow: hidden;
}
.chat-pane, .side-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.chat-pane { border-right: 1px solid var(--line); }
.metrics {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.metrics b { color: var(--accent); }
.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
}
.chat-form {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}
.chat-form textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 88px;
  font-family: var(--sans);
}
.chat-form button { flex: 0 0 44px; padding: 0; }

.msg {
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  max-width: 95%;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}
.msg.user { margin-left: auto; background: #1a2838; border: 1px solid var(--line); }
.msg.bot { background: #101820; border: 1px solid #243040; }
.msg.meta { font-size: 11px; color: var(--muted); background: transparent; border: none; padding: 2px 0; max-width: 100%; }
.msg.err { border-color: var(--bad); color: #fecaca; }
.msg img { max-width: 100%; max-height: min(50vh, 480px); border-radius: 8px; margin-top: 8px; display: block; object-fit: contain; }
.img-prompt { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.msg .meta { margin-top: 6px; font-size: 11px; color: var(--muted); }

.pane-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  background: #0d1117;
  font-size: 12px;
}
.pane-head .muted { margin-left: auto; font-size: 11px; }
.activity {
  flex: 0 0 35%;
  min-height: 80px;
  max-height: 40%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.5;
  border-bottom: 1px solid var(--line);
  background: #0a0e13;
}
.act-line { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.04); word-break: break-word; }
.act-line .t { color: var(--muted); font-family: var(--mono); font-size: 10px; margin-right: 6px; }
.act-info { color: #7dd3fc; }
.act-warn { color: var(--warn); }
.act-err { color: var(--bad); }
.act-ok { color: var(--ok); }

.terminal {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.4;
  background: #05080c;
  color: #b8c5d6;
}
.terminal .log-line {
  margin-bottom: 4px;
  word-break: break-all;
  white-space: pre-wrap;
}
.log-info { color: #7dd3fc; }
.log-warn { color: var(--warn); }
.log-error { color: var(--bad); }

@media (max-width: 800px) {
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .side-pane { border-top: 1px solid var(--line); }
  .activity { max-height: 30%; }
}
