/* HPMA mission control. Colours follow the architecture diagram:
   framework code (kernel, evaluators) in indigo, model sessions (agents) in green,
   the durable environment (you, sensorium, world state) in warm grey. */

:root {
  --bg: #121211;
  --panel: #181817;
  --panel-2: #1f1f1d;
  --line: #2b2b28;
  --line-2: #3a3a36;
  --text: #e9e7e0;
  --muted: #9c998f;
  --faint: #6b6962;

  --env-fill: #3b3b37;
  --env-stroke: #5b5a54;
  --env-text: #ecebe4;
  --fw-fill: #332f6b;
  --fw-stroke: #6c64d6;
  --fw-text: #dddaff;
  --fw-sub: #a9a3f3;
  --ag-fill: #1c4638;
  --ag-stroke: #3e9677;
  --ag-text: #d6f4e7;
  --ag-sub: #8fd3b6;

  --c-dispatch: #a99cff;
  --c-tool: #45d0c4;
  --c-claims: #f5c451;
  --c-pass: #6ee7a8;
  --c-fail: #f87171;
  --c-unverified: #f5a524;
  --c-publish: #63a8ff;
  --c-event: #f472b6;
  --c-mission: #e9e7e0;

  --ok: #6ee7a8;
  --warn: #f5a524;
  --bad: #f87171;
  --live: #63a8ff;
  --radius: 10px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f5f1; --panel: #fbfaf7; --panel-2: #f0eee8; --line: #e2dfd6; --line-2: #d3d0c6;
    --text: #23221f; --muted: #6d6a62; --faint: #9a978d;
    --env-fill: #e6e4dc; --env-stroke: #b9b6ab; --env-text: #2a2925;
    --fw-fill: #e5e2ff; --fw-stroke: #7c74e0; --fw-text: #2c266e; --fw-sub: #5a52bd;
    --ag-fill: #ddf3e9; --ag-stroke: #43a07f; --ag-text: #12392c; --ag-sub: #2f7c61;
    --c-tool: #0f9d92; --c-claims: #c98a00; --c-pass: #15a05a; --c-publish: #2f6fd6; --c-event: #d43f8f;
    --c-dispatch: #6c5ce7; --c-mission: #3a3934; --ok: #15a05a; --warn: #c07a00; --bad: #d64545; --live: #2f6fd6;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
h2 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
h3 { margin: 0; font-size: 15px; }
a { color: var(--live); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }

/* ------------------------------------------------------------ header */
header.top {
  display: flex; align-items: center; gap: 18px; padding: 9px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex: none;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; }
.mark { width: 14px; height: 14px; border-radius: 4px; background: linear-gradient(135deg, var(--fw-stroke), var(--ag-stroke)); }
.status { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 1; min-width: 0; }
.links { white-space: nowrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 9px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.pill b { color: var(--text); font-weight: 600; }
.pill.live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.demo { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; flex: none; }
.dot.beat { animation: beat 1.6s ease-out infinite; }
@keyframes beat { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 60%, transparent); } 70%, 100% { box-shadow: 0 0 0 6px transparent; } }

/* ------------------------------------------------------------ layout */
main.grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 310px minmax(520px, 1fr) 320px; }
.panel { min-height: 0; overflow: auto; }
.left { border-right: 1px solid var(--line); padding: 14px; background: var(--panel); }
.right { border-left: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); overflow: hidden; }
.floor { display: flex; flex-direction: column; justify-content: center; padding: 8px 10px; overflow: hidden; }
.floor svg { flex: 0 1 auto; min-height: 0; width: 100%; height: auto; max-height: calc(100% - 34px); }
@media (max-width: 1180px) {
  /* Stacked: the page scrolls, and each panel keeps its own height instead of being squeezed. */
  body { overflow: auto; }
  header.top { flex-wrap: wrap; row-gap: 8px; }
  header.top .status { order: 3; flex-basis: 100%; }
  main.grid { grid-template-columns: 1fr; flex: none; }
  .floor { order: -1; height: 72vh; }
  .left { overflow: visible; }
  .left, .right { border: 0; border-top: 1px solid var(--line); max-height: none; }
  .right { height: 60vh; }
}

