/* hekla admin console.
 *
 * Hand-written, no framework: a build step is what a framework would cost, and the
 * console is a few dozen components with one visual language. Every colour is a
 * token; nothing below the token block names a literal colour.
 *
 * Dark first, because this is a tool you open next to a terminal. `:root` holds the
 * dark palette, and light comes from either an explicit choice or the system
 * preference, so the toggle wins in both directions. */

:root {
  --bg: #0d0f12;
  --bg-raised: #14171c;
  --bg-inset: #1a1e24;
  --bg-hover: #1e232a;
  --bg-active: #252b34;
  --border: #23282f;
  --border-strong: #333a44;

  --text: #e7ebf0;
  --text-dim: #9aa4b1;
  --text-faint: #6b7480;

  --accent: #6ea8fe;
  --accent-dim: #2a4a7f;
  --accent-text: #0d0f12;

  --ok: #4ac97e;
  --warn: #e3b341;
  --err: #f2777a;
  --info: #a78bfa;

  --ok-bg: #14301f;
  --warn-bg: #33290d;
  --err-bg: #3a1a1c;
  --info-bg: #241b3d;
  --accent-bg: #16263f;

  /* Correlation colours are built from a hashed hue (`ui/correlation.js`); only the
   * lightness and the chroma are chosen, once per theme, so all sixteen land at the
   * same weight against this background instead of yellow shouting over blue. */
  --corr-l: 74%;
  --corr-c: 0.13;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  --radius: 6px;
  --radius-lg: 10px;
  --rail: 208px;
  /* The drawer is wider than the column it replaces: it is over the content rather
   * than beside it, so the space costs nothing, and a thumb needs the room. */
  --rail-open: 260px;
  --row: 30px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono",
    monospace;

  --shadow: 0 8px 24px rgb(0 0 0 / 45%);
  --motion: 130ms cubic-bezier(0.2, 0, 0.2, 1);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-raised: #f7f8fa;
  --bg-inset: #eef1f5;
  --bg-hover: #eaeef3;
  --bg-active: #dfe5ec;
  --border: #e2e6ec;
  --border-strong: #c8d0da;

  --text: #16191d;
  --text-dim: #5a636e;
  --text-faint: #8a939f;

  --accent: #2563c9;
  --accent-dim: #b9d0f5;
  --accent-text: #ffffff;

  --ok: #167d43;
  --warn: #97690b;
  --err: #c3312f;
  --info: #6d3fd4;

  --ok-bg: #e4f6eb;
  --warn-bg: #fdf3d9;
  --err-bg: #fdeaea;
  --info-bg: #efe9fd;
  --accent-bg: #e7f0fd;

  --corr-l: 48%;
  --corr-c: 0.16;

  --shadow: 0 8px 24px rgb(20 30 45 / 12%);

  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff;
    --bg-raised: #f7f8fa;
    --bg-inset: #eef1f5;
    --bg-hover: #eaeef3;
    --bg-active: #dfe5ec;
    --border: #e2e6ec;
    --border-strong: #c8d0da;

    --text: #16191d;
    --text-dim: #5a636e;
    --text-faint: #8a939f;

    --accent: #2563c9;
    --accent-dim: #b9d0f5;
    --accent-text: #ffffff;

    --ok: #167d43;
    --warn: #97690b;
    --err: #c3312f;
    --info: #6d3fd4;

    --ok-bg: #e4f6eb;
    --warn-bg: #fdf3d9;
    --err-bg: #fdeaea;
    --info-bg: #efe9fd;
    --accent-bg: #e7f0fd;

    --corr-l: 48%;
    --corr-c: 0.16;

    --shadow: 0 8px 24px rgb(20 30 45 / 12%);

    color-scheme: light;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
/* The app mounts into #root, so it is part of the chain a percentage height resolves
 * against. Without it the shell's `height: 100%` measures against an auto-height div
 * and the sidebar stops at the bottom of whatever the page happens to contain. */
#root {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Every number in this console is compared against the one above it. */
code,
kbd,
pre,
.num,
.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.num {
  text-align: right;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

::selection {
  background: var(--accent-dim);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* --- shell -------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  grid-template-rows: 100%;
  height: 100%;
  /* `height: 100%` resolves against the *large* viewport on a phone, which puts the
   * bottom of the shell behind the address bar. `.content` is the scroller, so the
   * dynamic unit resizes a container rather than reflowing a scrolling page. */
  height: 100dvh;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  padding: var(--s3) var(--s2);
  border-right: 1px solid var(--border);
  background: var(--bg-raised);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s1) var(--s2) var(--s3);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Larger than the letterform it replaced: the mark is faceted, so at 18px the facets
 * stop being shapes and become noise. */
.brand svg {
  width: 22px;
  height: 22px;
  flex: none;
}

.brand .project {
  color: var(--text-faint);
  font-weight: 400;
  font-size: 12px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  padding: 5px var(--s2);
  border-radius: var(--radius);
  color: var(--text-dim);
  transition: background var(--motion), color var(--motion);
}

.nav a:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}

.nav a[aria-current="page"] {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 500;
}

.rail-foot {
  margin-top: auto;
  padding-top: var(--s3);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--text-faint);
}

