:root {
  /* Native form widgets — the datetime picker, its calendar popup and the
     spin buttons — are drawn by the browser, not by this stylesheet. Without
     this declaration they are rendered for a light theme, which paints dark
     glyphs onto the dark background and makes the calendar and arrows
     effectively invisible. */
  color-scheme: dark;

  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1d212a;
  --line: #262b36;
  --text: #e6e6e6;
  --muted: #8b93a7;
  --accent: #6ea8fe;
  --ok: #3ecf8e;
  --warn: #ffb84d;
  --err: #ff6b6b;
  --radius: 10px;

  /* Type and rhythm scale fluidly between a phone and a desktop so the
     interface is never a shrunken desktop nor a stretched phone. */
  --fs: clamp(14px, 0.55vw + 12.4px, 15.5px);
  --fs-sm: clamp(12px, 0.3vw + 11.1px, 13px);
  --fs-xs: clamp(11px, 0.2vw + 10.4px, 12px);
  --fs-h1: clamp(20px, 1.5vw + 15.6px, 27px);
  --fs-h2: clamp(13px, 0.4vw + 11.8px, 15px);
  --gap: clamp(10px, 1.1vw + 6.5px, 16px);
  --pad: clamp(16px, 2vw + 9.6px, 28px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs)/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

/* Icons ------------------------------------------------------------------- */

/* Every glyph is a stroked outline that inherits the surrounding colour, so a
   single sprite serves buttons, badges and headings without variants. */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.22em;
}
.i .fill { fill: currentColor; stroke: none; }
h1 .i, h2 .i { vertical-align: -0.14em; margin-right: .4em; opacity: .75; }

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 12px var(--pad);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

header.top .brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: .5px;
  font-size: clamp(15px, 0.5vw + 13.4px, 17px);
  color: var(--text);
  text-decoration: none;
}
header.top .brand:hover { text-decoration: none; opacity: .85; }
header.top .brand .i { stroke-width: 2.1; color: var(--accent); }
header.top .brand b { color: var(--accent); font-weight: 700; }
header.top .meta { color: var(--muted); font-size: var(--fs-xs); }
.top-actions { gap: 8px; }

main { max-width: 1180px; margin: 0 auto; padding: var(--pad); }

h1 { font-size: var(--fs-h1); margin: 0 0 var(--gap); line-height: 1.2; }
h2 {
  display: flex;
  align-items: center;
  font-size: var(--fs-h2);
  margin: calc(var(--gap) * 1.9) 0 var(--gap);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .8px;
}
h3 { font-size: var(--fs); margin: 0 0 8px; }

/* 160px is the narrowest column that keeps the longest phase name on one line
   at every width; below it the grid squeezes a card until "Implementation"
   breaks in half. */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  /* A grid item defaults to min-width:auto, which refuses to shrink below its
     content and pushes the value past the border instead of wrapping it. */
  min-width: 0;
}
/* .n is the card's headline and is sized for a figure. A value that is a word
   rather than a number carries .lead — which must out-specify `.card .n` or it
   is silently dropped, and a phase name like "Implementation" then runs
   straight out of its own card. break-word is the backstop for a value no
   class anticipated, such as a long model name. */
