/* The desk: a persistent meter header, dense working tables, and a slide-over flow panel.
 * No scrolled plates, no rail, no tabs, no console, no tiles, no accordion. See SPEC.md.
 */

/* ---- shell ------------------------------------------------------------------------- */
.shell { position: relative; }
/* Every band of content sits above the plates; the plates are the only z-index 0 in here. */
.honest, .desk, .foot { position: relative; z-index: 1; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 var(--gutter); }

/* ---- the meter header: sticky, always on, every number in it labelled ------------- */
.meter {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--ground) 93%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.meter-top {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  padding: 11px 0 10px;
}
.wm { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); }
.wm img { display: block; border-radius: 50%; }
.wm b { font-weight: 600; font-size: 15px; letter-spacing: 0.01em; }
.wm span {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em;
  color: var(--ink-dim); text-transform: uppercase;
}
.meter-top .spacer { flex: 1 1 auto; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  white-space: nowrap;
}
.chip b { color: var(--ink); font-weight: 500; }
.chip.undeployed { border-color: color-mix(in srgb, var(--bad) 60%, transparent); color: var(--bad); }
.chip.undeployed b { color: var(--bad); font-weight: 600; }
.chip i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ember-1) 45%, transparent);
  flex: none;
}
.chip.mode i { background: var(--ember-4); }
.chip.mode { color: var(--ember-4); }

button, .btn {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--pane-2);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 6px 11px;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}
button:hover:not(:disabled) { border-color: var(--ember-4); color: var(--ember-max); }
button.primary { border-color: var(--ember-3); color: var(--ember-5); }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ember-0) 55%, transparent); }
button:disabled { color: var(--ink-dim); border-color: var(--rule-soft); cursor: not-allowed; opacity: 1; }
button.ghost { background: transparent; }

/* the meter cells */
/* A grid that WRAPS rather than an inner horizontal scroller: a scroller would park half its
 * cells to the right of the viewport, which is indistinguishable from page overflow to the
 * measurement that looks for boxes past `window.innerWidth`. */
.cells {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  /* Rules drawn by the cells themselves rather than by a 1 px grid gap over a tinted
   * background: the gap leaves the tail of the last row showing that background, and with a
   * blurred honesty band scrolling underneath it reads as a stray coloured rectangle. */
  border-top: 1px solid var(--rule-soft);
}
.cell {
  padding: 8px 11px 9px;
  min-width: 0;
  border-right: 1px solid var(--rule-soft);
  border-bottom: 1px solid var(--rule-soft);
}
/* The label wraps rather than truncating: a meter cell whose provenance tag is cut off by an
 * ellipsis is a number with no stated source, which is the one thing this page may not have. */
.cell .k {
  display: block;
  font-family: var(--mono);
  font-size: 9.5px;
  line-height: 1.35;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  min-height: 2.7em;
}
.cell .v {
  display: block;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell .u { font-size: 10.5px; color: var(--ink-dim); margin-left: 3px; letter-spacing: 0.04em; }
.cell.alert .v { color: var(--bad); }
.cell.hot .v { color: var(--ember-5); }

/* the health bar in a meter cell */
.bar { position: relative; height: 4px; margin-top: 6px; background: var(--ember-0); }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--ember-4); }
.bar > i.alert { background: var(--bad); }
.bar > u {
  position: absolute; top: -2px; bottom: -2px; width: 1px;
  background: var(--ink-dim);
}
.bar > u.liq { background: var(--bad); }

/* ---- provenance: the only three things a number on this page can be --------------- */
.p { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; }
.p-live { color: var(--ember-5); }
.p-calc { color: var(--ink); }
.p-const { color: var(--ink-dim); }
.p-sim { color: var(--ember-4); }
.legend {
  display: flex; flex-wrap: wrap; gap: 4px 16px;
  padding: 7px 0 8px;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.04em;
  color: var(--ink-dim);
  border-top: 1px solid var(--rule-soft);
}
.legend b { font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; }
.legend .lg-live b { color: var(--ember-5); }
.legend .lg-calc b { color: var(--ink); }
.legend .lg-const b { color: var(--ink-dim); }
.legend .lg-sim b { color: var(--ember-4); }

/* ---- the honesty ribbon: under the meter, before anything you can operate --------- */
.honest {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(90deg, color-mix(in srgb, var(--ember-0) 30%, transparent), transparent 70%);
}
.honest .wrap { position: relative; z-index: 1; padding-top: 15px; padding-bottom: 15px; }
.honest h2 {
  margin: 0 0 7px;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--bad);
}
.honest p { margin: 0 0 7px; color: var(--ink); font-size: 14.5px; max-width: 108ch; }
.honest p:last-child { margin-bottom: 0; }
.honest p b { color: var(--bad); font-weight: 600; }
.honest code { color: var(--ember-5); font-size: 0.9em; }
.honest a { color: var(--ember-5); }