.rail-foot .kv {
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
  padding: 1px var(--s2);
}

.rail-foot .kv span:last-child {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.rail-actions {
  display: flex;
  gap: var(--s1);
  padding-top: var(--s2);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s5);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

.topbar h1 {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar .spacer {
  flex: 1;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: var(--s5);
}

.content > * + * {
  margin-top: var(--s5);
}

/* --- primitives --------------------------------------------------------- */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  overflow: hidden;
}

.card > header {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.card > .body {
  padding: var(--s4);
}

.grid {
  display: grid;
  gap: var(--s4);
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-inset);
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion), color var(--motion), border-color var(--motion);
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 500;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent);
  color: var(--accent-text);
  filter: brightness(1.08);
}

.btn.danger {
  border-color: var(--err);
  color: var(--err);
}

.btn.danger:hover:not(:disabled) {
  background: var(--err-bg);
  color: var(--err);
}

.btn.icon {
  padding: 4px 6px;
}

/* An icon has no line box, so a button holding one came out shorter than the button
 * next to it holding a word. Taking the text's own line height gives the two the same
 * height without either naming a pixel, and the viewBox keeps the glyph its own size
 * inside the taller box. */
.btn > svg {
  width: 14px;
  height: 1.5em;
}

kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-inset);
  font-size: 11px;
  color: var(--text-dim);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.pill.plain::before {
  display: none;
}

.pill.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.pill.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.pill.err {
  background: var(--err-bg);
  color: var(--err);
}

.pill.info {
  background: var(--info-bg);
  color: var(--info);
}

.pill.mute {
  background: var(--bg-inset);
  color: var(--text-dim);
}

/* A trailing annotation after a value: "1284 <in memory>", "0 <since this process
 * started>". The gap comes from the margin rather than from a space in the template,
 * because htm drops whitespace that spans a newline: a space written inline vanishes
 * the moment the line is wrapped, which is a formatting change away at all times. */
.note {
  margin-left: var(--s2);
  color: var(--text-faint);
  font-size: 11.5px;
  font-weight: 400;
  /* Annotations sit inside uppercased, tracked-out headings as well as ordinary
   * values, and an annotation is prose either way. */
  text-transform: none;
  letter-spacing: 0;
}

.dim {
  color: var(--text-dim);
}

.faint {
  color: var(--text-faint);
}

.tiny {
  font-size: 11.5px;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.wrap {
  flex-wrap: wrap;
}

.scroll-x {
  overflow-x: auto;
}

/* --- tables ------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  /* A table is wider than a phone by design, so swiping one sideways is the normal
   * way to read it. Without this the swipe that runs off the end of the columns
   * becomes the browser's back gesture and leaves the view entirely. */
  overscroll-behavior-x: contain;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  white-space: nowrap;
}

table.data th.num {
  text-align: right;
}

/* A cell holding a sentence rather than a value. `max-width: 0` is what makes the auto
 * layout hand it whatever width is left instead of sizing it to its content, so one
 * long error ends in an ellipsis rather than pushing the columns after it out of the
 * card. The whole text stays in the cell's `title` and on the detail page. */
