/* Office floor: a robot works floor. Panels are cut machine plates, agents are robot units whose
   eyes carry their state, and orders run along circuit traces. */
:root {
  --bg: #0D1B26;
  --grid: rgba(120, 170, 200, 0.10);
  --plate: #13283A;
  --plate-2: #183248;
  --edge: #2A4A63;
  --ink: #E3EEF5;
  --muted: #8EA6B8;
  --trace: #2F5068;
  --signal: #3FD0E0;
  --ok: #43D17A;
  --late: #F5B342;
  --failing: #FF5D4F;
  --paused: #6D7F8C;
  --metal: #9FB4C4;
  --metal-dark: #577184;
  --mine: #1E4660;
  --on-signal: #0D1B26;
  --co-grace: #2BB39F;
  --co-respire: #9D7BEA;
  --co-queensoft: #4F9BD6;
  --co-private: #C97FB8;
  --co-borderless: #8DBB4A;
  --co-other: #7F92A3;
  --cut: 12px;
  --display: "Chakra Petch", "IBM Plex Sans", system-ui, sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #E2E9EE; --grid: rgba(40, 70, 95, 0.12); --plate: #F4F7F9; --plate-2: #E8EEF2; --edge: #A9BAC7;
    --ink: #13222E; --muted: #4E6474; --trace: #9DB0BF; --signal: #0B8FA3; --ok: #1F9A55; --late: #B27206;
    --failing: #D2392C; --paused: #8695A1; --metal: #6F8696; --metal-dark: #3E5566; --mine: #D4E9F0;
    --on-signal: #FFFFFF;
    --co-grace: #148B79; --co-respire: #7357C9; --co-queensoft: #2B73AE; --co-private: #9C4F8C;
    --co-borderless: #5C8A1F; --co-other: #687A89; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #E2E9EE; --grid: rgba(40, 70, 95, 0.12); --plate: #F4F7F9; --plate-2: #E8EEF2; --edge: #A9BAC7;
  --ink: #13222E; --muted: #4E6474; --trace: #9DB0BF; --signal: #0B8FA3; --ok: #1F9A55; --late: #B27206;
  --failing: #D2392C; --paused: #8695A1; --metal: #6F8696; --metal-dark: #3E5566; --mine: #D4E9F0;
  --on-signal: #FFFFFF;
  --co-grace: #148B79; --co-respire: #7357C9; --co-queensoft: #2B73AE; --co-private: #9C4F8C;
  --co-borderless: #5C8A1F; --co-other: #687A89; color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 1px, transparent 1.2px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
}
h1, h2, h3, h4 { margin: 0; font-family: var(--display); font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
a { color: inherit; }

/* a cut machine plate: the top-right corner is chamfered */
.plate {
  background: var(--plate);
  border: 1px solid var(--edge);
  clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, 0 100%);
  position: relative;
}
.plate::after {
  content: ""; position: absolute; top: calc(var(--cut) / 2 - 0.5px); right: calc(var(--cut) / -2 + 0.5px);
  width: calc(var(--cut) * 1.414); height: 1px; background: var(--plate-border, var(--edge)); transform: rotate(45deg);
}

/* --- the top bar ------------------------------------------------------------------- */
.top {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: end; gap: 28px;
  padding: 22px 28px 14px;
}
.brand h1 { font-size: 38px; line-height: 1; font-weight: 700; letter-spacing: 0.01em; }
.status-line { margin: 8px 0 0; font-size: 16px; color: var(--muted); max-width: 72ch; }
.status-line strong { color: var(--ink); font-weight: 600; }
.status-line .bad { color: var(--failing); }
.status-line .warn { color: var(--late); }
.counts { display: flex; gap: 6px; margin: 0; }
.counts div {
  display: flex; flex-direction: column-reverse; padding: 6px 12px 6px 10px; min-width: 84px;
  border-left: 2px solid var(--edge);
}
.counts div.hot { border-left-color: var(--signal); }
.counts div.hot dd { color: var(--signal); }
.counts div.warn { border-left-color: var(--late); }
.counts div.bad { border-left-color: var(--failing); }
.counts dt { font-size: 12.5px; color: var(--muted); }
.counts dd { margin: 0; font-family: var(--display); font-size: 28px; font-weight: 600; line-height: 1.05; }
.clock { text-align: right; }
.clock time { display: block; font-family: var(--display); font-size: 28px; font-weight: 600; }
.freshness { font-size: 12.5px; color: var(--muted); }
.freshness::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  margin-right: 6px; vertical-align: 1px;
}
.freshness.stale { color: var(--late); }
.freshness.stale::before { background: var(--late); }