/* ---- panes ------------------------------------------------------------------------ */
.desk { padding-bottom: 60px; }
.pane {
  position: relative;
  z-index: 1;
  background: var(--pane);
  border: 1px solid var(--rule-soft);
  margin: 16px 0;
}
.pane > header {
  display: flex; align-items: baseline; gap: 8px 14px; flex-wrap: wrap;
  padding: 9px 13px;
  border-bottom: 1px solid var(--rule-soft);
  background: var(--pane-2);
}
.pane > header h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ember-4);
}
.pane > header .note {
  font-family: var(--mono); font-size: 11px; color: var(--ink-dim);
  letter-spacing: 0.02em;
}
.pane > header .spacer { flex: 1 1 auto; }
.pane > .body { padding: 12px 13px 14px; }
.pane > .body > p { margin: 0 0 10px; color: var(--ink-dim); font-size: 14px; max-width: 96ch; }
.pane > .body > p:last-child { margin-bottom: 0; }
.pane > .body > p b, .pane > .body > p strong { color: var(--ink); font-weight: 500; }
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center;
  padding: 10px 13px;
  border-bottom: 1px solid var(--rule-soft);
}
.toolbar .why {
  font-family: var(--mono); font-size: 11px; color: var(--ink-dim);
  flex: 1 1 240px; min-width: 0;
}
.toolbar .why b { color: var(--bad); font-weight: 500; }

/* ---- the working tables ----------------------------------------------------------- */
.scroll { overflow-x: auto; overscroll-behavior-x: contain; }
.scroll:focus-visible { outline: 2px solid var(--ember-4); outline-offset: -2px; }
table.t {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
}
table.t th, table.t td {
  text-align: right;
  padding: 6px 10px;
  border-bottom: 1px solid var(--rule-soft);
  white-space: nowrap;
  vertical-align: middle;
}
table.t th {
  background: var(--pane-2);
  color: var(--ember-4);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--rule);
  z-index: 1;
}
table.t th .sub { display: block; color: var(--ink-dim); letter-spacing: 0.06em; font-size: 9px; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t td.l, table.t th.l { text-align: left; }
table.t tbody tr:hover { background: color-mix(in srgb, var(--ember-0) 22%, transparent); }
table.t tbody tr[aria-selected="true"] { background: color-mix(in srgb, var(--ember-0) 38%, transparent); }
table.t td { color: var(--ink); }
table.t td.dim { color: var(--ink-dim); }
table.t td.live { color: var(--ember-5); }
table.t td.bad { color: var(--bad); }
table.t td.actions { padding: 4px 10px; }
table.t td.actions button { padding: 3px 8px; font-size: 10.5px; }
table.t .empty { color: var(--ink-dim); text-align: left; padding: 14px 10px; white-space: normal; }
table.t td .felt { color: var(--ember-5); }
.tag {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.tag.live { border-color: color-mix(in srgb, var(--ember-3) 60%, transparent); color: var(--ember-5); }
.tag.retired { color: var(--ink-dim); }
.tag.locked { border-color: color-mix(in srgb, var(--bad) 60%, transparent); color: var(--bad); }
.tag.ok { border-color: color-mix(in srgb, var(--ember-3) 55%, transparent); color: var(--ember-4); }

/* ---- key/value grids (used in the flow panel and the chain pane) ------------------ */
.kv {
  display: grid;
  /* `max-content` alone will happily make a column wider than the viewport, and then the
   * second column's spans sit past the right edge with nothing to scroll them into view.
   * minmax(0, max-content) keeps the natural width as a CEILING rather than a floor. */
  grid-template-columns: minmax(0, max-content) minmax(0, 1fr);
  gap: 3px 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
}
.kv > .k { color: var(--ink-dim); word-break: break-word; }
.kv > .v { color: var(--ink); word-break: break-all; min-width: 0; }
/* Written AFTER the .v rule and with the same specificity path on purpose: `.kv .bad` on its
 * own is (0,2,0) and loses to a (0,2,1) selector, which is exactly how a FAILED chain read
 * gets painted in the success tint. Caught by reading the computed colour, not by looking. */
.kv > .v.live, .kv > .v.ok { color: var(--ember-5); }
.kv > .v.bad, .kv > .k.bad { color: var(--bad); }
.kv > .v.dim { color: var(--ink-dim); }

/* ---- the simulator ---------------------------------------------------------------- */
.sim-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .sim-grid { grid-template-columns: minmax(0, 320px) minmax(0, 1fr); } }
.dial { border: 1px solid var(--rule-soft); background: var(--pane-2); padding: 11px 12px; }
.dial h3 {
  margin: 0 0 9px;
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ember-4);
}
.dial .big {
  font-family: var(--mono); font-size: 25px; font-weight: 500; letter-spacing: -0.02em;
  color: var(--ember-5);
}
.dial .big small { font-size: 12px; color: var(--ink-dim); letter-spacing: 0.04em; margin-left: 5px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; margin: 8px 0 2px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: var(--ember-1); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%;
  background: var(--ember-5); border: 1px solid var(--void);
}
input[type="range"]::-moz-range-track { height: 3px; background: var(--ember-1); }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border: none; border-radius: 50%; background: var(--ember-5); }
.ticks {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 10px; color: var(--ink-dim); letter-spacing: 0.04em;
}
input[type="text"], input[type="number"], select {
  font-family: var(--mono); font-size: 12.5px;
  color: var(--ink); background: var(--void);
  border: 1px solid var(--rule); border-radius: 2px;
  padding: 6px 9px; width: 100%; min-width: 0;
}
label.f { display: block; margin-bottom: 10px; }
label.f > span {
  display: block; margin-bottom: 4px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.11em;
  text-transform: uppercase; color: var(--ink-dim);
}
label.f > span em { font-style: normal; color: var(--ember-4); text-transform: none; letter-spacing: 0.02em; }