.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.block { margin-top: 18px; }
.label { display: block; font-weight: 600; margin-bottom: 6px; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.note { font-size: 12px; color: var(--muted); }
.note.err { color: var(--bad); }
.hint { margin: 8px 0 0; font-size: 11.5px; color: var(--faint); }

textarea, input[type=password] {
  width: 100%; resize: vertical; min-height: 64px; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--bg); color: var(--text); font: inherit; outline: none;
}
input[type=password] { min-height: 0; margin: 10px 0; }
textarea:focus, input:focus { border-color: var(--fw-stroke); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fw-stroke) 25%, transparent); }
button.primary {
  background: var(--fw-stroke); color: #fff; border: 0; border-radius: 8px; padding: 7px 14px; font-weight: 600; cursor: pointer;
}
button.primary:disabled { opacity: .55; cursor: default; }
button.ghost { background: transparent; border: 1px solid var(--line-2); border-radius: 8px; padding: 4px 10px; cursor: pointer; color: var(--muted); }
button.ghost:hover { color: var(--text); border-color: var(--muted); }
button.danger { background: transparent; border: 1px solid color-mix(in srgb, var(--bad) 50%, transparent); color: var(--bad); border-radius: 8px; padding: 4px 10px; cursor: pointer; }

.when { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-top: 8px; font-size: 12px; color: var(--muted); }
.when select, .when input {
  background: var(--bg); color: var(--text); border: 1px solid var(--line-2); border-radius: 6px; padding: 3px 6px; font: inherit;
}
.st.scheduled { color: var(--c-dispatch); border-color: color-mix(in srgb, var(--c-dispatch) 50%, transparent); }
.mv-start { font-size: 12px; margin-top: 6px; color: var(--c-dispatch); }
details#agent-pick { margin-top: 8px; font-size: 12px; color: var(--muted); }
details#agent-pick summary { cursor: pointer; }
.choices { display: grid; grid-template-columns: 1fr; gap: 4px; margin-top: 6px; }
.choices label { display: flex; gap: 6px; align-items: center; color: var(--text); }
.choices .arch { color: var(--faint); margin-left: auto; font-size: 11px; }

