:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #687082;
  --line: #d9dde5;
  --ok: #1a7f37;
  --ok-bg: #e6f4ea;
  --run: #0b62d6;
  --run-bg: #e7f0fd;
  --wait: #9a6700;
  --wait-bg: #fff4d6;
  --bad: #c62828;
  --bad-bg: #fdecec;
  --idle: #8a91a0;
  --chip: #eef0f4;
  --accent: #3b5bdb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --ink: #e6e8ee;
    --muted: #949bab;
    --line: #2b303b;
    --ok: #4cc26b;
    --ok-bg: #12291a;
    --run: #5b9cff;
    --run-bg: #132238;
    --wait: #e2b34a;
    --wait-bg: #2e2412;
    --bad: #ff6b6b;
    --bad-bg: #331616;
    --idle: #6b7280;
    --chip: #222733;
    --accent: #7c93ff;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .sha { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 48px 16px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.updated { font-size: 12px; color: var(--muted); white-space: nowrap; }
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.btn {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; font: inherit; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { color: var(--bad); border-color: var(--bad); }
.btn.small { padding: 2px 8px; font-size: 12px; }

/* home grid */
.grid {
  margin: 10px 16px 0; width: calc(100% - 32px); border-collapse: separate; border-spacing: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.grid { table-layout: fixed; }
.grid th.svc-h { width: 160px; }
.grid th, .grid td { border-bottom: 1px solid var(--line); padding: 4px 10px; white-space: nowrap; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: left; }
.grid th.grp { color: var(--ink); font-size: 13px; border-left: 1px solid var(--line); }
.grid th.col { border-left: 1px solid var(--line); font-weight: 500; vertical-align: middle; }
.grid th.svc-h { vertical-align: bottom; }
.grid td.cell { border-left: 1px solid var(--line); }
.grid tr.row { cursor: pointer; }
.grid tr.row:hover td { background: var(--chip); }
.grid td.svc { overflow: hidden; text-overflow: ellipsis; }
.grid td.svc a { color: var(--ink); font-weight: 600; }
.grid td.na { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--chip) 6px 8px); }
.cell .sha { color: var(--muted); }
.latest { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 4px; margin-right: 6px; color: var(--ok); background: var(--ok-bg); }
.cell .when { margin-left: 4px; }
.flag { margin-right: 6px; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 10px; }
.flag.waiting { color: var(--wait); background: var(--wait-bg); }
.flag.run { color: var(--run); background: var(--run-bg); }
.flag.bad { color: var(--bad); background: var(--bad-bg); }
.hint { margin: 8px 18px 0; padding-bottom: 8px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.legend { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; align-items: center; margin: 8px 18px 6px; font-size: 12px; color: var(--muted); }
.legend dt, .legend dd { margin: 0; }
.legend .flag, .legend .latest { margin-right: 0; }
.legend .key { white-space: nowrap; margin-right: 0; }
.key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; margin-right: -8px; }
.grp-name { display: inline-flex; align-items: center; gap: 6px; }
.grp-icon { display: block; width: 16px; height: 16px; object-fit: contain; border-radius: 2px; }
.th-sort { all: unset; cursor: pointer; font: inherit; color: inherit; }
.th-sort:hover { color: var(--ink); }
.th-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.th-sort .dir { margin-left: 4px; font-size: 10px; color: var(--accent); }
.th-sort .dir.hint { visibility: hidden; opacity: .6; }
.th-sort:hover .dir.hint, .th-sort:focus-visible .dir.hint { visibility: visible; }
.col-h { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.col-h .btn { padding: 2px 5px; font-size: 11px; white-space: nowrap; flex: none; }
dialog { width: min(980px, calc(100vw - 32px)); max-height: 80vh; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 10px; font-size: 16px; }
dialog td { white-space: nowrap; }
dialog .commit .msg { max-width: 260px; display: inline-block; }
.warn { margin: 0 0 10px; padding: 6px 10px; border-radius: 6px; font-size: 13px; color: var(--wait); background: var(--wait-bg); }
.replaced { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); text-decoration: line-through; }
.result.good { color: var(--ok); font-weight: 600; }
.result.fail { color: var(--bad); white-space: normal; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.spin-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.spinner { display: block; width: 28px; height: 28px; animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.spin-pop { flex: none; }
.spin-pop.pop-in { animation: pop-in .28s cubic-bezier(.34, 1.56, .64, 1) both; }
.spin-row.leaving .spin-pop { animation: pop-out .2s ease-in both; }
.spin-row .muted { transition: opacity .2s; }
.spin-row.leaving .muted { opacity: 0; }
@keyframes pop-in { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pop-out { 0% { transform: scale(1); opacity: 1; } 35% { transform: scale(1.18); opacity: 1; } 100% { transform: scale(0); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .spinner, .spin-pop.pop-in { animation: none; } }
.summary h3 { margin: 10px 0 4px; font-size: 13px; }
.summary ul { margin: 0; padding-left: 18px; }
.summary li { margin: 3px 0; }
.summary p { margin: 4px 0; }
.summary-facts { color: var(--muted); font-size: 12px; }
.gate {
  flex: 0 0 200px; align-self: center; display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px; border: 1px dashed var(--wait); border-radius: 4px; background: var(--wait-bg);
}
.gate-title { font-size: 13px; font-weight: 700; color: var(--wait); }
.gate-to { font-size: 12px; color: var(--muted); }
.gate .commit .msg { max-width: 110px; }
.gate .actions { display: flex; gap: 6px; margin-top: 4px; }
.crumbs { padding: 12px 16px 0; }
.back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font-weight: 600; font-size: 13px;
}
.back:hover { text-decoration: none; border-color: var(--accent); background: var(--chip); }

.pipeline {
  margin: 12px 16px; padding: 12px 14px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.pipeline-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.pipeline-head h2 { margin: 0; font-size: 15px; }
.flow { display: flex; align-items: stretch; gap: 0; overflow-x: auto; padding-bottom: 4px; }
.arrow { flex: 0 0 22px; display: flex; align-items: center; justify-content: center; color: var(--idle); }
.arrow::before { content: "→"; font-size: 16px; }

.stage {
  flex: 0 0 auto; min-width: 190px; max-width: 320px;
  border: 1px solid var(--line); border-top: 4px solid var(--idle); border-radius: 8px;
  background: var(--panel); display: flex; flex-direction: column;
}
.stage.Succeeded { border-top-color: var(--ok); }
.stage.InProgress { border-top-color: var(--run); }
.stage.waiting { border-top-color: var(--wait); }
.stage.Failed, .stage.Stopped { border-top-color: var(--bad); }
.stage-head { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.stage-head b { font-size: 13px; }
.status { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.status.Succeeded { color: var(--ok); }
.status.InProgress { color: var(--run); }
.status.waiting { color: var(--wait); }
.status.Failed, .status.Stopped { color: var(--bad); }
.status.none { color: var(--idle); }
.stage-body { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }

.accounts { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--chip); }
.target { padding: 6px 8px; }
.target + .target { border-top: 1px solid var(--line); }
.target-head { display: flex; justify-content: space-between; gap: 8px; }
.target-alias { font-weight: 600; font-size: 12px; }
.commit { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.commit .msg { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.when { color: var(--muted); font-size: 11px; white-space: nowrap; }

.band { padding: 6px 8px; border-radius: 6px; font-size: 12px; }
.band.waiting { background: var(--wait-bg); color: var(--wait); }
.band.InProgress { background: var(--run-bg); color: var(--run); }
.band.Failed, .band.Stopped { background: var(--bad-bg); color: var(--bad); }
.band .actions { display: flex; gap: 6px; margin-top: 6px; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 10;
  max-width: 420px; padding: 10px 14px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.err { border-color: var(--bad); color: var(--bad); }

@media (max-width: 700px) {
  .top { position: static; }
  .pipeline { margin: 12px 8px; }
}

/* responsive: the grid gives things up in stages as it narrows */
.flag.behind { color: var(--muted); background: var(--chip); }
.m-list { display: none; }
@media (max-width: 1439px) {
  .w-latest { display: none; }
}
@media (max-width: 1399px) {
  .cell .when { display: none; }
}
@media (max-width: 1199px) {
  .w-count { display: none; }
}
@media (max-width: 1099px) {
  .cell .sha, .drop-narrow { display: none; }
  .grid th, .grid td { padding-left: 8px; padding-right: 8px; }
}
@media (max-width: 1079px) {
  [data-approve-all] { display: none; }
}
@media (max-width: 767px) {
  .grid, .hint { display: none; }
  .top { flex-wrap: wrap; }
  .who { font-size: 12px; }
  .m-list { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
  .m-card { display: block; padding: 10px 12px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
  .m-card:hover { text-decoration: none; }
  .m-name { font-weight: 700; margin-bottom: 6px; }
  .m-group { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
  .m-owner { flex: 0 0 92px; display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
  .m-accts { flex: 1; display: flex; flex-wrap: wrap; gap: 6px 14px; }
  .m-acct { display: flex; align-items: center; gap: 6px; }
  .m-label { font-size: 12px; color: var(--muted); }
  .m-acct .flag, .m-acct .latest { margin: 0; }
  /* service view: the pipeline reads top to bottom */
  .flow, .fork { flex-direction: column; overflow-x: visible; }
  .arrow { flex: 0 0 22px; }
  .arrow::before { content: "↓"; }
  .stage, .gate { flex: none; width: 100%; min-width: 0; max-width: none; align-self: stretch; }
  .commit { min-width: 0; }
  .commit .msg, .gate .commit .msg { max-width: none; flex: 1; min-width: 0; }
  .summary { overflow-wrap: anywhere; }
  .legend { margin: 4px 14px 14px; }
}
