:root {
  --bg: #f4f5f7; --card: #fff; --fg: #1f2328; --muted: #6b7280; --line: #e3e6ea; --accent: #1a73e8; --accent-dark: #1558b0;
  --them: #fde7d9; --them-fg: #9c3d00; --us: #eceff1; --us-fg: #455a64;
}
* { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: "Segoe UI", Roboto, Arial, sans-serif; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
main { max-width: 1000px; margin: 0 auto; padding: 18px 16px 60px; }
body.wide main { max-width: 1400px; }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 18px 0 8px; }
h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; padding: 30px 0; }
.error { color: #b3261e; }
.hidden { display: none; }
.spacer { flex: 1; }
.inline { display: inline; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.wrap { flex-wrap: wrap; }
code, .code { font-family: Consolas, monospace; background: #eef1f4; padding: 1px 5px; border-radius: 4px; }
.code { font-size: 18px; letter-spacing: .08em; padding: 8px 10px; display: inline-block; }

/* nav */
.nav { display: flex; align-items: center; gap: 4px; padding: 0 16px; height: 46px; background: #1f2328; color: #fff; position: sticky; top: 0; z-index: 5; }
.nav a { color: #cfd6de; padding: 0 10px; height: 46px; line-height: 46px; }
.nav a:hover { color: #fff; text-decoration: none; }
.nav a.on { color: #fff; box-shadow: inset 0 -3px 0 var(--accent); }
.nav .brand { color: #fff; font-weight: 600; margin-right: 8px; }
.nav .link { color: #cfd6de; background: none; border: 0; cursor: pointer; padding: 0 10px; font: inherit; }
.flash { max-width: 1400px; margin: 10px auto 0; padding: 8px 14px; background: #e8f0fe; color: #174ea6; border-radius: 6px; }

/* cards & forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.card.narrow { max-width: 420px; margin: 60px auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
label { display: block; margin: 0 0 10px; font-weight: 600; font-size: 13px; }
label small { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=submit]), select, textarea { display: block; width: 100%; margin-top: 4px; padding: 7px 9px; border: 1px solid #cfd5dc; border-radius: 6px; background: #fff; font-weight: 400; }
.row input, .row select { display: inline-block; width: auto; margin: 0; }
.filters input[type=search], .filters select { display: inline-block; width: auto; margin: 0; }
textarea { resize: vertical; }
button, .btn { font: inherit; padding: 7px 14px; border: 1px solid #cfd5dc; border-radius: 6px; background: #fff; color: var(--fg); cursor: pointer; }
button:hover { background: #f1f3f5; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-dark); }
button.small, .small button { padding: 3px 8px; font-size: 12px; }
button.link { border: 0; background: none; color: var(--accent); padding: 0 4px; }
button.q { padding: 3px 8px; border-radius: 12px; font-size: 12px; }
button[disabled] { cursor: default; opacity: .9; }
form .primary + .muted { margin-left: 8px; }

/* toolbar, filters, tables */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { flex: 1 1 260px; }
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafbfc; }
table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.waiting td.main { box-shadow: inset 3px 0 0 #f0883e; }
table.list tr.off { opacity: .55; }
table.list td.main a { color: inherit; }
table.list td.main .sub { color: var(--muted); font-size: 12px; }
table.list.small td, table.list.small th { padding: 5px 8px; }
.pager { display: flex; gap: 14px; justify-content: center; margin: 14px 0; }

/* pills */
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eef1f4; color: #3c4043; }
.pill.brand { background: #d9f2e6; color: #0b5d3b; }
.pill.wait { background: #fff1d6; color: #7a4d00; }
.pill.sent { background: #dbeafe; color: #1e3a8a; }
.pill.info { background: #e0e7ff; color: #3730a3; }
.pill.ok { background: #dcfce7; color: #166534; }
.pill.warn { background: #fde68a; color: #7a4d00; }
.pill.muted { background: #f1f3f5; color: var(--muted); font-weight: 400; }
.pill.them { background: var(--them); color: var(--them-fg); }
.pill.us { background: var(--us); color: var(--us-fg); }
.pill.late { background: #fce8e6; color: #a50e0e; }
.pill.today { background: #fef7e0; color: #8a4b00; }
.pill.later { background: #e8f0fe; color: #174ea6; }
.pill.act { background: #ede9fe; color: #4c1d95; }
a.pill.on, .pill.on { outline: 2px solid var(--accent); }

/* thread page */
.thread-head { margin-bottom: 12px; }
.thread-head h1 { margin: 6px 0 2px; }
.thread { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .thread { grid-template-columns: 1fr; } }
.msg { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; }
.msg.ours { border-left: 4px solid #90a4ae; }
.msg.theirs { border-left: 4px solid #f0883e; }
.msg header { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; flex-wrap: wrap; }
.msg .body { white-space: pre-wrap; word-break: break-word; font: inherit; margin: 0; max-height: 600px; overflow: auto; }
.msg .body.full { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; color: var(--muted); }
.msg footer { margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.msg iframe { width: 100%; height: 520px; border: 1px solid var(--line); border-radius: 6px; margin-top: 8px; background: #fff; }
.side .card { padding: 12px 14px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 8px 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.stages { display: flex; flex-wrap: wrap; gap: 5px; }
.stage { padding: 4px 10px; border-radius: 14px; font-size: 12px; }
.stage.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.notes { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; max-height: 420px; overflow: auto; }
.note { background: #f8f9fa; border: 1px solid #eceff1; border-radius: 6px; padding: 6px 9px; font-size: 13px; }
.note .note-text { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.hist { margin: 0; padding-left: 18px; font-size: 13px; }
.status p { margin: 4px 0; }
pre.log { font-size: 11.5px; max-height: 320px; overflow: auto; background: #f8f9fa; padding: 8px; border-radius: 6px; white-space: pre-wrap; }

/* Phase 2: pipeline, tasks, composer */
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: #f0883e; color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; margin-left: 2px; }
.pill.ready { background: #fef3c7; color: #92400e; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0 14px; }
.actions form { display: inline; }
button.accept { background: #16a34a; border-color: #16a34a; color: #fff; font-weight: 600; }
button.accept:hover { background: #15803d; }
button.danger { color: #b3261e; }
.banner { padding: 8px 12px; border-radius: 6px; background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; margin: 0 0 12px; font-size: 13px; }
.banner.test { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.task { display: flex; gap: 8px; align-items: flex-start; padding: 7px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task .t-body { flex: 1; min-width: 0; }
.task .t-title { font-weight: 600; }
.task.overdue .t-due { color: #a50e0e; font-weight: 600; }
.task.today .t-due { color: #8a4b00; font-weight: 600; }
.task form { margin: 0; }
.composer textarea { min-height: 220px; font-family: inherit; }
.composer .row select { flex: 1; }
.composer .vars { font-size: 12px; color: var(--muted); }
.composer .vars code { margin-right: 4px; }
.act-log { list-style: none; padding: 0; margin: 0; font-size: 12.5px; }
.act-log li { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.act-log li:last-child { border-bottom: 0; }
.act-log .k { display: inline-block; min-width: 70px; color: var(--muted); }
details.card summary { cursor: pointer; font-weight: 600; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs a { padding: 5px 12px; border-radius: 16px; border: 1px solid var(--line); background: #fff; color: var(--fg); font-size: 13px; }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs a:hover { text-decoration: none; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; }
.tpl-list .tpl { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.tpl-list .tpl pre { white-space: pre-wrap; font: inherit; margin: 6px 0; color: #374151; max-height: 160px; overflow: auto; }