.tabs { display: flex; align-items: end; gap: 4px; padding: 0 28px; border-bottom: 1px solid var(--edge); }
.tabs button {
  background: none; border: 0; padding: 10px 14px 12px; cursor: pointer; color: var(--muted);
  font-family: var(--display); font-weight: 600; font-size: 16px; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--signal); }
.tabs kbd { font: 11px var(--body); color: var(--muted); border: 1px solid var(--edge); padding: 0 4px; margin-left: 4px; }
.tab-hint { margin: 0 0 12px auto; font-size: 13px; color: var(--muted); }

main { padding: 18px 28px 48px; }
.view[hidden] { display: none !important; }

/* --- robot units --------------------------------------------------------------------- */
.bot { flex: none; display: block; overflow: visible; }
.bot .shell { fill: var(--plate-2); stroke: var(--metal); stroke-width: 1.6; }
.bot .dark { fill: var(--metal-dark); }
.bot .line { stroke: var(--metal); stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.bot .eye { fill: var(--eye, var(--ok)); }
.bot .tip { fill: var(--metal); }
.bot .lid { stroke: var(--paused); stroke-width: 2; stroke-linecap: round; fill: none; }
.bot:not(.paused) .lid { display: none; }
.bot.paused .eye { display: none; }
.bot.ok { --eye: var(--ok); }
.bot.late { --eye: var(--late); }
.bot.failing { --eye: var(--failing); }
.bot.failing .tip { fill: var(--failing); }
.bot.waiting .eye, .bot.unknown .eye { fill: none; stroke: var(--muted); stroke-width: 1.2; }
.bot.working { --eye: var(--signal); }
.bot.working .tip { fill: var(--signal); animation: blink 1.2s steps(2, jump-none) infinite; }
.bot.working .eyes { animation: scan 2.4s ease-in-out infinite; }
.bot.human .shell { fill: var(--signal); stroke: none; }
@keyframes blink { 50% { fill: var(--plate-2); } }
@keyframes scan { 0%, 100% { transform: translateX(-1.2px); } 50% { transform: translateX(1.2px); } }

.unit {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; padding: 6px 4px; cursor: pointer; color: inherit; min-width: 0;
}
.unit:hover .uname, .unit[aria-expanded="true"] .uname { color: var(--signal); }
.unit .utext { min-width: 0; display: flex; flex-direction: column; }
.unit .uname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit .uwho { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit .ustate { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; padding-left: 6px; }
.unit.is-late .ustate { color: var(--late); }
.unit.is-failing .ustate { color: var(--failing); }
.unit.is-working .ustate { color: var(--signal); }

/* --- the organisation ---------------------------------------------------------------- */
.view-org { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 28px; align-items: start; }
.chart-wrap { min-width: 0; }
.chart { position: relative; padding-bottom: 8px; }
.wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 0; }
.tier { position: relative; z-index: 1; display: flex; justify-content: center; }
.tier-chief { margin-top: 0; }
.tier-depts {
  margin-top: 40px; display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px; align-items: start;
}
.dept-col { min-width: 0; }

.owner-unit {
  --plate-border: var(--signal);
  display: inline-flex; align-items: center; gap: 12px; padding: 8px 22px 8px 10px; border-color: var(--signal);
}
.owner-unit h3 { font-size: 22px; line-height: 1.1; }
.owner-unit .uwho { color: var(--muted); font-size: 13px; }

.chief-unit { --plate-border: var(--signal); width: min(480px, 100%); padding: 14px 16px; border-color: var(--signal); }
.chief-unit .unit { padding: 0; gap: 14px; }
.chief-unit .uname { font-family: var(--display); font-size: 24px; }
.chief-unit .role { margin: 8px 0 0; font-size: 13.5px; color: var(--muted); }

.dept { padding: 12px 12px 10px; }
.dept-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.dept-head h3 { font-size: 18px; }
.dept-head .machine { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dept .role { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.dept .members { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--edge); }
.dept .members li { border-bottom: 1px dashed var(--edge); }
.dept .members li:last-child { border-bottom: 0; }
.machine-jobs {
  width: 100%; margin-top: 8px; background: none; border: 1px dashed var(--edge); color: var(--muted);
  padding: 5px 8px; cursor: pointer; font-size: 12.5px; text-align: left; display: flex; gap: 8px; align-items: center;
}
.machine-jobs:hover { color: var(--ink); border-color: var(--metal); }
.pips { display: inline-flex; flex-wrap: wrap; gap: 3px; margin-left: auto; max-width: 60%; justify-content: end; }
.pips i { width: 6px; height: 6px; background: var(--ok); display: block; }
.pips i.late { background: var(--late); }
.pips i.failing { background: var(--failing); }
.pips i.waiting, .pips i.unknown { background: transparent; box-shadow: inset 0 0 0 1px var(--muted); }

.fleet { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-top: 4px; }
.bay { background: var(--plate-2); border-top: 3px solid var(--co, var(--co-other)); padding: 6px 8px 4px; min-width: 0; }
.bay h4 { font-size: 13.5px; display: flex; justify-content: space-between; gap: 6px; }
.bay h4 span { color: var(--muted); font-family: var(--body); font-weight: 400; font-size: 12px; }
.bay.shared { border-top-style: dashed; border-top-color: var(--metal); }
.bay ul { list-style: none; margin: 2px 0 0; padding: 0; }
.bay .unit { padding: 4px 2px; gap: 8px; font-size: 13.5px; }

/* circuit traces */
.trace { fill: none; stroke: var(--trace); stroke-width: 2; stroke-linejoin: round; }
.trace.live { stroke: color-mix(in srgb, var(--signal) 45%, var(--trace)); }
.packets { fill: none; stroke: var(--signal); stroke-width: 4; stroke-dasharray: 5 15; animation: packets 1s linear infinite; }
.packets.up { animation-direction: reverse; }
.via { fill: var(--bg); stroke: var(--trace); stroke-width: 2; }
.via.live { stroke: var(--signal); }
@keyframes packets { to { stroke-dashoffset: -20; } }

.orders { list-style: none; margin: 0; padding: 0 0 10px 40px; display: grid; gap: 6px; align-content: end; min-height: 72px; }
.owner-orders { position: relative; z-index: 1; padding: 12px 0 12px calc(50% + 16px); min-height: 0; }
.order { display: flex; gap: 6px; font-size: 13px; line-height: 1.25; color: var(--muted); }
.order b { display: block; font-weight: 600; color: var(--ink); }
.order small { font-size: 12px; }
.order .arrow { font-family: var(--display); font-weight: 700; width: 12px; flex: none; }
.order.active b, .order.active .arrow { color: var(--signal); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 26px 0 0; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* the signal log */
.feed { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; padding: 12px 14px; }
.feed h2 { font-size: 17px; margin-bottom: 6px; }
.feed ol { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 8px; padding: 7px 0; border-top: 1px dashed var(--edge); font-size: 13.5px; }
.feed time { color: var(--muted); font-size: 12.5px; font-family: var(--display); }
.feed .fwho { font-weight: 600; }
.feed .ftext { overflow-wrap: anywhere; }
.feed .ftext a { text-decoration: none; }
.feed .ftext a:hover { text-decoration: underline; }
.feed li.health-bad .fwho { color: var(--failing); }
.feed li.health-good .fwho { color: var(--ok); }
.feed li.day { display: block; font-size: 12px; color: var(--muted); font-weight: 600; border-top: 0; padding: 10px 0 2px; }

/* --- the board ----------------------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: end; margin-bottom: 16px; }
.filters fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filters legend { font-size: 13px; color: var(--muted); float: left; margin-right: 6px; padding: 0; }
.chip {
  border: 1px solid var(--edge); background: var(--plate); padding: 3px 11px 3px 8px;
  cursor: pointer; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px;
}
.chip i { width: 8px; height: 8px; background: var(--co, var(--co-other)); }
.chip[aria-pressed="false"] { opacity: .45; }
.filters label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 3px; }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; padding-bottom: 6px; }
.filters select, .filters input[type="search"] {
  border: 1px solid var(--edge); background: var(--plate); padding: 5px 8px; color: var(--ink); min-width: 180px;
}

.board { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 12px; align-items: start; overflow-x: auto; padding-bottom: 12px; }
.column { padding: 10px; min-height: 120px; background: color-mix(in srgb, var(--plate) 70%, transparent); border: 1px solid var(--edge); }
.column h2 { font-size: 16px; display: flex; justify-content: space-between; padding: 0 2px 8px; }
.column h2 span { color: var(--muted); }
.column[data-col="working"] { border-color: var(--signal); }
.column[data-col="working"] h2 { color: var(--signal); }
.column[data-col="blocked"] h2 { color: var(--failing); }
.column ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.column .empty { color: var(--muted); font-size: 13px; padding: 4px; }
.card { --cut: 9px; padding: 8px 10px 8px 13px; background: var(--plate-2); }
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--co, var(--co-other)); }
.card .ref { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; font-family: var(--display); }
.card .ttl { margin: 2px 0 6px; font-weight: 500; overflow-wrap: anywhere; }
.card .ttl a { text-decoration: none; }
.card .ttl a:hover { text-decoration: underline; }
.card .meta { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.who-btn { display: inline-flex; align-items: center; gap: 5px; background: none; border: 0; padding: 0; cursor: pointer; color: var(--ink); font-weight: 600; font-size: 12.5px; }
.who-btn:hover { color: var(--signal); }
.who-you { color: var(--late); font-weight: 600; }
.card.running { --plate-border: var(--signal); border-color: var(--signal); }
.card.done { opacity: .66; }
.card .prio-high, .card .prio-critical, .card .prio-urgent { color: var(--failing); font-weight: 600; }

/* --- the unit panel (talk) ------------------------------------------------------------- */
.unit-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(470px, 100vw); z-index: 20;
  background: var(--plate); border-left: 1px solid var(--signal);
  box-shadow: -18px 0 40px rgba(0, 0, 0, .35); display: flex; flex-direction: column;
  animation: slide-in .18s ease-out;
}
.unit-panel[hidden] { display: none; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.panel-inner { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.panel-head { display: flex; gap: 14px; align-items: center; padding: 18px 18px 12px; border-bottom: 1px solid var(--edge); }
.panel-head h2 { font-size: 24px; line-height: 1.1; }
.panel-head .uwho { color: var(--muted); font-size: 13px; }
.panel-head .close {
  margin-left: auto; align-self: flex-start; background: none; border: 1px solid var(--edge);
  width: 32px; height: 32px; cursor: pointer; font-size: 18px; line-height: 1; color: var(--muted); flex: none;
}
.panel-head .close:hover { color: var(--ink); border-color: var(--metal); }
.panel-body { overflow: auto; padding: 4px 18px 18px; flex: 1; min-height: 0; }
.panel-body h3 { font-size: 15px; margin: 18px 0 6px; color: var(--muted); }
.panel-body .role { margin: 10px 0 0; }
.state-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 8px; border: 1px solid var(--edge); margin-top: 6px; }
.state-tag.late { color: var(--late); border-color: var(--late); }
.state-tag.failing { color: var(--failing); border-color: var(--failing); }
.state-tag.working { color: var(--signal); border-color: var(--signal); }
.state-tag.ok { color: var(--ok); border-color: var(--ok); }
.parts { list-style: none; padding: 0; margin: 0; display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.parts li { display: grid; grid-template-columns: 10px 1fr; gap: 8px; align-items: baseline; }
.parts li i { width: 8px; height: 8px; display: block; background: var(--ok); transform: translateY(1px); }
.parts li i.late { background: var(--late); }
.parts li i.failing { background: var(--failing); }
.parts li i.waiting, .parts li i.unknown { background: transparent; box-shadow: inset 0 0 0 1px var(--muted); }
.parts b { color: var(--ink); font-weight: 600; }
.parts .err { color: var(--failing); }
.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.task-list button {
  width: 100%; text-align: left; background: var(--plate-2); border: 1px solid var(--edge); padding: 7px 10px; cursor: pointer;
  display: grid; gap: 2px;
}
.task-list button:hover, .task-list button[aria-current="true"] { border-color: var(--signal); }
.task-list .tref { font-size: 12px; color: var(--muted); font-family: var(--display); display: flex; justify-content: space-between; gap: 8px; }
.task-list .tref .now { color: var(--signal); }
.note { font-size: 13.5px; color: var(--muted); margin: 8px 0 0; }
.link-out {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 14px; text-decoration: none;
  background: var(--signal); color: var(--on-signal); font-weight: 600; font-family: var(--display);
}
.home-pick { display: flex; flex-wrap: wrap; gap: 6px; }

.thread { display: grid; gap: 8px; margin-top: 8px; }
.msg { padding: 8px 10px; background: var(--plate-2); border: 1px solid var(--edge); max-width: 92%; }
.msg.mine { background: var(--mine); justify-self: end; }
.msg header { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; }
.msg header b { color: var(--ink); }
.msg p { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.msg .md { margin-top: 4px; font-size: 14px; gap: 8px; }
.msg .md p { margin: 0; }
.thread-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 14px; }
.thread-head h3 { margin: 0; color: var(--ink); }
.thread-head a { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.back { background: none; border: 0; color: var(--signal); cursor: pointer; padding: 0; font-size: 13px; margin-top: 14px; }

.compose { border-top: 1px solid var(--edge); padding: 12px 18px 16px; display: grid; gap: 8px; }
.compose[hidden] { display: none; }
.compose label { font-size: 13px; color: var(--muted); }
.compose textarea {
  width: 100%; min-height: 84px; resize: vertical; background: var(--plate-2); border: 1px solid var(--edge);
  padding: 8px 10px; color: var(--ink);
}
.compose textarea:focus { border-color: var(--signal); outline: none; }
.compose .row { display: flex; align-items: center; gap: 10px; }
.compose .hint { font-size: 12.5px; color: var(--muted); }
.compose button[type="submit"] {
  margin-left: auto; background: var(--signal); color: var(--on-signal); border: 0; padding: 8px 16px; cursor: pointer;
  font-family: var(--display); font-weight: 700; flex: none;
}
.compose button[disabled] { opacity: .5; cursor: default; }
.key-form { display: grid; gap: 8px; }
.key-form label { font-size: 13.5px; color: var(--muted); }
.key-form .row { display: flex; gap: 8px; }
.key-form input { flex: 1; min-width: 0; background: var(--plate-2); border: 1px solid var(--edge); padding: 7px 10px; }
.key-form input:focus { border-color: var(--signal); outline: none; }
.key-form button { background: var(--signal); color: var(--on-signal); border: 0; padding: 7px 16px; cursor: pointer; font-family: var(--display); font-weight: 700; }
.result { font-size: 13px; margin: 0; }
.result.bad { color: var(--failing); }
.result.good { color: var(--ok); }

/* --- the hangar ------------------------------------------------------------------------ */
.hangar-readout { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.hangar { overflow-x: auto; }
.scene { display: block; width: 100%; min-width: 860px; max-width: 1400px; margin: 0 auto; height: auto; overflow: visible; }
.scene text { font-family: var(--display); text-anchor: middle; fill: var(--ink); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }
.scene .lbl { font-size: 13px; font-weight: 600; }
.scene .lbl.big { font-size: 19px; font-weight: 700; }
.scene .sub { font-size: 11.5px; fill: var(--muted); font-family: var(--body); }

.scene .orbit { fill: none; stroke: var(--trace); stroke-width: 1.2; stroke-dasharray: 2 10; opacity: .8; animation: spin 90s linear infinite; }
.scene .orbit.o2 { stroke-dasharray: 26 14; opacity: .45; animation-direction: reverse; animation-duration: 140s; }
.scene .sweep { animation: spin 9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.scene .core .hex-out { fill: var(--plate); stroke: var(--signal); stroke-width: 2; }
.scene .core .hex-in { fill: none; stroke: var(--signal); stroke-width: 1; stroke-dasharray: 4 6; opacity: .7; animation: spin 30s linear infinite; }
.scene .core .pulse { fill: none; stroke: var(--signal); stroke-width: 2; opacity: 0; transform-box: fill-box; transform-origin: center; animation: ripple 3.6s ease-out infinite; }
.scene .core .pulse.p2 { animation-delay: -1.8s; }
.scene .core.late .pulse, .scene .core.late .hex-out { stroke: var(--late); }
.scene .core.failing .pulse, .scene .core.failing .hex-out { stroke: var(--failing); }
@keyframes ripple { 0% { opacity: .55; transform: scale(.85); } 100% { opacity: 0; transform: scale(1.7); } }

.scene .beam { fill: none; stroke: var(--trace); stroke-width: 3; stroke-linecap: round; }
.scene .beam.live { stroke: color-mix(in srgb, var(--signal) 55%, var(--trace)); filter: drop-shadow(0 0 6px var(--signal)); }
.scene .tether { fill: none; stroke: var(--trace); stroke-width: 1.4; stroke-dasharray: 3 5; opacity: .9; }
.scene .tether.live { stroke: var(--signal); stroke-dasharray: none; }
.scene .bay-link { stroke-width: 2; stroke-dasharray: none; opacity: .55; }
.scene .pkt { fill: var(--signal); filter: drop-shadow(0 0 5px var(--signal)); }

.scene .station .ring { fill: none; stroke: var(--edge); stroke-width: 1.5; stroke-dasharray: 3 4; transform-box: fill-box; transform-origin: center; animation: spin 40s linear infinite; }
.scene .station .hex-out { fill: var(--plate); stroke: var(--metal); stroke-width: 1.6; }
.scene .station .lamp { fill: var(--ok); }
.scene .station.late .lamp { fill: var(--late); }
.scene .station.failing .lamp { fill: var(--failing); }
.scene .station.working .lamp { fill: var(--signal); animation: glow 1.2s ease-in-out infinite; }
.scene .station.unknown .lamp, .scene .station.waiting .lamp { fill: none; stroke: var(--muted); }
.scene .station[role="button"] { cursor: pointer; }
.scene .station[role="button"]:hover .hex-out, .scene .station:focus-visible .hex-out { stroke: var(--signal); }
@keyframes glow { 50% { opacity: .35; } }

.scene .bay-dock circle { fill: var(--plate); stroke: var(--co); stroke-width: 3; }
.scene .bay-dock text { font-size: 11.5px; }

.scene .rb { cursor: pointer; outline: none; }
.scene .rb .shadow { fill: var(--metal-dark); opacity: .35; }
.scene .rb .body { animation: bob 3.4s ease-in-out infinite; animation-delay: var(--d); }
.scene .rb:hover .lbl, .scene .rb:focus-visible .lbl { fill: var(--signal); }
.scene .rb:focus-visible .shadow { fill: var(--signal); opacity: .6; }
.scene .rb.paused { opacity: .5; }
.scene .rb.paused .body { animation: none; transform: translateY(3px); }
.scene .rb .halo { fill: none; stroke: var(--signal); stroke-width: 2; stroke-dasharray: 6 8; transform-box: fill-box; transform-origin: center; animation: spin 3s linear infinite; }
.scene .rb .halo2 { stroke-width: 1; stroke-dasharray: 2 10; animation-direction: reverse; animation-duration: 5s; opacity: .7; }
.scene .rb .alarm { fill: var(--failing); opacity: 0; transform-box: fill-box; transform-origin: center; animation: alarm 1.4s ease-out infinite; }
.scene .rb .beacon { fill: var(--late); animation: glow .9s steps(2, jump-none) infinite; filter: drop-shadow(0 0 4px var(--late)); }
.scene .rb .zz { font-size: 13px; fill: var(--muted); animation: zz 3s ease-in-out infinite; }
.scene .owner .bot.human .shell { fill: var(--signal); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes alarm { 0% { opacity: .45; transform: scale(.7); } 100% { opacity: 0; transform: scale(1.6); } }
@keyframes zz { 0% { opacity: 0; transform: translate(0, 4px); } 50% { opacity: 1; } 100% { opacity: 0; transform: translate(6px, -8px); } }

/* one boot sequence, the first time the hangar is drawn: the robots power up one after another */
.scene:not(.booted) .rb { animation: boot .5s cubic-bezier(.2, .9, .3, 1.3) backwards; animation-delay: calc(var(--i) * 35ms + 150ms); transform-box: fill-box; transform-origin: center; }
@keyframes boot { from { opacity: 0; transform: scale(.3); } }

@media (prefers-reduced-motion: reduce) {
  .scene *, .scene .rb { animation: none !important; }
}

/* --- chats: a messaging app over the agents ------------------------------------------ */
/* Softer than the floor on purpose: rounded rails, speech bubbles and a pill to write in. */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.chat {
  display: grid; grid-template-columns: 270px 310px minmax(0, 1fr); height: calc(100vh - 230px); min-height: 520px;
  background: var(--plate); border: 1px solid var(--edge); border-radius: 18px; overflow: hidden;
}
.chat-rail, .chat-threads { border-right: 1px solid var(--edge); overflow-y: auto; min-height: 0; }
.chat-rail { background: color-mix(in srgb, var(--bg) 55%, var(--plate)); padding: 12px 10px 16px; }
.chat-find input {
  width: 100%; background: var(--plate); border: 1px solid var(--edge); border-radius: 999px; padding: 8px 14px; font-size: 14px;
}
.chat-find input:focus { border-color: var(--signal); outline: none; }
.chat-group { margin-top: 14px; }
.chat-group h3 {
  font: 600 12.5px var(--body); color: var(--muted); padding: 0 8px 4px; display: flex; align-items: center; gap: 6px;
}
.chat-group h3 i { width: 8px; height: 8px; border-radius: 50%; background: var(--co, var(--co-other)); }
.chat-group ul, .chat-threads ol { list-style: none; margin: 0; padding: 0; }
.chat-agent {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 8px; border: 0; border-radius: 12px;
  background: none; cursor: pointer; text-align: left;
}
.chat-agent:hover { background: color-mix(in srgb, var(--plate-2) 70%, transparent); }
.chat-agent[aria-current="true"] { background: var(--plate-2); box-shadow: inset 3px 0 0 var(--signal); }
.ca-text { display: grid; min-width: 0; flex: 1; }
.ca-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-count {
  font: 700 11.5px var(--display); min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  display: grid; place-items: center; background: var(--edge); color: var(--ink);
}
.chat-agent.is-working .ca-count { background: var(--signal); color: var(--on-signal); }
.chat-empty { color: var(--muted); font-size: 14px; padding: 18px 14px; margin: 0; }

.chat-threads { padding: 0 10px 16px; }
.ct-head {
  position: sticky; top: 0; z-index: 1; background: var(--plate); display: flex; align-items: center; gap: 8px;
  padding: 14px 4px 10px; flex-wrap: wrap;
}
.ct-head h2 { font-size: 18px; line-height: 1.2; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.new-thread {
  border: 1px solid var(--edge); background: var(--plate-2); border-radius: 999px; padding: 6px 14px; cursor: pointer;
  font: 600 13px var(--display);
}
.new-thread[aria-pressed="true"] { border-color: var(--signal); color: var(--signal); }
.chat-threads h3 { font: 600 12.5px var(--body); color: var(--muted); margin: 10px 6px 4px; }
.chat-thread {
  width: 100%; display: grid; gap: 3px; text-align: left; border: 0; border-radius: 12px; background: none;
  padding: 9px 10px; cursor: pointer;
}
.chat-thread:hover { background: color-mix(in srgb, var(--plate-2) 70%, transparent); }
.chat-thread[aria-current="true"] { background: var(--plate-2); }
.ct-title {
  font-size: 14px; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.ct-meta { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.ct-meta i { width: 7px; height: 7px; border-radius: 50%; background: var(--co, var(--co-other)); }
.ct-meta b { color: var(--signal); font-weight: 600; }
.chat-thread.running .ct-title::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--signal);
  margin-right: 7px; vertical-align: 1px; animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .25; } }

.chat-talk { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }
.chat-back { display: none; background: none; border: 0; color: var(--signal); cursor: pointer; padding: 4px 0; font-size: 13.5px; }
.chat-talk > .chat-back { position: absolute; top: 12px; left: 16px; }
.chat-hero {
  margin: auto; width: min(640px, 100%); padding: 32px 24px; display: grid; justify-items: center; gap: 12px; text-align: center;
}
.chat-hero h2 { font-size: 28px; line-height: 1.15; }
.chat-hero > p { color: var(--muted); margin: 0; max-width: 52ch; }
.chat-hero .pill { width: 100%; margin-top: 10px; }
.chat-hero .key-form { width: min(420px, 100%); text-align: left; }
.pill-link {
  display: inline-block; background: var(--ink); color: var(--bg); border-radius: 999px; padding: 9px 20px;
  text-decoration: none; font: 700 14px var(--display);
}
.pill-link.small { padding: 6px 14px; font-size: 12.5px; background: var(--plate-2); color: var(--ink); border: 1px solid var(--edge); white-space: nowrap; }

.convo-head { display: flex; align-items: center; gap: 14px; padding: 14px 22px; border-bottom: 1px solid var(--edge); }
.convo-title { flex: 1; min-width: 0; }
.convo-title h2 { font-size: 18px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-title p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.convo-status { border-radius: 999px; padding: 1px 9px; background: var(--plate-2); color: var(--ink); font-weight: 600; }
.convo-status.now { background: var(--signal); color: var(--on-signal); }
.convo-status.done { color: var(--ok); }
.convo-status.blocked { color: var(--failing); }
.convo { flex: 1; overflow-y: auto; padding: 22px max(22px, calc((100% - 760px) / 2)); display: grid; align-content: start; gap: 16px; }
.convo-day { justify-self: center; margin: 0; font-size: 12px; color: var(--muted); background: var(--plate-2); border-radius: 999px; padding: 2px 12px; }
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55; }
.bubble time { font-size: 11.5px; color: var(--muted); }
.bubble.mine {
  justify-self: end; max-width: min(78%, 560px); background: var(--mine); border-radius: 22px 22px 6px 22px;
  padding: 10px 16px 6px; display: grid; gap: 2px;
}
.bubble.mine time { justify-self: end; }
.bubble.theirs { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; max-width: 100%; }
.bubble.theirs header { display: flex; gap: 10px; align-items: baseline; margin-bottom: 2px; }
.bubble.theirs header b { font-family: var(--display); font-size: 14px; }
.typing { display: flex; gap: 12px; align-items: center; }
.typing span { display: inline-flex; gap: 5px; background: var(--plate-2); border-radius: 999px; padding: 10px 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--signal); animation: pulse 1.2s ease-in-out infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
.convo-note { padding: 12px 22px 18px; margin: 0; border-top: 1px solid var(--edge); }

.pill { padding: 10px max(22px, calc((100% - 760px) / 2)) 16px; }
.chat-hero .pill { padding: 0; }
.pill-box {
  display: flex; align-items: flex-end; gap: 10px; background: var(--plate-2); border: 1px solid var(--edge);
  border-radius: 28px; padding: 8px 8px 8px 20px; transition: border-color .15s;
}
.pill-box:focus-within { border-color: var(--signal); }
.pill textarea {
  flex: 1; min-width: 0; border: 0; background: none; resize: none; outline: none; padding: 8px 0; font-size: 15.5px;
  line-height: 1.45; max-height: 220px; text-align: left;
}
.pill textarea::placeholder { color: var(--muted); }
.send {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg); flex: none;
  display: grid; place-items: center; cursor: pointer;
}
.send[disabled] { opacity: .4; cursor: default; }
.pill-hint { margin: 6px 14px 0; font-size: 12.5px; color: var(--muted); text-align: left; }
.pill-hint.good { color: var(--ok); }
.pill-hint.bad { color: var(--failing); }

.md { display: grid; gap: 10px; font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.md p, .md ul, .md ol, .md pre { margin: 0; }
.md ul, .md ol { padding-left: 22px; display: grid; gap: 3px; }
.md h4 { font-size: 15.5px; margin-top: 4px; }
.md code { font-size: 13px; background: var(--plate-2); border-radius: 5px; padding: 1px 5px; }
.md pre { background: var(--plate-2); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; white-space: pre; }
.md a { color: var(--signal); }
.md-table { overflow-x: auto; border: 1px solid var(--edge); border-radius: 10px; }
.md table { border-collapse: collapse; font-size: 13.5px; min-width: 100%; }
.md th, .md td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--edge); vertical-align: top; }
.md th { background: var(--plate-2); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }

@media (max-width: 1180px) {
  .chat { grid-template-columns: 240px 270px minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .chat { grid-template-columns: minmax(0, 1fr); height: calc(100vh - 260px); min-height: 480px; }
  .chat > * { display: none !important; }
  .chat[data-show="agents"] > .chat-rail, .chat[data-show="threads"] > .chat-threads { display: block !important; }
  .chat[data-show="talk"] > .chat-talk { display: flex !important; }
  .chat-rail, .chat-threads { border-right: 0; }
  .chat-back { display: inline-block; }
  .chat-talk > .chat-back + .chat-hero { padding-top: 44px; }
  .convo-head { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .convo-title { flex-basis: 100%; order: 2; }
  .convo { padding: 16px 14px; }
  .pill { padding: 8px 10px 12px; }
  .bubble.mine { max-width: 88%; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-thread.running .ct-title::before, .typing i { animation: none; }
}

/* --- the lock (a published page shows nothing until you enter your key) ------------- */
.lock { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(6px); }
.lock-card { width: min(420px, 100%); background: var(--plate); border: 1px solid var(--edge); border-radius: 18px;
  padding: 28px 24px; justify-items: center; text-align: center; }
.lock-card h2 { font-size: 26px; }
.lock-card p { margin: 0; color: var(--muted); font-size: 14px; }
.lock-card .row { width: 100%; }

/* --- smaller screens ----------------------------------------------------------------- */
@media (max-width: 1180px) {
  .view-org { grid-template-columns: minmax(0, 1fr); }
  .feed { position: static; max-height: none; }
  .tier-depts { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .top { grid-template-columns: 1fr; gap: 12px; padding: 16px 16px 10px; }
  .clock { text-align: left; }
  .tabs, main { padding-left: 16px; padding-right: 16px; }
  .tab-hint { display: none; }
  .brand h1 { font-size: 30px; }
  .counts { flex-wrap: wrap; }
  .tier-depts { grid-template-columns: minmax(0, 1fr); margin-top: 24px; }
  .orders { padding-left: 0; min-height: 0; }
  .owner-orders { padding-left: 0; }
  .board { grid-template-columns: repeat(6, minmax(240px, 82vw)); }
}
@media (prefers-reduced-motion: reduce) {
  .packets { animation: none; stroke-dasharray: none; stroke-width: 2.5; }
  .bot.working .tip, .bot.working .eyes { animation: none; }
  .unit-panel { animation: none; }
}
