:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --accent: #4b3fd1;
  --accent-text: #ffffff;
  --ok: #18794e;
  --ok-bg: #e3f5ea;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --info: #1f5fbf;
  --info-bg: #e3edfc;
  --code-bg: #f3f4f7;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232b;
    --text: #e6e9ee;
    --muted: #96a1b0;
    --border: #2a313b;
    --accent: #8c82ff;
    --accent-text: #0f1216;
    --ok: #4cc38a;
    --ok-bg: #12301f;
    --warn: #f0b43c;
    --warn-bg: #33280e;
    --bad: #ff7a6b;
    --bad-bg: #3a1714;
    --info: #79a8ff;
    --info-bg: #142540;
    --code-bg: #12161b;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; line-height: 1.3; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
h3 { font-size: .95rem; margin: 1rem 0 .35rem; }
code, pre { font-family: var(--mono); font-size: .85em; }
code { background: var(--code-bg); padding: .05em .3em; border-radius: 4px; }
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem;
  margin: .4rem 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 32rem;
  overflow: auto;
}
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ── header ───────────────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.top nav a { padding: .3rem .65rem; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.top nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.top nav a:hover { text-decoration: none; color: var(--text); }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: .3rem; }
button.link:hover { color: var(--text); }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 6rem; }
main:focus { outline: none; }

/* ── building blocks ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: var(--shadow);
}
.banner {
  background: var(--info-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: .7rem 1rem; margin-bottom: 1.25rem;
}
.back { display: inline-block; margin-bottom: .6rem; font-size: .9rem; }
.badge {
  display: inline-block; vertical-align: middle;
  font-size: .75rem; font-weight: 600; line-height: 1.6;
  padding: 0 .5rem; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.badge.running, .badge.reviewing, .badge.queued { background: var(--info-bg); color: var(--info); }
.badge.done, .badge.published, .badge.VERIFIED { background: var(--ok-bg); color: var(--ok); }
.badge.waiting, .badge.stopped, .badge.PARTIAL, .badge.interrupted { background: var(--warn-bg); color: var(--warn); }
.badge.failed, .badge.rejected, .badge.REJECT { background: var(--bad-bg); color: var(--bad); }
.badge.running::before { content: ""; display: inline-block; width: .5em; height: .5em; border-radius: 50%; background: currentColor; margin-right: .35em; animation: pulse 1.4s infinite; vertical-align: .05em; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .badge.running::before { animation: none; } }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .5rem 1rem; margin: 1rem 0; }
.facts div { min-width: 0; }
.facts dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .5rem 0 1rem; }

.meter { display: flex; align-items: center; gap: .6rem; margin: .3rem 0; }
.meter .label { width: 6.5rem; flex: none; color: var(--muted); font-size: .9rem; }
.meter .track { flex: 1; height: .55rem; background: var(--surface-2); border-radius: 99px; overflow: hidden; position: relative; max-width: 420px; }
.meter .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.meter .start { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .5; }
.meter .value { font-variant-numeric: tabular-nums; font-size: .9rem; min-width: 7rem; }

/* ── lists ────────────────────────────────────────────────────── */
.runs { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.runs a { display: block; color: inherit; }
.runs a:hover { text-decoration: none; border-color: var(--accent); }
.runs .card { padding: .75rem 1rem; }
.runs .title { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.runs .title b { font-size: 1.02rem; }
.runs .minor { opacity: .75; }

.tasks { display: grid; gap: .4rem; }
.task {
  display: grid; grid-template-columns: 2.2rem 1fr auto; gap: .15rem .75rem; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: .55rem .75rem; color: inherit;
}
.task:hover { text-decoration: none; border-color: var(--accent); }
.task .id { font-family: var(--mono); font-size: .85rem; color: var(--muted); padding-top: .1rem; }
.task .main { min-width: 0; }
.task .t, .task .sub, .task .live { display: block; }
.task .t { font-weight: 500; overflow-wrap: anywhere; }
.task .sub { font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.task .live { font-family: var(--mono); font-size: .78rem; color: var(--info); overflow-wrap: anywhere; margin-top: .15rem; }
.task .side { text-align: right; display: grid; gap: .2rem; justify-items: end; }

table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.table-wrap { overflow-x: auto; }

details > summary { cursor: pointer; }
details.section { margin: 1rem 0; }
details.section > summary { font-weight: 600; padding: .3rem 0; }

/* ── task page ────────────────────────────────────────────────── */
.prose { white-space: pre-wrap; overflow-wrap: anywhere; }
.acceptance { padding-left: 1.2rem; margin: .3rem 0; }
.acceptance li { margin: .2rem 0; }
.acceptance .met { color: var(--ok); }
.acceptance .unmet { color: var(--bad); }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin: .5rem 0; }
.tabs button {
  font: inherit; font-size: .85rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .25rem .7rem; border-radius: 99px;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.feed-bar { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin: .3rem 0; }
.feed { display: grid; gap: .15rem; font-size: .88rem; }
.ev { display: grid; grid-template-columns: 3.2rem 1.3rem 1fr; gap: .4rem; align-items: start; padding: .2rem .3rem; border-radius: 6px; }
.ev:hover { background: var(--surface-2); }
.ev .at { font-family: var(--mono); font-size: .78rem; color: var(--muted); padding-top: .12rem; }
.ev .mk { text-align: center; }
.ev .body { min-width: 0; overflow-wrap: anywhere; }
.ev.tool .body summary, .ev.tool .body > span { font-family: var(--mono); font-size: .82rem; }
.ev summary { list-style: none; }
.ev summary::-webkit-details-marker { display: none; }
.ev details[open] > summary { font-weight: 600; }
.ev.text .body { white-space: pre-wrap; }
.ev.error .body { color: var(--bad); font-family: var(--mono); font-size: .8rem; white-space: pre-wrap; }
.ev.done { font-weight: 600; }
.ev.failed summary { color: var(--bad); }
.ev pre { max-height: 22rem; font-size: .78rem; }
.ev .out-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: .3rem; }
.ev .out-label.err { color: var(--bad); }
.ev.output .body { color: var(--muted); font-family: var(--mono); font-size: .78rem; }

/* ── repos page ───────────────────────────────────────────────── */
.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: .75rem 0; }
input[type="search"], input[type="password"], textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem;
}
input[type="search"] { flex: 1; min-width: 12rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg label { padding: .2rem .55rem; font-size: .8rem; cursor: pointer; border-left: 1px solid var(--border); white-space: nowrap; }
.seg label:first-child { border-left: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--surface-2); font-weight: 600; }
.seg label.p:has(input:checked) { background: var(--accent); color: var(--accent-text); }
.seg label.x:has(input:checked) { background: var(--bad-bg); color: var(--bad); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
tr.changed td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.repo-name { font-weight: 600; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: .75rem; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: .7rem 16px calc(.7rem + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); box-shadow: var(--shadow);
}
button.primary, button.secondary, label.secondary {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 8px; padding: .45rem 1rem; border: 1px solid var(--accent);
}
button.primary { background: var(--accent); color: var(--accent-text); }
button.secondary, label.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button:disabled { opacity: .5; cursor: default; }
.error { color: var(--bad); }
.notice { color: var(--ok); }

/* ── schedule page ────────────────────────────────────────────── */
.schedule-form { display: grid; gap: .9rem; }
.schedule-form fieldset { border: 0; padding: 0; margin: 0; }
.schedule-form legend { font-weight: 600; margin-bottom: .4rem; padding: 0; }
.days { display: flex; gap: .4rem; flex-wrap: wrap; }
.day { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--border); border-radius: 8px; padding: .3rem .6rem; cursor: pointer; }
.day:has(input:checked) { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.fields { display: flex; gap: .75rem 1.5rem; flex-wrap: wrap; }
.fields label { display: grid; gap: .25rem; font-size: .9rem; }
.fields .inline { display: inline-flex; align-items: center; gap: .4rem; }
.fields input[type=number] { width: 4.5rem; }
input[type=time], input[type=number] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .55rem; }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
tr.off td { color: var(--muted); }

