:root {
  --bg: #f7f7f5; --panel: #ffffff; --panel-2: #fafaf8; --ink: #1c1c1a; --muted: #6b6b66; --line: #e3e3de;
  --accent: #2456d6; --accent-ink: #ffffff; --hover: #f2f5fb;
  --ok: #1f7a3a; --ok-bg: #e3f4e8; --bad: #b42318; --bad-bg: #fbe9e7; --busy: #8a5a00; --busy-bg: #fff3d6;
  --quiet: #55555f; --quiet-bg: #ececf1;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px; --fs-xl: 20px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-6: 24px; --s-8: 32px;
  --cell-x: 12px; --cell-y: 10px; --gutter: 24px;
  --r-panel: 8px; --r-control: 6px; --control: 32px;
  /* List columns, shared by the filter row and the table; Description takes the rest. */
  --c-repo: 12.5rem; --c-env: 11.5rem; --c-state: 7.5rem; --c-ref: 8rem; --c-sha: 5rem; --c-creator: 13rem; --c-created: 9rem;
}
@media (min-width: 1440px) {
  :root { --c-repo: 12.5rem; --c-env: 12rem; --c-state: 8rem; --c-ref: 8.5rem; --c-creator: 13.5rem; --c-created: 9.5rem; }
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --panel: #1d1d21; --panel-2: #212126; --ink: #ececea; --muted: #9a9a95; --line: #34343b;
    --accent: #7ea2ff; --accent-ink: #0d1733; --hover: #24272f;
    --ok: #7fd79a; --ok-bg: #16301f; --bad: #ff9a8f; --bad-bg: #3a1c19; --busy: #ffcf70; --busy-bg: #3a2d10;
    --quiet: #b7b7c2; --quiet-bg: #2a2a31;
  }
}
* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: var(--fs-md)/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-family: var(--mono); font-size: var(--fs-sm); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.top { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.bar, main { max-width: 1400px; margin: 0 auto; padding-inline: var(--gutter); }
.bar { display: flex; justify-content: space-between; align-items: center; gap: var(--s-4); min-height: 48px; }
.brand { font-weight: 600; color: var(--ink); }
.brand:hover { text-decoration: none; }
.top nav { display: flex; align-items: center; gap: var(--s-3); font-size: var(--fs-sm); }
.who { color: var(--muted); }
.top form { margin: 0; }
main { padding-block: var(--s-6) var(--s-8); }
h1 { font-size: var(--fs-xl); line-height: 1.3; font-weight: 600; margin: 0 0 var(--s-4); overflow-wrap: anywhere; }
h1 .state { vertical-align: 3px; margin-left: var(--s-1); }
h2 { font-size: var(--fs-lg); font-weight: 600; margin: var(--s-8) 0 var(--s-3); }
.crumbs { color: var(--muted); font-size: var(--fs-sm); margin: 0 0 var(--s-1); }

button, .button {
  font: inherit; font-size: var(--fs-sm); height: var(--control); padding: 0 var(--s-3); cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-control); background: var(--panel); color: var(--ink);
}
button:hover { border-color: var(--muted); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; height: auto; }
button.link:hover { text-decoration: underline; }
.button { display: inline-flex; align-items: center; background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.button:hover { text-decoration: none; filter: brightness(0.92); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-panel); padding: var(--s-6); }
.card h1 { margin-bottom: var(--s-2); }
.signin { max-width: 440px; margin: 10vh auto 0; text-align: center; }
.signin p { color: var(--muted); margin: 0 0 var(--s-6); }

.filters {
  display: grid; align-items: center; padding: var(--s-3) 0; border-bottom: 1px solid var(--line);
  grid-template-columns: var(--c-repo) var(--c-env) var(--c-state) calc(var(--c-ref) + var(--c-sha)) var(--c-creator) minmax(0, 1fr);
}
.filters label, .filters .actions { padding-inline: var(--cell-x); min-width: 0; }
/* Pull each control left by its padding and border so typed text lines up with the column values below. */
.filters label { padding-left: calc(var(--cell-x) - var(--s-2) - 1px); }
.filters select, .filters input {
  font: inherit; color: var(--ink); background-color: var(--panel); width: 100%; min-width: 0; appearance: none;
  height: var(--control); padding: 0 var(--s-2); border: 1px solid var(--line); border-radius: var(--r-control);
}
.filters input::placeholder { color: var(--muted); }
.filters select {
  padding-right: var(--s-6); text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 13px center, right 9px center; background-size: 4px 4px; background-repeat: no-repeat;
}
.filters select:hover, .filters input:hover { border-color: var(--muted); }
.filters .actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--s-4); }
.filters .reset { font-size: var(--fs-sm); }
#results { transition: opacity 0.15s; }
.filters.htmx-request ~ #results { opacity: 0.5; }
.count { margin: 0; padding: var(--s-2) var(--cell-x); border-top: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font-size: var(--fs-sm); }
.empty { margin: 0; padding: var(--s-8) var(--cell-x); text-align: center; color: var(--muted); }
.empty p { margin: 0; }
.empty p + p { margin-top: var(--s-2); }