/* ------------------------------------------------------------ missions */
.mission-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mission-list li {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; cursor: pointer; background: var(--panel-2);
}
.mission-list li:hover { border-color: var(--line-2); }
.mission-list li.sel { border-color: var(--fw-stroke); box-shadow: inset 3px 0 0 var(--fw-stroke); }
.mission-list .m-top { display: flex; gap: 6px; align-items: center; font-size: 11.5px; color: var(--muted); }
.mission-list .m-task { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mission-list .empty { cursor: default; color: var(--faint); background: transparent; border-style: dashed; }

.st { font-size: 11px; border-radius: 999px; padding: 0 7px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.st.planning, .st.running, .st.dispatched, .st.finalizing, .st.leased, .st.checking { color: var(--live); border-color: color-mix(in srgb, var(--live) 45%, transparent); }
.st.done, .st.committed, .st.PASS { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.st.failed, .st.FAIL { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.st.cancelled, .st.noop, .st.waiting { color: var(--muted); }
.st.UNVERIFIED, .st.degraded { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }

.mv-head { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.mv-task { font-size: 14px; font-weight: 600; margin: 2px 0 6px; white-space: pre-wrap; word-break: break-word; }
.mv-meta { font-size: 11.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.mv-note { font-size: 11.5px; color: var(--warn); margin-top: 6px; }
.steps { list-style: none; margin: 12px 0 0; padding: 0; position: relative; }
.steps li { position: relative; padding: 0 0 12px 30px; }
.steps li::before { content: ""; position: absolute; left: 10px; top: 22px; bottom: 0; width: 1px; background: var(--line-2); }
.steps li:last-child::before { display: none; }
.steps .num {
  position: absolute; left: 0; top: 0; width: 21px; height: 21px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--muted);
}
.steps li.dispatched .num { border-color: var(--live); color: var(--live); animation: ring 1.4s ease-out infinite; }
.steps li.done .num { border-color: var(--ok); color: var(--ok); }
.steps li.failed .num { border-color: var(--bad); color: var(--bad); }
@keyframes ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 50%, transparent); } 80%, 100% { box-shadow: 0 0 0 7px transparent; } }
.steps .s-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.steps .s-agent { font-weight: 600; cursor: pointer; }
.steps .s-after { font-size: 11px; color: var(--faint); }
.steps .s-obj { color: var(--muted); font-size: 12px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.steps .s-obj.open { -webkit-line-clamp: unset; display: block; white-space: pre-wrap; }
.steps .s-out { font-size: 11.5px; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.key { font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }

.answer { margin-top: 14px; border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.answer.failed { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.answer h4 { margin: 0 0 6px; font-size: 14px; }
.answer .body { font-size: 12.5px; }
.answer .body p { margin: 0 0 8px; }
.answer .body ul { margin: 0 0 8px; padding-left: 18px; }
.answer .caveats { margin: 8px 0 0; padding-left: 16px; color: var(--warn); font-size: 12px; }
.answer .foot { margin-top: 8px; display: flex; gap: 8px; align-items: center; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }

/* ------------------------------------------------------------ the floor (SVG) */
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: 11.5px; color: var(--muted); padding: 6px 4px 0; flex: none; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.ln { height: 3px; border-radius: 2px; width: 14px; }

svg text { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
.zone-env { fill: var(--env-fill); stroke: var(--env-stroke); }
.zone-fw { fill: var(--fw-fill); stroke: var(--fw-stroke); }
.zone-soft { fill: color-mix(in srgb, var(--env-fill) 45%, transparent); stroke: var(--line-2); stroke-dasharray: 3 4; }
.zone-title { font-size: 13px; font-weight: 650; fill: var(--env-text); }
.zone-title.fw { fill: var(--fw-text); }
.zone-sub { font-size: 10.5px; fill: var(--muted); }
.zone-sub.fw { fill: var(--fw-sub); }
.flow { stroke: var(--line-2); stroke-width: 1.2; fill: none; marker-end: url(#arrow); }
#arrow path { fill: var(--line-2); }

.chip rect { fill: color-mix(in srgb, var(--fw-fill) 70%, var(--bg)); stroke: color-mix(in srgb, var(--fw-stroke) 55%, transparent); transition: fill .25s, stroke .25s; }
.chip text { font-size: 11px; fill: var(--fw-sub); font-weight: 600; }
.chip.on rect { fill: var(--fw-stroke); stroke: var(--fw-text); }
.chip.on text { fill: #fff; }
.chip.flash rect { animation: chipflash .7s ease-out; }
.chip.off { opacity: .38; }
.chip.off rect { stroke-dasharray: 3 3; }
@keyframes chipflash { 0% { fill: var(--fw-stroke); } 100% { fill: color-mix(in srgb, var(--fw-fill) 70%, var(--bg)); } }

.src rect { fill: color-mix(in srgb, var(--env-fill) 80%, var(--bg)); stroke: var(--env-stroke); stroke-width: .8; }
.src text { font-size: 11px; fill: var(--env-text); }
.src .sdot { fill: var(--faint); }
.src.ok .sdot { fill: var(--ok); }
.src.down .sdot { fill: var(--bad); }
.src.down text { fill: var(--muted); }
.src.hit rect { animation: srchit .8s ease-out; }
@keyframes srchit { 0% { fill: color-mix(in srgb, var(--c-tool) 55%, var(--env-fill)); stroke: var(--c-tool); } 100% {} }

.ev rect { fill: color-mix(in srgb, var(--fw-fill) 80%, var(--bg)); stroke: color-mix(in srgb, var(--fw-stroke) 60%, transparent); stroke-width: .8; }
.ev .eid { font-size: 11px; font-weight: 700; fill: var(--fw-text); }
.ev .ename { font-size: 11.5px; font-weight: 600; fill: var(--fw-text); }
.ev .ewhat { font-size: 9.5px; fill: var(--fw-sub); }
.ev.off { opacity: .42; }
.ev.off rect { stroke-dasharray: 3 3; }
.ev.pass rect { animation: evpass .9s ease-out; }
.ev.fail rect { animation: evfail .9s ease-out; }
.ev.warn rect { animation: evwarn .9s ease-out; }
@keyframes evpass { 0% { fill: color-mix(in srgb, var(--c-pass) 55%, var(--fw-fill)); stroke: var(--c-pass); } }
@keyframes evfail { 0% { fill: color-mix(in srgb, var(--c-fail) 55%, var(--fw-fill)); stroke: var(--c-fail); } }
@keyframes evwarn { 0% { fill: color-mix(in srgb, var(--c-unverified) 55%, var(--fw-fill)); stroke: var(--c-unverified); } }

.agent { cursor: pointer; }
.agent .body { fill: var(--ag-fill); stroke: var(--ag-stroke); stroke-width: 1; transition: stroke .3s; }
.agent:hover .body { stroke: var(--ag-text); }
.agent .aname { font-size: 12.5px; font-weight: 650; fill: var(--ag-text); }
.agent .aarch { font-size: 9.5px; fill: var(--ag-sub); text-transform: uppercase; letter-spacing: .06em; }
.agent .atext { font-size: 10.5px; fill: var(--ag-sub); }
.agent .bar-bg { fill: color-mix(in srgb, var(--ag-stroke) 25%, transparent); }
.agent .bar { fill: var(--ag-sub); transition: width .4s; }
.agent .ring { fill: none; stroke: var(--c-tool); stroke-width: 2; opacity: 0; }
.agent .badge rect { fill: var(--fw-stroke); }
.agent .badge text { font-size: 9.5px; font-weight: 700; fill: #fff; }
.agent .sdot { fill: var(--faint); }
.agent.idle .body { opacity: .78; }
.agent.leased .sdot { fill: var(--c-dispatch); }
.agent.running .sdot { fill: var(--c-tool); }
.agent.running .ring { opacity: 1; animation: running 1.8s ease-in-out infinite; }
.agent.checking .sdot { fill: var(--c-claims); }
.agent.checking .ring { opacity: 1; stroke: var(--c-claims); animation: running 1.2s ease-in-out infinite; }
.agent.degraded .body { stroke: var(--warn); stroke-dasharray: 4 3; }
.agent.just-committed .body { animation: committed 1.6s ease-out; }
.agent.just-failed .body { animation: failedflash 1.6s ease-out; }
.agent.dim { opacity: .35; }
@keyframes running { 0%, 100% { stroke-opacity: .25; } 50% { stroke-opacity: 1; } }
@keyframes committed { 0% { fill: color-mix(in srgb, var(--c-pass) 50%, var(--ag-fill)); stroke: var(--c-pass); } }
@keyframes failedflash { 0% { fill: color-mix(in srgb, var(--c-fail) 50%, var(--ag-fill)); stroke: var(--c-fail); } }

.world rect.cell { fill: color-mix(in srgb, var(--env-fill) 80%, var(--bg)); stroke: var(--env-stroke); stroke-width: .8; }
.world .wname { font-size: 11px; font-weight: 650; fill: var(--env-text); }
.world .wnum { font-size: 17px; font-weight: 700; fill: var(--env-text); }
.world .wlast { font-size: 10px; fill: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.world .cell.hit { animation: worldhit .9s ease-out; }
@keyframes worldhit { 0% { fill: color-mix(in srgb, var(--c-publish) 45%, var(--env-fill)); stroke: var(--c-publish); } }

.supply-line { stroke: var(--c-tool); stroke-opacity: .35; stroke-width: 1; fill: none; stroke-dasharray: 2 3; pointer-events: none; }
.particle .trail { fill: none; stroke-width: 1.6; stroke-linecap: round; opacity: .55; }
.particle .halo { opacity: .22; }
.particle .plabel { font-size: 9.5px; font-weight: 600; paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }

/* ------------------------------------------------------------ activity feed */
.feed-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px; border-bottom: 1px solid var(--line); flex: none; }
.feed-head h2 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 3px 9px; font-size: 11.5px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }
.feed { list-style: none; margin: 0; padding: 6px 0; overflow: auto; flex: 1; font-size: 12px; }
.feed li { display: grid; grid-template-columns: 54px 9px 1fr; gap: 7px; padding: 4px 14px; align-items: baseline; }
.feed li.click { cursor: pointer; }
.feed li.click:hover { background: var(--panel-2); }
.feed li.new { animation: feednew 1.2s ease-out; }
@keyframes feednew { 0% { background: color-mix(in srgb, var(--fw-stroke) 22%, transparent); } }
.feed .t { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 11px; }
.feed .k { width: 8px; height: 8px; border-radius: 2px; align-self: center; }
.feed .who { font-weight: 600; margin-right: 4px; }
.feed .what { color: var(--muted); word-break: break-word; }
.feed .what b { color: var(--text); font-weight: 600; }
.feed .empty { display: block; color: var(--faint); padding: 14px; }

/* ------------------------------------------------------------ drawer and auth */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 92vw); background: var(--panel); border-left: 1px solid var(--line-2);
  box-shadow: -18px 0 40px rgba(0, 0, 0, .35); display: flex; flex-direction: column; z-index: 20;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 14px 16px 30px; overflow: auto; font-size: 12.5px; }
.drawer-body h4 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 18px 0 6px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 3px 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.pre { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; max-height: 260px; overflow: auto; }
.trace { list-style: none; margin: 0; padding: 0; }
.trace li { display: grid; grid-template-columns: 62px 1fr; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.trace .t { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 11px; }
.pubs { display: flex; flex-direction: column; gap: 6px; }
.pubs .pub { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.pubs .pv { font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); margin-top: 3px; word-break: break-word; }

.auth { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 30; }
.auth .card { width: min(420px, 90vw); }
.auth p { font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  .agent.running .ring, .agent.checking .ring, .dot.beat, .steps li.dispatched .num { animation: none; }
}
