:root {
  color-scheme: dark;
  --ink: #e8eef7;
  --muted: #9aabbf;
  --line: #2a3a4d;
  --bg: #0e1724;
  --panel: #152233;
  --amber: #fbbf24;
  --mint: #34d399;
  --rose: #fb7185;
  --sky: #7dd3fc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.45 Inter, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.fold {
  padding: 20px 28px;
}

.engine-columns {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
  padding: 20px 28px 0;
}

#test-rail { min-width: 0; }
#test-rail h2 { margin-bottom: 12px; }
body:not(.test-on) #test-rail { display: none; }
body:not(.test-on) .engine-columns { grid-template-columns: minmax(0, 1fr); }

.test-mode {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 650;
}
.test-mode input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--amber);
}

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 22px;
  min-height: 64px;
  border-bottom: 1px solid var(--line);
  background: #101c2c;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.logo-slot {
  display: block;
  flex: 0 0 auto;
  height: 28px;
}
.logo-chip {
  height: 36px;
  background: #fff;
  border-radius: 8px;
  padding: 4px 10px;
}
.brand .logo {
  display: block;
  height: 28px;
  width: auto;
}
.look {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: #9db4cc;
  white-space: nowrap;
}
.look select {
  color: #fff;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  padding: 4px 8px;
}
#sign-out {
  color: #fff;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  padding: 4px 8px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.brand-copy { min-width: 0; }
.brand h1 { margin: 0; font-size: 20px; color: #fff; }
.brand .version { margin: 2px 0 0; font-size: 12px; color: #9db4cc; }
.brand .database { margin: 0; font-size: 12px; color: #9db4cc; }

.page-zoom {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 4px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  background: rgba(255, 255, 255, .08);
  flex: 0 0 auto;
}
.zoom-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}
.zoom-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .16); }
.zoom-btn:disabled { opacity: .35; cursor: default; }
#pageZoomPct {
  min-width: 2.8rem;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 28px; }
h2 { font-size: 16px; margin-bottom: 12px; color: var(--muted); }
.fold-bar h2 { margin: 0; }

.version, .note, .work-line { color: var(--muted); }
.version { margin: 0; }

.log { margin: 0; padding-left: 20px; }

.fold { border-top: 1px solid var(--line); }
.fold-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.fold-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  color: var(--amber);
  border: 1px solid var(--amber);
  font-weight: 700;
}
.fold-toggle svg { display: block; }
.fold-body { margin-top: 12px; min-height: 48px; }
.fold-body[hidden] { display: none; }
.fold-inset,
form .fold-inset {
  grid-column: 1 / -1;
  margin: 8px 0;
  padding: 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #101c2c;
}
.fold-inset .fold-body,
form .fold-inset .fold-body { margin-top: 10px; min-height: 0; }
.dataset { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
form .dataset { grid-column: 1 / -1; }

.outcome {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}
.outcome p {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #101c2c;
  color: var(--muted);
  font-size: 13px;
}
.outcome span {
  display: block;
  margin-bottom: 2px;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#history .outcome { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 0; }
#history .history-board { margin-bottom: 0; }
.history-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}
.history-card {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #101c2c;
}
.history-card strong {
  display: block;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.history-card span,
.history-card em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
}
.outcome .ok span { color: var(--mint); }
.outcome .wait span { color: var(--amber); }
.outcome .bad span { color: var(--rose); }

.flow {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0;
  margin: 0;
  padding: 14px 22px 16px;
  background: #101c2c;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.flow-live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.flow-node {
  flex: 1 1 140px;
  min-width: 132px;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0f1c2d;
  color: var(--muted);
  text-align: center;
}
.flow-ico {
  width: 36px;
  height: 36px;
  color: var(--muted);
}
.flow-ico svg { width: 36px; height: 36px; display: block; }
.flow-node strong { font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.flow-node .flow-detail { font-size: 12px; line-height: 1.3; }
.flow-node.on {
  border-color: var(--amber);
  box-shadow: 0 0 0 1px var(--amber), 0 0 16px rgba(251, 191, 36, 0.35);
  animation: flow-pulse 1.15s ease-in-out infinite;
}
.flow-node.on .flow-ico,
.flow-node.on strong { color: var(--amber); }
.flow-node.watch { border-color: var(--amber); }
.flow-node.watch .flow-ico,
.flow-node.watch strong { color: var(--amber); }
.flow-node.done {
  border-color: var(--mint);
  background: rgba(52, 211, 153, 0.08);
}
.flow-node.done .flow-ico,
.flow-node.done strong { color: var(--mint); }
.flow-node.fail {
  border-color: var(--rose);
  background: rgba(251, 113, 133, 0.1);
}
.flow-node.fail .flow-ico,
.flow-node.fail strong { color: var(--rose); }
.flow-link {
  flex: 0 0 22px;
  align-self: center;
  height: 2px;
  margin: 0 2px;
  background: var(--line);
  position: relative;
}
.flow-link::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -3px;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid var(--line);
}
.flow-link.lit { background: var(--mint); }
.flow-link.lit::after { border-left-color: var(--mint); }
@keyframes flow-pulse {
  50% { box-shadow: 0 0 0 1px var(--amber), 0 0 22px rgba(251, 191, 36, 0.55); }
}
@media (prefers-reduced-motion: reduce) {
  .flow-node.on { animation: none; }
}

main {
  display: block;
  min-width: 0;
  padding: 0 0 20px;
}

.cases { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

button, select, input {
  font: inherit;
  color: var(--ink);
  background: #0f1c2d;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

button { cursor: pointer; }
button.run, button.case {
  background: var(--amber);
  color: #0f172a;
  border: 0;
  font-weight: 700;
}
button.case { background: transparent; color: var(--amber); border: 1px solid var(--amber); }

form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label[hidden] { display: none; }
label.check { align-items: center; grid-template-columns: auto 1fr; }
form .run, .process-pick, #submit-note { grid-column: 1 / -1; }
.actions { display: flex; gap: 10px; margin: 8px 0 14px; }
.run-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 0 0 12px; }
.run-actions #start { grid-column: 1 / -1; }
button.case:disabled { opacity: 0.45; cursor: default; }
.bars { display: grid; gap: 8px; margin: 0 0 16px; }
.bar-row { display: grid; grid-template-columns: 118px 1fr 150px; gap: 8px; align-items: center; font-size: 13px; }
.bar-track { height: 16px; background: #0f1c2d; border-radius: 8px; overflow: hidden; }
.bar-fill { display: block; height: 100%; width: 0; }
.bar-fill.compute { background: var(--sky); }
.bar-fill.sql { background: var(--amber); }
.bar-fill.io { background: var(--mint); }
.bar-time { color: var(--muted); text-align: right; }
table.writes { margin: 0 0 16px; }
table.writes th:last-child, table.writes td:last-child { text-align: right; }
.process-combo { position: relative; }
#process-input { width: 100%; }
#process-list {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow: auto;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: #0f1c2d;
  border: 1px solid var(--line);
  border-radius: 8px;
}
#process-list li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
#process-list li[aria-selected="true"] { background: #1c3148; }
#process-list li.process-empty { color: var(--muted); cursor: default; }

.live {
  margin-top: 16px;
  min-height: 280px;
  max-height: calc(100vh - 280px);
  overflow: auto;
  background: #0b1320;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}
.live-hint, .live-now { margin: 0; color: var(--muted); font-size: 13px; }
.walker-steps { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; }
.walker-steps:empty { display: none; }
.walker-steps li {
  margin: 0;
  padding: 4px 8px;
  border-left: 2px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--muted);
}
.walker-steps li .mark {
  display: inline-block;
  width: 1.2em;
  font-weight: 700;
}
.walker-steps li.done { color: var(--ink); border-left-color: var(--mint); }
.walker-steps li.done .mark { color: var(--mint); }
.walker-steps li.waiting { color: var(--ink); border-left-color: var(--amber); }
.walker-steps li.waiting .mark { color: var(--amber); }
.walker-steps li.failed { color: var(--ink); border-left-color: var(--rose); }
.walker-steps li.failed .mark { color: var(--rose); }
.live-hint[hidden] { display: none; }
#live-tape {
  margin: 0;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--ink);
}
#live-tape:not(:empty) + .live-now { margin-top: 12px; }