table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { text-align: left; padding: var(--cell-y) var(--cell-x); border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
th { font-size: var(--fs-xs); font-weight: 600; color: var(--muted); background: var(--panel-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
th a { color: inherit; }
th a:hover { color: var(--ink); text-decoration: none; }
th a.active { color: var(--ink); }
tbody tr:last-child td { border-bottom: 0; }
col.c-repo { width: var(--c-repo); } col.c-env { width: var(--c-env); } col.c-state { width: var(--c-state); }
col.c-ref { width: var(--c-ref); } col.c-sha { width: var(--c-sha); } col.c-creator { width: var(--c-creator); } col.c-created { width: var(--c-created); }
col.c-when { width: 11rem; } col.c-by { width: 14rem; } col.c-links { width: 12rem; }
.statuses col.c-state { width: 7.5rem; }

.deployments tbody tr { position: relative; }
.deployments tbody tr:hover { background: var(--hover); }
.deployments .row-link { color: var(--ink); font-weight: 500; }
.deployments td.repo, .deployments td.env, .deployments td.git, .deployments td.creator { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deployments .row-link:hover { text-decoration: none; }
.deployments .row-link::after { content: ""; position: absolute; inset: 0; }
.deployments .row-link:focus-visible { outline: 0; }
.deployments tbody tr:has(.row-link:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
td.description, td.creator, td.created { color: var(--muted); }
td.created, td.when { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.when { color: var(--muted); }
.ref { font-weight: 500; }
.sha { color: var(--muted); }
.clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.links { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); }

.state {
  display: inline-block; padding: 0 var(--s-2); border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; line-height: 20px;
  background: var(--quiet-bg); color: var(--quiet); white-space: nowrap; vertical-align: middle;
}
.state-success { background: var(--ok-bg); color: var(--ok); }
.state-failure, .state-error { background: var(--bad-bg); color: var(--bad); }
.state-in_progress, .state-queued, .state-pending { background: var(--busy-bg); color: var(--busy); }
.forge-reconciled { color: var(--muted); }
.forge-mismatch { color: var(--bad); font-weight: 600; }
.forge-pending, .forge-sent { color: var(--busy); font-weight: 600; }

.facts {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(21rem, 1fr)); gap: var(--s-3) var(--s-6);
  margin: 0; padding: var(--s-4) var(--cell-x);
}
.facts > div { display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: var(--s-3); align-items: baseline; }
.facts > .full { grid-column: 1 / -1; }
.facts dt { color: var(--muted); font-size: var(--fs-xs); font-weight: 600; }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 1279px) {
  :root { --gutter: 20px; }
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: var(--s-3); align-items: end; }
  .filters label { padding-left: var(--cell-x); }
  .filters .vh { position: static; width: auto; height: auto; clip-path: none; display: block; margin-bottom: var(--s-1); font-size: var(--fs-xs); font-weight: 600; color: var(--muted); }
  .deployments colgroup, .deployments thead { display: none; }
  .deployments, .deployments tbody { display: block; }
  .deployments tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); }
  .deployments tbody tr:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .deployments tbody tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-1) var(--s-3); align-items: baseline;
    grid-template-areas: "repo state" "env created" "git creator" "sha sha" "desc desc";
    padding: var(--s-3) var(--cell-x); background: var(--panel); align-content: start;
  }
  .deployments tbody tr:hover { background: var(--hover); }
  .deployments td { display: block; padding: 0; border: 0; min-width: 0; }
  .deployments td.env, .deployments td.git, .deployments td.creator { white-space: normal; overflow: visible; }
  .deployments td.repo { grid-area: repo; }
  .deployments td.latest { grid-area: state; justify-self: end; }
  .deployments td.env { grid-area: env; }
  .deployments td.created { grid-area: created; justify-self: end; font-size: var(--fs-sm); }
  .deployments td.git { grid-area: git; overflow-wrap: anywhere; }
  .deployments td.commit { grid-area: sha; }
  .deployments td.creator { grid-area: creator; justify-self: end; text-align: right; font-size: var(--fs-sm); }
  .deployments td.description { grid-area: desc; font-size: var(--fs-sm); }
  .deployments td.description:empty { display: none; }
}
@media (max-width: 767px) {
  :root { --gutter: 16px; }
  main { padding-block: var(--s-4) var(--s-8); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .deployments tbody { grid-template-columns: minmax(0, 1fr); }
  .top button.link, .filters .reset { display: inline-flex; align-items: center; min-height: 44px; }
  .facts { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1023px) {
  .statuses colgroup, .statuses thead { display: none; }
  .statuses, .statuses tbody { display: block; }
  .statuses tbody tr {
    display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-1) var(--s-3); align-items: baseline;
    grid-template-areas: "state when" "desc desc" "by links";
    padding: var(--s-3) var(--cell-x); border-bottom: 1px solid var(--line);
  }
  .statuses tbody tr:last-child { border-bottom: 0; }
  .statuses td { display: block; padding: 0; border: 0; min-width: 0; }
  .statuses td.st { grid-area: state; }
  .statuses td.when { grid-area: when; justify-self: end; font-size: var(--fs-sm); }
  .statuses td.desc { grid-area: desc; }
  .statuses td.by { grid-area: by; color: var(--muted); font-size: var(--fs-sm); }
  .statuses td.links-cell { grid-area: links; justify-self: end; }
  .statuses td:empty, .statuses td.links-cell:not(:has(a)) { display: none; }
}
.log-status { margin: 0 0 var(--s-2); color: var(--muted); font-size: var(--fs-sm); }
.json-payload {
  margin: 0; padding: var(--s-4); background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-panel); overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5;
}
.deploy-log {
  margin: 0; background: #1b1b1b; color: #eee; border: 1px solid var(--line); border-radius: var(--r-panel);
  padding: var(--s-3) var(--cell-x); min-height: 4rem; max-height: 40rem; overflow: auto; white-space: pre-wrap;
  overflow-wrap: anywhere; font-family: var(--mono); font-size: var(--fs-sm); line-height: 1.5;
}
