/* style.css — The stylesheet of the pumphouse's pages */

/*
 * Four colours only: background, text, red and green, named once
 * below and used everywhere else through their names; the text colour
 * draws every line and the background fills every shape.  They are
 * white and black; in the dark scheme the background is a grey light
 * enough to read by with near-white text, and red and green are
 * lightened to keep their contrast, since on a dark ground a colour
 * gains contrast by getting lighter, not by the ground getting
 * lighter.  The header is on the background under a text-coloured
 * rule in the light scheme and black in the dark one; the output pane
 * is black with white text in both.  The dark scheme is the system's preference unless the reader has chosen
 * one with the button the theme script adds, which sets data-theme on
 * the root.
 *
 * Red and green are the pair colour-blind readers most often cannot
 * tell apart, so nothing is said by colour alone: every status also
 * has a line rhythm, a weight, a mark and its word.  Solid lines went
 * to plan, dashed ones did not or might not, dotted ones are context
 * rather than work.  Marks are ✓ for ended well, ✗ for ended badly,
 * ⋯ for under way, – for skipped and ! for needing attention.  Where
 * two colours share a line the second is the background for a step's
 * own failure and the text colour for one imposed on it.  Red and
 * green meet only the background, where both pass the contrast ratio
 * for text; on black there is only white.
 */

:root {
  --night: #000;
  --day: #fff;
  --background: var(--day);
  --text: var(--night);
  --header: var(--background);
  --red: #c00;
  --green: #070;
  color-scheme: light dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: #2a2a2a;
    --text: #eee;
    --header: var(--night);
    --red: #f66;
    --green: #4c4;
  }
}

:root[data-theme="dark"] {
  --background: #2a2a2a;
  --text: #eee;
  --header: var(--night);
  --red: #f66;
  --green: #4c4;
  color-scheme: dark;
}

/*
 * The page
 */

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  line-height: 1.4;
  color: var(--text);
  background: var(--background);
}

header {
  background: var(--header);
  color: var(--text);
  border-bottom: 2px solid var(--text);
  padding: 0.6rem 1rem;
}

header nav {
  display: flex;
  align-items: center;
}

header a {
  color: var(--text);
  text-decoration: none;
  margin-right: 1rem;
}

header a:hover {
  text-decoration: underline;
}

/* The theme button, added by the theme script; pressed means dark */

button.theme {
  margin-left: auto;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.1rem 0.6rem;
  background: none;
  color: var(--text);
  border: 1px solid var(--text);
  border-radius: 4px;
  cursor: pointer;
}

button.theme[aria-pressed="true"] {
  background: var(--text);
  color: var(--background);
}

main {
  padding: 1rem;
  max-width: 1200px;
}

h1 {
    margin-top: 0;
}

h1, h2 {
  font-weight: 600;
}

a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

::selection {
  background: var(--text);
  color: var(--background);
}

table {
  border-collapse: collapse;
  margin-bottom: 1rem;
}

th, td {
  text-align: left;
  padding: 0.3rem 0.6rem;
  vertical-align: top;
  border-bottom: 1px dotted var(--text);
}

th {
  font-weight: 600;
  border-bottom: 2px solid var(--text);
}

/* The front page: a section per prefix of the pipelines' names, the
   prefix heading it in the monospace of the names, and a section per
   pipeline beneath, drawn steps only with its runs. */

.pipelines h2 {
  font-family: ui-monospace, monospace;
  font-size: 1.1rem;
  margin: 2rem 0 0.5rem;
}

.pipeline h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1.5rem 0 0;
}

.pipeline .diagram {
  margin: 0.5rem 0;
}

table.runs td {
  padding: 0.2rem 1rem 0.2rem 0;
  border-bottom: none;
  white-space: nowrap;
}

table.runs td:last-child {
  white-space: normal;
}

code, pre {
  font-family: ui-monospace, monospace;
}

dl {
  display: grid;
  grid-template-columns: max-content auto;
  gap: 0.2rem 1rem;
}

