:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel-2: #1d2230;
  --fg: #e7ecf3;
  --muted: #8893a7;
  --accent: #d97757;
  --accent-hover: #e58b6d;
  --border: #252b39;
  --danger: #d96262;
  --ok: #6abf6a;
  --bubble-user: #223048;
  --bubble-asst: #1c2130;
  --tool: #1b2332;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.5 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif; }

/* --- login --- */
.center { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px 28px 24px; width: 340px; display: flex; flex-direction: column; gap: 12px; }
.card h1 { margin: 0; font-size: 22px; }
.card .muted { color: var(--muted); margin: 0 0 8px; }
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.card input { background: var(--panel-2); border: 1px solid var(--border); color: var(--fg);
  padding: 10px; border-radius: 6px; font: inherit; }
.card input:focus { outline: 2px solid var(--accent); }
.card button { background: var(--accent); color: #fff; border: 0; padding: 10px;
  border-radius: 6px; font: inherit; cursor: pointer; margin-top: 4px; }
.card button:hover { background: var(--accent-hover); }
.error { background: #3b1f22; color: #ffb0b0; padding: 8px 10px; border-radius: 6px; }

/* --- chat shell --- */
#app { display: grid; grid-template-columns: 240px 1fr 280px; height: 100vh;
  grid-template-rows: 100vh; }

.chats, .activity { background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; }
.activity { border-right: 0; border-left: 1px solid var(--border); }

.chats header, .activity header { display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.brand { color: var(--accent); }
.chats header form { margin: 0; }
.chats header button, .activity header button {
  background: transparent; color: var(--muted); border: 0; cursor: pointer; font-size: 14px; }

#new-chat { margin: 10px; padding: 8px; background: var(--panel-2); color: var(--fg);
  border: 1px dashed var(--border); border-radius: 6px; cursor: pointer; }
#new-chat:hover { border-color: var(--accent); color: var(--accent); }

#chat-list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
#chat-list li { padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-list li:hover { background: var(--panel-2); }
#chat-list li.active { background: var(--panel-2); border-left: 2px solid var(--accent); }
#chat-list li .meta { display: block; font-size: 11px; color: var(--muted); }

.user { padding: 10px 14px; color: var(--muted); border-top: 1px solid var(--border); font-size: 12px; }

/* --- messages pane --- */
.messages { display: flex; flex-direction: column; min-height: 0; }
#thread { flex: 1; overflow-y: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 760px; }
.msg.user { align-self: flex-end; background: var(--bubble-user); padding: 10px 14px;
  border-radius: 10px; }
.msg.assistant { background: var(--bubble-asst); padding: 12px 16px; border-radius: 10px;
  border: 1px solid var(--border); }
.msg .role { font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase;
  letter-spacing: 0.05em; }
.msg pre { background: #0a0c11; padding: 10px; border-radius: 6px; overflow-x: auto; }
.msg code { background: #0a0c11; padding: 1px 6px; border-radius: 4px; }
.msg.error { background: #3b1f22; color: #ffb0b0; }

.tool-card { background: var(--tool); border: 1px solid var(--border); border-radius: 6px;
  margin: 8px 0; overflow: hidden; }
.tool-card > summary { padding: 8px 12px; cursor: pointer; display: flex; gap: 8px; align-items: center;
  user-select: none; }
.tool-card > summary::-webkit-details-marker { display: none; }
.tool-card .badge { font-size: 11px; color: var(--accent); text-transform: uppercase;
  letter-spacing: 0.05em; }
.tool-card .preview { color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px;
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-card .body { padding: 10px 12px; border-top: 1px solid var(--border); font-family: ui-monospace, monospace;
  font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto; }
.tool-card.ok .badge { color: var(--ok); }
.tool-card.err .badge { color: var(--danger); }

/* --- composer --- */
#composer { border-top: 1px solid var(--border); padding: 12px 16px; display: flex; gap: 8px;
  background: var(--panel); }
#prompt { flex: 1; background: var(--panel-2); color: var(--fg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; font: inherit; resize: vertical; min-height: 60px; }
#send { background: var(--accent); color: #fff; border: 0; padding: 0 20px; border-radius: 8px;
  cursor: pointer; font: inherit; }
#send:disabled { background: var(--panel-2); color: var(--muted); cursor: wait; }

/* --- activity pane --- */
#activity-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; font-size: 12px; }
#activity-list li { padding: 6px 8px; border-radius: 4px; color: var(--muted); display: flex; gap: 6px;
  align-items: baseline; }
#activity-list li:hover { background: var(--panel-2); color: var(--fg); }
#activity-list .t { color: var(--accent); font-family: ui-monospace, monospace; font-size: 11px; }

#app.hide-activity { grid-template-columns: 240px 1fr 0; }
#app.hide-activity .activity { display: none; }

/* --- admin page --- */
.admin { max-width: 720px; margin: 40px auto; padding: 0 16px; }
.admin .status { display: flex; align-items: center; gap: 10px; margin: 16px 0; }
.chip { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.chip.ok { background: #1a3321; color: var(--ok); }
.chip.err { background: #3b1f22; color: var(--danger); }
.chip.unk { background: var(--panel-2); color: var(--muted); }
#pty-log { background: #0a0c11; border: 1px solid var(--border); border-radius: 6px;
  padding: 10px; font-family: ui-monospace, monospace; font-size: 12px; height: 360px;
  overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row input { flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--fg);
  padding: 8px 10px; border-radius: 6px; font: inherit; }
.row button { background: var(--accent); color: #fff; border: 0; padding: 8px 16px; border-radius: 6px;
  cursor: pointer; }