table.data td.clip {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.data td {
  position: relative;
  height: var(--row);
  padding: 0 var(--s3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}

/* A cell that wraps is buying room the table already has: `.table-wrap` scrolls
 * sideways, so the width is free and the height is not. Without this a narrow view
 * turned each event's tag list into three lines, which is a page you scroll past
 * rather than one you scan down. */
table.data td .wrap {
  flex-wrap: nowrap;
}

table.data tbody tr {
  transition: background var(--motion);
}

table.data tbody tr.clickable {
  cursor: pointer;
}

table.data tbody tr.clickable:hover {
  background: var(--bg-hover);
}

table.data tbody tr.cursor {
  background: var(--bg-active);
  box-shadow: inset 2px 0 0 var(--accent);
}

table.data tbody tr.selected td:first-child {
  color: var(--accent);
}

/* --- correlation -------------------------------------------------------- */

/* One chain, one colour, everywhere it appears. The hue is hashed from the id so it
 * survives paging and polling; `ui/correlation.js` has the argument for why that is
 * worth more than guaranteeing two neighbours differ, and what carries grouping
 * instead. */
.corr,
.corr-dot {
  --corr: oklch(var(--corr-l) var(--corr-c) var(--corr-hue, 0));
}

.corr {
  display: flex;
  align-items: center;
  height: 100%;
  /* Back out over the cell's padding so the rail sits on the column's own edge, then
   * put it back, which leaves the whole cell as the target that lights the chain. */
  margin-left: calc(-1 * var(--s3));
  padding-left: var(--s3);
  color: var(--corr);
  transition: opacity var(--motion);
}

.corr a {
  color: var(--corr);
}

/* One capsule per run of consecutive rows under the same id. The break between two
 * runs is what says they are different chains, which the hue cannot promise: sixteen
 * hues over an unbounded number of ids collide, and where they do the seam is still
 * exact. Absolute against the cell, and over the row's border, so a run reads as one
 * unbroken bar rather than as one dash per row. */
.corr-rail {
  position: absolute;
  left: 0;
  top: 0;
  bottom: -1px;
  width: 3px;
  background: var(--corr);
}

.corr-rail.opens {
  top: 4px;
  border-radius: 2px 2px 0 0;
}

.corr-rail.closes {
  bottom: 3px;
  border-radius: 0 0 2px 2px;
}

/* Hovering the column settles a collision outright: whatever the hues did, one chain
 * stays lit. Bound to the correlation cell rather than the row, so it is something you
 * ask for by pointing at it and not something the table does under a moving cursor. */
table.data tbody tr.corr-other .corr {
  opacity: 0.22;
}

/* The same colour on a page that is already one chain, so arriving here confirms you
 * followed the row you meant to. */
.corr-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--corr);
}

/* --- key/value ---------------------------------------------------------- */

dl.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--s2) var(--s4);
  margin: 0;
  font-size: 13px;
}

dl.kv dt {
  color: var(--text-faint);
  white-space: nowrap;
}

dl.kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* --- json --------------------------------------------------------------- */

.json {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  overflow-x: auto;
}

.json .line {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  white-space: pre;
}

.json .key {
  color: var(--text-dim);
}

.json .str {
  color: var(--ok);
}

.json .num-v {
  color: var(--info);
}

.json .bool {
  color: var(--warn);
}

.json .null {
  color: var(--text-faint);
}

.json .sealed {
  color: var(--text-faint);
  letter-spacing: 2px;
}

.json .toggle {
  border: 0;
  background: none;
  padding: 0 2px;
  cursor: pointer;
  color: var(--text-faint);
  width: 14px;
  text-align: left;
}

.json .toggle:hover {
  color: var(--text);
}

.json .indent {
  padding-left: var(--s4);
  border-left: 1px solid var(--border);
  margin-left: 5px;
}

/* --- states ------------------------------------------------------------- */

.empty,
.error-state {
  padding: var(--s6) var(--s4);
  text-align: center;
  color: var(--text-dim);
}

.empty h3,
.error-state h3 {
  margin: 0 0 var(--s2);
  font-size: 14px;
  color: var(--text);
}

.error-state {
  border: 1px solid var(--err);
  border-radius: var(--radius-lg);
  background: var(--err-bg);
}

.error-state code {
  color: var(--err);
}

.skeleton {
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    var(--bg-inset) 25%,
    var(--bg-hover) 37%,
    var(--bg-inset) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

.skeleton-stack {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s4);
}

/* --- detail panel -------------------------------------------------------- */

/* The list and its detail sit side by side, so opening another row swaps the panel
 * rather than needing the first one dismissed. Below the breakpoint the grid collapses
 * to one column and the panel goes *first*: stacked under fifty rows it would be off
 * screen at the moment it appeared. */
