:root {
  --bg: #0c0c0d;
  --panel: #141415;
  --panel-2: #1a1a1b;
  --border: #2a2a2c;
  --text: #ececee;
  --muted: #8b8b90;
  --accent: #f2f2f2;
  --accent-fg: #111;
  --blue: #6ea8fe;
  --amber: #e6b84d;
  --green: #5ecf8e;
  --danger: #ff7b7b;
  --user: #1c1c1e;
  --composer-max: 200px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 280px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 960px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100vh;
  }
  .sidebar, .rail { max-height: 180px; overflow: auto; }
  .main { min-height: 0; }
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 10px;
  min-height: 0;
}
.sidebar-head .logo { font-weight: 650; font-size: 0.95rem; }
.sidebar-head .logo-sub { color: var(--muted); font-size: 0.75rem; margin-top: 2px; }

.btn-new, .btn-primary, .btn-ghost, .btn-composer {
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.btn-new {
  width: 100%;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--panel-2); }

.mode-row {
  display: grid;
  gap: 4px;
}
.mode-row label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.mode-row select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
  font: inherit;
}

.agent-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
  min-height: 0;
}
.agent-item {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
}
.agent-item:hover { background: var(--panel-2); }
.agent-item.active {
  background: var(--panel-2);
  border-color: var(--border);
}
.agent-item .t {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-item .s {
  margin-top: 3px;
  font-size: 0.7rem;
  color: var(--muted);
}

.sidebar-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
}
.pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
}
.muted { color: var(--muted); }

.main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}
.main-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}
.main-bar-text { min-width: 0; }
.main-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.main-meta { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.main-actions { display: flex; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }

.transcript-wrap {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.transcript {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 20px 22px 36px;
  scroll-behavior: auto;
  overscroll-behavior: contain;
}
.jump-latest {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 2;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.jump-latest:hover { background: var(--panel-2); }
.jump-latest[hidden] { display: none !important; }

.empty {
  max-width: 560px;
  margin: 10vh auto 0;
  color: var(--muted);
  text-align: left;
}
.empty h1 {
  color: var(--text);
  font-size: 1.55rem;
  font-weight: 600;
  margin: 0 0 10px;
}
.empty p { margin: 0 0 18px; line-height: 1.55; }
.suggest-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.suggest-chip {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
  max-width: 100%;
}
.suggest-chip:hover { background: var(--panel-2); border-color: #3a3a3d; }

.msg {
  max-width: 760px;
  margin: 0 auto 18px;
  display: grid;
  gap: 6px;
}
.msg .role {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  font-weight: 600;
}
.msg .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 0.92rem;
}
.msg .bubble.md { white-space: normal; }
.msg .bubble.md > *:first-child { margin-top: 0; }
.msg .bubble.md > *:last-child { margin-bottom: 0; }
.msg .bubble.md p { margin: 0.55em 0; }
.msg .bubble.md h1,
.msg .bubble.md h2,
.msg .bubble.md h3 {
  margin: 0.9em 0 0.4em;
  font-weight: 650;
  line-height: 1.3;
}
.msg .bubble.md h1 { font-size: 1.2rem; }
.msg .bubble.md h2 { font-size: 1.08rem; }
.msg .bubble.md h3 { font-size: 1rem; }
.msg .bubble.md ul,
.msg .bubble.md ol { margin: 0.4em 0; padding-left: 1.3em; }
.msg .bubble.md li { margin: 0.2em 0; }
.msg .bubble.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: #0a0a0b;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
.msg .bubble.md pre {
  overflow: auto;
  background: #0a0a0b;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0.6em 0;
}
.msg .bubble.md pre code {
  border: 0;
  background: transparent;
  padding: 0;
}
.msg .bubble.md table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6em 0;
  font-size: 0.88em;
}
.msg .bubble.md th,
.msg .bubble.md td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}
.msg .bubble.md th { background: var(--panel-2); }
.msg .bubble.md blockquote {
  margin: 0.5em 0;
  padding-left: 12px;
  border-left: 3px solid #3a3a3d;
  color: var(--muted);
}
.msg .bubble.md a { color: var(--blue); }
.msg.user .bubble { background: var(--user); }
.msg.system .bubble {
  border-style: dashed;
  color: var(--amber);
}

.msg-status {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 1.2em;
}
.msg-status.thinking::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
  animation: pulse-dot 1.1s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

.tool-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--blue);
  border: 1px solid #2a3a55;
  border-radius: 6px;
  padding: 3px 8px;
  background: rgba(110, 168, 254, 0.06);
}
.tool-chip.done { color: var(--green); border-color: #2a4a38; }
.tool-chip.error { color: var(--danger); border-color: #553030; }

.cursor-blink {
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--text);
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

.approval-banner {
  max-width: 760px;
  margin: 0 auto 16px;
  border: 1px solid #5a4a20;
  background: rgba(230, 184, 77, 0.08);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.approval-banner .t { font-weight: 600; color: var(--amber); }
.approval-banner .d { color: var(--muted); font-size: 0.82rem; margin-top: 4px; }
.approval-banner .actions { display: flex; gap: 8px; }

.composer {
  padding: 0 16px 14px;
  background: linear-gradient(180deg, transparent, #0c0c0d 28%);
}
.composer-box {
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 10px 10px 14px;
}
.composer-box:focus-within {
  border-color: #3a3a3d;
}
.composer textarea {
  width: 100%;
  resize: none;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 6px 0;
  font: inherit;
  line-height: 1.45;
  max-height: var(--composer-max);
  overflow-y: auto;
  field-sizing: content;
}
.composer textarea:focus { outline: none; }
.composer textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-composer {
  align-self: end;
  min-width: 72px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  border-radius: 10px;
  padding: 9px 14px;
}
.btn-composer:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-composer.is-stop {
  background: #2a1a1a;
  color: var(--danger);
  border: 1px solid #553030;
}
.composer-hint {
  max-width: 760px;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.rail {
  border-left: 1px solid var(--border);
  background: var(--panel);
  padding: 14px 12px;
  overflow: auto;
  min-height: 0;
}
.rail h3 {
  margin: 14px 0 8px;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.rail h3:first-child { margin-top: 0; }
.rail-block {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  white-space: pre-wrap;
}
.status-idle { color: var(--muted); }
.status-running { color: var(--blue); }
.status-needs_approval { color: var(--amber); }
.status-completed { color: var(--green); }
.status-failed { color: var(--danger); }