.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 12px; }
.steps li {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.steps li.on { color: #0f172a; background: var(--sky); border-color: var(--sky); font-weight: 700; }
.steps li.done { background: var(--mint); border-color: var(--mint); color: #052e22; }
.steps li.parked { background: var(--rose); border-color: var(--rose); color: #3f0a14; }

table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.line-scroll {
  max-height: 220px;
  overflow: auto;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.line-scroll table { margin: 0; border-collapse: separate; border-spacing: 0; }
.line-scroll th {
  position: sticky;
  top: 0;
  background: #101c2c;
  z-index: 1;
}
#scheduler details { margin-top: 16px; }
#scheduler summary { cursor: pointer; color: var(--sky); }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
.log li { margin: 8px 0; }
.log code, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.http-202 { color: var(--mint); }
.http-400 { color: var(--rose); }
pre {
  white-space: pre-wrap;
  background: #0b1320;
  border-radius: 8px;
  padding: 10px;
  margin: 6px 0 0;
}
#mrr-file {
  max-height: 420px;
  overflow: auto;
}
#mrr-file:empty { display: none; }
#scheduler-json { max-height: 280px; overflow: auto; }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  header.top { flex-wrap: wrap; }
}

html[data-theme="day"] {
  color-scheme: light;
  --ink: #1c2430;
  --muted: #667085;
  --line: #d7dee6;
  --bg: #eef2f6;
  --panel: #ffffff;
}
html[data-theme="day"] .fold-inset,
html[data-theme="day"] form .fold-inset,
html[data-theme="day"] .outcome p,
html[data-theme="day"] .flow-node,
html[data-theme="day"] button,
html[data-theme="day"] select,
html[data-theme="day"] input,
html[data-theme="day"] .bar-track,
html[data-theme="day"] #process-list,
html[data-theme="day"] .live,
html[data-theme="day"] pre {
  background: #fff;
}
html[data-theme="day"] header.top,
html[data-theme="day"] header.top .look select,
html[data-theme="day"] header.top .zoom-btn,
html[data-theme="day"] header.top .page-zoom {
  background: #101c2c;
}
html[data-theme="day"] header.top .zoom-btn { background: transparent; }
html[data-theme="day"] button.run { background: var(--amber); color: #0f172a; }
html[data-theme="day"] button.case { background: transparent; color: var(--amber); }
html[data-theme="day"] #process-list li[aria-selected="true"] { background: #e8eef5; }
