:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5d6878;
  --line: #dfe3ea;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --green-bg: #dcf5e6; --green: #146c3a;
  --grey-bg: #eceff3; --grey: #3f4a5a;
  --amber-bg: #fdf0d3; --amber: #8a5300;
  --violet-bg: #ede7fb; --violet: #5b3aa8;
  --red-bg: #fde2e2; --red: #a3201f;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --card: #1b2129;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --line: #2d3540;
    --accent: #8b85ff;
    --accent-text: #12161c;
    --green-bg: #173a27; --green: #8be0ad;
    --grey-bg: #2a313b; --grey: #c9d0da;
    --amber-bg: #3d2f12; --amber: #f3c46b;
    --violet-bg: #30264a; --violet: #c9b6ff;
    --red-bg: #46201f; --red: #ffaaa8;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.4rem; margin: 0 0 0.2rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.error { color: var(--red); background: var(--red-bg); padding: 0.5rem 0.75rem; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.top, main { max-width: 960px; margin: 0 auto; padding: 1.25rem 1rem 0; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
main { padding-bottom: 2rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; margin-bottom: 1rem; }
.narrow { max-width: 380px; margin: 12vh auto 0; }
.login form { display: grid; gap: 0.6rem; margin-top: 1rem; }

label { font-weight: 600; }
textarea, input[type="password"], select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
}
textarea { margin-top: 0.4rem; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; }
select { width: auto; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-top: 0.9rem; }
.spread { justify-content: space-between; margin: 0 0 0.9rem; }
.spread h2 { margin: 0; }
fieldset { border: 0; padding: 0; }
legend { font-weight: 600; margin-bottom: 0.3rem; width: 100%; }
.choice { font-weight: 400; display: flex; gap: 0.4rem; align-items: center; }

button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.link { border: 0; background: none; color: var(--muted); padding: 0.25rem; text-decoration: underline; }
.file { font-weight: 400; cursor: pointer; }
.file input { position: absolute; opacity: 0; width: 1px; }
.file span { display: inline-block; border: 1px dashed var(--line); border-radius: 6px; padding: 0.45rem 0.9rem; }
.file input:focus-visible + span, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
progress { width: 100%; margin-top: 0.9rem; accent-color: var(--accent); }

.summary { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }
.badge { display: inline-block; border-radius: 999px; padding: 0.05rem 0.6rem; font-size: 0.82rem; font-weight: 600; white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.grey { background: var(--grey-bg); color: var(--grey); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.violet { background: var(--violet-bg); color: var(--violet); }

.job { padding: 0.75rem 0; border-top: 1px solid var(--line); }
.job:first-child { border-top: 0; padding-top: 0; }
.job .row { margin-top: 0.4rem; }
.job progress { margin-top: 0.6rem; height: 0.7rem; }
.counts { display: inline-flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; margin-top: 0.5rem; }
.job .counts { margin-top: 0.6rem; }
td .counts { margin-top: 0; }
.count { white-space: nowrap; font-variant-numeric: tabular-nums; }
progress { font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 0.4rem 0.5rem; }
td { border-bottom: 1px solid var(--line); padding: 0.45rem 0.5rem; vertical-align: top; }
#history td:first-child, #history td:nth-child(6), #api-recent td:first-child, #api-recent td:nth-child(4) { white-space: nowrap; }
.error-text { color: var(--red); }

.legend { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 0.9rem; margin: 0 0 0.75rem; }
.legend dd { margin: 0; }
@media (max-width: 560px) {
  .legend { grid-template-columns: 1fr; }
  .legend dd { margin-bottom: 0.4rem; }
  /* Rows as small cards: three columns don't fit on a phone */
  table, tbody, tr, td { display: block; }
  thead { display: none; }
  tr { border-bottom: 1px solid var(--line); padding: 0.5rem 0; }
  td { border: 0; padding: 0.15rem 0; }
  td:first-child { font-weight: 600; }
  td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-weight: 400; }
}
