:root {
  color-scheme: light;
  --paper: #f7f7f3;
  --surface: #ffffff;
  --sunken: #f0f0ea;
  --ink: #1f2a26;
  --muted: #66736d;
  --faint: #9aa59f;
  --line: #e2e4dc;
  --line-strong: #cdd2c8;
  --hover: #eef2ec;
  --accent: #2f6b4f;
  --green: #2f6b4f;
  --green-soft: #a9cdb8;
  --amber: #93600f;
  --amber-soft: #f6e7c8;
  --red: #b0322b;
  --red-soft: #f8dcd8;
  /* Outcome colours differ in lightness as well as hue, so they separate
     without relying on red/green discrimination. */
  --o-failed: #c0262d;
  --o-timeout: #f0b429;
  --o-building: #7c5cc4;
  --o-built: #1f5f99;
  --o-valid: #c9cec6;
  --o-none: #ecede8;
  --ansi-0: #26332e;
  --ansi-1: #962e29;
  --ansi-2: #315b46;
  --ansi-3: #875814;
  --ansi-4: #285e89;
  --ansi-5: #80438a;
  --ansi-6: #286a70;
  --ansi-7: #596a62;
  --ansi-8: #737c75;
  --ansi-9: #c13a32;
  --ansi-10: #3c7554;
  --ansi-11: #a67410;
  --ansi-12: #326fba;
  --ansi-13: #9952a2;
  --ansi-14: #337f89;
  --ansi-15: #26332e;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 6px;
  font: 14px/1.45 var(--sans);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #151a18;
    --surface: #1c2220;
    --sunken: #121614;
    --ink: #e3e8e4;
    --muted: #9aa69f;
    --faint: #69756f;
    --line: #2a322f;
    --line-strong: #3a4440;
    --hover: #232b28;
    --accent: #7cc49c;
    --green: #7cc49c;
    --green-soft: #2f5a44;
    --amber: #e3b25e;
    --amber-soft: #4a3a1c;
    --red: #f08a80;
    --red-soft: #4e2421;
    --o-failed: #ff6b6b;
    --o-timeout: #f5c24c;
    --o-building: #b39af0;
    --o-built: #5aa0e6;
    --o-valid: #4a534f;
    --o-none: #262d2a;
    --ansi-0: #c9d1cc;
    --ansi-1: #f08a80;
    --ansi-2: #7cc49c;
    --ansi-3: #e3b25e;
    --ansi-4: #7fb2e5;
    --ansi-5: #d39be0;
    --ansi-6: #6cc4c9;
    --ansi-7: #a8b3ad;
    --ansi-8: #7c8781;
    --ansi-9: #ff9d93;
    --ansi-10: #94d8b0;
    --ansi-11: #f0c674;
    --ansi-12: #99c4f0;
    --ansi-13: #e2b0ec;
    --ansi-14: #8ad6da;
    --ansi-15: #e3e8e4;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
button {
  padding: 3px 10px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); cursor: pointer;
}
button:hover { background: var(--hover); }
input, select {
  padding: 4px 8px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); min-width: 0;
}
label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }
h1, h2, p, pre { margin: 0; }
h1 { font-size: 22px; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; }
h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
pre { font: inherit; }
.pkg { font-weight: 600; }
.version { color: var(--muted); font-family: var(--mono); font-size: 0.86em; margin-left: 0.5em; }
td.version { margin-left: 0; }
.platform, .snapshot, .rail-count {
  font: 11px/1.5 var(--mono); color: var(--muted);
}

/* Status: a coloured pill for problems; plain coloured text for outcomes. */
.status {
  display: inline-block; padding: 0 8px; border-radius: 999px; font-size: 12px; line-height: 20px;
  font-weight: 550; white-space: nowrap; background: var(--sunken); color: var(--muted);
}
.status[data-status="built"] { background: transparent; color: var(--o-built); padding: 0; }
.status[data-status="already-valid"], .status[data-status="unattempted"] { background: transparent; color: var(--muted); padding: 0; font-weight: 400; }
.status[data-status="failed"], .status[data-status="interrupted"] { background: var(--red-soft); color: var(--red); }
.status[data-status="timed-out"], .status[data-status="incomplete"], .status[data-status="observing"] { background: var(--amber-soft); color: var(--amber); }
.record-mode { font-size: 12px; color: var(--muted); }
.record-mode[data-live="1"] { color: var(--amber); font-weight: 600; }
.record-mode[data-live="1"]::before { content: "● "; }

