/* Tokens lifted from the design file rather than approximated: same values, so
   a screenshot of this and a screenshot of the design differ only where the
   behaviour does. */
:root {
  --paper: oklch(0.962 0.017 152);
  --blobs:
    radial-gradient(760px 520px at 14% 8%, rgba(150, 182, 150, 0.3), transparent 62%),
    radial-gradient(680px 500px at 88% 74%, rgba(70, 120, 180, 0.1), transparent 62%),
    radial-gradient(560px 420px at 58% 42%, rgba(255, 255, 255, 0.55), transparent 68%);
  --ink: #201f1d;
  --ink-2: #444141;
  --ink-3: #605d5d;
  --ink-4: #7d7979;
  --hair: rgba(32, 31, 29, 0.16);
  --hair-soft: rgba(32, 31, 29, 0.07);
  --line: #d7d3d3;
  --grip: #bab6b6;
  --glass: rgba(255, 255, 255, 0.46);
  --glass-alert: rgba(255, 250, 248, 0.5);
  --glass-edge: rgba(255, 255, 255, 0.62);
  --glass-top: rgba(255, 255, 255, 0.7);
  --glass-shadow: 0 1px 1px rgba(45, 43, 43, 0.04), 0 14px 34px -14px rgba(45, 43, 43, 0.22);
  --panel: rgba(255, 255, 255, 0.58);
  --panel-shadow: 0 18px 48px -14px rgba(45, 43, 43, 0.3);
  --chrome: rgba(255, 255, 255, 0.4);
  --inset: rgba(32, 31, 29, 0.1);
  --gold: #2f7d4f;
  --gold-ink: #1f5e39;
  --on-gold: #ffffff;
  --warn: #b68235;
  --warn-ink: #7d5411;
  --ok: #2f6a5e;
  --bad: #8a2b20;
  --bad-edge: rgba(138, 43, 32, 0.3);
  --rail: 56px;
}

[data-theme='dark'] {
  --paper: oklch(0.158 0.008 160);
  --blobs:
    radial-gradient(760px 520px at 14% 8%, rgba(60, 92, 68, 0.5), transparent 62%),
    radial-gradient(680px 500px at 88% 74%, rgba(40, 60, 92, 0.35), transparent 62%);
  --ink: #e6e9e4;
  --ink-2: #c3c9c1;
  --ink-3: #abb3ab;
  --ink-4: #9aa29a;
  --hair: rgba(230, 233, 228, 0.16);
  --hair-soft: rgba(230, 233, 228, 0.08);
  --line: #3a403a;
  --grip: #555d55;
  --glass: rgba(28, 34, 30, 0.5);
  --glass-alert: rgba(48, 28, 26, 0.5);
  --glass-edge: rgba(255, 255, 255, 0.08);
  --glass-top: rgba(255, 255, 255, 0.06);
  --panel: rgba(28, 34, 30, 0.62);
  --chrome: rgba(28, 34, 30, 0.45);
  --gold: #93d5a6;
  --gold-ink: #a9e0b8;
  --on-gold: #0f1d16;
  --warn: #e0b169;
  --warn-ink: #e8c288;
  --ok: #6fb0a0;
  --bad: #dd8476;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.45 'IBM Plex Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

.blobs {
  position: fixed;
  inset: 0;
  background: var(--blobs);
  pointer-events: none;
  z-index: 0;
}

.mono { font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- rails ------------------------------------------------------------- */
/* They sit above the canvas and are deliberately narrow: the run is the
   subject, and chrome that competes with it is chrome that wins. */
.rail {
  position: fixed;
  top: 0;
  bottom: 62px;
  width: var(--rail);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 0;
  background: var(--chrome);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
}
.rail-left { left: 0; border-right: 1px solid var(--hair-soft); }
.rail-right { right: 0; border-left: 1px solid var(--hair-soft); }
.rail hr { width: 22px; border: 0; border-top: 1px solid var(--hair); margin: 6px 0; }
.rail-spacer { flex: 1; }

.rail-btn {
  position: relative;
  width: 34px;
  height: 34px;
  flex: none;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.rail-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn:hover { background: color-mix(in srgb, var(--gold) 14%, transparent); color: var(--gold-ink); }
.rail-btn.on { background: color-mix(in srgb, var(--gold) 14%, transparent); color: var(--gold-ink); }
.rail-btn.avatar {
  background: color-mix(in srgb, var(--gold) 12%, transparent);
  color: var(--gold-ink);
  font-size: 11px;
  font-weight: 600;
  border-radius: 50%;
}
.dot-warn, .dot-bad {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.dot-warn { background: var(--warn); }
.dot-bad { background: var(--bad); }

/* --- the crumb --------------------------------------------------------- */
#crumb {
  position: fixed;
  top: 0;
  left: var(--rail);
  right: var(--rail);
  z-index: 15;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 22px 28px 10px;
  pointer-events: none;
}
#crumb h1 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -0.2px; }
.crumb-meta { color: var(--ink-4); font-size: 12.5px; }
.crumb-progress {
  position: absolute;
  left: 28px;
  bottom: 2px;
  width: 220px;
  height: 3px;
  border-radius: 2px;
  background: var(--hair-soft);
  overflow: hidden;
}
.crumb-progress i { display: block; height: 100%; width: 0; background: var(--gold); transition: width 0.4s ease; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 11px;
  font-size: 12px;
  border: 1px solid transparent;
  background: color-mix(in srgb, var(--gold) 12%, transparent);
  color: var(--gold-ink);
  white-space: nowrap;
}
.pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn-ink); }
.pill.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.pill.grey { background: var(--hair-soft); color: var(--ink-4); }

/* --- the canvas -------------------------------------------------------- */
#canvas {
  position: absolute;
  /* The crumb wraps on a narrow screen, and a hardcoded offset then puts the
     first card under the run's own name. `--crumb-h` is measured, so the
     canvas starts wherever the header actually ends. */
  inset: var(--crumb-h, 64px) var(--rail) 62px var(--rail);
  overflow: auto;
  padding: 8px 28px 28px;
  z-index: 5;
}

