:root {
  --paper: #eef1f5;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #5b6577;
  --line: #d6dbe3;
  --action: #2b4edb;
  --action-ink: #ffffff;
  --ok: #17845a;
  --fail: #c4352b;
  --run: #b87407;
  --idle: #8b94a5;
  --ok-soft: #e1f3ea;
  --fail-soft: #fbe6e4;
  --run-soft: #fbf0d9;
  --idle-soft: #eceff3;
  --log-bg: #172033;
  --log-ink: #dfe5ef;
  --radius-lg: 14px;
  --radius-sm: 6px;
  --font: 'Instrument Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #10151f; --surface: #171e2b; --ink: #e4e8f0; --muted: #9aa3b4; --line: #283244;
    --action: #7c95ff; --action-ink: #0e1424;
    --ok: #3dbe88; --fail: #f0675c; --run: #f0b43c; --idle: #7d8699;
    --ok-soft: #15362a; --fail-soft: #3d1c1b; --run-soft: #3a2c10; --idle-soft: #222a38;
    --log-bg: #0b0f17; --log-ink: #d3dae6;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --paper: #10151f; --surface: #171e2b; --ink: #e4e8f0; --muted: #9aa3b4; --line: #283244;
  --action: #7c95ff; --action-ink: #0e1424;
  --ok: #3dbe88; --fail: #f0675c; --run: #f0b43c; --idle: #7d8699;
  --ok-soft: #15362a; --fail-soft: #3d1c1b; --run-soft: #3a2c10; --idle-soft: #222a38;
  --log-bg: #0b0f17; --log-ink: #d3dae6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  font-feature-settings: 'tnum' 1;
}
a { color: var(--action); text-underline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; line-height: 1.2; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- shell ---------- */
.shell { max-width: 1320px; margin: 0 auto; padding: 24px 24px 64px; }
.top {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 24px;
  justify-content: space-between; margin-bottom: 24px;
}
.top .host { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); }
.summary { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.top-actions { display: flex; gap: 8px; align-items: center; }

button, .btn {
  font: inherit; font-size: 0.88rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 7px 12px; border-radius: var(--radius-sm); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary { background: var(--action); border-color: var(--action); color: var(--action-ink); }
button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.55; cursor: progress; }
button.quiet { border-color: transparent; background: transparent; color: var(--muted); padding: 7px 8px; }
select, input[type='text'], input[type='email'], input[type='password'] {
  font: inherit; font-size: 0.9rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 7px 10px; min-width: 0;
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; padding: 16px 18px 10px; }
.panel-body { padding: 0 18px 16px; }
.empty { color: var(--muted); padding: 6px 0 4px; }

/* ---------- status vocabulary ---------- */
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; background: var(--idle); }
.s-success .dot, .dot.s-success, .dot.up, .dot.running-ok { background: var(--ok); }
.s-failed .dot, .dot.s-failed, .dot.down { background: var(--fail); }
.s-running .dot, .dot.s-running, .dot.busy { background: var(--run); }
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600;
  padding: 2px 9px 2px 8px; border-radius: 99px; background: var(--idle-soft); color: var(--muted); white-space: nowrap;
}
.badge.s-success, .badge.up { background: var(--ok-soft); color: var(--ok); }
.badge.s-failed, .badge.down { background: var(--fail-soft); color: var(--fail); }
.badge.s-running, .badge.busy, .badge.s-queued { background: var(--run-soft); color: var(--run); }

/* ---------- staging band ---------- */
.envs { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); gap: 16px; margin-bottom: 20px; }
.env { padding: 20px 22px; display: grid; gap: 14px; }
.env-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.env-state { font-size: 1.35rem; font-weight: 600; display: flex; align-items: center; gap: 10px; line-height: 1.2; }
.env-state .dot { width: 12px; height: 12px; }
.env-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; font-size: 0.9rem; }
.env-facts dt { color: var(--muted); }
.env-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.env-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.env-actions select { max-width: 260px; }
.links { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.9rem; }

