/* gym — pipeline console
 *
 * The look is a lab instrument readout rather than a dashboard: monospace is the
 * display face, because every primary datum on every page is an identifier, a
 * score, a token count or a cost. Prose gets the system UI face and stays out of
 * the way.
 *
 * Two accents, and they mean something rather than decorate: teal is clinical,
 * magenta is communication. Those are the pipeline's two independent score axes,
 * which the stage-1 rubric says are meant to disagree, so anywhere the two appear
 * together they keep these colours.
 *
 * No web fonts and no external anything: this runs on localhost, often on a
 * machine that is offline, and a stylesheet that reaches for a CDN is a console
 * that renders wrong exactly when you need it.
 */

:root {
  --paper: #e9edf0;
  --card: #ffffff;
  --card-sunk: #f4f6f8;
  --ink: #0f1518;
  --ink-soft: #3b4a52;
  --muted: #64757e;
  --rule: #d0d9de;
  --rule-strong: #b3c0c7;

  --clinical: #0f6a5f;
  --comms: #97276a;
  --alert: #a8261f;
  --ok: #1f6b3a;
  --pending: #8a6a12;

  /* Text sitting on a filled accent. The accents lighten in dark mode to stay
   * legible on a dark surface, at which point white text on them fails contrast
   * — so the foreground has to flip with them rather than being hardcoded. */
  --on-accent: #ffffff;

  /* Let checkboxes, radios and the select arrow follow the theme; without it
   * they stay light-mode white on a dark page. */
  color-scheme: light dark;

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

  --rail: 232px;
  --pad: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d1215;
    --card: #151d21;
    --card-sunk: #101619;
    --ink: #e6edf0;
    --ink-soft: #b3c2c9;
    --muted: #7e919a;
    --rule: #263238;
    --rule-strong: #35464e;

    --clinical: #4bc4b0;
    --comms: #e07ab5;
    --alert: #ef7b72;
    --ok: #5fc287;
    --pending: #d8b24a;
    --on-accent: #08110f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

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

.shell { display: flex; min-height: 100vh; }

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--card);
  border-right: 1px solid var(--rule);
  padding: var(--pad) 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 0 var(--pad) 4px;
  text-decoration: none;
  display: block;
}

.brand-sub {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
  padding: 0 var(--pad) 18px;
}

.rail-group { padding: 12px 0 4px; }

.rail-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 var(--pad) 6px;
}

.rail a.nav {
  display: block;
  padding: 5px var(--pad);
  text-decoration: none;
  color: var(--ink-soft);
  border-left: 2px solid transparent;
}

.rail a.nav:hover { background: var(--card-sunk); color: var(--ink); }

.rail a.nav.on {
  border-left-color: var(--clinical);
  color: var(--ink);
  font-weight: 600;
  background: var(--card-sunk);
}

.main { flex: 1; min-width: 0; padding: var(--pad) 28px 64px; }

/* --------------------------------------------------------------- header -- */

.topbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 22px;
}

h1 {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
}