/* ── prompts page ─────────────────────────────────────────────── */
.prompt-card { margin-bottom: 1rem; }
.prompt-card pre { max-height: 40rem; }

/* ── login ────────────────────────────────────────────────────── */
body.login main { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: .6rem; }
.login-card h1 { margin-bottom: .5rem; }

/* ── feedback widget ──────────────────────────────────────────── */
.fb-button {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 30;
  font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer;
  background: var(--text); color: var(--bg); border: 0; border-radius: 99px;
  padding: .5rem .9rem; box-shadow: var(--shadow); opacity: .92;
}
body:has(.savebar) .fb-button { bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
.fb-dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.fb-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.fb-dialog h2 { margin: 0 0 .6rem; }
.fb-dialog form { display: grid; gap: .65rem; }
.fb-dialog textarea { width: 100%; min-height: 7rem; resize: vertical; }
.fb-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.fb-drop { border: 1.5px dashed var(--border); border-radius: 8px; padding: .6rem; font-size: .85rem; color: var(--muted); }
.fb-drop.over { border-color: var(--accent); background: var(--surface-2); }
.fb-thumbs { display: flex; gap: .5rem; flex-wrap: wrap; }
.fb-thumbs figure { margin: 0; position: relative; }
.fb-thumbs img { height: 64px; border-radius: 6px; border: 1px solid var(--border); display: block; }
.fb-thumbs button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); cursor: pointer; font-size: 12px; line-height: 20px; padding: 0; }
.fb-actions { display: flex; justify-content: flex-end; gap: .5rem; }
@media print { .fb-button, .fb-dialog, .savebar, .top { display: none !important; } }

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .task { grid-template-columns: 2rem 1fr; }
  .task .side { grid-column: 2; justify-items: start; text-align: left; display: flex; gap: .4rem; flex-wrap: wrap; }
  .ev { grid-template-columns: 2.6rem 1.1rem 1fr; }
  .hide-sm { display: none; }
  .top { gap: .4rem .75rem; padding-bottom: .4rem; }
  .top .brand { flex: 1; }
  .top nav { order: 3; flex-basis: 100%; gap: 0; }
  .top nav a { padding: .3rem .45rem; }
  /* Repos: one block per repo, the choice under its name, so all three options fit. */
  .repos-table thead { display: none; }
  .repos-table, .repos-table tbody, .repos-table tr, .repos-table td { display: block; }
  .repos-table tr { padding: .5rem 0; border-bottom: 1px solid var(--border); }
  .repos-table td { border: 0; padding: .15rem 0; }
  .repos-table td.hide-sm { display: inline; font-size: .8rem; color: var(--muted); }
  .repos-table td.hide-sm + td.hide-sm::before { content: " · "; }
  .repos-table td.lastnight::before { content: " · last night: " !important; }
  .repos-table tr.changed { box-shadow: inset 3px 0 0 var(--warn); padding-left: .5rem; }
  .repos-table tr.changed td:first-child { box-shadow: none; }
  .fb-button { padding: .45rem .8rem; font-size: .82rem; }
}