.with-detail {
  display: grid;
  gap: var(--s4);
  grid-template-columns: minmax(0, 1fr) minmax(0, 480px);
  /* Deliberately not `align-items: start`: a sticky element needs room to move inside
   * its grid area, and a start-aligned item's area is exactly its own height, so it
   * would scroll away with the table. Stretching gives the panel the full row height
   * to stick within, and its own `max-height` keeps it viewport-sized. */
  align-items: stretch;
}

.panel {
  /* `.content` is the scroll container, so the panel stays put while the table scrolls
   * under it, and never grows taller than the viewport. */
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  /* The viewport less the topbar (52px) and the content padding above and below
   * (24px each), so a long payload scrolls inside the panel rather than pushing it
   * off the bottom of the page. */
  max-height: calc(100vh - 100px);
  animation: panel-in var(--motion);
}

@keyframes panel-in {
  from {
    transform: translateX(6px);
    opacity: 0;
  }
}

.panel-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-weight: 600;
  font-family: var(--mono);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--s4);
}

.section-title {
  margin: var(--s5) 0 var(--s2);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.panel-body > .section-title:first-child {
  margin-top: 0;
}

/* --- filters ------------------------------------------------------------ */

.filters {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
}

.filter-input {
  display: flex;
  align-items: center;
  gap: var(--s1);
}

input,
select,
textarea {
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-inset);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: none;
}

/* --- command runner ------------------------------------------------------ */

/* The same two-column grid `dl.kv` uses, so a parameter list and a value list line up
   the same way even though only one of them is a definition list. */
.cmd-form {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--s3) var(--s4);
  align-items: start;
  padding: var(--s4);
}

/* Capped, because a `max-content` track is sized by its longest line and a declared
 * kind has no length limit: one twelve-variant union wrote a 200-character label that
 * took the whole card and left every input in the form a few pixels wide. `shortKind`
 * keeps that out of the text; this keeps it out of the layout whatever the text says. */
.cmd-form > label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 5px;
  max-width: 18rem;
  overflow-wrap: anywhere;
}

.cmd-field {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.cmd-field > input[type='text'],
.cmd-field > select,
.cmd-field > textarea {
  flex: 1;
  min-width: 0;
}

.cmd-field > input[type='checkbox'] {
  flex: none;
}

.cmd-json {
  width: 100%;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
}

.cmd-headers > summary {
  cursor: pointer;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 8px;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  background: var(--accent-bg);
  font-size: 12px;
}

.chip-kind {
  color: var(--text-faint);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chip button {
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--text-faint);
  padding: 0 3px;
  line-height: 1;
}

.chip button:hover {
  color: var(--err);
}

/* --- modal and palette --------------------------------------------------- */

.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  background: rgb(0 0 0 / 45%);
  backdrop-filter: blur(2px);
}

.modal,
.palette {
  width: min(520px, 92vw);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal {
  padding: var(--s5);
}

.modal h2 {
  margin: 0 0 var(--s3);
  font-size: 15px;
}

.modal p {
  margin: 0 0 var(--s3);
}

.confirm-field {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  margin: var(--s4) 0;
}

.confirm-field input {
  font-family: var(--mono);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s2);
}

.palette input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  padding: var(--s4);
  font-size: 15px;
}

.palette-list {
  max-height: 46vh;
  overflow-y: auto;
  padding: var(--s2);
}

.palette-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: 6px var(--s3);
  border: 0;
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
  text-align: left;
}

.palette-item.active {
  background: var(--accent-bg);
}

.palette-group {
  width: 76px;
  flex: none;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.palette-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-empty {
  padding: var(--s4);
  color: var(--text-faint);
  text-align: center;
}

/* --- trace -------------------------------------------------------------- */

.trace,
.trace-children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.trace-children {
  margin-left: 9px;
  padding-left: var(--s4);
  border-left: 1px solid var(--border-strong);
}

.trace-node {
  padding: 2px 0;
}

.trace-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 3px 0;
}

.trace-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
}

.trace-meta {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 0 0 4px 19px;
}

/* --- overview and schema ------------------------------------------------- */