/* A card appears at the first receipt and grows (§9). It is glass so the run
   behind it stays visible: the cards are a reading of the run, not a lid. */
.card {
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  border-radius: 14px;
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  resize: vertical;
  animation: rise 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.card.alert { background: var(--glass-alert); border-color: var(--bad-edge); }
@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.card > header {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--hair-soft);
  background: var(--glass-top);
}
.card > header b { font-weight: 600; }
.card .shape { color: var(--ink-4); font-size: 12px; }
.card .count { margin-left: auto; color: var(--ink-4); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.card .close { border: 0; background: transparent; color: var(--ink-4); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 4px; border-radius: 6px; }
.card .close:hover { background: var(--hair-soft); color: var(--ink); }
.card .body { padding: 6px 14px 12px; overflow: auto; flex: 1; min-height: 0; }

/* Cards tile themselves. The analyst's attention follows the run, so the
   layout is a consequence of what arrived rather than a thing to arrange. */
#canvas .tiles { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; align-items: start; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; } .span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
@media (max-width: 1100px) { .span-3, .span-4, .span-5, .span-7, .span-8 { grid-column: span 12; } }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 5px 4px; text-align: left; border-bottom: 1px solid var(--hair-soft); vertical-align: middle; }
th { font-weight: 500; color: var(--ink-4); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
tr:last-child td { border-bottom: 0; }

.bar { height: 6px; background: var(--hair-soft); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar i { display: block; height: 100%; background: var(--gold); transition: width 0.4s ease; }
.bar i.warn { background: var(--warn); }
.bar i.bad { background: var(--bad); }

.tree-row { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
.tree-row .n { margin-left: auto; color: var(--ink-4); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.tree-row .live { color: var(--gold-ink); font-size: 12px; }
.tree-row .halt { color: var(--bad); font-size: 12px; }

.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--hair-soft); }
.kv:last-child { border-bottom: 0; }
.faint { color: var(--ink-4); font-style: italic; }

/* --- inbox ------------------------------------------------------------- */
#inbox {
  position: fixed;
  top: 64px;
  right: calc(var(--rail) + 14px);
  bottom: 76px;
  width: 340px;
  z-index: 18;
  background: var(--panel);
  border: 1px solid var(--glass-edge);
  border-radius: 14px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  display: flex;
  flex-direction: column;
}
#inbox h3 { margin: 0; padding: 13px 15px; font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--hair-soft); display: flex; }
#inbox h3 span { margin-left: auto; color: var(--ink-4); font-weight: 400; }
#inbox-items { overflow: auto; }
.item { padding: 11px 15px; border-bottom: 1px solid var(--hair-soft); border-left: 3px solid transparent; }
.item.bad { border-left-color: var(--bad); }
.item.warn { border-left-color: var(--warn); }
.item.grey { opacity: 0.68; }
.item .t { display: flex; justify-content: space-between; gap: 8px; }
.item .t b { font-weight: 500; }
.item .t small { color: var(--ink-4); }
.item p { margin: 4px 0 7px; color: var(--ink-3); font-size: 12.5px; }
.item .act { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- transport --------------------------------------------------------- */
#transport {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 62px;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--chrome);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-top: 1px solid var(--hair-soft);
}
.transport-play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.transport-play::before { content: '❚❚'; font-size: 11px; letter-spacing: 1px; }
.transport-play.paused::before { content: '▶'; font-size: 12px; margin-left: 2px; }
.transport-state { font-weight: 600; min-width: 92px; }

/* The timeline is the run's own clock, not the wall's: one tick per minute of
   the stream, the current one filled. Scrubbing is reading the past, which is
   free — every frame is a projection of events already in the store. */
.ticks { display: flex; gap: 6px; align-items: center; overflow: auto; flex: 1; }
.tick {
  border: 1px solid var(--hair);
  background: var(--glass);
  color: var(--ink-3);
  border-radius: 9px;
  padding: 3px 9px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  white-space: nowrap;
}
.tick.on { background: var(--gold); border-color: var(--gold); color: var(--on-gold); }
.tick.seen { border-color: color-mix(in srgb, var(--gold) 45%, transparent); }
.t-cards { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }

.lanes { display: flex; gap: 5px; align-items: center; }
.lane { width: 11px; height: 11px; border-radius: 50%; background: var(--ink-4); opacity: 0.35; }
.lane.on { opacity: 1; background: var(--gold); }
.lane.warn { opacity: 1; background: var(--warn); }
.lane.bad { opacity: 1; background: var(--bad); }

.btn {
  border: 1px solid var(--hair);
  background: var(--glass);
  color: var(--ink);
  border-radius: 9px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: var(--glass-top); }
.btn.ghost { border-color: transparent; color: var(--ink-4); }
/* A verb that needs a hardware key says so, everywhere it appears. */
.btn.touch::after { content: ' ⌘'; color: var(--ink-4); }

.sheet {
  position: fixed;
  right: 78px;
  bottom: 76px;
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--glass-edge);
  border-radius: 14px;
  box-shadow: var(--panel-shadow);
  padding: 14px 16px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.sheet h3 { margin: 0 0 8px; font-size: 13px; }
.key-row { display: flex; gap: 10px; align-items: center; padding: 3px 0; color: var(--ink-3); font-size: 13px; }
.cap {
  display: inline-flex;
  min-width: 22px;
  justify-content: center;
  border: 1px solid var(--hair);
  border-radius: 5px;
  padding: 0 5px;
  font-size: 11.5px;
  color: var(--ink-2);
  background: var(--glass);
}
[hidden] { display: none !important; }

/* The events this build does not model. Muted, but present: a number the
   screen refuses to show is the silence this whole system exists to break. */
.t-unknown {
  font-size: 11px;
  color: var(--ink-4);
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 2px 8px;
  cursor: help;
  white-space: nowrap;
}

/* The transport is a timeline, not a row of tabs — which is how it read to the
   first person who used it, who quite reasonably asked whether clicking one
   started a test run. A word helps; so does the picker beside it, which is
   where switching between runs actually happens. */
.t-label {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-4);
  white-space: nowrap;
}
.run-picker {
  font: 500 11.5px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 3px 8px;
  max-width: 230px;
}