.crumb {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.spacer { flex: 1; }

.stamp {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- cards -- */

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.card > h2, .card-head > h2 {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 12px;
  font-weight: 600;
}

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* ------------------------------------------------------- the stage ladder --
 * The signature. Stages read left to right; the queue between two stages sits
 * in the connector, because that queue is the work and it belongs between the
 * things it is between. Each gap is a link into the filtered article list.
 */

.ladder {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  gap: 0;
  padding-bottom: 4px;
}

.rung {
  flex: 0 0 auto;
  min-width: 104px;
  padding-right: 8px;
}

.rung-n {
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.rung-l {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}

.link {
  flex: 1 1 64px;
  min-width: 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 6px 14px;
  text-decoration: none;
}

.link-rule {
  width: 100%;
  height: 1px;
  background: var(--rule-strong);
  position: relative;
}

.link-rule::after {
  content: "";
  position: absolute;
  right: 0;
  top: -3px;
  border-left: 5px solid var(--rule-strong);
  border-top: 3.5px solid transparent;
  border-bottom: 3.5px solid transparent;
}

.link-gap {
  font-family: var(--mono);
  font-size: 11px;
  margin-top: 5px;
  color: var(--muted);
  white-space: nowrap;
  border-bottom: 1px dotted transparent;
}

.link.has-gap .link-gap { color: var(--comms); font-weight: 600; }
/* A queue only a person can clear. Coloured apart from the others because it is
   the one number on the ladder that no scheduled run will bring down. */
.link.has-gap.human .link-gap { color: var(--pending); }
.link:hover .link-gap { border-bottom-color: currentColor; }

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

table { width: 100%; border-collapse: collapse; }

th {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  font-weight: 600;
  padding: 0 10px 7px 0;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

td {
  padding: 7px 10px 7px 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--card-sunk); }

.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { text-align: right; }
.wrap-title { max-width: 46ch; }

/* --------------------------------------------------------------- scores -- */

.score {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.score.clinical { color: var(--clinical); }
.score.comms { color: var(--comms); }
.score.none { color: var(--muted); font-weight: 400; }

/* The dual-axis chip: the two numbers the rubric keeps independent, kept
 * visually independent too. */
.axes { display: inline-flex; gap: 7px; align-items: baseline; }
.axes .sep { color: var(--rule-strong); }

.bar {
  display: block;
  height: 4px;
  background: var(--card-sunk);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 3px;
}
.bar span { display: block; height: 100%; }
.bar.clinical span { background: var(--clinical); }
.bar.comms span { background: var(--comms); }

/* ----------------------------------------------------------------- tags -- */

.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 1px 6px;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.tag.on { border-color: var(--clinical); color: var(--clinical); }
.tag.warn { border-color: var(--alert); color: var(--alert); }
.tag.soft { color: var(--muted); }

.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: baseline;
  background: var(--muted);
}
.dot.running { background: var(--pending); animation: pulse 1.1s ease-in-out infinite; }
.dot.queued { background: var(--muted); }
.dot.succeeded { background: var(--ok); }
.dot.failed { background: var(--alert); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

@media (prefers-reduced-motion: reduce) {
  .dot.running { animation: none; }
  * { scroll-behavior: auto !important; }
}

/* ---------------------------------------------------------------- forms -- */

form.stack { display: grid; gap: 15px; max-width: 620px; }

.field label.lbl {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

input[type="text"], input[type="number"], input[type="password"], textarea, select {
  width: 100%;
  font-family: var(--mono);
  font-size: 13px;
  padding: 7px 9px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
}

textarea { min-height: 74px; resize: vertical; }

input:focus-visible, textarea:focus-visible, select:focus-visible,
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--clinical);
  outline-offset: 2px;
}

.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 12.5px;
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

button, .btn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 8px 15px;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button:hover, .btn:hover { border-color: var(--ink-soft); }

button.go, .btn.go {
  background: var(--clinical);
  border-color: var(--clinical);
  color: var(--on-accent);
}
button.go:hover, .btn.go:hover { filter: brightness(1.1); }

button.danger, .btn.danger {
  background: var(--alert);
  border-color: var(--alert);
  color: var(--on-accent);
}
button.danger:hover { filter: brightness(1.1); }

button.link-btn {
  background: none; border: 0; padding: 0; text-transform: none;
  letter-spacing: 0; color: var(--muted); font-size: 12px;
  text-decoration: underline; cursor: pointer;
}

/* -------------------------------------------------------------- settings -- */

/* One row of tabs across the top of the settings page. Scrolls sideways rather
 * than wrapping to a second row: nine tabs on a narrow window would otherwise
 * reflow into a block that pushes the form below the fold, and a tab strip that
 * changes height as you resize stops reading as a strip. */
.tabs {
  display: flex;
  gap: 2px;
  margin: 0 0 20px;
  border-bottom: 1px solid var(--rule);
  overflow-x: auto;
  scrollbar-width: thin;
}

.tabs .tab {
  flex: none;
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}

.tabs .tab:hover { color: var(--ink); background: var(--card-sunk); }

.tabs .tab.on {
  color: var(--ink);
  border-bottom-color: var(--clinical);
  font-weight: 600;
}

/* Two columns where there is room. A settings group is a list of short controls
 * with long explanations under them, and one column of those on a wide screen is
 * a very tall page with most of it empty. */
.settings {
  display: grid;
  gap: 22px 28px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  align-items: start;
}

.setting { min-width: 0; }

.setting-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.setting-head .lbl { margin-bottom: 0; }

/* The provenance badge, and the pointer at the code that reads the value. Both
 * are deliberately quiet: they answer a question you only ask sometimes, and a
 * page where every field shouts its own metadata is a page nobody reads. */
.setting-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: center;
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.setting-foot .path { font-size: 11px; opacity: 0.75; }
.setting-foot .stamp { font-size: 11.5px; }
.setting-foot .check.reset { font-size: 11.5px; color: var(--alert); }

/* A unit that belongs to the number rather than to the label: "s" after a
 * timeout box says which of seconds and minutes the box is in, which is not
 * guessable and has been guessed wrong. */
.with-unit { display: flex; align-items: center; gap: 8px; }
.with-unit input { flex: 1; min-width: 0; }
.with-unit .unit { color: var(--muted); font-size: 11.5px; white-space: nowrap; }

.hint.caution { color: var(--alert); }

.difflist { margin: 8px 0 0; padding-left: 18px; }
.difflist li { font-size: 12.5px; }

.notice.ok-note { border-left-color: var(--ok); }

/* --------------------------------------------------------------- notice -- */

.notice {
  border-left: 3px solid var(--rule-strong);
  background: var(--card-sunk);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
}
.notice.warn { border-left-color: var(--alert); }
.notice.cost { border-left-color: var(--comms); }
.notice strong { font-family: var(--mono); }

/* A card whose heading shares its line with a control. The `h2` stays a direct
 * child of this row rather than of the card, which is why the rule above names
 * both parents. */
.card-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head > h2 { margin-bottom: 0; }
.card-head .spacer { flex: 1; }

/* ------------------------------------------------------------- terminal -- */

/* The Output pane's level filter. `select` is width:100% everywhere else, which
 * is right for a form field and wrong for a control sitting on a heading. */
.loglevel {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.loglevel select {
  width: auto;
  font-size: 12px;
  padding: 3px 6px;
  letter-spacing: normal;
  text-transform: none;
}

/* Says what the filter is holding back. A pane that has quietly dropped half a
 * run should never look like a run that was quiet. */
.log-note {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
}
.log-note:empty { display: none; }

.term {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  background: var(--card-sunk);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 12px 14px;
  max-height: 62vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.cmdline {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--card-sunk);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--clinical);
  border-radius: 2px;
  padding: 10px 13px;
  overflow-x: auto;
  white-space: pre;
  margin: 0 0 14px;
}

/* ---------------------------------------------------------------- misc  -- */

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { min-width: 130px; }
.filters .field.grow { flex: 1; min-width: 200px; }

.pager { display: flex; gap: 10px; align-items: center; margin-top: 14px; }

.kv { display: grid; grid-template-columns: minmax(130px, auto) 1fr; gap: 4px 18px; }
.kv dt {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted); padding-top: 2px;
}
.kv dd { margin: 0; }

.empty { color: var(--muted); padding: 10px 0; }

.oplist { display: grid; gap: 2px; }
.oprow {
  display: flex; align-items: baseline; gap: 12px;
  padding: 9px 11px; text-decoration: none;
  border: 1px solid transparent; border-radius: 2px;
}
.oprow:hover { background: var(--card-sunk); border-color: var(--rule); }
.oprow .t { font-family: var(--mono); font-weight: 600; min-width: 148px; }
.oprow .d { color: var(--muted); font-size: 13px; }

@media (max-width: 880px) {
  .shell { flex-direction: column; }
  .rail {
    width: 100%; flex: none; height: auto; position: static;
    border-right: 0; border-bottom: 1px solid var(--rule);
  }
  .main { padding: 16px; }
  .wrap-title { max-width: none; }
}
