@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600&display=swap");

:root {
  --bg: #090a0c;
  --bg-2: #101216;
  --bg-3: #171a20;
  --line: #262a33;
  --text: #e8eaed;
  --muted: #8b919c;
  --mint: #7dffb3;
  --mint-dim: #2a6b4a;
  --blue: #7db8ff;
  --amber: #ffc857;
  --rose: #ff6b7a;
  --mono: "IBM Plex Mono", "ui-monospace", Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --side-w: 280px;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; }
a { color: var(--mint); }

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 500px at 10% -10%, #123326 0%, transparent 50%),
    var(--bg);
}
.auth-card {
  width: 380px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 28px;
  max-height: 90vh;
  overflow: auto;
}
.brand {
  font-family: var(--mono);
  font-size: 28px;
  letter-spacing: -0.06em;
  color: var(--mint);
  text-decoration: none;
}
a.brand { color: var(--mint); }
.sub { color: var(--muted); margin: 6px 0 22px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.field input, .field textarea, .field select {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 10px 12px;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--mint-dim); }
.btn, a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  border: 0;
  border-radius: 4px;
  background: var(--mint);
  color: #06140c;
  text-decoration: none;
  flex: none;
}
.btn.ghost, a.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.danger { background: var(--rose); color: #1a0408; }
.btn.ghost.danger {
  background: transparent;
  color: var(--rose);
  border-color: transparent;
}
.btn.ghost.danger:hover { border-color: var(--rose); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.row-del {
  width: 28px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  flex: none;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.err { color: var(--rose); font-size: 13px; margin: 8px 0; }

.shell {
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr);
  height: 100%;
  overflow: hidden;
}
.top {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.tabs { display: flex; gap: 4px; height: 100%; }
.tab {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 0 14px;
  border-bottom: 2px solid transparent;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.tab.on { color: var(--text); border-bottom-color: var(--mint); }
a.tab { color: var(--muted); }
a.tab.on { color: var(--text); }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 12px; }

.split {
  display: grid;
  grid-template-columns: var(--side-w) 5px minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.side {
  background: var(--bg-2);
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.side-resizer {
  position: relative;
  cursor: col-resize;
  background: var(--line);
  touch-action: none;
}
.side-resizer::after {
  content: "";
  position: absolute;
  inset: 0 -4px;
}
.side-resizer:hover,
body.resizing .side-resizer {
  background: var(--mint);
}
body.resizing {
  cursor: col-resize;
  user-select: none;
}
body.resizing iframe,
body.resizing textarea,
body.resizing input {
  pointer-events: none;
}
.side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.project { border-bottom: 1px solid var(--line); }
.project-h {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px 10px 12px;
  background: none;
  border: 0;
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.project-h .name {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.caret { color: var(--muted); width: 12px; }
.chat-row {
  display: flex;
  align-items: center;
  min-width: 0;
  width: 100%;
}
.chat-row:hover,
.chat-row.on { background: var(--bg-3); }
.chat-item {
  display: flex;
  flex: 1;
  min-width: 0;
  width: auto;
  background: none;
  border: 0;
  text-align: left;
  padding: 8px 4px 8px 12px;
  color: var(--muted);
  gap: 8px;
  align-items: center;
  text-decoration: none;
  box-sizing: border-box;
}
a.chat-item { color: var(--muted); }
.chat-row.on .chat-item,
.chat-row:hover .chat-item { color: var(--text); }
.chat-item.sub { color: var(--muted); }
.chat-item.has-kids .caret {
  color: var(--mint);
  cursor: pointer;
}
.chat-item .spacer-caret { visibility: hidden; }
.chat-node { min-width: 0; }
.chat-kids {
  margin: 0 0 4px 20px;
  border-left: 1px solid var(--line);
}
.chat-item .title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item .tag {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--blue);
  flex: none;
}
.chat-row .row-del { margin-right: 8px; }
.project-h .btn { flex: none; }
.file-item {
  display: flex;
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  padding: 6px 12px;
  color: var(--muted);
  gap: 8px;
  align-items: center;
  box-sizing: border-box;
}
.file-item .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: inherit;
}
.file-item .caret { width: 12px; flex: none; }
.file-item.on, .file-item:hover { background: var(--bg-3); color: var(--text); }
.file-item.dir .name { font-weight: 500; }
.file-pane { grid-template-rows: auto minmax(0, 1fr); }
.file-editor {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  background: var(--bg);
  border: 0;
  padding: 16px 20px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  outline: none;
  color: var(--text);
}
.file-warn {
  padding: 40px 28px;
  color: var(--text);
  max-width: 42em;
}
.side-empty { color: var(--muted); padding: 16px 12px; font-size: 13px; }
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  padding: 8px 12px;
  color: var(--muted);
  text-decoration: none;
  box-sizing: border-box;
}
a.nav-item { color: var(--muted); }
.nav-item .name {
  color: inherit;
  font-weight: 500;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-item .sub {
  font-size: 11px;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-item.on, .nav-item:hover { background: var(--bg-3); color: var(--text); }
.pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.pane-body {
  overflow: auto;
  min-height: 0;
  padding: 24px 28px 48px;
}
.pane-form { max-width: 720px; }
.pane-form textarea {
  min-height: 96px;
  resize: vertical;
}
.pane-form textarea.tall {
  min-height: 280px;
  font-family: var(--mono);
  font-size: 12px;
}
.pane-form .field input,
.pane-form .field textarea,
.pane-form .field select { width: 100%; }
.dot { width: 7px; height: 7px; border-radius: 99px; background: var(--line); margin-top: 5px; flex: none; }
.dot.run { background: var(--mint); box-shadow: 0 0 8px var(--mint); }
.dot.err { background: var(--rose); }

.thread {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.msgs {
  overflow: auto;
  min-height: 0;
  padding: 20px 28px 40px;
  overscroll-behavior: contain;
}
.msg { margin: 0 0 18px; max-width: 860px; }
.turn { margin: 0 0 18px; max-width: 860px; }
.turn > .msg { margin: 0 0 10px; }
.turn > .msg:last-child { margin-bottom: 0; }
.turn > .work { margin-bottom: 10px; }
.turn > .work:last-child { margin-bottom: 0; }
.msg .role {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.msg.user .role { color: var(--blue); }
.msg.assistant .role { color: var(--mint); }
.msg.error .role { color: var(--rose); }
.msg .body { line-height: 1.55; }
.msg.error .body {
  color: var(--rose);
  background: #1a0c10;
  border: 1px solid #5a2430;
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}
.work {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  background: var(--bg-2);
  border-radius: 4px;
}
.work.running { border-left-color: var(--amber); }
.work-h {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: none;
  border: 0;
  width: 100%;
  min-width: 0;
  text-align: left;
  color: var(--text);
}
.work-h .dot { margin-top: 0; }
.work-label {
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.work.running .work-label { color: var(--amber); }
.work-dur, .tool-time, .tool-dur {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.work.running .work-dur { color: var(--amber); }
.tool-time:empty, .tool-dur:empty, .work-dur:empty { display: none; }
.work-body {
  border-top: 1px solid var(--line);
  padding: 8px 10px 10px;
}
.work-body .tool { margin: 6px 0; }
.work-body .tool:first-child { margin-top: 0; }
.work-body .tool:last-child { margin-bottom: 0; }
.md { overflow-wrap: anywhere; }
.md p { margin: 0 0 0.7em; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 0.9em 0 0.4em; line-height: 1.25; font-weight: 600; }
.md h1 { font-size: 1.35em; }
.md h2 { font-size: 1.2em; }
.md h3, .md h4 { font-size: 1.05em; }
.md h1:first-child, .md h2:first-child, .md h3:first-child { margin-top: 0; }
.md ul, .md ol { margin: 0.4em 0 0.7em; padding-left: 1.4em; }
.md li { margin: 0.2em 0; }
.md blockquote {
  margin: 0.5em 0;
  padding: 0.2em 0 0.2em 0.9em;
  border-left: 3px solid var(--mint-dim);
  color: var(--muted);
}
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md a { color: var(--mint); }
.md code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: #1d2430;
  padding: 0.12em 0.4em;
  border-radius: 3px;
}
.md pre {
  margin: 0.6em 0;
  padding: 12px 14px;
  background: #12151b;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
}
.md pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  display: block;
  white-space: pre;
}
.md table {
  border-collapse: collapse;
  margin: 0.6em 0 0.8em;
  width: 100%;
  font-size: 13px;
}
.md th, .md td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.md th { background: var(--bg-3); font-weight: 600; }
.tool {
  margin: 8px 0;
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  background: var(--bg-3);
  border-radius: 4px;
}
.tool.ok { border-left-color: var(--mint); }
.tool.error, .tool.err { border-left-color: var(--rose); }
.tool.running, .tool.pending { border-left-color: var(--amber); }
.tool.think { border-left-color: var(--blue); }
.tool.think.running { border-left-color: var(--blue); }
.tool-h {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: none;
  border: 0;
  width: 100%;
  min-width: 0;
  text-align: left;
  color: var(--text);
}
.tool-h .dot { margin-top: 0; }
.tool-status {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--amber);
}
.tool-status.ok { color: var(--mint); }
.tool-status.error, .tool-status.err { color: var(--rose); }
.tool-status.running, .tool-status.pending { color: var(--amber); }
.pill {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  background: #1d2430;
  color: var(--amber);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: min(52ch, 62%);
}
.pill.ok { color: var(--mint); }
.pill.error, .pill.err { color: var(--rose); }
.pill.running, .pill.pending { color: var(--amber); }
.pill.think { color: var(--blue); }
.tool-status.think { color: var(--blue); }
.tool pre {
  margin: 0;
  padding: 10px;
  border-top: 1px solid var(--line);
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: #c9cdd4;
  white-space: pre-wrap;
  max-height: 240px;
}
.qdock:empty { display: none; }
.qdock {
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  padding: 12px 16px 14px;
  max-height: 46vh;
  overflow: auto;
}
.qdock-h {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.qdock-title {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--mint);
}
.qdock-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.qtab {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 4px;
}
.qtab.on { border-color: var(--mint-dim); color: var(--mint); background: #102018; }
.qtab.done { color: var(--text); }
.qprompt {
  font-size: 14px;
  line-height: 1.45;
  margin: 0 0 10px;
}
.qopt {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  margin: 0 0 6px;
}
.qopt:hover { border-color: var(--mint-dim); }
.qopt.on { border-color: var(--mint); background: #102018; }
.qopt-label { font-weight: 600; }
.qopt-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.qcustom {
  margin: 8px 0 0;
}
.qcustom input, .qcustom textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 8px 10px;
  outline: none;
}
.qcustom input:focus, .qcustom textarea:focus { border-color: var(--mint-dim); }
.qreview { display: flex; flex-direction: column; gap: 8px; }
.qreview-row { font-size: 13px; }
.qreview-h { color: var(--muted); margin-right: 6px; }
.qreview-miss { color: var(--rose); }
.qdock-f {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}
.qdock-f:empty { display: none; }
.composer {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  background: var(--bg-2);
}
.composer-side { display: flex; flex-direction: column; gap: 8px; min-width: 180px; }
.composer-side select {
  background: var(--bg);
  border: 1px solid var(--line);
  height: 32px;
  padding: 0 10px;
}
.composer-side .btn { width: 100%; }
.composer textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  min-height: 64px;
  resize: vertical;
  padding: 10px;
  outline: none;
}
.composer.readonly {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  min-height: 48px;
}
.tool-child {
  display: inline-flex;
  margin: 0 10px 8px;
  font-size: 12px;
}
.field .check {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--text);
  margin: 0;
}
.check-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin-top: 8px;
}
.empty {
  color: var(--muted);
  padding: 48px;
  text-align: center;
}

.page {
  padding: 24px 28px;
  overflow: auto;
  min-height: 0;
  height: 100%;
}
.grid { display: grid; gap: 16px; }
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 16px;
}
h1 { font-size: 18px; font-weight: 600; margin: 0 0 16px; }
h2 { font-size: 14px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.mono { font-family: var(--mono); font-size: 12px; }
.models th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 500; }
.models select { background: var(--bg); border: 1px solid var(--line); padding: 6px 8px; }
.models .check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  min-height: 40px;
}
.ctx {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  justify-content: center;
}
.ctx-bar {
  width: 72px;
  height: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 99px;
  overflow: hidden;
  flex: none;
}
.ctx-bar > i {
  display: block;
  height: 100%;
  background: var(--mint);
  width: 0;
}
.ctx.warn .ctx-bar > i { background: var(--amber); }
.ctx.hot .ctx-bar > i { background: var(--rose); }
.ctx-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.compact-div {
  margin: 14px 16px;
}
.compact-h {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.compact-line {
  flex: 1;
  height: 1px;
  background: var(--line);
}
.compact-label { flex: none; }
.compact-div.open .compact-label { color: var(--mint); }
.compact-div.compacting .compact-label {
  color: var(--amber);
  animation: compact-pulse 1.4s ease-in-out infinite;
}
.compact-div.compacting .dot {
  margin-top: 0;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}
@keyframes compact-pulse {
  50% { opacity: 0.55; }
}
.compact-body {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--text);
}
.ctx-input {
  width: 7.5rem;
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 6px 8px;
}
.kv-rows { display: grid; gap: 6px; }
.kv-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
  align-items: center;
}
.kv-row input {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 8px 10px;
  min-width: 0;
}
