:root {
  color-scheme: light;
  --bg: #f7f8f9;
  --surface: #ffffff;
  --text: #172b4d;
  --muted: #5e6c84;
  --border: #dfe1e6;
  --accent: #0c66e4;
  --accent-text: #ffffff;
  --row-hover: #f1f2f4;
  --ok: #1f845a;
  --ok-bg: #dcfff1;
  --fail: #c9372c;
  --fail-bg: #ffeceb;
  --run: #0055cc;
  --run-bg: #e9f2ff;
  --wait: #a54800;
  --wait-bg: #fff7d6;
  --idle: #44546f;
  --idle-bg: #f1f2f4;
  --log-bg: #161a1d;
  --log-text: #dee4ea;
  --log-muted: #738496;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #1d2125;
    --surface: #22272b;
    --text: #dee4ea;
    --muted: #9fadbc;
    --border: #38414a;
    --accent: #579dff;
    --accent-text: #1d2125;
    --row-hover: #2c333a;
    --ok: #4bce97;
    --ok-bg: #164b35;
    --fail: #f87168;
    --fail-bg: #5d1f1a;
    --run: #85b8ff;
    --run-bg: #09326c;
    --wait: #fea362;
    --wait-bg: #533f04;
    --idle: #9fadbc;
    --idle-bg: #2c333a;
    --log-bg: #101214;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 8px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.error { color: var(--fail); }
[hidden] { display: none !important; }

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

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; color: var(--text); }
.brand span { color: var(--muted); font-weight: 400; }
.crumbs { flex: 1; display: flex; gap: 6px; color: var(--muted); min-width: 0; overflow: hidden; white-space: nowrap; }
.crumbs a { color: var(--muted); }
.crumbs > :not(:first-child)::before { content: "/"; margin-right: 6px; color: var(--border); }

.banner {
  margin: 12px 24px 0;
  padding: 8px 12px;
  border-radius: 4px;
  background: var(--fail-bg);
  color: var(--fail);
}
.banner.info { background: var(--run-bg); color: var(--run); }

main { padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; }

/* ---------- buttons ---------- */

button {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 5px 12px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button:disabled { opacity: .55; cursor: default; }
button.secondary { background: var(--idle-bg); color: var(--text); border-color: var(--border); }
button.link { background: none; color: var(--muted); padding: 4px 6px; }
button.link:hover { color: var(--text); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- status badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 8px;
  border-radius: 3px;
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .02em;
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.s-successful { color: var(--ok); background: var(--ok-bg); }
.s-failed, .s-error, .s-invalid, .s-timed-out { color: var(--fail); background: var(--fail-bg); }
.s-running, .s-in-progress { color: var(--run); background: var(--run-bg); }
.s-running::before, .s-in-progress::before { animation: pulse 1.2s ease-in-out infinite; }
.s-paused, .s-waiting { color: var(--wait); background: var(--wait-bg); }
.s-queued, .s-pending, .s-not-run { color: var(--idle); background: var(--idle-bg); }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .s-running::before { animation: none; } }

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

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }
td.num, th.num { text-align: right; white-space: nowrap; }
.sub { display: block; font-size: 12.5px; color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.more { padding: 10px; text-align: center; border-top: 1px solid var(--border); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }

/* ---------- run page ---------- */

.run-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.run-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 6px 0 0; color: var(--muted); }
.facts dt { display: none; }
.facts dd { margin: 0; }
.notice { margin: 0 0 14px; padding: 8px 12px; border-radius: 4px; background: var(--wait-bg); color: var(--wait); }
.notice.bad { background: var(--fail-bg); color: var(--fail); }
.notice ul { margin: 4px 0 0; padding-left: 20px; }

.run-body { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 800px) { .run-body { grid-template-columns: 1fr; } }

.steps { list-style: none; margin: 0; padding: 4px; }
.steps button {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  color: var(--text);
  text-align: left;
  border-radius: 4px;
}
.steps button:hover { background: var(--row-hover); }
.steps button[aria-current="true"] { background: var(--run-bg); }
.steps .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.steps .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps .time { font-size: 12px; color: var(--muted); }

.log-card { display: flex; flex-direction: column; min-height: 0; }
.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.log-head .title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.log-tools { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.log-tools label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.step-message { padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--wait-bg); color: var(--wait); }
.step-message.bad { background: var(--fail-bg); color: var(--fail); }