/* The stream card: what the box sent, in the order it sent it.
   Dense on purpose — it is read by scanning for a break in a sequence, not by
   reading each line. */
.stream {
  font: 11.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  /* Fills whatever height the card has been dragged to, rather than a fixed
     one. A resizable card whose contents do not resize with it is a handle
     that does nothing. */
  flex: 1 1 auto;
  min-height: 140px;
  overflow: auto;
  color: var(--ink-3);
}

.stream-chips {
  display: flex;
  gap: 5px;
  padding: 0 0 7px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}
.chip {
  font: 500 10.5px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.04em;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--hair);
  background: transparent;
  color: var(--ink-4);
  cursor: pointer;
}
.chip:hover { color: var(--ink-2); border-color: var(--hair); }
.chip.on { color: var(--gold); border-color: var(--gold); }

/* The stream card's body is a column so the list takes the slack when the card
   is dragged taller. `.card .body` already scrolls; the inner list must be the
   thing that scrolls instead, or the chips scroll away with it. */
.card[data-card='stream'] .body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.card[data-card='stream'] { min-height: 260px; }
.stream-note {
  color: var(--warn);
  padding: 2px 0 6px;
  font-style: italic;
}
.stream-row {
  display: grid;
  grid-template-columns: 4.6em 7.4em 5.2em 13em 1fr;
  gap: 10px;
  padding: 1px 4px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.stream-row:hover { background: var(--hair-soft); }
.stream-row.open { background: var(--hair-soft); }
.s-seq { color: var(--ink-4); }
.s-at { color: var(--ink-4); }
.s-kind { color: var(--ink); font-weight: 500; }
.s-gist { color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; }
.s-lane { font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; align-self: center; }
.lane-custody { color: var(--gold); }
.lane-health  { color: var(--ink-4); }
.lane-audit   { color: var(--warn); }
.lane-clerk   { color: #4a7fb5; }
.stream-body {
  margin: 2px 0 8px 4.6em;
  padding: 8px 10px;
  background: var(--hair-soft);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink-2);
  max-height: 260px;
  overflow: auto;
}
