:root {
  --bg: #f6f6f4; --panel: #ffffff; --ink: #1b1d21; --muted: #6b6f76; --line: #e3e3df;
  --accent: #3b6ef5; --accent-ink: #ffffff; --good: #1f9d55; --warn: #c47f00; --bad: #d14343;
  --you: #e8eefc; --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --panel: #1a1d22; --ink: #e9eaec; --muted: #9aa0a8; --line: #2a2e35; --you: #1f2a44; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
#app { max-width: 760px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

header.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid var(--line); }
header.bar h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.bar .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.icon-btn { border: 0; background: transparent; padding: 6px 8px; border-radius: 10px; cursor: pointer; font-size: 15px; color: var(--accent); }
.icon-btn:hover { background: var(--line); }

main { flex: 1; padding: 16px; }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 9px 14px; border-radius: 12px; cursor: pointer; font-weight: 600; box-shadow: var(--shadow); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 6px 10px; font-size: 13px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
.room-card { display: block; color: inherit; }
.room-card .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.room-card .name { font-weight: 650; }
.room-card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.running, .pill.pausing { color: var(--accent); }
.pill.waiting_approval, .pill.waiting_you, .pill.paused { color: var(--warn); }
.pill.done { color: var(--good); }
.pill.error, .pill.stopped { color: var(--bad); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--agent, var(--muted)); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; background: var(--panel); }

form label { display: block; font-weight: 600; font-size: 14px; margin: 16px 0 6px; }
form .hint { color: var(--muted); font-size: 13px; font-weight: 400; margin-top: 2px; }
input[type=text], input[type=password], input[type=number], textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
textarea { resize: vertical; min-height: 72px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.member-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.member-row input[type=checkbox] { width: 20px; height: 20px; flex: none; }
.member-row .who { width: 92px; flex: none; display: flex; align-items: center; gap: 6px; font-weight: 600; }
.member-row input[type=text] { flex: 1; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--panel); padding: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.error-text { color: var(--bad); font-size: 14px; margin-top: 10px; min-height: 1em; }

/* room */
.room { display: flex; flex-direction: column; min-height: 100vh; }
.room .status-line { padding: 8px 16px; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.feed { flex: 1; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 92%; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--agent, var(--line)); border-radius: 12px; padding: 9px 12px; box-shadow: var(--shadow); }
.msg .who { font-size: 12px; font-weight: 700; color: var(--agent, var(--muted)); margin-bottom: 3px; display: flex; gap: 8px; }
.msg .who time { color: var(--muted); font-weight: 400; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.you { align-self: flex-end; background: var(--you); border-left-color: var(--accent); }
.msg.live .body::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }
.sys { align-self: center; font-size: 12.5px; color: var(--muted); text-align: center; padding: 2px 10px; }
.sys a { cursor: pointer; }
details.tools { font-size: 13px; color: var(--muted); padding-left: 10px; border-left: 2px dashed var(--line); margin-left: 6px; }
details.tools summary { cursor: pointer; list-style: none; padding: 2px 0; }
details.tools summary::before { content: "▸ "; }
details.tools[open] summary::before { content: "▾ "; }
details.tools div { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; padding: 2px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.approval { border: 2px solid var(--warn); border-radius: 12px; padding: 12px; background: var(--panel); }
.approval .q { font-weight: 650; margin-bottom: 4px; }
.approval .d { font-family: ui-monospace, Menlo, monospace; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 10px; }
.approval .actions { display: flex; gap: 8px; }
.approval.decided { border-color: var(--line); opacity: .8; }
.dock { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--line); padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.controls { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; border-radius: 12px; }

/* lists */
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list-row:last-child { border-bottom: 0; }
.list-row .l { min-width: 0; overflow-wrap: anywhere; }
.list-row .s { color: var(--muted); font-size: 12.5px; }
.ok { color: var(--good); font-weight: 600; }
.notok { color: var(--bad); font-weight: 600; }
h2 { font-size: 15px; margin: 20px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: 90vw; }
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; }
.login h1 { font-size: 24px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.room-top { position: sticky; top: 0; z-index: 6; background: var(--bg); }
.room-top header.bar { position: static; }
.btn { white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; }
.ok, .notok { white-space: nowrap; }

.gap { margin-top: 10px; }
.gap-sm { margin-top: 6px; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.vault-state { display: flex; justify-content: space-between; align-items: center; font-weight: 650; }
.chip.check { cursor: pointer; font-weight: 400; margin: 0; padding: 6px 12px; }
.chip.check input { width: 18px; height: 18px; margin: 0; }
.small-note { font-size: 12.5px; margin-bottom: 8px; }
.approval input[type=password] { margin-bottom: 8px; }
ul.muted { padding-left: 20px; }