/* Overview: one page, one scroll. */
.brand { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 6px; }
.brand span { color: var(--faint); margin: 0 2px; }
.overview { padding: 20px 28px 28px; max-width: 1280px; margin: 0 auto; min-width: 0; }
.summary-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.campaign-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tally-bar {
  display: flex; gap: 2px; height: 12px; margin-top: 14px; border-radius: 3px; overflow: hidden;
}
.tally-bar span { min-width: 10px; background: var(--o-none); }
[data-status="failed"] { --o: var(--o-failed); }
[data-status="timed-out"] { --o: var(--o-timeout); }
[data-status="observing"] { --o: var(--o-building); }
[data-status="built"] { --o: var(--o-built); }
[data-status="already-valid"] { --o: var(--o-valid); }
[data-status="unattempted"] { --o: var(--o-none); }
.tally-bar span[data-status] { background: var(--o); }
.tally-bar [data-status="timed-out"] {
  background: repeating-linear-gradient(135deg, var(--o-timeout) 0 4px, color-mix(in srgb, var(--o-timeout) 60%, var(--paper)) 4px 7px);
}
.campaign-line { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; }
.chip { border: 0; background: none; padding: 0; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { background: none; color: var(--ink); text-decoration: underline; }
.chip::before { content: ""; width: 11px; height: 11px; border-radius: 2px; background: var(--o); }
.chip[data-status="unattempted"]::before { box-shadow: inset 0 0 0 1px var(--line-strong); }
.chip b { color: var(--ink); font-variant-numeric: tabular-nums; }
.duration { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; text-align: right; }

#rail-controls { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 18px 0 6px; }
#rail-controls input { width: 22ch; }
.rail-count { padding: 0 0 4px; }
.campaign-table { width: 100%; table-layout: fixed; border-collapse: collapse; }
.campaign-table th, .campaign-table td { padding: 4px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.campaign-table th {
  position: sticky; top: 0; z-index: 1; background: var(--paper); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-bottom-color: var(--line-strong);
}
.campaign-table th:nth-child(2) { width: 15ch; }
.campaign-table th:nth-child(3) { width: 14ch; }
.campaign-table th:nth-child(4) { width: 12ch; text-align: right; }
.campaign-table td.duration { text-align: right; }
.campaign-table th:nth-child(5) { width: 40%; }
.campaign-table td.pkg-cell { font-weight: 600; overflow-wrap: anywhere; }
.campaign-table td.pkg-cell a { color: var(--ink); display: block; }
.campaign-table td.version { font-size: 12.5px; margin: 0; overflow-wrap: anywhere; }
.campaign-table tbody tr:hover { background: var(--hover); }
.campaign-table tbody tr:hover td.pkg-cell a { color: var(--accent); }
.campaign-table tr[data-status="unattempted"] td { color: var(--faint); }
.session-observation { color: var(--muted); overflow-wrap: anywhere; font-size: 13px; }
tr[data-status="failed"] .session-observation, tr[data-status="interrupted"] .session-observation { color: var(--red); }
.paging { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 0; }
.empty, .log-empty { padding: 8px 10px; color: var(--muted); }

/* Session: inspector beside a console that flows with the page. */
.detail-shell { padding: 10px 16px 24px; }
.detail-nav { font-size: 13px; margin-bottom: 8px; }
.detail-layout { display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); gap: 20px; align-items: start; }
#state {
  min-width: 0; display: flex; flex-direction: column; gap: 12px;
  position: sticky; top: 0; max-height: 100dvh; overflow: auto; overscroll-behavior: contain;
  padding: 4px 4px 16px 0; scrollbar-gutter: stable;
}
#state .summary-head { display: block; flex: none; }
.head-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 6px; }