/* ---- the terminal log ------------------------------------------------------------- */
.log {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.75;
  background: var(--void);
  border: 1px solid var(--rule-soft);
  padding: 9px 11px;
  max-height: 232px;
  overflow-y: auto;
}
.log div { white-space: pre-wrap; word-break: break-word; color: var(--ink-dim); }
.log div b { color: var(--ember-4); font-weight: 500; }
.log div i { color: var(--ink); font-style: normal; }
.log div.bad b, .log div.bad i { color: var(--bad); }
.log .seed { color: var(--ink-dim); }

/* ---- gates: one row per assert the entrypoint makes ------------------------------- */
.gates { list-style: none; margin: 0; padding: 0; font-family: var(--mono); font-size: 11.5px; }
.gates li {
  display: grid; grid-template-columns: 3.4ch minmax(0, 1fr); gap: 9px;
  padding: 4px 0; border-bottom: 1px solid var(--rule-soft);
  color: var(--ink-dim);
}
.gates li:last-child { border-bottom: 0; }
.gates li > b { font-weight: 500; letter-spacing: 0.04em; }
.gates li.ok > b { color: var(--ember-4); }
.gates li.no > b { color: var(--bad); }
.gates li.no { color: var(--bad); }
.gates li > span { min-width: 0; word-break: break-word; }

/* ---- the slide-over flow panel ---------------------------------------------------- */
.scrim {
  position: fixed; inset: 0; z-index: 50;
  background: color-mix(in srgb, var(--void) 72%, transparent);
  opacity: 0; transition: opacity 180ms ease;
}
.flow {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 51;
  width: min(560px, 100vw);
  display: flex; flex-direction: column;
  background: var(--ground);
  border-left: 1px solid var(--rule);
  transform: translateX(100%);
  transition: transform 240ms cubic-bezier(.22,.8,.3,1);
}
/* 🔴 `display:` beats the `hidden` attribute, and a panel "closed" by transform alone still
 * eats every click on the page behind it. Both nodes are taken out of the flow when shut. */
.scrim[hidden], .flow[hidden] { display: none !important; }
body.flow-open .scrim { opacity: 1; }
body.flow-open .flow { transform: translateX(0); }
.flow > header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--pane-2);
}
.flow > header h2 {
  margin: 0; flex: 1 1 auto; min-width: 0;
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ember-5);
}
.flow > header .sub {
  display: block; margin-top: 3px;
  font-size: 10.5px; letter-spacing: 0.06em; text-transform: none;
  color: var(--ink-dim); font-weight: 400;
}
.flow > .body { flex: 1 1 auto; overflow-y: auto; padding: 13px 14px 20px; }
.flow > footer {
  border-top: 1px solid var(--rule);
  background: var(--pane-2);
  padding: 11px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.flow > footer .row { display: flex; gap: 9px; flex-wrap: wrap; }
.flow > footer .reason {
  font-family: var(--mono); font-size: 10.5px; line-height: 1.6; color: var(--bad);
}
.flow > footer .reason b { color: var(--bad); font-weight: 600; }

.step { border: 1px solid var(--rule-soft); background: var(--pane); margin-bottom: 12px; }
.step > h3 {
  margin: 0; padding: 8px 11px;
  border-bottom: 1px solid var(--rule-soft);
  background: var(--pane-2);
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ember-4);
}
.step > h3 em { font-style: normal; color: var(--ink-dim); font-weight: 400; letter-spacing: 0.04em; text-transform: none; }
.step > div { padding: 10px 11px; }
.step > div > p { margin: 0 0 9px; font-size: 13px; color: var(--ink-dim); }
.step > div > p:last-child { margin-bottom: 0; }
.step > div > p b { color: var(--ink); font-weight: 500; }

