/* Mission Control — dark space theme. 8 px spacing grid, WCAG AA text contrast, no inline styles (CSP). */
:root {
  --bg: #060914;
  --bg2: #0a1024;
  --panel: rgba(13, 19, 42, .86);
  --card: #121a36;
  --card-hi: #172146;
  --line: #243058;
  --line-hi: #34427a;
  --text: #e8ebf7;
  --muted: #aab2d0;
  --faint: #8790b4;
  --accent: #a596ff;
  --accent-2: #7c6cf2;
  --accent-ink: #120d33;
  --cyan: #67d8ea;
  --green: #5ee0a6;
  --amber: #f4c95d;
  --orange: #ffa766;
  --red: #ff7d8a;
  --magenta: #e59bff;
  --gray: #a7aecb;
  --s1: 4px; --s2: 8px; --s3: 16px; --s4: 24px; --s5: 32px;
  --r1: 8px; --r2: 12px; --r3: 16px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --tap: 36px;
  --topbar-h: 56px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
@media (max-width: 759px), (pointer: coarse) { :root { --tap: 44px; } }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.5 var(--font); color: var(--text); background-color: var(--bg);
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,.55) 50%, transparent 51%),
    radial-gradient(1px 1px at 72% 12%, rgba(255,255,255,.45) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 38% 68%, rgba(200,210,255,.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 58%, rgba(255,255,255,.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 22% 86%, rgba(255,255,255,.35) 50%, transparent 51%),
    radial-gradient(1px 1px at 56% 34%, rgba(255,255,255,.3) 50%, transparent 51%),
    radial-gradient(900px 600px at 85% -10%, rgba(124,108,242,.16), transparent 60%),
    radial-gradient(800px 600px at -10% 110%, rgba(103,216,234,.10), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 13px; } .mono { font-family: var(--mono); font-size: 12.5px; }
a { color: var(--cyan); }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .01em; }
.noscript { padding: var(--s4); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); min-width: var(--tap); padding: 0 var(--s3);
  border-radius: var(--r1); border: 1px solid var(--line-hi); background: var(--card-hi); color: var(--text);
  font: 600 14px/1 var(--font); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #1d2856; border-color: #4a5aa0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #b6aaff; border-color: #b6aaff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(165,150,255,.1); color: var(--text); border-color: transparent; }
.btn-danger { background: #c9364a; border-color: #c9364a; color: #fff; }
.btn-danger:hover { background: #db4559; border-color: #db4559; }
.btn-danger-ghost { background: rgba(255,125,138,.08); border-color: rgba(255,125,138,.35); color: #ffb3bb; }
.btn-danger-ghost:hover { background: rgba(255,125,138,.16); border-color: var(--red); }
.btn-icon { padding: 0; width: var(--tap); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
@media (max-width: 759px), (pointer: coarse) { .btn-sm { min-height: 44px; } }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.link-btn { background: none; border: 0; padding: 0 var(--s1); color: var(--cyan); font: 600 13px var(--font); cursor: pointer; min-height: var(--tap); }

/* ---------- boot ---------- */
.boot { position: fixed; inset: 0; display: flex; flex-direction: column; gap: var(--s3); align-items: center; justify-content: center; color: var(--muted); }
.boot-mark, .brand-mark { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--accent); position: relative; flex: none; box-shadow: 0 0 18px rgba(165,150,255,.35); }
.boot-mark::after, .brand-mark::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--accent); }
.boot-mark { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }

/* ---------- app shell ---------- */
.app {
  height: 100%; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: 0 var(--safe-r) 0 var(--safe-l);
}
.topbar {
  display: flex; align-items: center; gap: var(--s2); padding: calc(var(--s2) + var(--safe-t)) var(--s3) var(--s2);
  min-height: var(--topbar-h); border-bottom: 1px solid var(--line); background: rgba(8, 12, 28, .9); backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 800; font-size: 16px; letter-spacing: .02em; margin-right: var(--s2); }
.proj select {
  appearance: none; min-height: var(--tap); max-width: 260px; padding: 0 36px 0 12px; border-radius: var(--r1);
  background: var(--card) url("../img/chev.svg") no-repeat right 10px center / 14px; border: 1px solid var(--line-hi);
  color: var(--text); font: 600 14px var(--font); text-overflow: ellipsis;
}
.agents { display: flex; gap: var(--s2); margin-left: var(--s2); min-width: 0; overflow: hidden; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 14px; background: rgba(255,255,255,.04); border: 1px solid var(--line); color: var(--muted); font-size: 13px; white-space: nowrap; }
.chip b { color: var(--text); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray); flex: none; }
.dot.IDLE { background: var(--green); } .dot.BUSY { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.dot.STALE { background: var(--amber); } .dot.OFFLINE { background: #646c8c; } .dot.AUTH_REQUIRED { background: var(--orange); } .dot.PAUSED { background: var(--magenta); }
.topbar-spacer { flex: 1; }
.ctxver { font: 12px var(--mono); color: var(--faint); white-space: nowrap; }
.mode { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; border-radius: 14px; font: 700 12px var(--font); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.mode::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.mode.RUN { color: var(--green); background: rgba(94,224,166,.12); }
.mode.PAUSED { color: var(--amber); background: rgba(244,201,93,.13); }
.mode.STOPPED { color: var(--red); background: rgba(255,125,138,.14); }
.em-ic { width: 16px; height: 16px; border-radius: 3px; background: var(--red); flex: none; }
.btn-account-ic { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-2); color: #fff; font: 700 13px var(--font); }
.btn-ops .badge { position: static; }

.banner { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); font-size: 14px; border-bottom: 1px solid var(--line); }
.banner.down { background: rgba(255,125,138,.12); color: #ffc2c8; }
.banner.connecting { background: rgba(244,201,93,.10); color: #f8dc94; }
.banner.info { background: rgba(165,150,255,.10); color: #d6cfff; }
.banner .grow { flex: 1; min-width: 0; }

/* ---------- columns ---------- */
.cols {
  min-height: 0; display: grid; gap: 0;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.22fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "lead dir codex" "lead comp codex";
}
.col { min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.col-lead { grid-area: lead; border-right: 1px solid var(--line); }
.col-dir { grid-area: dir; }
.col-codex { grid-area: codex; border-left: 1px solid var(--line); }
.col-head { display: flex; align-items: center; gap: var(--s2); min-height: 56px; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); }
.col-head h2 { font-size: 17px; white-space: nowrap; }
.col-state { color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.col-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: var(--s3); display: flex; flex-direction: column; gap: var(--s2); overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-hi) transparent; }
.col-scroll:focus { outline: none; }
.side-switch { display: none; margin-left: auto; }
.segs, .side-switch { gap: 2px; padding: 2px; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 10px; }
.segs { display: flex; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.segs::-webkit-scrollbar { display: none; }
.seg { min-height: calc(var(--tap) - 6px); padding: 0 12px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); font: 600 13px var(--font); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.seg.on { background: var(--card-hi); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-hi); }
.cnt { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--amber); color: #2a1d00; font: 700 12px/20px var(--font); text-align: center; }
.cnt:empty { display: none; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r2); padding: 12px var(--s3); display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.card.attn { border-color: rgba(244,201,93,.55); box-shadow: inset 3px 0 0 var(--amber); }
.card.bad { border-color: rgba(255,125,138,.5); box-shadow: inset 3px 0 0 var(--red); }
.card.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 2px var(--accent); } }
.card-head { display: flex; align-items: center; gap: var(--s2); min-height: 24px; min-width: 0; }
.who { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.who .arrow { color: var(--faint); font-weight: 400; }
.card-head .time { margin-left: auto; color: var(--faint); font-size: 12.5px; white-space: nowrap; }
.card-head .sid { color: var(--faint); font: 12px var(--mono); white-space: nowrap; }
.card-title { font-weight: 650; font-size: 15px; }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; font: 700 11px/1 var(--font); letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; flex: none; color: var(--gray); background: rgba(167,174,203,.12); }
.pill.QUEUED, .pill.CANCELLED, .pill.WITHDRAWN, .pill.EXPIRED, .pill.CONSUMED { color: #c3c8de; background: rgba(167,174,203,.13); }
.pill.DELIVERED, .pill.ACKNOWLEDGED { color: #9fc4ff; background: rgba(122,170,255,.14); }
.pill.RUNNING { color: var(--cyan); background: rgba(103,216,234,.13); }
.pill.WAITING_DIRECTOR, .pill.PENDING { color: var(--amber); background: rgba(244,201,93,.14); }
.pill.BLOCKED { color: var(--orange); background: rgba(255,167,102,.14); }
.pill.FAILED, .pill.DENIED { color: var(--red); background: rgba(255,125,138,.14); }
.pill.DONE, .pill.GRANTED, .pill.DECIDED, .pill.QA_PASS { color: var(--green); background: rgba(94,224,166,.13); }
.pill.DIRECTOR_ACCEPTED { color: #0f2a1e; background: var(--green); }
.pill.NEEDS_RECONCILIATION { color: var(--magenta); background: rgba(229,155,255,.14); }
.pill.STALE { color: #2b1f00; background: var(--amber); }
.pill.readonly { color: var(--cyan); background: rgba(103,216,234,.12); }

.md { font-size: 14.5px; line-height: 1.55; overflow-wrap: anywhere; color: #dde1f2; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0 0 var(--s2); }
.md ul, .md ol { padding-left: 22px; }
.md code { font: 12.5px var(--mono); background: rgba(255,255,255,.06); padding: 1px 5px; border-radius: 4px; }
.md pre { overflow-x: auto; background: #0a1024; padding: var(--s2); border-radius: var(--r1); }
.md strong { color: #fff; }
.md a { overflow-wrap: anywhere; }
.clamp { position: relative; max-height: calc(1.55em * 6); overflow: hidden; }
.clamp.over::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2.4em; background: linear-gradient(transparent, var(--card)); pointer-events: none; }
.clamp.open { max-height: none; }
.clamp.open::after { display: none; }
.more { align-self: flex-start; margin-top: calc(-1 * var(--s1)); }
.note { font-size: 13.5px; color: #f3dca0; display: flex; gap: var(--s2); align-items: flex-start; }
.note::before { content: ""; width: 3px; align-self: stretch; border-radius: 2px; background: var(--amber); flex: none; }
.note.err { color: #ffc6cc; } .note.err::before { background: var(--red); }
.note.info { color: var(--muted); } .note.info::before { background: var(--line-hi); }
.note .txt { min-width: 0; overflow-wrap: anywhere; }

.actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; padding-top: var(--s1); border-top: 1px solid rgba(52,66,122,.45); }
.actions .btn { min-height: 32px; padding: 0 12px; font-size: 13px; }
@media (max-width: 759px), (pointer: coarse) { .actions .btn { min-height: 44px; } }
.actions .spacer { flex: 1; }

details.tech { font-size: 13px; color: var(--muted); }
details.tech > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; min-height: 28px; color: var(--faint); font-weight: 600; user-select: none; }
@media (max-width: 759px), (pointer: coarse) { details.tech > summary { min-height: 44px; } }
details.tech > summary::-webkit-details-marker { display: none; }
details.tech > summary::before { content: ""; width: 0; height: 0; border-left: 5px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent; transition: transform .12s; }
details.tech[open] > summary::before { transform: rotate(90deg); }
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px var(--s3); margin: var(--s1) 0 0; }
dl.kv dt { color: var(--faint); } dl.kv dd { margin: 0; font: 12.5px var(--mono); color: var(--muted); overflow-wrap: anywhere; }

/* lifecycle stepper */
.stepper { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.step { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11.5px; color: var(--faint); text-align: center; min-width: 0; }
.step::before { content: ""; position: absolute; top: 5px; left: -50%; width: 100%; height: 2px; background: var(--line-hi); }
.step:first-child::before { display: none; }
.step i { position: relative; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line-hi); background: var(--card); z-index: 1; }
.step span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.step.done { color: var(--muted); } .step.done i { background: var(--accent); border-color: var(--accent); } .step.done::before { background: var(--accent); }
.step.cur { color: var(--text); font-weight: 700; } .step.cur::before { background: var(--accent); }
.step.cur i { border-color: var(--cyan); background: var(--cyan); box-shadow: 0 0 0 4px rgba(103,216,234,.18); }
.step.cur.run i { animation: pulse 1.2s infinite; }
.step.cur.ok i { background: var(--green); border-color: var(--green); box-shadow: 0 0 0 4px rgba(94,224,166,.16); }
.step.cur.warn i { background: var(--amber); border-color: var(--amber); box-shadow: 0 0 0 4px rgba(244,201,93,.16); }
.step.cur.bad i { background: var(--red); border-color: var(--red); box-shadow: 0 0 0 4px rgba(255,125,138,.16); }
.step.cur.ok { color: var(--green); } .step.cur.warn { color: var(--amber); } .step.cur.bad { color: var(--red); }

/* workers strip + lists */
.strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }
.wk { background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: var(--r1); padding: var(--s2) 12px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wk-top { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13.5px; }
.wk-sub { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sec-title { display: flex; align-items: center; gap: var(--s2); margin: var(--s2) 0 0; font: 700 12px var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.sec-title:first-child { margin-top: 0; }
.attn-bar { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) 12px; border-radius: var(--r2); background: rgba(244,201,93,.08); border: 1px solid rgba(244,201,93,.35); color: #f8dc94; font-size: 14px; }
.attn-bar .grow { flex: 1; min-width: 0; }
.opts { display: flex; flex-wrap: wrap; gap: var(--s2); }
.filter { display: flex; align-items: center; gap: var(--s2); }
.filter select { min-height: var(--tap); padding: 0 12px; border-radius: var(--r1); background: var(--card); color: var(--text); border: 1px solid var(--line-hi); font: 600 14px var(--font); }
.task { display: flex; flex-direction: column; gap: 6px; }
.task-top { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.task-top .ttl { font-weight: 650; min-width: 0; overflow-wrap: anywhere; flex: 1; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--faint); font-size: 12.5px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--s2); }
.thumbs.big { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.thumb { position: relative; padding: 0; border: 1px solid var(--line-hi); border-radius: var(--r1); overflow: hidden; background: #0a1024; cursor: zoom-in; aspect-ratio: 16 / 9; min-height: 44px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover { border-color: var(--accent); }
.thumb.file-card { cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: var(--s2); color: var(--text); min-width: 0; }
.thumb.file-card .ic { width: 28px; height: 28px; color: var(--accent); }
.thumb.file-card .fname { font-size: 13px; max-width: 100%; overflow-wrap: anywhere; text-align: center; line-height: 1.2; }
.thumb.file-card .fsize { font-size: 12px; color: var(--faint); }
.ev-card .ev-dl { align-self: flex-start; }
.vw-stage.vw-file { cursor: default; touch-action: auto; }
.file-panel { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s4, 24px); text-align: center; max-width: 100%; }
.file-panel > .ic { width: 64px; height: 64px; color: var(--accent); }
.file-panel .fname { font-size: 16px; overflow-wrap: anywhere; }
.file-actions { display: flex; gap: var(--s2); flex-wrap: wrap; justify-content: center; }
.ev-card .cap { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.ev-card { gap: 6px; padding: var(--s2); }

/* states */
.empty, .errbox { text-align: center; padding: var(--s5) var(--s3); color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: var(--s2); }
.empty b, .errbox b { color: var(--text); font-size: 15px; }
.errbox b { color: #ffc6cc; }
.skel { border-radius: var(--r2); background: linear-gradient(90deg, var(--card) 0%, #1a2348 40%, var(--card) 80%); background-size: 300% 100%; animation: sk 1.4s linear infinite; height: 112px; border: 1px solid var(--line); flex: none; }
.skel.sm { height: 64px; }
@keyframes sk { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.loadmore { align-self: center; }

/* ---------- composer ---------- */
.composer { grid-area: comp; display: flex; flex-direction: column; gap: var(--s2); padding: 12px var(--s3) var(--s2); background: rgba(10, 15, 34, .97); border-top: 1px solid var(--line); }
.recips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; padding: 2px; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 10px; }
.recip { position: relative; display: block; min-width: 0; }
.recip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.recip span { display: flex; align-items: center; justify-content: center; min-height: calc(var(--tap) - 4px); padding: 0 8px; border-radius: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; }
.recip b { font-weight: 600; }
.recip .short { display: none; }
.recip input:checked + span { background: var(--accent); color: var(--accent-ink); }
.recip input:focus-visible + span { outline: 2px solid var(--cyan); outline-offset: 1px; }
.refs { display: flex; flex-wrap: wrap; gap: var(--s2); }
.ref { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 4px 0 10px; border-radius: 16px; background: rgba(103,216,234,.1); border: 1px solid rgba(103,216,234,.35); color: var(--cyan); font: 12.5px var(--mono); }
.ref button { width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; display: grid; place-items: center; padding: 0; }
@media (max-width: 759px), (pointer: coarse) { .ref { height: 44px; border-radius: 22px; } .ref button { width: 40px; height: 40px; } }
.compose-row { display: flex; gap: var(--s2); align-items: flex-end; }
.compose-row textarea {
  flex: 1; min-width: 0; min-height: 44px; max-height: 168px; resize: none; padding: 11px 12px; border-radius: var(--r2);
  background: #0b1229; border: 1px solid var(--line-hi); color: var(--text); font: 15px/1.4 var(--font);
}
.compose-row textarea::placeholder { color: var(--faint); }
.compose-row textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(165,150,255,.18); }
.btn-send { min-height: 44px; padding: 0 20px; }
.compose-hint { font-size: 12.5px; color: var(--faint); min-height: 18px; overflow-wrap: anywhere; }
.compose-hint.warn { color: var(--amber); }

/* ---------- tab bar (mobile only) ---------- */
.tabbar { display: none; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font: 700 11px/18px var(--font); text-align: center; }

/* ---------- ops slide-over ---------- */
.scrim { position: fixed; inset: 0; background: rgba(2, 4, 12, .55); z-index: 30; }
.ops { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%); z-index: 31; display: flex; flex-direction: column; background: #0b1128; border-left: 1px solid var(--line-hi); box-shadow: -20px 0 60px rgba(0,0,0,.5); padding: var(--safe-t) var(--safe-r) var(--safe-b) 0; animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } }
.ops-head { display: flex; align-items: center; gap: var(--s2); min-height: 56px; padding: var(--s2) var(--s2) var(--s2) var(--s3); border-bottom: 1px solid var(--line); }
.ops-head h2 { font-size: 17px; }
.ops-head .btn { margin-left: auto; }
.ops-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s3); display: flex; flex-direction: column; gap: var(--s3); }
.osec { display: flex; flex-direction: column; gap: var(--s2); }
.osec h3 { font: 700 12px var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--faint); display: flex; align-items: center; gap: var(--s2); }
.osec h3 .pill { margin-left: auto; }
.rows { background: var(--card); border: 1px solid var(--line); border-radius: var(--r2); }
.row { display: flex; align-items: center; gap: var(--s2); padding: 10px 12px; min-height: 44px; font-size: 14px; min-width: 0; }
.row + .row { border-top: 1px solid var(--line); }
.row .k { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .v { color: var(--muted); font-size: 13px; white-space: nowrap; }
.row.wrap .k { white-space: normal; overflow-wrap: anywhere; }
.qgrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--s2); }
.qbox { background: var(--card); border: 1px solid var(--line); border-radius: var(--r1); padding: var(--s2); text-align: center; }
.qbox b { display: block; font-size: 20px; line-height: 1.2; }
.qbox span { font-size: 11.5px; color: var(--faint); }
.qbox.run b { color: var(--cyan); } .qbox.que b { color: var(--text); } .qbox.blk b { color: var(--amber); } .qbox.fail b { color: var(--red); } .qbox.done b { color: var(--green); }
.bar { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; gap: 12px; font-size: 13px; }
.bar .track { height: 8px; border-radius: 4px; background: #1b2550; overflow: hidden; }
.bar .fill { height: 100%; width: var(--pct, 0%); border-radius: 4px; background: var(--green); }
.bar .fill.mid { background: var(--amber); } .bar .fill.hi { background: var(--red); }
.bar .v { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bars { display: flex; flex-direction: column; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r2); padding: 12px; }

/* ---------- dialog ---------- */
.dlg { border: 1px solid var(--line-hi); border-radius: var(--r3); background: #0e1531; color: var(--text); padding: 0; width: min(460px, calc(100% - 32px)); max-height: calc(100% - 32px); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.dlg::backdrop { background: rgba(2, 4, 12, .65); }
.dlg-in { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4) var(--s4) var(--s3); }
.dlg-in h2 { font-size: 18px; }
.dlg-in p { margin: 0; color: var(--muted); }
.dlg-actions { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field textarea { min-height: 44px; padding: 10px 12px; border-radius: var(--r1); background: #0a1024; border: 1px solid var(--line-hi); color: var(--text); font: 15px var(--font); }
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(165,150,255,.18); }
.form-err { color: #ffc6cc; font-size: 13.5px; min-height: 0; }
.form-err:empty { display: none; }
.menu { display: flex; flex-direction: column; gap: var(--s2); }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px var(--s3); border-radius: var(--r2); background: var(--card); border: 1px solid var(--line); color: var(--text); cursor: pointer; text-align: left; font: 15px var(--font); }
.menu-item:hover { border-color: var(--line-hi); background: var(--card-hi); }
.menu-item .mi-t { display: flex; flex-direction: column; min-width: 0; }
.menu-item b { font-weight: 700; }
.menu-item small { color: var(--muted); font-size: 13px; }
.menu-item .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.sw.run { background: var(--green); } .sw.pause { background: var(--amber); } .sw.cancel { background: var(--orange); } .sw.force { background: var(--red); }
.menu-item.force { border-color: rgba(255,125,138,.45); }
.scope { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.04); }
.scope .seg { min-height: 40px; justify-content: center; }
@media (max-width: 759px), (pointer: coarse) { .scope .seg, .seg { min-height: 44px; } }
.confirm-word { font: 700 14px var(--mono); color: var(--red); }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px var(--s3); font: 14px var(--mono); background: #0a1024; padding: 12px; border-radius: var(--r1); border: 1px solid var(--line); }
.sess { display: flex; flex-direction: column; gap: var(--s2); }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: var(--s2); align-items: center; pointer-events: none; width: min(480px, calc(100% - 32px)); }
.toast-item { pointer-events: auto; background: #1b2450; border: 1px solid var(--line-hi); border-radius: var(--r2); padding: 10px var(--s3); font-size: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.45); max-width: 100%; }
.toast-item.err { border-color: rgba(255,125,138,.6); color: #ffd0d5; }
.toast-item.ok { border-color: rgba(94,224,166,.5); }

/* ---------- evidence viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: #03050e; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
.vw-head, .vw-foot { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); min-width: 0; }
.vw-head .cap { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vw-head .n { color: var(--faint); font-size: 13px; white-space: nowrap; }
.vw-stage { position: relative; overflow: hidden; touch-action: none; cursor: grab; display: grid; place-items: center; }
.vw-stage.drag { cursor: grabbing; }
.vw-stage img { max-width: 100%; max-height: 100%; transform-origin: center center; transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(var(--z, 1)); user-select: none; -webkit-user-drag: none; image-rendering: auto; }
.vw-foot { justify-content: center; flex-wrap: wrap; }
.vw-foot .zv { min-width: 56px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.vw-foot .meta { justify-content: center; width: 100%; }

/* ---------- auth pages ---------- */
.auth { position: fixed; inset: 0; overflow-y: auto; display: flex; align-items: center; justify-content: center; padding: calc(var(--s4) + var(--safe-t)) var(--s3) calc(var(--s4) + var(--safe-b)); }
.auth-card { width: min(420px, 100%); background: rgba(14, 21, 49, .92); border: 1px solid var(--line-hi); border-radius: var(--r3); padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); box-shadow: 0 30px 80px rgba(0,0,0,.45); }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand .brand-mark { width: 36px; height: 36px; }
.auth-brand .brand-mark::after { inset: 9px; }
.auth-brand h1 { font-size: 20px; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 13.5px; }
.auth-card form { display: flex; flex-direction: column; gap: var(--s3); }
.auth-card .btn-primary { min-height: 48px; font-size: 15px; }
.auth-foot { color: var(--faint); font-size: 12.5px; text-align: center; }
.qr { background: #fff; border-radius: var(--r1); padding: 12px; width: 200px; height: 200px; align-self: center; }
.qr svg { width: 100%; height: 100%; display: block; }
.secret { font: 15px var(--mono); letter-spacing: .08em; text-align: center; color: var(--text); background: #0a1024; border-radius: var(--r1); padding: 10px; overflow-wrap: anywhere; }
.steps-n { display: flex; gap: var(--s2); font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.steps-n .on { color: var(--accent); }

/* ---------- tablet: Director + one switchable side panel ---------- */
@media (min-width: 760px) and (max-width: 1199px) {
  .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "dir side" "comp side"; }
  .col-lead, .col-codex { grid-area: side; border-right: 0; border-left: 1px solid var(--line); }
  .cols[data-side="lead"] .col-codex, .cols[data-side="codex"] .col-lead { display: none; }
  .side-switch { display: flex; }
  .col-dir { border-right: 0; }
  .agents .chip .lbl { display: none; }
  .ctxver { display: none; }
  .brand-name { display: none; }
  .recip .full { display: none; } .recip .short { display: inline; }
  .col-head .col-state { display: none; }
}
@media (min-width: 760px) and (max-width: 1399px) { .ctxver { display: none; } }

/* ---------- mobile: one panel at a time + bottom tabs ---------- */
@media (max-width: 759px) {
  body { font-size: 15px; }
  .topbar { gap: var(--s2); padding-left: 12px; padding-right: 12px; }
  .brand { margin-right: 0; } .brand-name, .agents, .ctxver, .btn-ops, .em-label { display: none; }
  .proj { flex: 1; min-width: 0; } .proj select { width: 100%; max-width: none; }
  .btn-danger-ghost { padding: 0; width: 44px; }
  .mode { height: 26px; padding: 0 10px; font-size: 11px; }
  .cols { display: flex; flex-direction: column; }
  .col { flex: 1; border: 0; }
  .cols[data-tab="lead"] .col-dir, .cols[data-tab="lead"] .col-codex,
  .cols[data-tab="director"] .col-lead, .cols[data-tab="director"] .col-codex,
  .cols[data-tab="codex"] .col-lead, .cols[data-tab="codex"] .col-dir { display: none; }
  .col-head { padding: var(--s2) 12px; min-height: 52px; }
  .col-head h2 { font-size: 16px; }
  .col-scroll { padding: 12px; }
  .card { padding: 12px; }
  #col-director .col-head h2 { display: none; }
  #col-director .segs { margin-left: 0; flex: 1; }
  #col-director .seg { flex: 1 0 auto; justify-content: center; }
  .composer { padding: var(--s2) 12px; gap: var(--s2); }
  .recip .full { display: none; } .recip .short { display: inline; }
  .compose-hint { display: none; }
  .compose-hint.warn { display: block; }
  .btn-send { padding: 0; width: 52px; }
  .send-label { display: none; }
  .btn-send::before { content: ""; width: 20px; height: 20px; background: currentColor; -webkit-mask: url("../img/send.svg") center / contain no-repeat; mask: url("../img/send.svg") center / contain no-repeat; }
  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: rgba(8, 12, 28, .98); padding: 0 0 var(--safe-b); }
  .tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; border: 0; background: transparent; color: var(--faint); font: 600 12px var(--font); cursor: pointer; }
  .tab.on { color: var(--text); }
  .tab.on::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  .tab .badge { position: absolute; top: 6px; left: calc(50% + 8px); }
  .tab-ic { width: 22px; height: 22px; background: currentColor; -webkit-mask: center / contain no-repeat; mask: center / contain no-repeat; }
  .ti-lead { -webkit-mask-image: url("../img/t-lead.svg"); mask-image: url("../img/t-lead.svg"); }
  .ti-dir { -webkit-mask-image: url("../img/t-dir.svg"); mask-image: url("../img/t-dir.svg"); }
  .ti-codex { -webkit-mask-image: url("../img/t-codex.svg"); mask-image: url("../img/t-codex.svg"); }
  .ti-ops { -webkit-mask-image: url("../img/t-ops.svg"); mask-image: url("../img/t-ops.svg"); }
  .app.ops-tab .composer { display: none; }
  /* Ops = full-screen sheet above the tab bar */
  .ops { left: 0; width: 100%; bottom: calc(57px + var(--safe-b)); border-left: 0; box-shadow: none; padding: var(--safe-t) var(--safe-r) 0 var(--safe-l); animation: none; z-index: 20; }
  .scrim.mobile-hide { display: none; }
  .strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .qgrid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .qbox { padding: 6px 2px; }
  .dlg { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: var(--r3) var(--r3) 0 0; max-height: 92%; }
  .dlg-in { padding: var(--s4) var(--s3) calc(var(--s3) + var(--safe-b)); }
  .dlg-actions .btn { flex: 1; }
  .vw-foot .meta { display: none; }
}
@media (max-width: 380px) {
  .card-head .sid { display: none; }
  .step { font-size: 10.5px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* late additions */
button.row { width: 100%; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
button.row:hover { background: rgba(165,150,255,.06); }
.card.sys { background: transparent; border-style: dashed; padding: var(--s2) 12px; }
.card.sys .md { color: var(--muted); font-size: 13.5px; }
.side-switch .seg .badge { margin-left: 2px; }
.foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); padding-top: var(--s1); border-top: 1px solid rgba(52,66,122,.45); }
.foot > .actions { border-top: 0; padding-top: 0; flex: 1 1 auto; min-width: 0; }
.foot > .spacer { flex: 1; }
.foot > details.tech { margin-left: auto; }
.foot > details.tech[open] { flex-basis: 100%; margin-left: 0; }
.actions .upd { margin-left: auto; }
.actions .btn-ghost { color: #c9cfe6; }
.app > .topbar { grid-row: 1; } .app > .banner { grid-row: 2; } .app > .cols { grid-row: 3; } .app > .tabbar { grid-row: 4; }
.segs { min-width: 0; }
@media (max-width: 759px) {
  .brand, #proj-mode { display: none !important; }
  .topbar { min-height: 56px; }
}
details.tech:not([open]) > :not(summary) { display: none; }
.app { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 759px) {
  .topbar-spacer { display: none; }
  .proj { flex: 1 1 auto; }
  #col-director .seg { flex: 1 1 auto; padding: 0 8px; }
  .segs { padding: 2px; }
}
@media (max-width: 759px), (pointer: coarse) { .recip span { min-height: 44px; } .recips { padding: 2px; } }
.brand { white-space: nowrap; }
.proj select { max-width: 240px; }
@media (max-width: 1499px) { .ctxver { display: none; } .agents .chip .lbl { display: none; } }
@media (max-width: 759px) { .vw-foot { gap: 2px; flex-wrap: nowrap; padding: var(--s2) 4px; } .vw-foot .zv { min-width: 48px; } }
.topbar > .btn, .topbar > .mode, .topbar > .brand, .topbar > .pill { flex-shrink: 0; }
.agents { flex: 0 1 auto; }
.agents .chip { flex-shrink: 0; }
@media (max-width: 1799px) { .ctxver { display: none; } }
@media (max-width: 1399px) { .brand-name { display: none; } }
@media (max-width: 1199px) { .agents { display: none; } }
@media (min-width: 760px) { .toast { top: calc(68px + var(--safe-t)); bottom: auto; } }

/* chain of command: one colour per level (outlined, distinct from filled status pills) */
.role { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px 0 3px; border-radius: 6px; border: 1px solid currentColor; font: 700 12.5px/1 var(--font); white-space: nowrap; flex: none; background: rgba(255,255,255,.02); }
.role i { font: 700 10px/16px var(--mono); font-style: normal; padding: 0 4px; border-radius: 4px; background: currentColor; }
.role i { color: inherit; }
.r-dir { color: #f6d27a; } .r-dir i { color: #2b2000; background: #f6d27a; }
.r-lead { color: #b9adff; } .r-lead i { color: #1a1240; background: #b9adff; }
.r-adv { color: #6fdcec; } .r-adv i { color: #062a31; background: #6fdcec; }
.r-wk { color: #9fc4ff; } .r-wk i { color: #0e2246; background: #9fc4ff; }
.r-sys { color: #aab2d0; } .r-sys i { color: #151b33; background: #aab2d0; }
.chain { display: inline-flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; }
.chain .arrow, .fwd .arrow { color: var(--faint); }
.kind { font-weight: 700; font-size: 14px; }
.prov { font: 12px var(--mono); color: var(--faint); margin-top: -4px; overflow-wrap: anywhere; }
.advisory { font-size: 12.5px; color: #8fdbe7; font-style: italic; margin-top: -4px; }
.fwd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.meta .role { height: 20px; font-size: 11.5px; }
.subnav { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); }
.subnav .segs { margin: 0; display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; }
.subnav .seg { justify-content: center; }
.subnav .seg .n { font: 700 11px var(--font); color: var(--faint); }
.wk-head { background: rgba(159,196,255,.05); }
.btn-chain { font: 800 16px var(--font); color: var(--muted); border: 1px solid var(--line-hi); border-radius: 50%; width: 32px; min-width: 32px; min-height: 32px; height: 32px; padding: 0; }
@media (max-width: 759px), (pointer: coarse) { .btn-chain { width: 44px; min-width: 44px; height: 44px; } }
.coc { gap: 12px; }
.coc-row { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: var(--r2); background: var(--card); border: 1px solid var(--line); font-size: 13.5px; }
.coc-who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.coc-can { color: var(--text); } .coc-cannot { color: var(--muted); }
.coc-can b, .coc-cannot b { color: var(--faint); font-weight: 700; }
.coc-rules { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13.5px; display: flex; flex-direction: column; gap: 4px; }
.dlg { max-height: calc(100% - 32px); overflow-y: auto; }
@media (max-width: 759px) { .subnav { padding: var(--s2) 12px; } .mode { padding: 0 8px; } }
@media (max-width: 400px) { .mode { font-size: 0; gap: 0; width: 28px; justify-content: center; padding: 0; } }
@media (max-width: 420px) { .card-head .chain ~ .time { display: none; } .chain .role { padding-right: 6px; } }
@media (max-width: 420px) { .card-head:has(.chain) .time { display: none; } .chain { gap: 4px; } .chain .role { font-size: 11.5px; gap: 4px; padding-right: 5px; } .card-head:has(.chain) .pill { padding: 0 6px; } }