/* ---------- pipeline rail (the signature element) ---------- */
.rail { display: flex; gap: 3px; height: 26px; border-radius: 7px; overflow: hidden; min-width: 0; }
.rail .seg {
  flex: 1 1 0; min-width: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.74rem; font-weight: 600; padding: 0 6px;
  background: var(--idle-soft); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rail .seg.success { background: var(--ok); color: var(--surface); }
.rail .seg.failed { background: var(--fail); color: #fff; }
.rail .seg.cancelled { background: var(--idle); color: var(--surface); }
.rail .seg.skipped { background: repeating-linear-gradient(135deg, var(--idle-soft) 0 6px, transparent 6px 10px); }
.rail .seg.running {
  color: #1d1400;
  background: repeating-linear-gradient(-45deg, var(--run) 0 10px, color-mix(in srgb, var(--run) 78%, white) 10px 20px);
  background-size: 28px 28px;
  animation: crawl 1s linear infinite;
}
@keyframes crawl { to { background-position: 28px 0; } }
@media (prefers-reduced-motion: reduce) { .rail .seg.running { animation: none; } }
.rail.compact { height: 8px; gap: 2px; border-radius: 4px; }
.rail.compact .seg { font-size: 0; padding: 0; }

/* ---------- main grid ---------- */
.grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.stack { display: grid; gap: 20px; min-width: 0; }
@media (max-width: 980px) { .grid { grid-template-columns: minmax(0, 1fr); } }

/* builds */
#build-form { flex-wrap: wrap; min-width: 0; }
#build-form select { max-width: 100%; }
#build-form select[name='branch'] { flex: 1 1 140px; }
.jobs { list-style: none; margin: 0; padding: 0; }
.job {
  display: grid; grid-template-columns: 1fr minmax(160px, 260px); gap: 6px 18px; align-items: center;
  padding: 12px 18px; border-top: 1px solid var(--line); color: inherit; text-decoration: none;
}
.job:hover { background: color-mix(in srgb, var(--paper) 55%, transparent); }
.job-title { display: flex; gap: 8px; align-items: center; min-width: 0; font-weight: 600; }
.job-title span.msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-meta { grid-column: 1; font-size: 0.83rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.job .rail { grid-column: 2; grid-row: 1 / span 2; }
@media (max-width: 620px) {
  .job { grid-template-columns: 1fr; }
  .job .rail { grid-column: 1; grid-row: auto; }
}
.kind { font-size: 0.75rem; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; flex: none; }
.kind.deploy { color: var(--action); border-color: color-mix(in srgb, var(--action) 45%, transparent); }

/* side lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.list li { display: grid; gap: 2px; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: 0.83rem; color: var(--muted); overflow-wrap: anywhere; }

.meters { display: grid; gap: 12px; }
.meter-label { display: flex; justify-content: space-between; font-size: 0.85rem; }
.meter { height: 6px; border-radius: 3px; background: var(--idle-soft); overflow: hidden; margin-top: 4px; }
.meter > i { display: block; height: 100%; background: var(--action); border-radius: 3px; }
.meter > i.hot { background: var(--fail); }

/* containers */
.ctr-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.ctr-table th { text-align: left; font-weight: 600; color: var(--muted); padding: 8px 18px; border-bottom: 1px solid var(--line); font-size: 0.8rem; }
.ctr-table td { padding: 8px 18px; border-top: 1px solid var(--line); vertical-align: top; }
.ctr-table tr.stack-row td { background: color-mix(in srgb, var(--paper) 60%, transparent); font-weight: 600; font-size: 0.83rem; padding-top: 6px; padding-bottom: 6px; }
.ctr-table td.name { display: flex; align-items: center; gap: 8px; }
.table-wrap { overflow-x: auto; }
@media (max-width: 700px) { .ctr-table .hide-sm { display: none; } }

/* job page */
.job-page { display: grid; gap: 16px; }
.job-page .rail { height: 34px; font-size: 0.8rem; }
.job-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-start; }
.log {
  background: var(--log-bg); color: var(--log-ink); border-radius: var(--radius-lg);
  font: 12.5px/1.55 var(--mono); padding: 16px 18px; margin: 0;
  white-space: pre-wrap; overflow-wrap: anywhere; min-height: 320px; max-height: 72vh; overflow: auto;
}
.log .b { font-weight: 700; color: #fff; }
.log .g { color: #6fdca5; } .log .r { color: #ff8a80; } .log .y { color: #f6cf6b; } .log .c { color: #7fd3ff; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(100%, 380px); padding: 28px; display: grid; gap: 18px; }
.login form { display: grid; gap: 14px; }
.login label { display: grid; gap: 5px; font-size: 0.88rem; font-weight: 600; }
.login input { padding: 10px 12px; font-size: 1rem; }
.login button { justify-content: center; padding: 10px; font-size: 0.95rem; }
.form-error { margin: 0; color: var(--fail); background: var(--fail-soft); padding: 8px 12px; border-radius: var(--radius-sm); font-size: 0.9rem; }
.login .rail { height: 6px; }

dialog { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); padding: 22px; width: min(92vw, 380px); }
dialog::backdrop { background: rgb(10 14 22 / 0.45); }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-size: 0.88rem; font-weight: 600; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 9px 16px; border-radius: 8px; font-size: 0.9rem; z-index: 10; max-width: calc(100vw - 32px); }

@media (max-width: 560px) {
  .shell { padding: 16px 16px 48px; }
  .panel-head, .panel-body { padding-left: 14px; padding-right: 14px; }
  .job { padding: 12px 14px; }
  .ctr-table th, .ctr-table td { padding-left: 14px; padding-right: 14px; }
  .env { padding: 16px; }
}
