/* The Merge Train panel (web/merge-train.mjs). Colours and sizes are the
   control room's own tokens from styles.css; nothing here names a colour. */

/* Its own height, always whole: the scene, its line, the bar, two buttons and
   the last three runs. A rail block left to shrink is squeezed to its border
   by the panels around it, which each hold a minimum. */
#rail-train { flex: 0 0 auto; }
#train-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3) var(--sp-3);
  overflow: visible;
}

/* ---- the scene: sky, train, track ---------------------------------------- */

.train-scene {
  position: relative;
  height: 92px;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: linear-gradient(to bottom, var(--surface-inset) 0%, var(--surface-inset) 62%, var(--accent-wash) 100%);
  overflow: hidden;
}

.train-rail {
  position: absolute;
  inset: 0 6px 13px 8px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 2px;
}

/* Two rails and the sleepers between them. While a run is under way the
   sleepers run backwards under the train, which is what makes it move. */
.train-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 5px;
  height: 8px;
  border-top: 2px solid var(--ink-faint);
  background-image: repeating-linear-gradient(to right, var(--edge) 0 3px, transparent 3px 14px);
  background-size: 14px 100%;
  opacity: 0.9;
}

.train-cars {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-start;
  align-items: flex-end;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 3px 0 0;
  padding: 0;
  list-style: none;
}

/* A wagon: a box on a flat bed, a coupling to the one ahead, two wheels. */
.train-car {
  position: relative;
  flex: 1 1 0;
  max-width: 44px;
  min-width: 0;
  height: 23px;
  margin-bottom: 8px;
  border: 1px solid var(--accent-line-hot);
  border-bottom-width: 3px;
  border-radius: 4px 4px 2px 2px;
  background: var(--accent-tint);
  color: var(--ink);
  transition: background-color 0.3s ease, border-color 0.3s ease, opacity 0.3s ease;
}
.train-car-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 19px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}
.train-car::before {
  /* The coupling to whatever is ahead (to the right). */
  content: '';
  position: absolute;
  right: -6px;
  bottom: 0;
  width: 6px;
  height: 2px;
  background: var(--ink-faint);
}
.train-car::after {
  /* Both wheels, as one strip with two discs. */
  content: '';
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: -10px;
  height: 7px;
  background:
    radial-gradient(circle at 3.5px 3.5px, var(--ink-dim) 0 3.2px, transparent 3.5px),
    radial-gradient(circle at calc(100% - 3.5px) 3.5px, var(--ink-dim) 0 3.2px, transparent 3.5px);
}
.train-car.is-empty { border-style: dashed; border-color: var(--edge); background: transparent; opacity: 0.55; }
.train-car.is-empty::before,
.train-car.is-empty::after { opacity: 0.35; }
.train-car.is-riding { background: var(--teal); border-color: var(--teal-hot); color: var(--on-accent); }

.train-engine { flex: 0 0 auto; width: 92px; height: 69px; margin-bottom: -2px; overflow: visible; }
.train-paint { fill: var(--teal); }
.train-metal { fill: var(--ink-dim); }
.train-band { fill: var(--on-accent); opacity: 0.28; }
.train-window { fill: var(--surface-inset); stroke: var(--on-accent); stroke-opacity: 0.35; stroke-width: 1; }
.train-lamp { fill: var(--ink-faint); }
.train-tyre { fill: var(--surface-inset); stroke: var(--ink-dim); stroke-width: 2.2; }
.train-spoke { stroke: var(--ink-dim); stroke-width: 1.2; }
.train-hub { fill: var(--ink-dim); }
.train-rod { fill: var(--ink); opacity: 0.85; }
.train-wheel { transform-box: fill-box; transform-origin: center; }
.train-rod { transform-box: fill-box; transform-origin: center; }
.train-puff { fill: var(--ink-dim); opacity: 0; transform-box: fill-box; transform-origin: center; }

/* Nobody aboard: the engine is cold. */
[data-train='empty'] .train-paint,
[data-train='off'] .train-paint { fill: var(--ink-faint); }
[data-train='empty'] .train-engine { opacity: 0.7; }
/* Switched off for this project: the whole scene stands dim. */
[data-train='off'] .train-scene { opacity: 0.45; }
[data-train='off'] .train-meter { display: none; }
.train-power { flex: 0 0 auto; }
[data-train='off'] .train-power { order: -1; flex: 1 1 auto; justify-content: center; height: var(--ctl-h-lg); color: var(--teal-hot); border: 1px solid var(--accent-line-hot); background: var(--accent-wash); font-size: var(--fs-md); font-weight: 600; }