.stat {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.spark-wrap {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-top: var(--s3);
  color: var(--accent);
}

.spark {
  width: 120px;
  height: 26px;
  flex: none;
}

.module-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.attention {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.attention:last-child {
  border-bottom: 0;
}

.graph {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.graph-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.graph-event {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 240px;
}

.graph-arrow {
  color: var(--text-faint);
  flex: none;
}

.graph-consumers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.graph-fields {
  padding: 0 0 var(--s3) var(--s2);
  border-bottom: 1px solid var(--border);
}

.graph-fields summary {
  cursor: pointer;
  padding: 2px 0;
}

.graph-fields dl {
  padding-top: var(--s2);
}

.effect-edges {
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--border);
}

.effect-edges:last-child {
  border-bottom: 0;
}

.split {
  display: grid;
  gap: var(--s4);
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  align-items: start;
}

/* --- the source editor --------------------------------------------------- */

/* A painted layer under a transparent textarea. Every metric below that either one
 * uses is set on both, because a single pixel of disagreement puts the caret beside
 * the character instead of on it. `resize` lives on the wrapper rather than the
 * textarea, which is absolutely positioned and so cannot carry a handle. */
.hk-editor {
  display: flex;
  height: clamp(11rem, 30vh, 28rem);
  overflow: hidden;
  resize: vertical;
  border-top: 1px solid var(--border);
  background: var(--bg-inset);
  --hk-pad: 10px;
  --hk-size: 12.5px;
  --hk-leading: 1.6;
}

.hk-gutter {
  flex: none;
  overflow: hidden;
  padding: var(--hk-pad) var(--s2) var(--hk-pad) var(--s3);
  border-right: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: var(--hk-size);
  line-height: var(--hk-leading);
  text-align: right;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.hk-gutter .bad {
  color: var(--err);
  font-weight: 600;
}

.hk-scroll {
  position: relative;
  flex: 1;
  min-width: 0;
}

.hk-paint,
.hk-input {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: var(--hk-pad);
  border: 0;
  font-family: var(--mono);
  font-size: var(--hk-size);
  line-height: var(--hk-leading);
  /* No wrapping, in both: it is what makes one source line one painted line, which is
   * what lets the gutter be a list of numbers rather than a measurement. */
  white-space: pre;
  tab-size: 2;
}

.hk-paint {
  overflow: hidden;
  pointer-events: none;
  background: none;
  color: var(--text);
}

.hk-input {
  width: 100%;
  height: 100%;
  overflow: auto;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  border-radius: 0;
}

.hk-input:focus {
  outline: none;
}

/* The text is transparent, so the selection cannot tint it and has to be visible on
 * its own. */
.hk-input::selection {
  background: var(--accent-dim);
}

.hk-input::placeholder {
  color: var(--text-faint);
}

/* Five colours, all of them tokens already carrying this meaning elsewhere: `.json`
 * paints a string with `--ok` and a comment is as quiet as a `.faint`. A type name is
 * left alone on purpose, because a declaration is mostly type names and colouring them
 * colours the whole file. */
.hk-comment {
  color: var(--text-faint);
  font-style: italic;
}

.hk-string {
  color: var(--ok);
}

.hk-number {
  color: var(--warn);
}

.hk-keyword {
  color: var(--accent);
}

.hk-path {
  color: var(--info);
}

/* --- projections --------------------------------------------------------- */

/* A saved projection is two buttons in one chip: the name loads it and the ✕ deletes
 * it, so the destructive one is never the bigger target. */
.chip-open {
  font: inherit;
  color: var(--text);
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-open:hover {
  color: var(--accent);
}

.chip.on {
  border-color: var(--accent);
}

.hk-insert {
  max-width: 14rem;
}

/* A label above its field rather than beside it: four of them sit in one row, and a
 * leading label doubles the width each one costs. */
.hk-knob {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hk-knob.row {
  flex-direction: row;
  align-items: center;
  gap: var(--s1);
  align-self: flex-end;
  padding-bottom: 5px;
}

.hk-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-inset);
  overflow: hidden;
}

.hk-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width var(--motion);
}

/* Before the first tick there is no denominator to fill against, and a bar sitting at
 * zero reads as stalled. This one says "working" without claiming to know how far. */
.hk-bar.waiting .hk-bar-fill {
  width: 30% !important;
  animation: hk-sweep 1.1s ease-in-out infinite;
}

@keyframes hk-sweep {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(333%);
  }
}

.hk-finding {
  display: grid;
  grid-template-columns: max-content max-content minmax(0, 1fr);
  align-items: baseline;
  gap: var(--s2);
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--border);
}