.log {
  margin: 0;
  padding: 10px 0;
  min-height: 240px;
  max-height: calc(100vh - 260px);
  overflow: auto;
  background: var(--log-bg);
  color: var(--log-text);
  font: 12.5px/1.5 var(--mono);
  counter-reset: line;
}
.log .ln {
  position: relative;
  padding: 0 14px 0 64px;
  min-height: 1.5em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.log .ln::before {
  counter-increment: line;
  content: counter(line);
  position: absolute;
  left: 0;
  width: 48px;
  text-align: right;
  color: var(--log-muted);
  user-select: none;
}
.log .ln.cmd { color: #fff; font-weight: 650; }
.log .placeholder { padding: 0 14px; color: var(--log-muted); font-family: system-ui, sans-serif; }

/* ANSI colours (SGR 30–37, 90–97 and backgrounds), tuned for the dark log background. */
.log .b { font-weight: 700; }
.log .d { opacity: .7; }
.log .i { font-style: italic; }
.log .u { text-decoration: underline; }
.log .f0 { color: #6b7785; } .log .f1 { color: #f87168; } .log .f2 { color: #4bce97; } .log .f3 { color: #e2b203; }
.log .f4 { color: #579dff; } .log .f5 { color: #c97cf4; } .log .f6 { color: #60c6d2; } .log .f7 { color: #dee4ea; }
.log .f8 { color: #8c9bab; } .log .f9 { color: #ff9c8f; } .log .f10 { color: #7ee2b8; } .log .f11 { color: #f5cd47; }
.log .f12 { color: #85b8ff; } .log .f13 { color: #e2b4ff; } .log .f14 { color: #9dd9ee; } .log .f15 { color: #ffffff; }
.log .g0 { background: #2c333a; } .log .g1 { background: #5d1f1a; } .log .g2 { background: #164b35; } .log .g3 { background: #533f04; }
.log .g4 { background: #09326c; } .log .g5 { background: #352c63; } .log .g6 { background: #1d474c; } .log .g7 { background: #596773; }

/* ---------- signed-in user and sign-in pages ---------- */

.who { display: flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.message { max-width: 560px; margin: 15vh auto 0; padding: 0 24px; }
.message h1 { margin-bottom: 8px; }

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

a.button {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 5px 12px;
  background: var(--accent);
  color: var(--accent-text);
  white-space: nowrap;
}
a.button.secondary { background: var(--idle-bg); color: var(--text); border-color: var(--border); }
a.button:hover { text-decoration: none; filter: brightness(.97); }
button.link.danger { color: var(--fail); }
.head-links { display: flex; gap: 14px; flex-wrap: wrap; justify-content: flex-end; padding-top: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

input[type="text"], input[type="password"], input[type="number"], textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  min-width: 0;
}
textarea { width: 100%; resize: vertical; }
textarea.mono, input.mono { font-family: var(--mono); font-size: 12.5px; }
input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.settings { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 28px; align-items: start; }
@media (max-width: 800px) { .settings { grid-template-columns: 1fr; gap: 12px; } }
.settings-nav { display: flex; flex-direction: column; gap: 2px; }
.settings-nav .nav-head { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 10px 4px; }
.settings-nav .nav-head:first-child { padding-top: 0; }
.settings-nav a { padding: 6px 10px; border-radius: 4px; color: var(--text); }
.settings-nav a:hover { background: var(--row-hover); text-decoration: none; }
.settings-nav a[aria-current="page"] { background: var(--run-bg); color: var(--run); font-weight: 600; }
.settings-body { max-width: 960px; min-width: 0; }
.settings-body.narrow { margin: 0 auto; }
.settings-body h2 { margin-top: 24px; }
.settings-body h3 { font-size: 13px; margin: 0 0 8px; }
.intro { margin: 4px 0 18px; max-width: 72ch; }

.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.inline-form input[type="text"], .inline-form input[type="password"] { flex: 1 1 180px; }
.inline-form input.port { width: 90px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.form-error { margin: -2px 0 10px; color: var(--fail); }
td .inline-form { margin: 0; }
td .form-error { margin: 6px 0 0; }
td.mono, .value { overflow-wrap: anywhere; }
td.num button.link { padding: 2px 6px; }

.card.pad { padding: 14px; }
.card.pad > p:first-child { margin-top: 0; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.public-key { margin-bottom: 4px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.own-key { margin-top: 14px; }
.own-key .muted { margin: 4px 0 8px; }
.fetched { margin: 0 0 12px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--wait-bg); }
.fetched p { margin: 0 0 6px; }
.fingerprints { margin: 0 0 10px; padding-left: 20px; overflow-wrap: anywhere; }

.env-group { margin-bottom: 8px; }
.env-group .card { margin-bottom: 8px; }
.env-group .card:empty { display: none; }
.environment { border-bottom: 1px solid var(--border); }
.environment:last-child { border-bottom: 0; }
.environment summary {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
}
.environment summary::-webkit-details-marker { display: none; }
.environment summary::before { content: "▸"; color: var(--muted); width: 10px; }
.environment[open] summary::before { content: "▾"; }
.environment summary:hover { background: var(--row-hover); }
.env-name { font-weight: 600; flex: 1; }
.env-latest { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.env-body { padding: 4px 14px 14px 36px; }
.env-actions { margin-top: 10px; }
.add-env input[type="text"] { flex: 0 1 260px; }

/* ---------- run pipeline ---------- */

.run-dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.run-dialog::backdrop { background: rgb(9 30 66 / 45%); }
.run-form { display: flex; flex-direction: column; gap: 6px; padding: 18px 20px; }
.run-form h2 { margin-bottom: 4px; }
.run-form .field-label { margin: 8px 0 0; }
.run-form select, .run-form input[type="text"], .run-vars select {
  font: inherit;
  width: 100%;
  padding: 5px 8px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.run-form .note { margin: 4px 0 0; }
.run-form .note ul { margin: 4px 0 0; padding-left: 20px; }
.run-vars:not(:empty) { margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--border); }
.run-var { margin-bottom: 8px; }
.run-var .field-label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; color: var(--text); }
.run-var .muted { font-size: 12.5px; margin-top: 2px; }
.run-form .actions { margin-top: 12px; }
.run-form .form-error { margin: 6px 0 0; }

/* ---------- step runs ---------- */

.run-head .actions { flex-shrink: 0; }
.steps .runs { color: var(--muted); font-size: 12px; }
.log-head .title select {
  font: inherit;
  font-size: 12.5px;
  padding: 2px 6px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}
