:root {
  color-scheme: light dark;
  --bg: #ffffff; --fg: #1a1a1a; --muted: #6b7280; --line: #e5e7eb;
  --accent: #3451b2; --ok: #15803d; --fail: #b91c1c; --warn: #b45309;
  --chip-bg: #f3f4f6; --code-bg: #f6f8fa; --surface: #fafafa;
  --btn-bg: #f8fafc; --btn-hover: #eef2ff; --input-border: #cbd5e1;
  /* tinted backgrounds + readable foregrounds on them */
  --red-bg: #fee2e2;    --red-fg: #b91c1c;
  --green-bg: #dcfce7;  --green-fg: #15803d;
  --amber-bg: #ffedd5;  --amber-fg: #b45309;
  --yellow-bg: #fef9c3; --yellow-fg: #854d0e;
  --blue-bg: #dbeafe;   --blue-fg: #1e40af;
  --indigo-bg: #e0e7ff; --indigo-fg: #3730a3;
  --purple-bg: #ede9fe; --purple-fg: #5b21b6;
  --sky-bg: #e0f2fe;    --sky-fg: #075985;
  --gap-bg: #eef2f7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --fg: #dde1e6; --muted: #8b93a1; --line: #2a3038;
    --accent: #8ba7ff; --ok: #4ade80; --fail: #f87171; --warn: #fbbf24;
    --chip-bg: #21262e; --code-bg: #1a1e25; --surface: #191d23;
    --btn-bg: #21262e; --btn-hover: #2a3242; --input-border: #3b4350;
    --red-bg: #4b1d1d;    --red-fg: #fca5a5;
    --green-bg: #17301f;  --green-fg: #86efac;
    --amber-bg: #3c2a12;  --amber-fg: #fcd34d;
    --yellow-bg: #37310f; --yellow-fg: #fde68a;
    --blue-bg: #16263e;   --blue-fg: #93c5fd;
    --indigo-bg: #232244; --indigo-fg: #a5b4fc;
    --purple-bg: #2d2249; --purple-fg: #c4b5fd;
    --sky-bg: #12293a;    --sky-fg: #7dd3fc;
    --gap-bg: #1d222a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
nav {
  display: flex; gap: 1.2em; align-items: baseline; padding: 10px 20px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
nav .brand { font-weight: 700; color: var(--accent); text-decoration: none;
             display: inline-flex; align-items: center; gap: 7px; }
nav a { color: var(--fg); text-decoration: none; }
nav a:hover { color: var(--accent); }
nav a.active-project { font-weight: 700; color: var(--accent);
                       border-bottom: 2px solid var(--accent); }
main { margin: 0; padding: 16px 24px 60px; }
footer { padding: 8px 24px 16px; border-top: 1px solid var(--line); }
footer a { color: var(--muted); }
h1 { font-size: 1.35em; } h2 { font-size: 1.1em; margin-top: 1.6em; }
a { color: var(--accent); }
table { border-collapse: collapse; width: 100%; margin: .5em 0; }
th, td { text-align: left; padding: 4px 10px 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85em; }
code, .mono { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
code { background: var(--code-bg); padding: 1px 4px; border-radius: 3px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

.whoami { display: inline-flex; gap: 6px; align-items: center; }
.whoami img { width: 20px; height: 20px; border-radius: 50%; vertical-align: middle; }
.role-admin { background: var(--purple-bg); color: var(--purple-fg); }
.role-add-delete { background: var(--blue-bg); color: var(--blue-fg); }
.role-add { background: var(--green-bg); color: var(--ok); }
.role-read { background: var(--chip-bg); color: var(--muted); }
button.linky { border: none; background: none; padding: 0; color: var(--accent);
               text-decoration: underline; cursor: pointer; font-size: .9em; }

.chips { display: flex; gap: .6em; flex-wrap: wrap; margin: .8em 0; }
.chip { background: var(--chip-bg); border-radius: 999px; padding: 2px 12px; font-size: .9em; }
.chip b { font-size: 1.05em; }
.chip.ok b { color: var(--ok); } .chip.fail b { color: var(--fail); } .chip.warn b { color: var(--warn); }

.badge { display: inline-block; padding: 0 7px; border-radius: 4px; font-size: .8em; font-weight: 600; }
.st-test, .st-load { background: var(--green-bg); color: var(--ok); }
.st-fail { background: var(--red-bg); color: var(--fail); }
.st-crash { background: #7f1d1d; color: #fff; }
.st-kill { background: var(--amber-bg); color: var(--warn); }
.st-error { background: var(--indigo-bg); color: var(--indigo-fg); }
.st-skip { background: var(--chip-bg); color: var(--muted); }
.kind { background: var(--chip-bg); color: var(--muted); }
.kind.julia-regression { background: var(--red-bg); color: var(--fail); }
.kind.package-fault { background: var(--amber-bg); color: var(--warn); }
.kind.infra { background: var(--indigo-bg); color: var(--indigo-fg); }
.kind.tolerance { background: var(--yellow-bg); color: var(--yellow-fg); }
.workflow { background: var(--chip-bg); color: var(--muted); }
.status-needs-review { background: var(--yellow-bg); color: var(--yellow-fg); }
.status-open { background: var(--red-bg); color: var(--red-fg); }
.status-investigating { background: var(--purple-bg); color: var(--purple-fg); }
.status-fix-pending { background: var(--blue-bg); color: var(--blue-fg); }
.status-verified { background: var(--green-bg); color: var(--green-fg); }
.status-waived { background: var(--chip-bg); color: var(--muted); }
.severity { background: var(--chip-bg); color: var(--muted); }
.severity-blocker { background: var(--red-bg); color: var(--red-fg); }
.severity-high { background: var(--amber-bg); color: var(--amber-fg); }
.issue-open { background: var(--green-bg); color: var(--green-fg); }
.issue-closed { background: var(--purple-bg); color: var(--purple-fg); }
.tri-open { background: var(--red-bg); color: var(--fail); }
.tri-issue-filed { background: var(--blue-bg); color: var(--blue-fg); }
.tri-fixed-upstream { background: var(--green-bg); color: var(--ok); }
.tri-pkg-fault, .tri-ignored { background: var(--chip-bg); color: var(--muted); }

details { margin: .7em 0; border: 1px solid var(--line); border-radius: 6px; padding: 0 12px; }
details > summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
details[open] > summary { border-bottom: 1px solid var(--line); }
.singleton-cluster { margin: .7em 0; border: 1px solid var(--line); border-radius: 6px;
                     padding: 0 12px; }
.singleton-cluster-head { padding: 8px 0; font-weight: 600;
                          border-bottom: 1px solid var(--line); }

form.inline { display: inline-flex; gap: 6px; align-items: center; }
input[type=text], input[type=url], select, textarea {
  font: inherit; padding: 4px 8px; border: 1px solid var(--input-border); border-radius: 5px;
  background: var(--bg); color: var(--fg); max-width: 100%;
}
input[type=text].wide { width: 480px; }
button {
  font: inherit; padding: 4px 12px; border: 1px solid var(--input-border); border-radius: 5px;
  background: var(--btn-bg); color: var(--fg); cursor: pointer;
}
button:hover { background: var(--btn-hover); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--fail); }
.copy-command { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.copy-command svg { width: 15px; height: 15px; fill: none; stroke: currentColor;
                    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.copy-command.compact { margin-left: 6px; padding: 1px 7px; font-size: .78em;
                        font-weight: 400; vertical-align: middle; }
.copy-command.copied { color: var(--ok); border-color: var(--ok); }
.formbox { border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin: 1em 0; background: var(--surface); }
.formbox > div { margin: 6px 0; }
.issue-card { max-width: 900px; }

.errline { display: inline-block; max-width: 640px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* failure tables: fixed layout so the error column absorbs remaining width
   instead of forcing horizontal overflow */
table.fails { table-layout: fixed; width: 100%; }
table.fails td, table.fails th { overflow: hidden; }
table.fails td:nth-child(1) { width: 15%; }
table.fails td:nth-child(2) { width: 130px; }
table.fails td:nth-child(4) { width: 185px; }
table.fails td:nth-child(5) { width: 210px; }
table.fails .errline { display: block; max-width: none; }
table.fails select { max-width: 130px; }
.chart { width: 100%; max-width: 720px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.chart .axis { font-size: 11px; fill: var(--muted); }
.progress { display: inline-block; width: 160px; height: 10px; background: var(--chip-bg); border-radius: 5px; overflow: hidden; vertical-align: middle; }
.progress > i { display: block; height: 100%; background: var(--accent); }
.run-progress .progress { width: min(240px, 35vw); margin: 0 5px; }
.run-progress form { margin-left: 6px; }
.error-text { color: var(--fail); margin-top: 5px; }

pre.log { background: var(--code-bg); padding: 12px; border-radius: 8px; overflow-x: auto;
          font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
pre.log .err { background: var(--red-bg); display: inline-block; width: 100%; }
pre.log .cruft { color: var(--muted); }
pre.log.hidecruft .cruft { display: none; }
tr.disabled-run > td:not(:last-child) { opacity: .45; }

/* investigation notes and revisioned comment threads */
.notes-feed { display: grid; gap: 12px; max-width: 1100px; }
.note-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px;
             background: var(--surface); }
.note-card h2 { margin: 0 0 6px; }
.comment-head { display: flex; flex-wrap: wrap; gap: 7px; align-items: baseline;
                border-bottom: 1px solid var(--line); padding-bottom: 7px; margin-bottom: 8px; }
.comment-head .js-edit-toggle { margin-left: auto; }
.investigation-thread { max-width: 950px; margin: 1.2em 0; }
.investigation-note-panels { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
                             gap: 12px; align-items: start; }
.investigation-note-panels > .note-card { min-width: 0; }
.investigation-note-panels .comment-head { min-height: 31px; }
.human-note .comment-editor textarea { margin-top: 4px; }
.save-status { margin-left: 8px; }
.llm-note-entries { display: grid; gap: 10px; }
.llm-note-entries > .investigation-comment { padding: 8px 10px; }
.llm-note-entries > .empty-thread { margin: 0; }
.investigation-comments { display: grid; gap: 12px; }
.investigation-comment { border: 1px solid var(--line); border-radius: 8px;
                         background: var(--surface); padding: 10px 14px; }
.comment-editor textarea { width: 100%; display: block; margin: 8px 0;
                           font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
                           resize: vertical; }
.form-error { color: var(--fail); margin-left: 8px; }
.filterbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: .8em 0; }
.filterbar a { padding: 2px 8px; border-radius: 999px; text-decoration: none;
               background: var(--chip-bg); }
.filterbar a.selected { color: #fff; background: var(--accent); }

/* rendered markdown */
.md { line-height: 1.55; }
.md p, .md ul, .md ol, .md table, .md blockquote, .md pre { margin: .5em 0; }
.md ul, .md ol { padding-left: 1.5em; }
.md h1, .md h2, .md h3, .md h4 { margin: .8em 0 .3em; font-size: 1.05em; }
.md pre { background: var(--code-bg); padding: 8px 12px; border-radius: 6px; overflow-x: auto;
          font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--line); padding: 3px 8px; }

.banner { padding: 8px 14px; border-radius: 6px; background: var(--yellow-bg); margin: .8em 0; }
.banner.error { background: var(--red-bg); }
.banner.ok { background: var(--green-bg); }
.cluster-head { display: flex; gap: 1em; align-items: baseline; }
.cluster-head .n { font-weight: 700; color: var(--fail); }

pre.log .d-add { display: block; background: var(--red-bg); }
pre.log .d-del { display: block; background: var(--green-bg); }
pre.log a.d-gap { display: block; background: var(--gap-bg); color: var(--muted);
                  text-decoration: none; padding: 1px 8px; }
pre.log a.d-gap:hover { background: var(--btn-hover); }
.d-badge-add { background: var(--red-bg); color: var(--red-fg); }
.d-badge-del { background: var(--green-bg); color: var(--green-fg); }

.badge.dsb { background: var(--sky-bg); color: var(--sky-fg); font-weight: 500; }
a.badge.dsb { text-decoration: none; }
a.badge.dsb[href]:hover { text-decoration: underline; }
table.fails tr:target > td { background: var(--sky-bg); }
.ds-label { display: block; margin: 8px 0 0; cursor: pointer; }

tr.peek-row > td { padding: 2px 0 12px; }
tr.peek-row pre.log { max-height: 420px; overflow: auto; margin: 4px 0 0; }
.peek-head { margin-top: 4px; }

.layout { display: grid; grid-template-columns: var(--sbw, 260px) 6px minmax(0, 1fr);
          gap: 8px; align-items: start; }
.sidebar { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto;
           border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
           font-size: .82em; background: var(--surface); }
.sb-resize { position: sticky; top: 12px; height: calc(100vh - 24px); cursor: col-resize;
             border-radius: 3px; touch-action: none; }
.sb-resize:hover, .sb-resize.dragging { background: var(--line); }
.sidebar h3 { margin: 10px 0 4px; font-size: 1em; }
.sidebar label { display: flex; gap: 6px; align-items: baseline; cursor: pointer; }
.sidebar ul { list-style: none; margin: 2px 0 8px; padding-left: 16px; }
.sidebar li { margin: 1px 0; display: flex; gap: 5px; align-items: baseline; }
.sidebar li a { text-decoration: none; overflow: hidden; text-overflow: ellipsis;
                white-space: nowrap; flex: 1; min-width: 0; }
.sidebar .cnt { color: var(--muted); margin-left: auto; padding-left: 6px; }
.sidebar input[type=checkbox] { margin: 0; flex: none; }
.sb-head { display: flex; gap: 5px; align-items: baseline; }
.sb-head label { flex: 1; min-width: 0; }
.sidebar .fold { display: inline-block; width: 1em; flex: none;
                 color: var(--muted); text-decoration: none; }
.sidebar .sb-bucket.singleton > .sb-head { padding-left: calc(1em + 5px); }
.sidebar .fold::before { content: '▾'; }
.folded > h3 .fold::before, .folded > .sb-head .fold::before { content: '▸'; }
.sb-sec.folded > :not(h3) { display: none; }
.sb-bucket.folded > ul { display: none; }
@media (max-width: 950px) { .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; } .sb-resize { display: none; } }
@media (max-width: 760px) { .investigation-note-panels { grid-template-columns: 1fr; } }
