:root {
  color-scheme: dark;
  --bg: #0e1013;
  --panel: #15181d;
  --hover: #1a1e25;
  --active: #1d2633;
  --line: #262b33;
  --text: #cfd6df;
  --dim: #7d8794;
  --good: #6cc48a;
  --warn: #e0b354;
  --bad: #f0706a;
  --info: #6fb0e8;
  --accent: #b79cf0;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: #2b313b #0e1013;
}
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: var(--bg); }
*::-webkit-scrollbar-thumb { background: #2b313b; }
*::-webkit-scrollbar-thumb:hover { background: #3e4756; }
*::-webkit-scrollbar-corner { background: var(--bg); }

html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.35 ui-monospace, "JetBrains Mono", "DejaVu Sans Mono", Menlo, monospace;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-rows: auto 1fr;
  padding-top: env(safe-area-inset-top);
}

.hidden { display: none !important; }
.dim { color: var(--dim); }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.info { color: var(--info); }
.accent { color: var(--accent); }
.fill { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button, a, input, textarea {
  font: inherit;
  color: inherit;
}

/* Top 1-line status strip (homunculus style) */
#strip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 3px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
}
#strip b { font-weight: 600; }
#strip a, #strip button {
  background: none;
  border: none;
  padding: 0;
  color: var(--dim);
  text-decoration: none;
  cursor: pointer;
}
#strip a:hover, #strip button:hover { color: var(--text); }

/* 1px hairline grid shell */
.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 1px;
  background: var(--line);
  min-height: 0;
}

.rail, .pane {
  background: var(--bg);
  display: grid;
  min-height: 0;
  min-width: 0;
}
.rail { grid-template-rows: auto 1fr; }
.pane { grid-template-rows: auto 1fr auto; }

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  white-space: nowrap;
  min-height: 24px;
}
.bar b { color: var(--text); font-weight: 600; }
.bar input {
  flex: 1;
  min-width: 50px;
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 0 5px;
  color: var(--text);
  outline: none;
}
.bar input:focus { border-color: var(--info); }
.bar button {
  background: none;
  border: 1px solid var(--line);
  color: var(--dim);
  padding: 0 5px;
  cursor: pointer;
}
.bar button:hover { color: var(--text); border-color: var(--dim); }

.mobile-only { display: none; }
.scroll { overflow-y: auto; overflow-x: hidden; min-height: 0; -webkit-overflow-scrolling: touch; }

/* Dense terminal topic list — zero icons/avatars */
.sec {
  padding: 4px 8px 2px;
  color: var(--dim);
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}
.sec:first-child { border-top: none; }

.t-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: none;
  border: none;
  border-bottom: 1px solid #171a20;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.t-row:hover { background: var(--hover); }
