:root {
  --bg: #f6f6f4; --panel: #ffffff; --text: #16181d; --muted: #6b7078; --line: #e3e3df;
  --accent: #111318; --accent-text: #ffffff; --user: #e9eefc; --warn: #b45309; --warn-bg: #fff4e0;
  --live: #15803d; --danger: #b91c1c; --code: #f1f1ee; --add: #e6f6ea; --del: #fde8e8;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #171a20; --text: #e8e9ec; --muted: #9298a2; --line: #2a2e36;
    --accent: #f1f2f4; --accent-text: #0f1115; --user: #1f2a44; --warn: #f59e0b; --warn-bg: #2d2412;
    --live: #4ade80; --danger: #f87171; --code: #1d2027; --add: #12301c; --del: #3a1717;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
main { max-width: 860px; min-width: 0; overflow-wrap: anywhere; margin: 0 auto; padding: 0 12px calc(16px + env(safe-area-inset-bottom)); min-height: 100vh; display: flex; flex-direction: column; }
a { color: inherit; }
button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 16px;
  min-height: 44px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.secondary { background: var(--panel); }
.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.ghost { background: transparent; }
.wide { width: 100%; margin: 12px 0; }
.small-button { padding: 8px 10px; font-size: 14px; border-color: transparent; color: var(--muted); }
.icon { min-width: 44px; padding: 8px 10px; font-size: 20px; background: transparent; border-color: transparent; }
.back { font-size: 30px; line-height: 1; padding: 0 8px 4px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 12px; min-height: 44px;
}
textarea { resize: none; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; margin-bottom: 0; }
.center { text-align: center; }
.error { color: var(--danger); }
.note { color: var(--muted); font-size: 14px; text-align: center; margin: 6px 0; }

.banner {
  position: sticky; top: 0; z-index: 20; background: var(--warn-bg); color: var(--warn);
  text-align: center; padding: 8px; font-size: 14px;
}
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--accent); color: var(--accent-text); padding: 10px 16px; border-radius: 12px; max-width: 90vw;
}

/* header */
.bar {
  position: sticky; top: 0; z-index: 10; background: var(--bg); display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 0 8px; border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; }
.actions { display: flex; gap: 4px; align-items: center; }
.title-wrap { flex: 1; min-width: 0; }
.thread-title { font-size: 17px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.4s infinite; flex: none; }
@keyframes pulse { 50% { opacity: .3; } }

/* login */
.login { margin: auto; width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center; padding: 24px 0; }
.login h1 { margin: 0; }
.login p { margin: 0; }
.logo { width: 64px; height: 64px; margin: 0 auto; }

/* list */
.threads { list-style: none; margin: 0; padding: 0; }
.threads li { border-bottom: 1px solid var(--line); }
.thread-row { display: block; padding: 14px 4px; text-decoration: none; }
.row-top { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.pill { flex: none; font-size: 12px; border-radius: 999px; padding: 2px 10px; border: 1px solid currentColor; white-space: nowrap; }
.pill.live { color: var(--live); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }

/* new task */
.new-task { display: grid; gap: 16px; padding: 16px 0; }

/* thread */
.turns { flex: 1; min-width: 0; padding: 8px 0; }
.turn { padding: 6px 0; }
.items { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.msg { padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.msg.user { background: var(--user); margin-left: 12%; white-space: pre-wrap; }
.msg.agent { background: var(--panel); border: 1px solid var(--line); }
.md p { margin: 0 0 8px; }
.md p:last-child { margin-bottom: 0; }
.md .md-h { font-weight: 700; }
.md ul { margin: 0 0 8px; padding-left: 22px; }
.md code { background: var(--code); border-radius: 6px; padding: 1px 5px; font-size: 14px; }
pre { margin: 0; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
pre.code { background: var(--code); border-radius: 10px; padding: 10px; margin: 6px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
.card-head { display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.cmd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-head > :first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-status { flex: none; color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 4px 0; }
pre.output { background: var(--code); border-radius: 8px; padding: 8px; max-height: 50vh; overflow: auto; }
.diff .add { background: var(--add); }
.diff .del { background: var(--del); }
.diff .hunk { color: var(--muted); }

/* approvals */
.approvals { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.approval { border: 2px solid var(--warn); background: var(--warn-bg); border-radius: 14px; padding: 12px; }
.approval-title { font-weight: 700; margin: 0 0 6px; }
.approval p { margin: 4px 0; }
.approval-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.approval-buttons button { flex: 1 1 120px; }
.option { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 15px; padding: 4px 0; }
.option input { width: auto; min-height: 0; }

/* composer */
.composer {
  position: sticky; bottom: 0; background: var(--bg); padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); display: grid; gap: 8px;
}
.composer-row { display: flex; gap: 6px; align-items: flex-end; }
.composer-row textarea { flex: 1; max-height: 220px; }
.send { min-width: 48px; }
.composer-settings { display: grid; }