dt {
  font-weight: 600;
}

dd {
  margin: 0;
}

ol.events {
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
}

pre.output {
  background: var(--night);
  color: var(--day);
  padding: 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  min-height: 4rem;
}

.orientation a {
  margin-right: 0.6rem;
}

.orientation a[aria-current] {
  font-weight: 600;
  text-decoration: none;
  border-bottom: 3px solid var(--text);
}

/*
 * Statuses, outcomes and attachment states in text
 *
 * The word is always there; the mark before it and the underline
 * repeat it.  Two-colour underlines are tiled gradients, since
 * text-decoration has one colour.
 */

span[data-status],
span[data-outcome],
span[data-state] {
  font-weight: 600;
  white-space: nowrap;
}

/* Ended well: green, ✓ */

span:is([data-status="succeeded"],
        [data-outcome="succeeded"],
        [data-state="live"]) {
  color: var(--green);
}

span:is([data-status="succeeded"],
        [data-outcome="succeeded"],
        [data-state="live"])::before {
  content: "✓\00a0";
}

/* Ended badly: red, ✗; its own failure dashed red and background,
   one imposed on it dashed red and text */

span:is([data-status="errored"],
        [data-outcome="errored"],
        [data-status="abandoned"],
        [data-outcome="abandoned"]) {
  color: var(--red);
}

span:is([data-status="errored"],
        [data-outcome="errored"],
        [data-status="abandoned"],
        [data-outcome="abandoned"])::before {
  content: "✗\00a0";
}

span:is([data-status="errored"],
        [data-outcome="errored"]) {
  padding-bottom: 2px;
  background: repeating-linear-gradient(90deg,
                                        var(--red) 0 6px,
                                        var(--background) 6px 12px)
              bottom / 12px 3px repeat-x;
}

span:is([data-status="abandoned"],
        [data-outcome="abandoned"],
        [data-state="stale"]) {
  padding-bottom: 2px;
  background: repeating-linear-gradient(90deg,
                                        var(--red) 0 6px,
                                        var(--text) 6px 12px)
              bottom / 12px 3px repeat-x;
}

/* Needing attention: red, ! */

span[data-state="stale"] {
  color: var(--red);
}

span[data-state="stale"]::before {
  content: "!\00a0";
}

/* Under way: text and background dashes creeping along, ⋯ */

span:is([data-status="running"],
        [data-outcome="running"],
        [data-state="attached"]) {
  padding-bottom: 2px;
  background: repeating-linear-gradient(90deg,
                                        var(--text) 0 6px,
                                        var(--background) 6px 12px)
              bottom / 12px 3px repeat-x;
  animation: creep 1s linear infinite;
}

span:is([data-status="running"],
        [data-outcome="running"],
        [data-state="attached"])::before {
  content: "⋯\00a0";
}

/* Waiting to start: the same dashes, still, ⋯ */

span[data-outcome="requested"] {
  padding-bottom: 2px;
  background: repeating-linear-gradient(90deg,
                                        var(--text) 0 6px,
                                        var(--background) 6px 12px)
              bottom / 12px 3px repeat-x;
}

span[data-outcome="requested"]::before {
  content: "⋯\00a0";
}

/* Skipped: struck through, – */

span[data-status="skipped"] {
  font-weight: normal;
  text-decoration: line-through;
}

span[data-status="skipped"]::before {
  content: "–\00a0";
}

/* Not yet, or not at all: plain */

span[data-status="pending"],
span[data-status="none"],
span[data-state="detached"] {
  font-weight: normal;
}

/*
 * The diagram
 *
 * A node is a frame, a trim over it for a second colour, its label,
 * and a mark on its corner shown by status.
 */

.diagram {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1rem 0;
  overflow: visible;
}

.diagram text {
  font-size: 13px;
  fill: var(--text);
}

/* Nodes */

.diagram .node rect {
  fill: var(--background);
  stroke: var(--text);
  stroke-width: 1.5;
}

