:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-subtle: #f6f8fa;
  --bg-hover: #eaeef2;
  --bg-active: #ddf4ff;
  --fg: #1f2328;
  --fg-muted: #59636e;
  --border: #d1d9e0;
  --accent: #0969da;
  --success: #1a7f37;
  --danger: #d1242f;
  --danger-bg: #ffebe9;
  --warning: #9a6700;
  --warning-bg: #fff8c5;
  --notice-bg: #ddf4ff;
  --log-bg: #f6f8fa;
  --log-fg: #1f2328;
  --log-muted: #6e7781;
  --log-hover: #eaeef2;
  --log-hl: #fff8c5;
  --sealed: #8250df;
  --sealed-bg: #fbefff;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  --radius: 6px;

  --ansi-black: #24292f;
  --ansi-red: #cf222e;
  --ansi-green: #116329;
  --ansi-yellow: #4d2d00;
  --ansi-blue: #0969da;
  --ansi-magenta: #8250df;
  --ansi-cyan: #1b7c83;
  --ansi-white: #6e7781;
  --ansi-bright-black: #57606a;
  --ansi-bright-red: #a40e26;
  --ansi-bright-green: #1a7f37;
  --ansi-bright-yellow: #633c01;
  --ansi-bright-blue: #218bff;
  --ansi-bright-magenta: #a475f9;
  --ansi-bright-cyan: #3192aa;
  --ansi-bright-white: #8c959f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-subtle: #151b23;
    --bg-hover: #212830;
    --bg-active: #1f2a3a;
    --fg: #f0f6fc;
    --fg-muted: #9198a1;
    --border: #3d444d;
    --accent: #4493f8;
    --success: #3fb950;
    --danger: #f85149;
    --danger-bg: #25171c;
    --warning: #d29922;
    --warning-bg: #272115;
    --notice-bg: #121d2f;
    --log-bg: #010409;
    --log-fg: #e6edf3;
    --log-muted: #7d8590;
    --log-hover: #161b22;
    --log-hl: #3b2e00;
    --sealed: #ab7df8;
    --sealed-bg: #1d1530;

    --ansi-black: #484f58;
    --ansi-red: #ff7b72;
    --ansi-green: #3fb950;
    --ansi-yellow: #d29922;
    --ansi-blue: #58a6ff;
    --ansi-magenta: #bc8cff;
    --ansi-cyan: #39c5cf;
    --ansi-white: #b1bac4;
    --ansi-bright-black: #6e7681;
    --ansi-bright-red: #ffa198;
    --ansi-bright-green: #56d364;
    --ansi-bright-yellow: #e3b341;
    --ansi-bright-blue: #79c0ff;
    --ansi-bright-magenta: #d2a8ff;
    --ansi-bright-cyan: #56d4dd;
    --ansi-bright-white: #f0f6fc;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--sans);
  overflow-x: hidden;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 12px var(--mono); background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.muted { color: var(--fg-muted); }

/* ---- buttons and inputs ---- */
.btn {
  font: 500 13px/20px var(--sans);
  color: var(--fg);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-small { font-size: 12px; padding: 2px 10px; }
.btn-primary { background: var(--success); border-color: transparent; color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--success); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
input[type="text"], input[type="password"], input[type="search"] {
  font: 14px var(--sans);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  min-width: 0;
}
input:focus-visible, .btn:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.framed { margin: 48px 16px; text-align: center; font-weight: 600; }

/* ---- top bar and banner ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  min-width: 0;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--fg); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.run-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; flex: 1; min-width: 0; }
.run-link { font-weight: 600; color: var(--fg); overflow-wrap: anywhere; }
.chip { font-size: 12px; color: var(--fg-muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.attempts { font-size: 12px; color: var(--fg-muted); }
.attempt { display: inline-block; min-width: 20px; text-align: center; border-radius: 4px; padding: 0 4px; }
.attempt.current { background: var(--bg-active); font-weight: 600; }

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--danger-bg);
  color: var(--fg);
  border-bottom: 1px solid var(--danger);
}
.banner-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* ---- pick a run ---- */
.pick { max-width: 640px; margin: 48px auto; padding: 0 16px; }
.pick h1 { font-size: 20px; margin: 0 0 8px; }
.pick-form { display: flex; gap: 8px; }
.pick-form input { flex: 1; }

/* ---- layout ---- */
.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: calc(100vh - 53px); }
.sidebar { border-right: 1px solid var(--border); padding: 12px 8px; min-width: 0; }
.side-h { font-size: 12px; font-weight: 600; color: var(--fg-muted); margin: 8px 8px 4px; text-transform: uppercase; letter-spacing: .04em; }
.jobs { list-style: none; margin: 0 0 12px; padding: 0; }
.job {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  color: var(--fg);
}
.job:hover { background: var(--bg-hover); text-decoration: none; }
.job.active { background: var(--bg-active); font-weight: 600; }
.job-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-dur { font-size: 12px; color: var(--fg-muted); white-space: nowrap; }