/* Somebody aboard: steam up, a lazy puff now and then. */
[data-train='waiting'] .train-puff { animation: train-puff-idle 3.6s ease-out infinite; }
[data-train='waiting'] .train-puff-1 { animation-delay: 1.2s; }
[data-train='waiting'] .train-puff-2 { animation-delay: 2.4s; }
[data-train='waiting'] .train-puff-3 { animation: none; }
[data-train='waiting'] .train-lamp,
[data-train='running'] .train-lamp { fill: var(--amber); }

/* Merging: wheels turn, the rod works, the track runs, the smoke streams back. */
[data-train='running'] .train-puff { animation: train-puff-run 1.3s linear infinite; fill: var(--ink); }
[data-train='running'] .train-puff-1 { animation-delay: 0.32s; }
[data-train='running'] .train-puff-2 { animation-delay: 0.65s; }
[data-train='running'] .train-puff-3 { animation-delay: 0.97s; }
[data-train='running'] .train-wheel { animation: train-spin 0.9s linear infinite; }
[data-train='running'] .train-rod { animation: train-rod 0.9s linear infinite; }
[data-train='running'] .train-track { animation: train-track 0.35s linear infinite; }
[data-train='running'] .train-body,
[data-train='running'] .train-car { animation: train-bob 0.45s ease-in-out infinite; }
[data-train='running'] .train-car:nth-child(even) { animation-delay: 0.22s; }
[data-train='running'] .train-lamp { filter: drop-shadow(0 0 3px var(--amber)); }

@keyframes train-puff-idle {
  0% { opacity: 0; transform: translate(0, 0) scale(0.45); }
  20% { opacity: 0.5; }
  100% { opacity: 0; transform: translate(-5px, -22px) scale(1.7); }
}
@keyframes train-puff-run {
  0% { opacity: 0; transform: translate(0, 0) scale(0.5); }
  12% { opacity: 0.85; }
  100% { opacity: 0; transform: translate(-58px, -16px) scale(3.2); }
}
@keyframes train-spin { to { transform: rotate(360deg); } }
@keyframes train-rod {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(2.2px, 2.2px); }
  50% { transform: translate(0, 4.4px); }
  75% { transform: translate(-2.2px, 2.2px); }
}
@keyframes train-track { to { background-position: -14px 0; } }
@keyframes train-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-0.8px); }
}

/* ---- what it is doing now ----------------------------------------------- */
/* The headline names the step or the wait; its clock says how long it has
   lasted. Nothing on this panel may stand still without saying why. */

.train-now { display: flex; flex-direction: column; gap: 3px; }
.train-line {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  margin: 0;
  min-height: 1.45em;
  color: var(--ink-dim);
  font-size: var(--fs-md);
  line-height: 1.35;
}
.train-line-text { flex: 1 1 auto; min-width: 0; }
.train-clock {
  flex: 0 0 auto;
  color: var(--ink-faint);
  font-family: var(--mono);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.train-clock:empty { display: none; }
[data-train='running'] .train-line { color: var(--ink); font-weight: 600; }
[data-train='running'] .train-clock { color: var(--teal-hot); }
.train-sub { margin: 0; color: var(--ink-faint); font-size: var(--fs-sm); line-height: 1.4; }
.train-sub[hidden] { display: none; }

/* The wait, as a bar that fills until the train goes by itself. */
.train-meter { height: 3px; margin-top: 2px; border-radius: 2px; background: var(--edge); overflow: hidden; }
.train-meter-fill { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--teal); transition: width 1s linear; }
[data-train='empty'] .train-meter,
[data-train='off'] .train-meter,
[data-train='running'] .train-meter { display: none; }

/* The steps of the run under way, each with its time: what is done, what is
   happening, what is next. Shown only while a run is under way. */
.train-steps { display: none; gap: 3px; margin: 0; padding: 0; list-style: none; }
[data-train='running'] .train-steps { display: flex; }
.train-step {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 0 1px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  color: var(--ink-faint);
  font-size: var(--fs-xs);
  line-height: 1.25;
}
.train-step-time { font-family: var(--mono); font-variant-numeric: tabular-nums; opacity: 0.85; }
.train-step.is-done { color: var(--ink-dim); border-color: var(--accent-line); background: var(--accent-wash); }
.train-step.is-now { color: var(--on-accent); border-color: var(--teal-hot); background: var(--teal); font-weight: 600; }