.card .n {
  font-size: 26px; font-weight: 700; line-height: 1.2;
  overflow-wrap: break-word; min-width: 0;
}
.card .n.lead { font-size: clamp(14px, 0.35vw + 12.6px, 16px); line-height: 1.3; }
.card .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .7px; font-weight: 600; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge .i { width: 1em; height: 1em; stroke-width: 2.4; }
.badge.running { color: #0f1115; background: var(--accent); border-color: var(--accent); }
.badge.done    { color: #0f1115; background: var(--ok); border-color: var(--ok); }
.badge.failed, .badge.blocked { color: #0f1115; background: var(--err); border-color: var(--err); }
.badge.stalled { color: #0f1115; background: var(--warn); border-color: var(--warn); }
.badge.queued, .badge.scheduled { color: var(--accent); }
.badge.waiting { color: #0f1115; background: var(--warn); border-color: var(--warn); }
/* Outcomes and statuses nobody judged — interrupted, abandoned, cancelled,
   paused. They must not wear the error colour: the work was never rejected,
   it was never read. `statusBadge` uses the status itself as the class, which
   is why `cancelled` is named here rather than mapped. */
.badge.neutral, .badge.cancelled { color: var(--muted); border-style: dashed; }

/* A native <progress> carries its value in an attribute rather than a style
   attribute, which the content security policy blocks outright. The element
   needs one rule per engine because the fill is a pseudo-element. */
progress.bar {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  border: 0;
  width: 100%;
  min-width: 90px;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--panel-2);
  color: var(--accent);
}
progress.bar::-webkit-progress-bar { background: var(--panel-2); border-radius: 999px; }
progress.bar::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress.bar::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
progress.bar.credits { color: var(--warn); }
progress.bar.credits::-webkit-progress-value { background: var(--warn); }
progress.bar.credits::-moz-progress-bar { background: var(--warn); }

.timeline { display: grid; gap: 6px; }
.step {
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}
.step .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.step.done .dot { background: var(--ok); }
.step.running .dot { background: var(--accent); }
.step.current .dot { background: var(--warn); }
.step.skipped { opacity: .45; }
.step .t { color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }

/* A phase that produced output is a disclosure: the summary is the timeline
   row it always was, and expanding it reveals the runs instead of sending the
   operator to a second table that repeated the same rows in full. */
details.step { display: block; padding: 0; }
details.step > summary {
  display: grid;
  grid-template-columns: 22px 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 9px 12px;
  cursor: pointer;
  list-style: none;
  border-radius: 8px;
}
details.step > summary::-webkit-details-marker { display: none; }
details.step > summary:hover { background: var(--panel); }
details.step > summary::after {
  content: "▸";
  color: var(--muted);
  font-size: 12px;
  grid-column: 1;
  grid-row: 1;
  justify-self: center;
  margin-left: 14px;
}
details.step[open] > summary::after { content: "▾"; }
details.step > summary .dot { grid-column: 1; grid-row: 1; }
details.step > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
details.step[open] > summary { border-bottom: 1px solid var(--line); border-radius: 8px 8px 0 0; }

.runs { display: grid; gap: 10px; padding: 12px; }
.run { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--panel); }
.run-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.run-head .t { color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.run-outcome { margin: 8px 0 0; font-size: var(--fs-sm); }
.run pre.log { margin-top: 8px; max-height: 240px; }
.run pre.log.gate { border-color: var(--err); }

form.stack { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .6px; }
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}
textarea { min-height: 150px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }

/* The calendar button is the whole point of a datetime input. color-scheme
   above already makes the browser draw it light-on-dark; this only widens the
   hit area and adds a hover affordance, because tinting it further flattens
   the glyph into a featureless block. */
input.picker { padding-right: 6px; }
input.picker::-webkit-calendar-picker-indicator {
  cursor: pointer;
  padding: 4px 6px;
  margin-left: 4px;
  border-radius: 6px;
}
input.picker::-webkit-calendar-picker-indicator:hover { background: var(--panel-2); }

.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #0f1115;
  font-weight: 600;
  font-size: var(--fs-sm);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: filter .12s ease, border-color .12s ease, background-color .12s ease;
}
button:hover, .btn:hover { filter: brightness(1.09); text-decoration: none; }
button:active, .btn:active { filter: brightness(.94); }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button[disabled], .btn[disabled] { opacity: .45; cursor: not-allowed; filter: none; }

button.ghost, .btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover, .btn.ghost:hover { background: var(--panel-2); border-color: var(--accent); filter: none; }
button.danger, .btn.danger { background: var(--err); border-color: var(--err); color: #0f1115; }
button.small, .btn.small { padding: 6px 11px; min-height: 32px; font-size: var(--fs-xs); }
button.icon-only, .btn.icon-only { padding: 6px 9px; }
button.icon-only .i, .btn.icon-only .i { width: 1.25em; height: 1.25em; }

.flash, .error {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: var(--gap);
  font-size: var(--fs-sm);
}
.flash { background: rgba(62, 207, 142, .12); border: 1px solid var(--ok); color: var(--ok); }
.error { background: rgba(255, 107, 107, .12); border: 1px solid var(--err); color: var(--err); }

pre.log {
  margin: 0;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c8cede;
  max-height: 320px;
  overflow: auto;
}

.events { display: grid; gap: 4px; font-size: 12px; }
.events .ev { display: grid; grid-template-columns: 130px 160px 1fr; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }

/* Event kinds are dotted names that grew past the original column: without a
   clamp they overlap the message instead of wrapping. */
.events .ev > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.events .ev .ts { color: var(--muted); font-variant-numeric: tabular-nums; }
.events .ev.warn .msg { color: var(--warn); }
.events .ev.error .msg { color: var(--err); }

/* The dashboard interleaves missions running in parallel, so its feed carries
   an extra column naming the mission each line belongs to. A stable tint per
   mission lets the eye separate the streams without reading every label. */
.events.by-mission .ev { grid-template-columns: 130px 150px 150px 1fr; }
.events .who a.tint { text-decoration: none; font-weight: 600; }
.events .who a.tint:hover { text-decoration: underline; }
.tint.t0 { color: #6ea8fe; }
.tint.t1 { color: #3ecf8e; }
.tint.t2 { color: #ffb84d; }
.tint.t3 { color: #d9a2ff; }
.tint.t4 { color: #5ad0d0; }
.tint.t5 { color: #ff9ec4; }

.muted { color: var(--muted); }
.empty { padding: 22px; text-align: center; color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.login {
  max-width: 380px;
  margin: 12vh auto;
  text-align: center;
}
.login .panel { padding: 32px 28px; }
.login .provider { display: block; margin-top: 10px; }

/* Phase strip on the output page. The page follows a mission across phases on
   its own, so it has to say which one is on screen and what is still ahead. */
.steps {
  display: flex; flex-wrap: wrap; gap: .35rem;
  list-style: none; margin: 0 0 var(--gap); padding: 0;
}
.steps li {
  font-size: var(--fs-xs); border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
  padding: .2rem .55rem;
}
/* A step that has produced output is a link to it, so the whole pill has to be
   the target — not just the few pixels the text covers. The anchor is pulled
   back over the padding the li already reserves. */
.steps li a {
  color: inherit; display: block; border-radius: 999px;
  margin: -.2rem -.55rem; padding: .2rem .55rem;
}
/* The pill already lights up on hover, so the global underline only makes the
   label look like it broke out of its border. */
.steps li a:hover, .steps li a:focus-visible { background: var(--panel-2); text-decoration: none; }
.steps li.was a:hover, .steps li.was a:focus-visible {
  background: color-mix(in srgb, var(--ok) 16%, transparent);
}
.steps .tries { opacity: .7; font-variant-numeric: tabular-nums; }
.steps li.was  { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.steps li.now  { color: #0f1115; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.steps li.skip { opacity: .45; text-decoration: line-through; }

@media (max-width: 720px) {
  /* Narrow screens drop the phases that are still ahead, but never one that
     already produced output the operator can open. */
  .steps li:not(.now):not(.was):not(.has-log) { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .events .ev { grid-template-columns: 1fr; }
  .events.by-mission .ev { grid-template-columns: 1fr; }
  .events .ev > span { white-space: normal; }

  /* A wide table cannot be reflowed without losing the row-to-row comparison
     that makes it worth reading, so it scrolls sideways inside its panel
     instead of overflowing the viewport. */
  .panel > table { display: block; overflow-x: auto; font-size: var(--fs-sm); }
  th, td { padding: 9px 10px; }

  header.top { padding: 10px 14px; }
  header.top .brand-name { font-size: 15px; }
  .top-actions .meta { display: none; }

  /* Fingers need a larger target than a pointer does. */
  button, .btn { min-height: 42px; padding: 10px 15px; }
  button.small, .btn.small { min-height: 36px; }
  .step { grid-template-columns: 16px 1fr auto; }
  .step .t:last-child { grid-column: 2 / -1; }
  details.step > summary { grid-template-columns: 16px 1fr auto; }
  details.step > summary .t:last-child { grid-column: 2 / -1; }
  details.step > summary::after { margin-left: 8px; }
}

/* Utilities --------------------------------------------------------------- */

/* The content security policy forbids inline style attributes, so every
   one-off spacing decision has to be a class or it is silently dropped by the
   browser and the page loses its rhythm. */
.pad { padding: 14px; }
.pad-lg { padding: var(--pad); }
.mt-0 { margin-top: 0; }
.mt { margin-top: 10px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb { margin-bottom: 6px; }
.mb-md { margin-bottom: 12px; }
.m-0 { margin: 0; }
.tight { margin: -8px 0 4px; }
.lead { font-size: clamp(15px, 0.6vw + 13.2px, 18px); }
.small { font-size: var(--fs-sm); }
.inline { display: inline-flex; }
.baseline { align-items: baseline; }
.wrap { flex-wrap: wrap; }

/* Mission controls -------------------------------------------------------- */

fieldset.group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px 14px;
  margin: 0;
  min-width: 0;
}
fieldset.group > legend {
  padding: 0 6px;
  font-size: var(--fs-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}

.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--fs-sm);
  color: var(--text);
  margin-bottom: 0;
}
.check:hover { border-color: var(--accent); }
.check input { width: auto; margin: 0; flex: none; accent-color: var(--accent); }
.check .why { color: var(--muted); font-size: var(--fs-xs); }

.danger-hint {
  margin: 8px 0 0;
  padding: 9px 11px;
  border: 1px solid var(--warn);
  border-radius: 8px;
  background: rgba(255, 184, 77, .1);
  color: var(--warn);
  font-size: var(--fs-xs);
}

td.actions { white-space: nowrap; }
td.when { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Operator request -------------------------------------------------------- */

/* The panel is deliberately loud: a parked mission burns wall-clock time until
   somebody notices it, so it must be impossible to scroll past. */
.ask {
  padding: 16px;
  border-color: var(--warn);
  box-shadow: 0 0 0 1px rgba(230, 168, 61, .25);
}
.ask-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.ask-form { margin-top: 12px; }
.ask-form label { display: block; margin-bottom: 6px; }
.ask-form button { margin-top: 12px; }
.ask-form .row button { margin-top: 0; }

.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.choice:hover { border-color: var(--accent); }
.choice input { width: auto; margin: 0; }

/* Options are written by the agent and can be whole sentences, so the global
   uppercase treatment for labels would make them unreadable. */
.choice, .choice span {
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 0;
}

/* Live output ------------------------------------------------------------- */

/* column-reverse pins the scroll position to the bottom on every load, which
   is what makes a meta-refresh tail behave like `tail -f` without any script.
   The <pre> inside keeps the text in its natural order. */
.stream-box {
  display: flex;
  flex-direction: column-reverse;
  max-height: 68vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0d12;
  padding: 12px;
}
.stream-box .log {
  margin: 0;
  background: none;
  border: 0;
  padding: 0;
  white-space: pre-wrap;
  word-break: break-word;

  /* pre.log caps itself at 320px and scrolls; inside the stream box that
     clips the tail and hands scrolling to the wrong element, so the outer box
     must own both. flex-shrink stops flex layout compressing it. */
  max-height: none;
  overflow: visible;
  flex-shrink: 0;
}