.content { padding: 16px; min-width: 0; }
.content-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.job-title { display: flex; align-items: center; gap: 8px; font-size: 18px; margin: 0; min-width: 0; overflow-wrap: anywhere; }
.job-title-dur { font-size: 13px; font-weight: 400; color: var(--fg-muted); }
.tools { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tools input[type="search"] { width: 220px; max-width: 100%; }
.toggle { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--fg-muted); white-space: nowrap; }
.notice { margin: 0 0 12px; padding: 8px 12px; border-radius: var(--radius); background: var(--notice-bg); border: 1px solid var(--border); }
.loading { color: var(--fg-muted); }

/* ---- status icons (text glyphs, no images) ---- */
.icon { display: inline-grid; place-items: center; flex: 0 0 auto; width: 16px; height: 16px; border-radius: 50%; font-size: 10px; font-weight: 700; line-height: 1; color: #fff; }
.icon-success { background: var(--success); }
.icon-success::before { content: "✓"; }
.icon-failure, .icon-timed_out { background: var(--danger); }
.icon-failure::before { content: "✕"; }
.icon-timed_out::before { content: "!"; }
.icon-cancelled, .icon-skipped, .icon-neutral, .icon-action_required { background: var(--fg-muted); }
.icon-cancelled::before { content: "⊘"; font-size: 12px; }
.icon-skipped::before { content: "–"; }
.icon-neutral::before { content: "–"; }
.icon-action_required::before { content: "!"; }
.icon-queued { border: 2px solid var(--fg-muted); }
.icon-running { border: 2px solid var(--warning); border-right-color: transparent; animation: spin 1s linear infinite; }
.icon-step { width: 8px; height: 8px; background: var(--fg-muted); margin: 0 4px; }
.icon-box { border-radius: 3px; background: var(--fg-muted); }
.icon-box::before { content: "▤"; font-size: 11px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-running { animation: none; } }

/* ---- log ---- */
.log { background: var(--log-bg); color: var(--log-fg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.step { border-top: 1px solid var(--border); }
.step:first-child { border-top: 0; }
.step-h {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  min-width: 0;
}
.step-h::-webkit-details-marker { display: none; }
.step-h:hover { background: var(--log-hover); }
.chev { width: 0; height: 0; border-left: 5px solid var(--log-muted); border-top: 4px solid transparent; border-bottom: 4px solid transparent; transition: transform .1s; flex: 0 0 auto; }
.step[open] > .step-h .chev { transform: rotate(90deg); }
.step-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 13px; }
.step-h.failed .step-title { color: var(--danger); }
.step-sealed { font-size: 11px; color: var(--sealed); border: 1px solid var(--sealed); border-radius: 999px; padding: 0 6px; }
.step-dur { font-size: 12px; color: var(--log-muted); white-space: nowrap; }

.lines {
  overflow-x: auto;
  font: 12px/20px var(--mono);
  padding-bottom: 8px;
}
.line { display: flex; white-space: pre; min-width: max-content; }
.line:hover { background: var(--log-hover); }
.line.hl, .line:target { background: var(--log-hl); }
.ln {
  position: sticky;
  left: 0;
  flex: 0 0 auto;
  width: 56px;
  padding-right: 8px;
  text-align: right;
  color: var(--log-muted);
  background: var(--log-bg);
  user-select: none;
}
.line:hover .ln, .line.hl .ln { background: inherit; }
.ln:hover { color: var(--log-fg); text-decoration: none; }
.gut { flex: 0 0 auto; width: 16px; border-left: 2px solid transparent; }
.line.sealed .gut { border-left-color: var(--sealed); }
.line.sealed .gut::before { content: "🔒"; font-size: 9px; opacity: .55; padding-left: 1px; }
.line.sealed:not(:first-child) .gut::before { content: ""; }
.line:not(.sealed) + .line.sealed .gut::before { content: "🔒"; }
.ts { display: none; flex: 0 0 auto; color: var(--log-muted); padding-right: 12px; }
.log.show-ts .ts { display: inline; }
.tx { padding-right: 16px; }
.line.unavailable .tx { color: var(--sealed); font-style: italic; }
.l-error .tx { color: var(--danger); }
.l-error { background: var(--danger-bg); }
.l-warning .tx { color: var(--warning); }
.l-warning { background: var(--warning-bg); }
.l-notice .tx { color: var(--accent); }
.l-debug .tx { color: var(--ansi-magenta); }
.l-command .tx { color: var(--accent); }
.l-group .tx { font-weight: 600; }
.tx a { color: inherit; text-decoration: underline; }

.step-summary { margin: 0 12px 12px 72px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--fg); }
.step-summary-h { font-size: 12px; font-weight: 600; padding: 4px 10px; border-bottom: 1px solid var(--border); color: var(--fg-muted); }
.step-summary pre { margin: 0; padding: 8px 10px; font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ANSI colours (class mode; the CSP forbids inline styles). */
.ansi-black-fg { color: var(--ansi-black); }
.ansi-red-fg { color: var(--ansi-red); }
.ansi-green-fg { color: var(--ansi-green); }
.ansi-yellow-fg { color: var(--ansi-yellow); }
.ansi-blue-fg { color: var(--ansi-blue); }
.ansi-magenta-fg { color: var(--ansi-magenta); }
.ansi-cyan-fg { color: var(--ansi-cyan); }
.ansi-white-fg { color: var(--ansi-white); }
.ansi-bright-black-fg { color: var(--ansi-bright-black); }
.ansi-bright-red-fg { color: var(--ansi-bright-red); }
.ansi-bright-green-fg { color: var(--ansi-bright-green); }
.ansi-bright-yellow-fg { color: var(--ansi-bright-yellow); }
.ansi-bright-blue-fg { color: var(--ansi-bright-blue); }
.ansi-bright-magenta-fg { color: var(--ansi-bright-magenta); }
.ansi-bright-cyan-fg { color: var(--ansi-bright-cyan); }
.ansi-bright-white-fg { color: var(--ansi-bright-white); }
.ansi-black-bg { background-color: var(--ansi-black); }
.ansi-red-bg { background-color: var(--ansi-red); }
.ansi-green-bg { background-color: var(--ansi-green); }
.ansi-yellow-bg { background-color: var(--ansi-yellow); }
.ansi-blue-bg { background-color: var(--ansi-blue); }
.ansi-magenta-bg { background-color: var(--ansi-magenta); }
.ansi-cyan-bg { background-color: var(--ansi-cyan); }
.ansi-white-bg { background-color: var(--ansi-white); }
.ansi-bright-black-bg { background-color: var(--ansi-bright-black); }
.ansi-bright-red-bg { background-color: var(--ansi-bright-red); }
.ansi-bright-green-bg { background-color: var(--ansi-bright-green); }
.ansi-bright-yellow-bg { background-color: var(--ansi-bright-yellow); }
.ansi-bright-blue-bg { background-color: var(--ansi-bright-blue); }
.ansi-bright-magenta-bg { background-color: var(--ansi-bright-magenta); }
.ansi-bright-cyan-bg { background-color: var(--ansi-bright-cyan); }
.ansi-bright-white-bg { background-color: var(--ansi-bright-white); }
.ansi-bold { font-weight: 700; }
.ansi-faint { opacity: .7; }
.ansi-italic { font-style: italic; }
.ansi-underline { text-decoration: underline; }

/* ---- artifacts ---- */
.art { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.art-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 12px; background: var(--bg-subtle); }
.art-name { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.art-meta { font-size: 12px; color: var(--fg-muted); }
.art-body:empty { display: none; }
.art-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--border); }
.entry { border-top: 1px solid var(--border); }
.entry > summary { list-style: none; cursor: pointer; }
.entry > summary::-webkit-details-marker { display: none; }
.entry-h { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 6px 12px; }
.entry > summary:hover .entry-h { background: var(--bg-hover); }
.entry-path { flex: 1; min-width: 0; font: 12px var(--mono); overflow-wrap: anywhere; }
.preview-note { margin: 0; padding: 6px 12px; border-top: 1px solid var(--border); font-size: 13px; }
.preview {
  margin: 0;
  padding: 8px 12px;
  max-height: 480px;
  overflow: auto;
  font: 12px/1.5 var(--mono);
  background: var(--log-bg);
  color: var(--log-fg);
  border-top: 1px solid var(--border);
}

/* ---- settings dialog ---- */
.dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  padding: 20px;
}
.dialog::backdrop { background: rgb(1 4 9 / .5); }
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog input { width: 100%; font-family: var(--mono); font-size: 13px; }
.field { display: block; font-weight: 600; margin: 16px 0 6px; }
.hint { color: var(--fg-muted); font-size: 13px; margin: 6px 0 0; }
.field-error { color: var(--danger); font-size: 13px; margin: 6px 0 0; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 20px; }
.spacer { flex: 1; }

/* ---- phone width ---- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; }
  .run-meta { order: 3; flex-basis: 100%; }
  .layout { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); padding: 8px; max-height: 40vh; overflow-y: auto; }
  .content { padding: 12px 16px; }
  .tools { flex-wrap: wrap; width: 100%; }
  .tools input[type="search"] { flex: 1; width: auto; }
  .ln { width: 44px; }
  .step-summary { margin-left: 12px; }
  .pick-form { flex-direction: column; }
}