.calldata {
  font-family: var(--mono); font-size: 11px; line-height: 1.7;
  background: var(--void); border: 1px solid var(--rule-soft);
  padding: 9px 10px; margin: 0;
  overflow-x: auto; white-space: pre;
  color: var(--ember-5);
}
.calldata .cm { color: var(--ink-dim); }
.calldata .idx { color: var(--ink-dim); }

.warn {
  border-left: 2px solid var(--bad);
  padding: 3px 0 3px 12px;
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--ink);
}
.warn b { color: var(--bad); font-weight: 600; }

/* ---- footer ----------------------------------------------------------------------- */
.foot {
  position: relative; z-index: 1;
  border-top: 1px solid var(--rule);
  padding: 22px 0 44px;
  display: flex; flex-wrap: wrap; gap: 10px 22px; justify-content: space-between;
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-dim);
}
.foot a { color: var(--ink-dim); text-decoration: none; }
.foot a:hover { color: var(--ember-5); }

/* ---- the reference sheet (/docs) -------------------------------------------------- */
.ref { padding-top: 4px; }
.ref-head .wrap { padding-top: 26px; padding-bottom: 22px; }
.ref h1, .ref-head h1 {
  margin: 0 0 10px;
  font-size: clamp(27px, 4.6vw, 40px); font-weight: 600; letter-spacing: -0.03em; line-height: 1.05;
}
.ref-head .lede { color: var(--ink); font-size: clamp(15px, 2vw, 17.5px); max-width: 76ch; margin: 0 0 18px; }
.ref .lede b { font-weight: 500; }
.pane > .body h3 {
  margin: 18px 0 8px;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ember-4);
}
.pane > .body h3:first-child { margin-top: 0; }
.pane > .body ul { margin: 0 0 12px; padding-left: 0; list-style: none; }
.pane > .body li { position: relative; padding-left: 20px; margin-bottom: 7px; color: var(--ink-dim); font-size: 14px; }
.pane > .body li::before { content: ''; position: absolute; left: 2px; top: 0.7em; width: 10px; height: 1px; background: var(--ember-3); }
.pane > .body li b { color: var(--ink); font-weight: 500; }
.pane > .body code { color: var(--ember-5); font-size: 0.88em; word-break: break-word; }

/* ---- phone ------------------------------------------------------------------------- */
@media (max-width: 760px) {
  /* The meter stays persistent on a phone, so it has to be worth its height: the two cells
   * that are also columns of a table twenty pixels further down come out, the rest get
   * compact type, and the chips drop their second clause. Measured at 390x844 it costs about
   * a quarter of the viewport, which is what a permanent meter is allowed to cost. */
  .cell.secondary { display: none; }
  .legend { display: none; }
  .meter-top { padding: 7px 0 6px; gap: 6px 8px; }
  .meter-top .spacer { display: none; }
  /* Reordered so the two rows fill rather than leaving a third with one chip on it. */
  .meter-top .wm { order: 0; }
  .meter-top .chip.undeployed { order: 1; }
  .meter-top a.chip { order: 2; }
  .meter-top .chip.mode { order: 3; }
  .meter-top #connect { order: 4; }
  .wm span { display: none; }
  .wm b { font-size: 13.5px; }
  .wm img { width: 21px; height: 21px; }
  .chip { font-size: 10px; padding: 3px 7px; letter-spacing: 0.04em; }
  .chip .wide { display: none; }
  button, .btn { font-size: 10px; padding: 4px 8px; }
  .cells { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cell { padding: 6px 8px 7px; }
  .cell .k { font-size: 8.5px; letter-spacing: 0.07em; min-height: 2.5em; }
  .cell .v { font-size: 13px; }
  .bar { margin-top: 5px; }
  .pane > .body { padding: 11px 11px 12px; }
  .pane > header { padding: 8px 11px; }
  table.t th, table.t td { padding: 6px 8px; }
  .flow { width: 100vw; }
  /* One column on a phone: key over value. A two-column grid of felts at 390 px either
   * overflows or squeezes the value to nothing. */
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv > .k { margin-top: 9px; }
  .kv > .k:first-child { margin-top: 0; }
}

/* The desk now sits under the application's route nav, which is the one sticky element on the
 * page. Two stickies at top:0 overlap, so the meter stays where it is written. */
.meter--static { position: static; backdrop-filter: none; -webkit-backdrop-filter: none; }
.meter--static .wm { padding-right: 4px; }
