
:root { color-scheme: light dark; --bg: #f7f7f5; --card: #fff; --fg: #1c1c1a; --muted: #6b6b66;
  --line: #deded8; --accent: #2f5bd3; --accent-fg: #fff; --error: #b3261e; --mine: #dfe7fb;
  --current: #e9eefb; --ok: #2e8b57; --warn: #b7791f; }
@media (prefers-color-scheme: dark) { :root { --bg: #141413; --card: #1f1f1d; --fg: #ececea;
  --muted: #a3a39d; --line: #3a3a36; --accent: #7d9cf0; --accent-fg: #10131c; --error: #f2b8b5;
  --mine: #25304a; --current: #262b38; --ok: #6fcf97; --warn: #f2c46d; } }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: var(--bg); color: var(--fg); font: 16px/1.5 system-ui, sans-serif; }
main { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 24px; }
h1 { font-size: 1.4rem; margin: 0 0 16px; }
label { display: block; font-size: .9rem; color: var(--muted); margin: 12px 0 4px; }
input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg); font: inherit; }
button, .button { display: block; width: 100%; margin-top: 16px; padding: 10px 12px; border: 0;
  border-radius: 8px; background: var(--accent); color: var(--accent-fg); font: inherit;
  text-align: center; text-decoration: none; cursor: pointer; }
.secondary { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.or { text-align: center; color: var(--muted); font-size: .9rem; margin: 16px 0 0; }
.error { color: var(--error); margin: 0 0 8px; }

body.app { display: block; place-items: normal; padding: 0; height: 100vh; height: 100dvh; }
.threads { display: grid; grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr); height: 100%; }
.agents { background: var(--card); border-right: 1px solid var(--line); overflow-y: auto; }
.agents-head { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); }
.agents-head h1 { margin: 0; font-size: 1.2rem; }
.agents-head button { width: auto; margin: 0; padding: 6px 12px; font-size: .85rem; }
.agents ul { list-style: none; margin: 0; padding: 8px; }
.agents li a { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; padding: 10px 12px;
  border-radius: 8px; color: inherit; text-decoration: none; }
.agents li a:hover { background: var(--bg); }
.agents li a[aria-current] { background: var(--current); }
.agents .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agents .state { grid-column: 1; }
.state { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.state::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 6px;
  border-radius: 50%; background: var(--muted); vertical-align: 1px; }
.state[data-state=working]::before { background: var(--ok); }
.state[data-state=waiting]::before { background: var(--warn); }
.state[data-state=stopped]::before, .state[data-state=failed]::before { background: var(--error); }
.unread { grid-column: 2; grid-row: 1 / span 2; align-self: center; min-width: 26px;
  padding: 2px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-fg);
  font-size: .8rem; font-weight: 700; text-align: center; }
.thread { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px;
  border-bottom: 1px solid var(--line); background: var(--card); }
.thread-head h2 { margin: 0; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; color: var(--accent); text-decoration: none; white-space: nowrap; }
/* Reversed, so the newest messages show first without any script; .msgs keeps reading order. */
.scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column-reverse; }
.msgs { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 860px;
  margin: 0 auto; padding: 20px; }
.msg { max-width: min(660px, 85%); padding: 10px 14px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.theirs { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.mine { align-self: flex-end; background: var(--mine); border-color: transparent;
  border-bottom-right-radius: 4px; }
.msg-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline;
  font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.msg .subject { color: var(--fg); font-size: .9rem; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote { margin: 0 0 8px; }
.md ul, .md ol { padding-left: 22px; }
.md pre { overflow-x: auto; padding: 10px 12px; border-radius: 8px; background: var(--bg);
  font-size: .85rem; }
.md code { font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; }
.md :not(pre) > code { padding: 1px 4px; border-radius: 4px; background: var(--bg); }
.md a { color: var(--accent); }
.md blockquote { padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.older, .newer { align-self: center; color: var(--accent); font-size: .9rem; }
.start { align-self: center; margin: 0; color: var(--muted); font-size: .85rem; }
.empty { margin: auto; padding: 24px; color: var(--muted); text-align: center; }
@media (max-width: 720px) {
  .threads { grid-template-columns: 1fr; }
  .has-thread .agents, .no-thread .thread { display: none; }
  .agents { border-right: 0; }
  .back { display: inline; }
  .thread-head { padding: 12px 16px; }
  .msgs { padding: 16px; }
  .msg { max-width: 90%; }
}
