:root {
  color-scheme: dark;
  --bg: #171716;
  --panel: #222220;
  --line: #3a3a36;
  --ink: #f1efe8;
  --muted: #a7a49a;
  --accent: #d8d2c4;
  --danger: #d96b63;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  height: 100dvh;
}
button, input, textarea { font: inherit; }
button {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--accent);
  color: #171716;
  padding: 9px 13px;
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--ink); }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #1c1c1a;
  color: var(--ink);
  padding: 9px 10px;
}
textarea { resize: vertical; min-height: 48px; max-height: 30dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar > div { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 12px; }
.pill { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; color: var(--muted); }
.pill[data-state="on"] { color: #9bd49b; border-color: #3f6b3f; }
.connect-panel { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; background: var(--panel); }
.connect-panel summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.connect-grid { display: grid; gap: 8px; padding-top: 9px; }
.connect-grid label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.connect-actions { display: flex; gap: 8px; }
.timeline { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 0 20px; }
.empty { color: var(--muted); text-align: center; margin: auto; }
.msg { border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; max-width: 92%; }
.msg-agent { background: var(--panel); align-self: flex-start; }
.msg-user { background: #2c2a25; align-self: flex-end; }
.msg-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.msg-body { line-height: 1.5; overflow-wrap: anywhere; }
.msg-body p { margin: 0 0 9px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body h1, .msg-body h2, .msg-body h3 { margin: 12px 0 6px; line-height: 1.25; }
.msg-body ul, .msg-body ol { padding-left: 20px; }
.msg-body pre { overflow-x: auto; background: #111; padding: 9px; border-radius: 8px; font-family: var(--mono); font-size: 12px; }
.msg-body code { font-family: var(--mono); font-size: 0.92em; background: #111; padding: 1px 4px; border-radius: 4px; }
.msg-body pre code { background: none; padding: 0; }
.msg-body img { max-width: 100%; height: auto; border-radius: 8px; display: block; margin: 8px 0; }
.msg-body a { color: #9db7ff; }
.msg-body table { border-collapse: collapse; width: 100%; font-size: 12px; }
.msg-body th, .msg-body td { border: 1px solid var(--line); padding: 5px 6px; text-align: left; }
.attachments { display: grid; gap: 4px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #1d1d1b; color: var(--muted); }
.card summary { cursor: pointer; color: var(--ink); }
.card pre { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12px; }
.card-error { border-color: #6b3434; color: #e3a3a0; }
.card-compaction { border-color: #5b5135; color: #d8c58d; }
.card-task { border-color: #3f6b3f; color: #a9d4a9; }
.card-unknown { border-style: dashed; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.composer textarea { grid-column: 1 / -1; }
.composer button { min-width: 86px; }
@media (min-width: 720px) {
  body { max-width: 820px; margin: 0 auto; }
  .connect-grid { grid-template-columns: 1fr 1fr; }
  .connect-grid label:last-of-type, .connect-actions { grid-column: 1 / -1; }
}