.diagram .node rect.trim {
  fill: none;
  stroke: none;
}

.diagram .node.resource rect.frame,
.diagram .node.param rect.frame {
  stroke-dasharray: 1 3;
  stroke-linecap: round;
}

.diagram a text {
  text-decoration: underline;
}

.diagram a:hover text {
  font-weight: 600;
}

/* Nodes by status */

.diagram .node[data-status="running"] rect.frame {
  stroke-width: 3;
  stroke-dasharray: 6 4;
  animation: march 1s linear infinite;
}

.diagram .node[data-status="succeeded"] rect.frame {
  stroke: var(--green);
  stroke-width: 3;
}

.diagram .node[data-status="errored"] rect.frame {
  stroke: var(--red);
  stroke-width: 3;
}

.diagram .node[data-status="errored"] rect.trim {
  stroke: var(--background);
  stroke-width: 3.5;
  stroke-dasharray: 6 6;
}

.diagram .node[data-status="abandoned"] rect.frame {
  stroke-width: 3;
}

.diagram .node[data-status="abandoned"] rect.trim {
  stroke: var(--red);
  stroke-width: 3;
  stroke-dasharray: 6 6;
}

.diagram .node[data-status="skipped"] rect.frame {
  stroke-dasharray: 5;
}

.diagram .node[data-status="skipped"] .label {
  text-decoration: line-through;
}

/* Marks: every status's glyph is in each mark, and the status shows
   its own */

.diagram .mark {
  display: none;
  color: var(--text);
}

.diagram .mark circle {
  fill: var(--background);
  stroke: currentColor;
  stroke-width: 1.5;
}

.diagram .mark text {
  font-size: 13px;
  font-weight: 700;
  fill: currentColor;
  text-decoration: none;
}

.diagram .mark tspan {
  display: none;
}

.diagram .node:is([data-status="running"],
                  [data-status="succeeded"],
                  [data-status="errored"],
                  [data-status="abandoned"],
                  [data-status="skipped"]) .mark {
  display: inline;
}

.diagram .node[data-status="succeeded"] .mark {
  color: var(--green);
}

.diagram .node[data-status="errored"] .mark,
.diagram .node[data-status="abandoned"] .mark {
  color: var(--red);
}

.diagram .node[data-status="running"] .mark tspan.running,
.diagram .node[data-status="succeeded"] .mark tspan.succeeded,
.diagram .node[data-status="errored"] .mark tspan.errored,
.diagram .node[data-status="abandoned"] .mark tspan.abandoned,
.diagram .node[data-status="skipped"] .mark tspan.skipped {
  display: inline;
}

/* Edges */

.diagram .edge path {
  fill: none;
  stroke: var(--text);
  stroke-width: 1.5;
  marker-end: url(#arrow);
}

.diagram .edge.optional path {
  stroke-dasharray: 5;
}

.diagram .edge.error path {
  stroke: var(--red);
  stroke-width: 2.5;
  marker-end: url(#arrow-error);
}

.diagram .edge-label {
  font-size: 11px;
}

.diagram .edge.error .edge-label {
  fill: var(--red);
  font-weight: 600;
}

.diagram marker path {
  fill: var(--text);
}

.diagram marker#arrow-error path {
  fill: var(--red);
}

/* Groups */

.diagram .group rect {
  fill: none;
  stroke: var(--text);
  stroke-width: 1;
  stroke-dasharray: 1 3;
  stroke-linecap: round;
}

.diagram .group-label {
  font-size: 11px;
}

/*
 * Motion
 *
 * Dashes march along whatever is under way, unless the reader has
 * asked for less of it; the mark says the same without.
 */

@keyframes march {
  to { stroke-dashoffset: -20; }
}

@keyframes creep {
  to { background-position: 12px bottom; }
}

@media (prefers-reduced-motion: reduce) {
  .diagram .node[data-status="running"] rect.frame,
  span[data-status="running"],
  span[data-outcome="running"],
  span[data-state="attached"] {
    animation: none;
  }
}
