:root {
  --bg: #0b0d11;
  --bg-1: #11141a;
  --bg-2: #171b23;
  --line: #2a3140;
  --text: #e8edf4;
  --muted: #8b95a7;
  --accent: #5eead4;
  --accent-dim: color-mix(in srgb, var(--accent) 18%, transparent);
  --run: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --log: #7dd3fc;
  --mono: "JetBrains Mono", "SF Mono", "Cascadia Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  --rail: 320px;
  --font: 16px;
  --font-log: 16px;
  --font-small: 13px;
  --font-tiny: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: var(--font)/1.45 var(--sans); }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }

#app { display: flex; flex-direction: column; height: 100%; }

.login {
  margin: 12vh auto 0;
  width: min(420px, calc(100% - 32px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login.hidden { display: none; }
.login h1 { font-size: 22px; font-weight: 650; margin: 0; }
.login p { margin: 0; color: var(--muted); }
.login input {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.login button {
  align-self: start;
  background: var(--accent-dim);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
}
body.shared #share,
body.shared #dismiss,
body.shared .clean-wrap { display: none; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}
.brand { display: flex; align-items: center; gap: 10px; letter-spacing: 0.12em; text-transform: lowercase; font-weight: 650; }
.mark {
  width: 18px; height: 18px; border: 1.5px solid var(--accent); border-radius: 4px;
  box-shadow: inset 0 -7px 0 -5.5px var(--accent);
}
.word { color: var(--text); }
.top-meta { display: flex; gap: 12px; align-items: center; }
.quiet { color: var(--muted); font-size: var(--font-small); }

.pill {
  font-size: var(--font-tiny);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
}
.pill.up { color: var(--run); border-color: color-mix(in srgb, var(--run) 40%, var(--line)); }
.pill.down { color: var(--warn); }

.shell { display: flex; flex: 1; min-height: 0; }
.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  border-right: 1px solid var(--line);
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail-head {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px 8px;
  color: var(--muted);
  font-size: var(--font-tiny);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.clean-wrap { position: relative; display: flex; }
.clean-wrap > #clear-ended { border-radius: 7px 0 0 7px; border-right-width: 0; }
.clean-wrap > .clean-more {
  border-radius: 0 7px 7px 0;
  padding: 4px 7px;
}
.clean-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 15rem;
  padding: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--font-small);
  color: var(--text);
  box-shadow: 0 10px 30px rgb(0 0 0 / 35%);
}
.clean-menu p { margin: 0 0 4px; color: var(--muted); font-size: var(--font-tiny); }
.clean-menu button[data-older] {
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.clean-menu button[data-older]:hover { background: var(--bg); }
.clean-menu form {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}
.clean-menu input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  color: var(--text);
  font-size: var(--font-small);
}
.session-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 10px 10px;
}
.session-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--muted);
  font-size: var(--font-tiny);
}
.session-chip span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 14rem;
}
.session-chip .n { opacity: 0.7; font-variant-numeric: tabular-nums; }
.session-chip:hover { color: var(--text); border-color: var(--muted); }
.session-chip.active { color: var(--text); border-color: var(--accent); background: var(--accent-dim); }
.session-chip.running { box-shadow: 0 0 0 1px color-mix(in srgb, var(--run) 50%, transparent); }

.stream-list { overflow: auto; flex: 1; padding: 4px; }
.empty-rail { color: var(--muted); padding: 8px 14px 16px; font-size: var(--font-small); line-height: 1.5; }

.stream {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 8px;
  align-items: start;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--text);
}
.stream:hover { background: var(--bg-2); }
.stream.active { background: var(--bg-2); border-color: var(--line); }
.stream .dot {
  width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--muted);
}
.stream.running .dot { background: var(--run); box-shadow: 0 0 0 4px color-mix(in srgb, var(--run) 22%, transparent); }
.stream.error .dot { background: var(--err); }
.stream.done .dot { background: var(--muted); }
.stream .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream .meta { color: var(--muted); font-size: var(--font-tiny); margin-top: 2px; }
.stream .kind {
  font-size: var(--font-tiny);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.empty { margin: auto; max-width: 36rem; padding: 2rem; }
.empty h1 { font-size: 1.6rem; font-weight: 600; margin: 0 0 0.6rem; }
.empty p { color: var(--muted); margin: 0 0 1.2rem; }
.empty pre {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: var(--font-small);
  color: var(--accent);
  overflow: auto;
}

.pane { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.hidden { display: none !important; }
.pane-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}
.pane-title h2 { margin: 0; font-size: 1.05rem; font-weight: 650; }
.pane-title p { margin: 2px 0 0; color: var(--muted); font-size: var(--font-small); font-family: var(--mono); }
.pane-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.share-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.share-bar input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--font-small);
}
.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 9px;
  cursor: pointer;
  color: var(--muted);
}
.ghost:hover, .ghost.on { color: var(--text); border-color: var(--muted); }
#dismiss:hover { color: var(--err); border-color: color-mix(in srgb, var(--err) 50%, var(--line)); }
.search input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 8px;
  width: 180px;
}

.view { flex: 1; min-height: 0; overflow: auto; }
.log {
  margin: 0;
  padding: 12px 16px 24px;
  font: var(--font-log)/1.55 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}
.log .line { min-height: 1.55em; }
.doc, .json {
  margin: 0 auto;
  max-width: 52rem;
  padding: 28px 32px 48px;
}
.doc h1, .doc h2, .doc h3 { line-height: 1.25; }
.doc h1 { font-size: 1.8rem; }
.doc pre, .json {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  overflow: auto;
  font-family: var(--mono);
  font-size: var(--font-log);
}
.doc code { font-family: var(--mono); font-size: 0.92em; }
.doc :not(pre) > code { background: var(--bg-2); padding: 0.1em 0.35em; border-radius: 4px; }
.doc a { color: var(--accent); }
.doc blockquote { border-left: 3px solid var(--line); margin: 1em 0; padding: 0 1em; color: var(--muted); }
.doc .table-wrap { overflow-x: auto; margin: 1.1em 0; }
.doc table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
}
.doc th, .doc td {
  border: 1px solid var(--line);
  padding: 8px 12px;
  vertical-align: top;
}
.doc thead th {
  background: var(--bg-2);
  font-weight: 650;
}
.doc tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--bg-2) 60%, transparent);
}
.doc .mermaid {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  overflow: auto;
  display: flex;
  justify-content: center;
  margin: 1.1em 0;
}
.doc .mermaid svg { max-width: 100%; height: auto; }
.doc .mermaid-error { color: var(--err); white-space: pre-wrap; }
.frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
.image-wrap { display: grid; place-items: center; height: 100%; padding: 24px; }
.image-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }

.pane-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg-1);
  color: var(--muted);
  font-size: var(--font-small);
}

dialog {
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
dialog ul { padding-left: 1.1rem; color: var(--muted); }
kbd {
  font-family: var(--mono);
  font-size: var(--font-small);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  color: var(--text);
}

.ansi-bold { font-weight: 700; }
.ansi-dim { opacity: 0.7; }
.ansi-italic { font-style: italic; }
.ansi-underline { text-decoration: underline; }
.ansi-strike { text-decoration: line-through; }

@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .rail { width: 100%; flex: 0 0 auto; max-height: 30vh; border-right: 0; border-bottom: 1px solid var(--line); }
}