.hk-finding:last-child {
  border-bottom: 0;
}

/* --- responsive ---------------------------------------------------------- */

/* Two controls exist only on one side of the narrow breakpoint: the drawer's own
 * open and close buttons, which a desktop has no use for, and the ⌘K hint and event
 * count, which a phone has no room for and no keyboard to act on. */
.narrow-only {
  display: none;
}

@media (max-width: 1100px) {
  .split,
  .with-detail {
    grid-template-columns: minmax(0, 1fr);
  }

  .with-detail .panel {
    /* Stacked under fifty rows the panel would be off screen the moment it opened,
     * so it leads instead, and stops being sticky because there is nothing beside it
     * to stay level with. */
    order: -1;
    position: static;
    max-height: none;
  }
}

/* Below this the rail stops being a column and becomes a drawer. It is the same
 * markup either way: it leaves the grid, sits over the content, and is opened from
 * the topbar button that only exists here. 208px of permanent navigation is over
 * half of a phone, which left every table reading through a 180px slot. */
@media (max-width: 760px) {
  /* A row is something you tap here, not something you point at. */
  :root {
    --row: 38px;
  }

  .narrow-only {
    display: inline-flex;
  }

  .wide-only {
    display: none;
  }

  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 70;
    width: min(var(--rail-open), 84vw);
    border-right: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
    /* Parked off the left edge, which browsers clip rather than make scrollable, so
     * a closed drawer is never one sideways swipe from opening itself. `app.js`
     * marks it `inert` to take it out of the tab order to match. */
    transform: translateX(-100%);
    transition: transform var(--motion);
  }

  .shell.nav-open .rail {
    transform: none;
  }

  .nav-scrim {
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgb(0 0 0 / 45%);
  }

  .topbar {
    gap: var(--s2);
    padding: var(--s2) var(--s3);
  }

  .content {
    padding: var(--s3);
  }

  .content > * + * {
    margin-top: var(--s3);
  }

  .card > header,
  .card > .body,
  .filters,
  .panel-head,
  .panel-body {
    padding: var(--s3);
  }

  .card > header {
    flex-wrap: wrap;
    row-gap: var(--s1);
  }

  /* One value per line rather than beside its label, for the same reason `.cmd-form`
   * stacks. `.row` inside a value has to give up its single line with it. */
  dl.kv dd.row {
    flex-wrap: wrap;
  }

  /* One column per parameter: the `max-content` label column is sized by the longest
   * name in the form, and `triggering_event_id` against a uuid leaves neither side
   * readable on a phone. */
  .cmd-form {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s2);
  }

  .cmd-form > label {
    padding-top: var(--s2);
  }

  dl.kv {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  dl.kv dt {
    margin-top: var(--s3);
  }

  dl.kv dt:first-of-type {
    margin-top: 0;
  }

  /* The graph reads down the page instead of across it, so the arrow has to turn
   * with it or it points at the card's edge. */
  .graph-row {
    flex-direction: column;
    align-items: stretch;
    gap: var(--s1);
  }

  .graph-event {
    min-width: 0;
  }

  .graph-arrow {
    transform: rotate(90deg);
    width: 1em;
  }

  .modal-scrim {
    padding: var(--s4) var(--s3) 0;
  }

  .modal {
    padding: var(--s4);
  }

  .palette-list {
    max-height: 52vh;
  }
}

/* Touch, at any width: a tablet shows the rail as a column and still has no pointer
 * to hover with, so the sizes that make a control tappable belong here rather than
 * behind the width above. */
@media (pointer: coarse) {
  .btn {
    padding: 7px 12px;
  }

  .btn.icon {
    padding: 7px 9px;
  }

  .nav a {
    padding: 9px var(--s2);
  }

  .palette-item {
    padding: 10px var(--s3);
  }

  /* Safari zooms the whole page when a field under 16px takes focus, so every tap
   * into a filter or a command parameter rescaled the layout under it. Anything that
   * sets its own size is named again here, or it keeps it. The editor's three layers
   * have to move together, or the paint stops sitting under the caret. */
  input,
  select,
  textarea,
  .palette input,
  .cmd-json,
  .hk-input,
  .hk-paint,
  .hk-gutter {
    font-size: 16px;
  }
}
