:root {
  --bg: #111418; --panel: #181c22; --line: #2a303a; --text: #e8eaed; --muted: #9aa3ad;
  --accent: #4f8cff; --user: #2b4c8c; --bot: #1f242c; --bad: #e5534b; --ok: #3fb950;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: .55em 1em; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.danger { color: var(--bad); }
button.wide { width: 100%; }
button.icon { border: 0; background: none; font-size: 1.4rem; padding: .2em .5em; }
input, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .6em .8em; width: 100%; }
textarea { resize: none; }
code { font-size: .85em; color: var(--muted); }

/* login */
.login-body { display: grid; place-items: center; padding: 1rem; }
.login { width: min(360px, 100%); display: grid; gap: .6rem; background: var(--panel); padding: 2rem; border-radius: 16px; border: 1px solid var(--line); }
.login h1 { margin: 0 0 .5rem; font-size: 1.4rem; }
.login-error { color: var(--bad); min-height: 1.5em; margin: 0; }
.login button { margin-top: .5rem; }

/* layout */
.app { display: flex; height: 100dvh; }
.sidebar { width: 280px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: .8rem; gap: .8rem; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-row { display: flex; border-radius: 8px; }
.chat-row.active, .chat-row:hover { background: var(--bot); }
.chat-open { flex: 1; text-align: left; border: 0; background: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: .5em .6em; }
.chat-del { border: 0; background: none; color: var(--muted); padding: 0 .6em; }
.sidebar-foot { display: grid; gap: .5rem; }
.status { font-size: .8rem; color: var(--muted); }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: .6rem; padding: .5rem .8rem; border-bottom: 1px solid var(--line); }
.topbar h1 { flex: 1; font-size: 1rem; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menu { display: none; }
.tabs { display: flex; gap: 4px; }
.tab { padding: .35em .9em; background: none; }
.tab.active { background: var(--bot); border-color: var(--accent); }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view[hidden] { display: none; }

/* messages */
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .7rem; }
.msg { display: flex; max-width: 820px; width: 100%; margin: 0 auto; }
.msg.user { justify-content: flex-end; }
.bubble { white-space: pre-wrap; overflow-wrap: anywhere; padding: .6em .9em; border-radius: 14px; max-width: 85%; }
.msg.user .bubble { background: var(--user); }
.msg.assistant .bubble { background: var(--bot); }
.msg.typing .bubble::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg.tool, .msg.note { color: var(--muted); font-size: .85rem; font-family: ui-monospace, monospace; overflow-wrap: anywhere; }
.msg.error, .error { color: var(--bad); font-size: .9rem; }
.composer { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--line); max-width: 860px; width: 100%; margin: 0 auto; padding-bottom: max(.7rem, env(safe-area-inset-bottom)); }

/* jobs */
.jobs { overflow-y: auto; }
.jobs-inner { max-width: 820px; width: 100%; margin: 0 auto; padding: 1rem; }
.jobs h2 { font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .9rem; margin: .3rem 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; margin-bottom: .6rem; }
.card summary { cursor: pointer; }
.job.paused { opacity: .6; }
.job.waiting { border-color: var(--bad); }
.hint.warn { color: var(--bad); }
.fact { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.fact span { white-space: pre-wrap; overflow-wrap: anywhere; }
.job-head { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.job-prompt { white-space: pre-wrap; margin: .4rem 0; }
.job-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.job-form { display: grid; gap: .6rem; margin-top: .8rem; }
.job-form label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }
.badge { font-size: .75rem; padding: .1em .5em; border-radius: 6px; background: var(--line); }
.badge.ok { background: #1f3d29; color: var(--ok); }
.badge.bad { background: #3d1f1f; color: var(--bad); }
.run-output { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .85rem; margin: .6rem 0 0; }

/* phone */
.scrim { position: fixed; inset: 0; background: #0008; z-index: 9; }
@media (max-width: 760px) {
  #menu { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; width: 82vw; max-width: 320px; }
  .sidebar.open { transform: none; }
  .bubble { max-width: 92%; }
  .messages { padding: .7rem; }
}

/* approvals / audit (M3) */
.tab-badge { display: inline-block; min-width: 1.2em; padding: 0 .35em; margin-left: .25em; border-radius: 999px; background: var(--bad); color: #fff; font-size: .7rem; vertical-align: top; }
.tab-badge[hidden] { display: none; }
.approval-card { border-color: #8a5a2b; }
.approval-card .summary { font-weight: 600; margin: .2rem 0; }
.approval-card .taint { color: #e0a060; font-size: .85rem; }
.approval-card .agent-says { font-style: italic; color: var(--muted); }
.approval-card dl { display: grid; grid-template-columns: auto 1fr; gap: .2rem .8rem; margin: .4rem 0; font-size: .9rem; }
.approval-card dt { color: var(--muted); }
.approval-card .exact pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .8rem; background: var(--bg); padding: .5rem; border-radius: 8px; }
.approval-card .actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }
.approval-card .note { flex: 1; min-width: 140px; }
.composer.locked #input, .composer.locked #send { opacity: .5; pointer-events: none; }
.audit-row { font-size: .85rem; font-family: ui-monospace, monospace; display: grid; grid-template-columns: 9rem 5rem 7rem 1fr; gap: .4rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
@media (max-width: 760px) {
  .tabs { flex-wrap: wrap; }
  .audit-row { grid-template-columns: 1fr; }
}

.audit-actions { margin-bottom: .8rem; }

/* files (M5) */
.files-actions { align-items: center; margin-bottom: .6rem; }
.files-crumb { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; font-size: .9rem; }
.files-crumb button { border: 0; background: none; color: var(--accent); padding: 0 .2em; }
.file-row { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; }
.file-row .meta { color: var(--muted); font-size: .8rem; }
.file-row .origin { font-size: .7rem; padding: .1em .4em; border-radius: 6px; background: var(--line); }
.file-card { max-width: 320px; }
.file-card img { max-width: 100%; border-radius: 8px; margin-top: .4rem; }
.composer .icon { padding: .35em .55em; font-size: 1.1rem; }