.failure {
  flex: none; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--red); border-radius: var(--radius);
}
.failure[data-status="timed-out"] { border-left-color: var(--o-timeout); }
.failure h2 { margin-bottom: 6px; }
.failure > .cause-what { font-weight: 600; overflow-wrap: anywhere; white-space: pre-wrap; }
.cause-context { color: var(--muted); margin-top: 2px; }
.cause-chain { list-style: none; margin: 0; padding: 0; }
.cause {
  position: relative; display: grid; grid-template-columns: max-content minmax(0,1fr) auto;
  align-items: baseline; gap: 0 8px; padding: 4px 0 4px 18px;
}
.cause > .pkg { grid-row: 1; grid-column: 1; }
.cause > .version { grid-row: 1; grid-column: 2; margin-left: 0; }
.cause > .cause-what { grid-column: 1 / 3; overflow-wrap: anywhere; }
.cause > button { grid-row: 1; grid-column: 3; }
.cause::before {
  content: ""; position: absolute; left: 4px; top: 12px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--faint);
}
.cause:not(:last-child)::after {
  content: ""; position: absolute; left: 7px; top: 21px; bottom: -11px; width: 1px; background: var(--line-strong);
}
.cause.origin::before { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.cause-what { color: var(--muted); }
.cause.origin .cause-what { color: var(--red); font-weight: 550; }
.cause button { font-size: 12px; padding: 0 8px; }

#inspection-scroll { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, auto)); justify-content: start; gap: 8px 28px; margin: 0; }
.facts > div { min-width: 0; }
.drv-fact { grid-column: 1/-1; }
.facts dt { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; color: var(--muted); }
.facts dt button { margin-left: 8px; font-size: 11px; padding: 0 6px; letter-spacing: 0; }
.facts dd { margin: 0; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12.5px; }
details { border-top: 1px solid var(--line); }
summary { cursor: pointer; padding: 6px 0; color: var(--muted); font-size: 13px; }
summary:hover { color: var(--ink); }
#inspection-scroll pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.5 var(--mono); padding: 2px 0 8px; }
.reported-errors > button { font-size: 12px; padding: 0 8px; }

.phase-ledger { border-top: 1px solid var(--line); padding-top: 8px; }
.phase-ledger table { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: 13px; }
.phase-ledger td { padding: 2px 8px 2px 0; vertical-align: middle; }
.phase-ledger td:first-child { width: 1%; white-space: nowrap; }
.phase-ledger td:nth-child(2) { width: 1%; white-space: nowrap; text-align: right; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.phase-ledger button {
  white-space: nowrap; text-align: left; padding: 0; border: 0; background: none;
  color: var(--accent); font-family: var(--mono); font-size: 12px;
}
.phase-bar { display: block; height: 6px; border-radius: 2px; background: var(--o-built); opacity: 0.55; width: calc(var(--share) / 10 * 1%); min-width: 2px; }

.graph-panel { border-top: 1px solid var(--line); min-width: 0; padding-top: 8px; }
.panel-head { flex: none; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-head > span { color: var(--muted); font-size: 13px; }
.graph-panel .panel-head { margin-bottom: 4px; }
.graph-scroll { overflow-x: auto; }
.graph-scroll > details { border-top: 0; }
.graph-node {
  padding: 1px 6px; padding-left: calc(6px + var(--depth)*14px); font-size: 13px;
  border-left: 1px solid var(--line); overflow-wrap: anywhere;
}
.graph-node .node-name { color: var(--ink); }
.graph-node .node-name .pkg { font-weight: 400; }
.graph-node.native .node-name, .graph-node.native .pkg { color: var(--muted); }
.graph-panel .panel-head > span { font-size: 12px; }
.graph-node.failed { background: var(--red-soft); border-left-color: var(--red); }
.graph-node.failed .node-name, .graph-node.failed .pkg { color: var(--red); }
.graph-node:target { background: var(--amber-soft); }
.graph-node > span, .graph-node > a.node-output { margin-left: 8px; }
.graph-node > span:not(.status) { color: var(--muted); font-size: 12px; }
.graph-node .ref { color: var(--faint); margin-right: 6px; font-size: 11px; }
.node-activity { color: var(--muted); }
#selected-node { padding: 2px 0; font-family: var(--mono); font-size: 12px; }

/* Console */
.log-panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.log-panel > .panel-head {
  position: sticky; top: 0; z-index: 2; padding: 8px 10px; gap: 6px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0;
}
.log-panel > .panel-head h2 { margin-right: 4px; }
.log-panel > .panel-head button { font-size: 12px; padding: 1px 10px; }
.log-panel > .panel-head label { font-size: 13px; }
.log-find { flex: 1; min-width: 140px; }
#log-find { flex: 1; width: 100%; padding: 2px 8px; }
.log-scope { padding: 6px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--sunken); }
#log-earlier { display: block; margin: 8px auto; font-size: 12px; }
.console-footer { padding: 3px 10px; border-top: 1px solid var(--line); font: 11px/1.5 var(--mono); color: var(--muted); }
.log-rows { width: 100%; font: 12px/1.5 var(--mono); }
.log-row { display: grid; grid-template-columns: 7ch minmax(0,1fr); scroll-margin-top: 56px; }
.log-row:hover { background: var(--hover); }
.log-source {
  grid-column: 1 / -1; padding: 6px 10px 1px; font: 600 11px/1.5 var(--sans); color: var(--o-built);
  border-top: 1px solid var(--line);
}
.log-row:first-child .log-source { border-top: 0; }
.log-row.same .log-source { display: none; }
.log-row time { white-space: nowrap; padding: 0 0 0 10px; color: var(--faint); font-variant-numeric: tabular-nums; }
.log-row pre { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; padding: 0 10px 0 8px; }
.log-panel.nowrap .log-row pre { white-space: pre; overflow-x: auto; overflow-wrap: normal; }
#log-cursor { display: none; }
mark { background: #f1dc8a; color: inherit; border-radius: 2px; }

@media (max-width: 800px) {
  .overview { padding: 12px 14px 20px; }
  h1 { font-size: 19px; }
  .summary-head { display: block; }
  #rail-controls input { width: 14ch; }
  .campaign-table thead tr { display: none; }
  .campaign-table tr {
    display: grid; grid-template-columns: max-content minmax(0,1fr) auto 7ch; align-items: baseline;
    column-gap: 8px; border-bottom: 1px solid var(--line); padding: 5px 0;
  }
  .campaign-table th, .campaign-table td { width: auto !important; border: 0; padding: 0; }
  .campaign-table td.version { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .campaign-table td.duration { text-align: right; font-size: 13px; }
  .campaign-table td.session-observation { grid-column: 1 / -1; font-size: 12px; }
  .campaign-table td.session-observation:empty { display: none; }
  .detail-shell { padding: 8px 10px 20px; }
  .detail-layout { grid-template-columns: minmax(0,1fr); gap: 14px; }
  #state { position: static; max-height: none; overflow: visible; padding: 0; }
  .failure { padding: 8px 10px; }
  .log-panel > .panel-head { padding: 6px 8px; }
  .log-row { grid-template-columns: minmax(0,1fr); }
  .log-row time { display: none; }
  .log-row pre { padding: 0 8px; }
  .log-source { padding: 6px 8px 1px; }
}

/* Campaign list and survey table. */
.brand a { color: inherit; }
.ledger { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 13px; }
.ledger th, .ledger td { padding: 4px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.ledger th {
  position: sticky; top: 0; z-index: 1; background: var(--paper); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-bottom-color: var(--line-strong);
}
.ledger td.num { text-align: right; font-variant-numeric: tabular-nums; }
.ledger td.mono, .ledger td.version { font-family: var(--mono); font-size: 12px; }
.ledger td.pkg-cell { font-weight: 600; overflow-wrap: anywhere; }
.ledger td.pkg-cell a { color: var(--ink); }
.ledger tbody tr:hover { background: var(--hover); }
.ledger .sub { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.ledger .state[data-state="running"] { color: var(--amber); font-weight: 600; }
.ledger .state[data-state="queued"], .ledger .state[data-state="paused"] { color: var(--accent); }
.ledger .state[data-state="historical"] { color: var(--muted); }
.ledger tr[data-state="historical"] td.pkg-cell a { color: var(--muted); }
.survey td.session-observation { font-family: var(--mono); font-size: 12px; }
.status a { color: inherit; }

/* Narrow screens: each ledger row becomes a block, and with no header
   row nothing sticky sits under the phone's status bar. */
@media (max-width: 800px) {
  .ledger, .ledger tbody { display: block; }
  .ledger thead { display: none; }
  .ledger tr { display: grid; column-gap: 10px; row-gap: 2px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .ledger td { display: block; padding: 0; border: 0; min-width: 0; }
  .ledger td:empty { display: none; }
  .ledger td.pkg-cell { overflow-wrap: break-word; }
  .ledger:not(.survey) td.num::before {
    display: block; white-space: nowrap; font-size: 10.5px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  }

  /* Survey: name and version; filcc, then nanofil, each with its time;
     objects; the first error. */
  .survey tr { grid-template-columns: minmax(0,1fr) auto; }
  .survey td:nth-child(1) { grid-area: 1 / 1; }
  .survey td:nth-child(2) { grid-area: 1 / 2; text-align: right; color: var(--muted); }
  .survey td:nth-child(3) { grid-area: 2 / 1; }
  .survey td:nth-child(4) { grid-area: 2 / 2; }
  .survey td:nth-child(5) { grid-area: 3 / 1; }
  .survey td:nth-child(6) { grid-area: 3 / 2; }
  .survey td:nth-child(3)::before { content: "filcc"; }
  .survey td:nth-child(5)::before { content: "nanofil"; }
  .survey td:nth-child(3)::before, .survey td:nth-child(5)::before {
    display: inline-block; width: 66px; font-size: 10.5px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  }
  .survey td.duration { font-size: 12px; }
  .survey td.duration .sub { display: inline; margin-left: 4px; font-size: 11px; }
  .survey td:nth-child(7) { grid-area: 4 / 1 / 5 / -1; font-size: 12px; color: var(--muted); text-align: left; }
  .survey td:nth-child(7)::after { content: " objects"; }
  .survey td:nth-child(8), .survey td:nth-child(9) { display: none; }
  .survey td.session-observation {
    grid-area: 5 / 1 / 6 / -1; margin-top: 2px; font-size: 11.5px; overflow-wrap: anywhere;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
  }
  .survey td.session-observation:empty { display: none; }

  /* Campaign list: id and name; state, kind and revision; options; counts; start and time. */
  .ledger:not(.survey) tr { grid-template-columns: repeat(5, minmax(0,1fr)); }
  .ledger:not(.survey) td:nth-child(1) { grid-column: 1 / -1; }
  .ledger:not(.survey) td:nth-child(5) { grid-row: 2; grid-column: 1 / 3; }
  .ledger:not(.survey) td:nth-child(2) { grid-row: 2; grid-column: 3 / 5; }
  .ledger:not(.survey) td:nth-child(3) { grid-row: 2; grid-column: 5; text-align: right; }
  .ledger:not(.survey) td:nth-child(4) { grid-column: 1 / -1; color: var(--muted); }
  .ledger:not(.survey) td.num { text-align: left; }
  .ledger:not(.survey) td:nth-child(6)::before { content: "roots"; }
  .ledger:not(.survey) td:nth-child(7)::before { content: "ok"; }
  .ledger:not(.survey) td:nth-child(8)::before { content: "failed"; }
  .ledger:not(.survey) td:nth-child(9)::before { content: "timeout"; }
  .ledger:not(.survey) td:nth-child(10)::before { content: "not run"; }
  .ledger:not(.survey) td:nth-child(11) { grid-column: 1 / 4; color: var(--muted); }
  .ledger:not(.survey) td:nth-child(12) { grid-column: 4 / 6; }
  .ledger:not(.survey) .state + .sub { display: inline; margin-left: 6px; }
}