.t-row.active { background: var(--active); color: #eef2f7; }
.t-dot { width: 1ch; flex: none; text-align: center; }
.t-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.t-age { color: var(--dim); flex: none; font-size: 11px; }
.t-cnt {
  flex: none;
  padding: 0 4px;
  background: var(--info);
  color: #0b0e12;
  font-weight: 700;
  font-size: 11px;
}
.t-cnt.warn { background: var(--warn); }

/* Dense full-width terminal message log */
.stream {
  display: flex;
  flex-direction: column;
}

.notice {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 8px;
}
.notice button {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 1px 7px;
  cursor: pointer;
}
.notice button:hover { border-color: var(--info); }

.msg {
  padding: 5px 8px 6px;
  border-bottom: 1px solid var(--line);
  touch-action: pan-y;
}
.msg:hover { background: #111419; }
.msg.out { border-left: 2px solid var(--info); padding-left: 6px; }
.msg.in { border-left: 2px solid var(--accent); padding-left: 6px; }
.msg.sys { border-left: 2px solid var(--dim); padding-left: 6px; color: var(--dim); background: #111419; }
.msg.hl { background: #1e2837; }
.t-sep {
  padding: 2px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  font-size: 11px;
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}
.msg-reply {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--dim);
  padding: 0;
  cursor: pointer;
  opacity: 0.55;
}
.msg:hover .msg-reply { opacity: 1; }
.msg-reply:hover { color: var(--text); }

.msg-quote {
  margin: 2px 0 2px 0;
  padding: 1px 6px;
  border-left: 2px solid var(--dim);
  color: var(--dim);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-quote:hover { color: var(--text); }

.msg-body {
  margin-top: 2px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}
.msg-body code {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 0 3px;
}
.msg-body pre {
  margin: 4px 0 2px;
  padding: 4px 7px;
  background: var(--panel);
  border-left: 2px solid var(--accent);
  overflow-x: auto;
  position: relative;
}
.msg-body pre code {
  background: none;
  border: none;
  padding: 0;
}
.code-copy {
  position: absolute;
  top: 2px;
  right: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--dim);
  padding: 0 5px;
  font-size: 11px;
  cursor: pointer;
  opacity: 0.7;
}
.code-copy:hover { opacity: 1; color: var(--text); border-color: var(--dim); }
.msg-body a { color: var(--info); }

/* General view rows */
.g-sec {
  padding: 3px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--dim);
}
.g-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  border-bottom: 1px solid #171a20;
  white-space: nowrap;
}
.g-row:hover { background: var(--hover); }
.g-row button {
  background: none;
  border: 1px solid var(--line);
  padding: 0 6px;
  cursor: pointer;
}
.g-row button:hover { border-color: var(--dim); }

/* Flush terminal composer + slash/mention autocomplete menu */
.composer-wrap {
  position: relative;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom);
}
.cmd-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  background: var(--panel);
  border-top: 1px solid var(--line);
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
}
.cmd-item {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 4px 8px;
  background: none;
  border: none;
  border-bottom: 1px solid #1b1f26;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.cmd-item:hover, .cmd-item.sel {
  background: var(--active);
}
.cmd-item .cmd-name { color: var(--info); font-weight: 600; min-width: 14ch; flex: none; }
.cmd-item .cmd-desc { color: var(--dim); flex: 1; overflow: hidden; text-overflow: ellipsis; }
.cmd-hint-bar {
  padding: 2px 8px;
  color: var(--dim);
  font-size: 11px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
@keyframes pulse-dim { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.waiting { color: var(--info); animation: pulse-dim 1.2s ease-in-out infinite; }
.reply-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-bottom: 1px solid var(--line);
  background: #12161d;
}
.reply-bar button {
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  padding: 0 4px;
}
.composer {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 4px 8px;
}
.prompt { padding-top: 2px; user-select: none; }
.composer textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  padding: 2px 0;
  max-height: 140px;
  line-height: 1.35;
}
.composer button {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--info);
  padding: 2px 10px;
  cursor: pointer;
  flex: none;
}
.composer button:hover:not(:disabled) { border-color: var(--info); }
.composer button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Sharp schematic modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 13, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 50;
}
.modal-box {
  width: 100%;
  max-width: 520px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.modal-body { padding: 8px; }
.m-label { color: var(--dim); margin: 6px 0 3px; }
.m-label:first-child { margin-top: 0; }
.cmd {
  margin: 0 0 8px;
  padding: 5px 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--good);
  overflow-x: auto;
  cursor: pointer;
}
.cmd:hover { border-color: var(--good); }
.m-form { margin-top: 8px; }
.m-row { display: flex; gap: 4px; }
.m-row input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 3px 6px;
  outline: none;
}
.m-row input:focus { border-color: var(--info); }
.m-row button {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--info);
  padding: 3px 10px;
  cursor: pointer;
}
.m-row button:hover { border-color: var(--info); }
.m-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.m-foot button {
  background: none;
  border: 1px solid var(--line);
  padding: 1px 7px;
  cursor: pointer;
}

/* Mobile: single-column terminal topics <-> chat */
@media (max-width: 768px) {
  html, body { font-size: 13px; }
  .shell {
    grid-template-columns: 1fr;
    position: relative;
  }
  .rail, .pane {
    position: absolute;
    inset: 0;
  }
  .shell.view-topics .rail { display: grid; z-index: 2; }
  .shell.view-topics .pane { display: none; }
  .shell.view-chat .rail { display: none; }
  .shell.view-chat .pane { display: grid; z-index: 2; }
  .mobile-only { display: inline-block; }
  .t-row { padding: 7px 10px; }
  .bar { min-height: 32px; padding: 4px 8px; }
  .msg { padding: 7px 10px; }
  .composer { padding: 6px 8px; }
}