/* Every ticket in the queue, and what it is doing or waiting for. */
.train-queue { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); }
.train-queue[hidden] { display: none; }
.train-queue-row { display: flex; align-items: baseline; gap: var(--sp-2); min-width: 0; color: var(--ink-dim); }
.train-queue-ticket { flex: 0 0 3.4em; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.train-queue-words { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.train-queue-clock { flex: 0 0 auto; color: var(--ink-faint); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.train-queue-row.is-now .train-queue-words { color: var(--teal-hot); }
.train-queue-row.is-warn .train-queue-words { color: var(--amber); }

.train-car.is-scanning { border-style: dashed; animation: train-scanning 1.6s ease-in-out infinite; }
@keyframes train-scanning { 50% { opacity: 0.55; } }

.train-controls { display: flex; gap: var(--sp-2); align-items: center; }
.train-go { flex: 1 1 auto; justify-content: center; }
.train-go:disabled { opacity: 0.45; cursor: default; }
.train-sound { flex: 0 0 auto; }
/* In the header it is a third button beside the grip and the fold, drawn
   exactly as they are (.rail-grip, .rail-fold), and before them. */
.rail-head > .train-sound {
  order: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--ctl-h-sm);
  height: var(--ctl-h-sm);
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--edge-control);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-dim);
}
.rail-head > .train-sound:hover { color: var(--ink); background: var(--wash-2); }
.rail-head > .train-sound svg { width: 13px; height: 13px; }
#rail-train > .rail-head > .rail-acts { order: 2; margin-left: calc(var(--sp-h) - var(--sp-2)); }
.train-controls:not(:has(> :not([hidden]))) { display: none; }
.train-sound svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.train-sound[aria-pressed='true'] { color: var(--teal-hot); border-color: var(--accent-line-hot); }

/* The last runs: what each did and where its time went, and every ticket it
   sent back with the reason written out, not hidden in a tooltip. */
.train-history { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; color: var(--ink-faint); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.train-run { position: relative; display: flex; flex-direction: column; gap: 1px; padding-left: 12px; min-width: 0; }
.train-run-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.train-run-reason { color: var(--ink-dim); font-size: var(--fs-xs); line-height: 1.35; overflow-wrap: anywhere; }
.train-run::before { content: ''; position: absolute; left: 1px; top: 0.5em; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.train-run.has-returns .train-run-line { color: var(--amber); }
.train-run.has-returns::before { background: var(--amber); }
/* Opened out, the whole list, scrolling inside the panel. */
.train-history.is-open { max-height: 220px; overflow-y: auto; padding-right: var(--sp-1); scrollbar-width: thin; overscroll-behavior: contain; }
.train-more { align-self: flex-start; padding: 0; border: 0; background: none; color: var(--teal); font: inherit; font-size: var(--fs-sm); cursor: pointer; }
.train-more:hover { text-decoration: underline; }
.train-more[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .train-puff, .train-wheel, .train-rod, .train-track, .train-body, .train-car, .train-car.is-scanning { animation: none !important; }
  [data-train='waiting'] .train-puff-0, [data-train='running'] .train-puff-0 { opacity: 0.6; transform: translate(-6px, -10px) scale(1.6); }
  .train-meter-fill { transition: none; }
}

/* Hosts a project's containers could not reach (web/blocked-hosts.mjs). */
.blocked-hosts { margin: 0 0 10px; padding: 8px 12px; border: 1px solid color-mix(in srgb, var(--amber) 45%, transparent);
  border-radius: 8px; background: color-mix(in srgb, var(--amber) 9%, transparent); display: grid; gap: 6px; }
.blocked-hosts[hidden] { display: none; }
/* A long list scrolls inside the strip rather than taking the board. */
#blocked-hosts { max-height: 30vh; overflow-y: auto; margin: 0; }
.blocked-hosts-head { font-weight: 600; font-size: 12px; letter-spacing: .02em; }
.blocked-host { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; }
.blocked-host-text { flex: 1 1 260px; min-width: 0; overflow-wrap: anywhere; }
