/* Review viewer for modern Chrome (§4). */

:root {
  /* template.ts sets --bg, --text, and color-scheme from the active Shiki theme. Other page colours derive from these; defaults match plastic. */
  --bg: #21252b;
  --text: #a9b2c3;
  --bg-raised: color-mix(in srgb, var(--text) 5%, var(--bg));
  --bg-sidebar: color-mix(in srgb, var(--text) 8%, var(--bg));
  --bg-hover: color-mix(in srgb, var(--text) 8%, transparent);
  --border: color-mix(in srgb, var(--text) 14%, transparent);
  --border-strong: color-mix(in srgb, var(--text) 26%, transparent);
  --text-dim: color-mix(in srgb, var(--text) 65%, var(--bg));
  --text-faint: color-mix(in srgb, var(--text) 42%, var(--bg));
  /* accent + diff + severity stay theme-independent: muted tones that read on any dark editor background. */
  --accent: #6a9fb5;
  --add-bg: color-mix(in srgb, #6a8759 14%, transparent);
  --add-bg-strong: color-mix(in srgb, #6a8759 24%, transparent);
  --add-fg: #a5c261;
  --del-bg: color-mix(in srgb, #cc6666 13%, transparent);
  --del-bg-strong: color-mix(in srgb, #cc6666 22%, transparent);
  --del-fg: #cc7a7a;
  --severity-review: #cc9955;
  --severity-nit: #6a9fb5;
  --severity-fyi: #808b94;
  --danger: #cc6666;
  --radius: 6px;
  /* Shared top offset for sticky headers and collapse scrolling; mobile clears the fixed nav toggle. */
  --sticky-top: 0px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --sidebar-w: 280px;
}

/* ---------- reset ---------- */
/* Reset browser defaults before applying component styles. */

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

h1,
h2,
h3,
h4,
p,
ul,
ol,
figure {
  margin: 0;
}

ul,
ol {
  list-style: none;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
}

a {
  color: inherit;
  text-decoration: none;
}

img,
svg {
  display: block;
  max-width: 100%;
}

html {
  scroll-behavior: smooth;
  interpolate-size: allow-keywords;
  /* Reserve scrollbar space so expanding diffs / gap fills don't shift the sticky sidebar a few pixels. */
  scrollbar-gutter: stable;
}

html,
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  /* clip (not hidden) so we don't create a scroll containment that breaks position:sticky on file headers */
  overflow-x: clip;
}

.touch-target {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

@media (pointer: coarse) {
  button,
  .line-num,
  input[type="checkbox"] {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ---------- layout ---------- */

.nav-toggle-input {
  position: absolute;
}

.layout {
  display: grid;
  grid-template-columns: auto 1fr;
  min-height: 100vh;
}

.sidebar {
  grid-column: 1;
  width: var(--sidebar-w);
  min-width: 200px;
  max-width: 480px;
  /* Sticky full-viewport chrome: stays pinned while main scrolls; own scrollport for long nav trees. */
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  max-height: 100dvh;
  resize: horizontal;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  /* Rows own the padding so the nav band fills the sidebar width. .bucket-nav owns scrolling. */
  padding: 0 0 16px;
  z-index: 5;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.main-col {
  grid-column: 2;
  padding: 24px 32px 140px;
  min-width: 0;
}

.nav-toggle-label {
  display: none;
}

.mobile-bar {
  display: none;
}

.review-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.review-title {
  font-size: 30px;
  font-weight: 600;
  line-height: 1.25;
}

.main-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.sidebar-prefs {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 10px 0;
  border-top: 1px solid var(--border);
}

/* UI setting, not a review action — plain labelled checkbox so its state reads as text, not colour */
.wrap-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.wrap-toggle-label input {
  cursor: pointer;
}

.theme-select-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.theme-select-label select {
  cursor: pointer;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 4px 6px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color 100ms,
    border-color 100ms,
    color 100ms;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn-approve {
  border-color: color-mix(in srgb, #3fb950 50%, var(--border-strong));
  color: var(--add-fg);
}

.btn-request-changes {
  border-color: color-mix(in srgb, #f85149 50%, var(--border-strong));
  color: var(--del-fg);
}

.btn-publish[data-state="sending"] {
  opacity: 0.7;
  cursor: progress;
}

.btn-publish[data-state="posted"] {
  border-color: color-mix(in srgb, #3fb950 50%, var(--border-strong));
  color: var(--add-fg);
}

.btn-fix {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border-strong));
  color: var(--accent);
}

.btn-fix:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-fix[data-state="sending"] {
  opacity: 0.7;
  cursor: progress;
}

/* client.js inserts this when an SSE update arrives while a composer is open, instead of reloading over an in-progress draft */
.reload-pill {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  translate: -50% 0;
  z-index: 40;
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.4);
}

/* GitHub read-sync failure state (template renders it on load, client.js updates it from sync_error SSE events) */
.sync-error-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  translate: -50% 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(90vw, 560px);
  padding: 8px 12px;
  border: 1px solid var(--danger, #e5534b);
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger, #e5534b) 12%, var(--bg-sidebar));
  color: var(--text, #e6e6e6);
  font-size: 13px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.4);
}

.sync-error-dismiss {
  border: none;
  background: none;
  color: inherit;
  font-size: 16px;
  cursor: pointer;
}

/* Upstream mcp-review install is behind nkbt/mcp-review HEAD */
.update-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  translate: -50% 0;
  z-index: 41;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(92vw, 640px);
  padding: 10px 12px;
  border: 1px solid var(--severity-nit);
  border-radius: 8px;
  background: color-mix(in srgb, var(--severity-nit) 14%, var(--bg-sidebar));
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.4);
}

/* Static demo export (scripts/build-static-demo.ts) — sits in .main-col only so sidebar layout stays intact */
.demo-banner {
  margin: -24px -32px 16px;
  padding: 8px 32px;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 14%, transparent);
  background: color-mix(in srgb, var(--severity-review) 16%, var(--bg));
  color: var(--text);
  font-size: 13px;
  text-align: center;
}

.static-demo [data-decision]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .demo-banner {
    margin: -44px -6px 12px;
    padding: 8px 6px;
  }
}

.update-banner-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.update-banner-cmd {
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 8px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--text) 8%, transparent);
  overflow-x: auto;
  white-space: pre;
}

.update-banner-dismiss {
  border: none;
  background: none;
  color: inherit;
  font-size: 16px;
  cursor: pointer;
  flex: none;
  line-height: 1;
}

/* ---------- bucket nav (sidebar) ---------- */

/* Sits above the nav's scrollport, so it stays put while the section list scrolls */
.sidebar-head {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.lines-left {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* client.js positions the visible-row band in nav scroll coordinates. The nav must stay transparent for z-index: -1. */
.nav-band {
  position: absolute;
  inset-inline: 0;
  z-index: -1;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  pointer-events: none;
}

.bucket-nav {
  display: flex;
  flex-direction: column;
  /* Every section is listed, so the nav — not the whole sidebar — is the scrollport; viewer prefs stay put below it. */
  flex: 1;
  /* offset parent for .nav-band */
  position: relative;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Rows own horizontal padding; adjacent sections join into one full-width nav band. */
.nav-bucket {
  padding: 9px 0;
}

/* Nest directory names under section titles and align filenames with directory names. */
.nav-bucket-top {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-inline: 10px;
}

/* Same triangle as the file chevron, pointing down when the section is open */
.nav-bucket-collapse {
  color: var(--text-dim);
  cursor: pointer;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  padding: 0;
}

.nav-bucket-collapse::before {
  content: "";
  border-style: solid;
  border-width: 4px 0 4px 6px;
  border-color: transparent transparent transparent currentColor;
  rotate: 90deg;
  transition: rotate 150ms;
}

.nav-bucket.is-collapsed .nav-bucket-collapse::before {
  rotate: 0deg;
}

/* The triangle indicates severity; brighten it on hover. */
.nav-bucket-collapse:hover {
  filter: brightness(1.35);
}

.nav-bucket-collapse[data-severity="review"] {
  color: var(--severity-review);
}

.nav-bucket-collapse[data-severity="nit"] {
  color: var(--severity-nit);
}

.nav-bucket-collapse[data-severity="fyi"] {
  color: var(--severity-fyi);
}

/* Collapses in place like a file body (same 150ms height, same interpolate-size trick) */
.nav-file-list {
  height: auto;
  overflow: clip;
  transition: height 150ms;
}

.nav-bucket.is-collapsed .nav-file-list {
  height: 0;
}

.nav-bucket-link {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 3px 6px 3px 0;
  text-decoration: none;
  color: var(--text);
  border-radius: var(--radius);
  font-size: 13px;
  transition:
    background-color 100ms,
    border-color 100ms,
    color 100ms;
}

.nav-bucket-link:hover {
  background: var(--bg-hover);
}

.nav-bucket-label {
  flex: 1;
  overflow-wrap: anywhere;
}

/* Keep progress in the section header row. */
.bucket-reviewed {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
}

.bucket-progress {
  font-variant-numeric: tabular-nums;
}

.nav-dir {
  /* space above sets the section title apart from its file list; groups separate via the bottom margin */
  margin: 8px 0 2px;
}

/* nested under the section title: its triangle starts where the title text does */
.nav-dir-name {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 26px;
  list-style: none;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 100ms;
}

.nav-dir-name::-webkit-details-marker {
  display: none;
}

.nav-dir-name:hover {
  color: var(--text);
}

.nav-dir-name::before {
  content: "";
  flex: none;
  border-style: solid;
  border-width: 4px 0 4px 6px;
  border-color: transparent transparent transparent currentColor;
  rotate: 0deg;
  transition: rotate 150ms;
}

.nav-dir[open] > .nav-dir-name::before {
  rotate: 90deg;
}

.nav-dir-children {
  list-style: none;
  margin: 0 0 2px;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.nav-leaf {
  display: flex;
}

/* sidebar filename anchor — reads as the current filename row, not a link. Names sit on the directory name's rail. */
.nav-file-link {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  padding: 4px 10px 4px 38px;
  font-size: 12px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 100ms;
}

.nav-file-link:hover {
  background: var(--bg-hover);
}

.nav-file-name {
  flex: 1;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  color: var(--text-dim);
}

.nav-file-stat {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.stat-add {
  color: var(--add-fg);
}

.stat-del {
  color: var(--del-fg);
}

/* ---------- github threads ---------- */

.gh-thread,
.line-threads,
.file-footer-threads {
  font-size: 12.5px;
}

.gh-thread {
  max-inline-size: 720px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin: 4px 0;
}

.gh-thread--resolved summary {
  cursor: pointer;
  color: var(--text-faint);
}

.gh-comment + .gh-comment {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.gh-author {
  font-weight: 600;
  color: var(--text-dim);
}

.gh-body {
  margin: 2px 0 0;
  color: var(--text);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.gh-body > :first-child {
  margin-top: 0;
}

.gh-body > :last-child {
  margin-bottom: 0;
}

.gh-body p,
.gh-body ul,
.gh-body ol,
.gh-body pre,
.gh-body blockquote,
.gh-body table {
  margin: 0.5em 0;
}

.gh-body ul,
.gh-body ol {
  padding-left: 1.4em;
}

/* Restore list markers removed by the page reset. */
.gh-body ul {
  list-style: disc;
}

.gh-body ol {
  list-style: decimal;
}

.gh-body code {
  font-family: var(--mono);
  font-size: 0.92em;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.gh-body pre {
  padding: 8px 10px;
  border-radius: 4px;
  overflow-x: auto;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border: 1px solid var(--border);
}

.gh-body pre code {
  padding: 0;
  background: none;
  font-size: 12px;
}

.gh-body img {
  /* Allow inline images and preserve markdown dimensions while constraining large screenshots to the column. */
  display: inline-block;
  vertical-align: middle;
  max-width: 100%;
  height: auto;
}

.gh-body picture {
  display: inline-block;
  vertical-align: middle;
  max-width: 100%;
  line-height: 0;
}

.gh-body a {
  color: var(--accent);
}

.gh-body blockquote {
  margin-inline: 0;
  padding: 0 0.8em;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}

.gh-body table {
  border-collapse: collapse;
  font-size: 12px;
}

.gh-body th,
.gh-body td {
  border: 1px solid var(--border);
  padding: 4px 8px;
}

.line-threads {
  padding-block: 2px;
}

.file-footer-threads {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

/* ---------- main column / buckets ---------- */

.bucket {
  margin-bottom: 144px;
  /* marking a whole section reviewed scrolls its top back into view when it went off above (client.js) */
  scroll-margin-top: var(--sticky-top);
}

/* Avoid trailing margin overflow, which lets the page scroll beyond the sticky sidebar. .main-col supplies bottom spacing. */
.bucket:last-child {
  margin-bottom: 0;
}

/* interpolate-size animates auto height; allow-discrete keeps content visible during closing. */
.bucket::details-content {
  height: 0;
  overflow: clip;
  transition:
    height 150ms,
    content-visibility 150ms allow-discrete;
}

.bucket[open]::details-content {
  height: auto;
}

.bucket-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
  padding: 4px 0;
}

.bucket-heading::-webkit-details-marker {
  display: none;
}

/* Explicit toggle affordance — default details marker is hidden above. */
.bucket-heading::before {
  content: "";
  flex: none;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 11px;
  border-color: transparent transparent transparent var(--text-dim);
  rotate: 0deg;
  transition: rotate 150ms;
}

.bucket[open] > .bucket-heading::before {
  rotate: 90deg;
}

/* The triangle is the severity marker here too (no separate dot) — the summary's title says what the colour means */
.bucket[data-severity="review"] > .bucket-heading::before {
  border-left-color: var(--severity-review);
}

.bucket[data-severity="nit"] > .bucket-heading::before {
  border-left-color: var(--severity-nit);
}

.bucket[data-severity="fyi"] > .bucket-heading::before {
  border-left-color: var(--severity-fyi);
}

/* brighten rather than recolour, so hover keeps the severity hue */
.bucket-heading:hover::before {
  filter: brightness(1.35);
}

.bucket-heading h2 {
  font-size: 30px;
  font-weight: 600;
  line-height: 1.25;
}

/* Section / review prose — Linear Guide metrics (15/24 body, ~14px mono chips), full column width */
.bucket-explanation,
.review-header .review-summary {
  color: var(--text);
  font-family:
    "Inter Variable", "SF Pro Display", -apple-system, system-ui, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  font-feature-settings: "calt";
  font-size: 15px;
  font-weight: 450;
  letter-spacing: -0.1px;
  line-height: 24px;
}

.bucket-explanation {
  margin: 10px 0 40px;
}

.bucket-explanation > :first-child {
  margin-top: 0;
}

.bucket-explanation > :last-child {
  margin-bottom: 0;
}

.review-header .review-summary > :first-child {
  margin-top: 0;
}

.review-header .review-summary > :last-child {
  margin-bottom: 0;
}

.bucket-explanation p,
.bucket-explanation ul,
.bucket-explanation ol,
.bucket-explanation pre,
.bucket-explanation blockquote,
.bucket-explanation table,
.review-header .review-summary p,
.review-header .review-summary ul,
.review-header .review-summary ol,
.review-header .review-summary pre,
.review-header .review-summary blockquote,
.review-header .review-summary table {
  margin: 0 0 24px;
}

.bucket-explanation p:last-child,
.bucket-explanation ul:last-child,
.bucket-explanation ol:last-child,
.bucket-explanation pre:last-child,
.bucket-explanation blockquote:last-child,
.bucket-explanation table:last-child,
.review-header .review-summary p:last-child,
.review-header .review-summary ul:last-child,
.review-header .review-summary ol:last-child,
.review-header .review-summary pre:last-child,
.review-header .review-summary blockquote:last-child,
.review-header .review-summary table:last-child {
  margin-bottom: 0;
}

.bucket-explanation li + li,
.review-header .review-summary li + li {
  margin-top: 8px;
}

.bucket-explanation ul,
.bucket-explanation ol,
.review-header .review-summary ul,
.review-header .review-summary ol {
  padding-left: 1.5em;
}

.bucket-explanation ul,
.review-header .review-summary ul {
  list-style: disc;
}

.bucket-explanation ol,
.review-header .review-summary ol {
  list-style: decimal;
}

.bucket-explanation h3,
.bucket-explanation h4,
.review-header .review-summary h3,
.review-header .review-summary h4 {
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.15px;
  line-height: 24px;
  margin: 32px 0 12px;
}

.bucket-explanation h3,
.review-header .review-summary h3 {
  font-size: 18px;
}

.bucket-explanation h4,
.review-header .review-summary h4 {
  font-size: 15px;
}

.bucket-explanation code,
.review-header .review-summary code {
  font-family:
    "Berkeley Mono", "SFMono-Regular", "SF Mono", Consolas, "Liberation Mono", Menlo, Courier,
    monospace;
  font-feature-settings: normal;
  font-size: 14.0625px;
  font-weight: 450;
  letter-spacing: -0.1px;
  line-height: 18.28125px;
  padding: 1px 4px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
  color: var(--text);
}

.bucket-explanation pre,
.review-header .review-summary pre {
  padding: 12px 14px;
  border-radius: 6px;
  overflow-x: auto;
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.bucket-explanation pre code,
.review-header .review-summary pre code {
  padding: 0;
  background: transparent;
  font-size: 14.0625px;
  line-height: 20px;
}

.mermaid-wrap {
  position: relative;
  margin: 0 0 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--text) 5%, var(--bg));
  overflow: auto;
}

.mermaid-wrap:last-child {
  margin-bottom: 0;
}

.mermaid-fs-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  min-height: 32px;
  padding: 4px 10px;
  font-size: 12px;
}

.mermaid-wrap .mermaid {
  margin: 0;
  padding: 44px 16px 14px;
  overflow-x: auto;
}

.mermaid-wrap .mermaid svg {
  max-width: none;
}

.mermaid-wrap:fullscreen {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 48px 24px 24px;
  background: var(--bg);
  border: none;
  border-radius: 0;
  display: grid;
  align-content: center;
  justify-items: center;
}

.mermaid-wrap:fullscreen .mermaid {
  width: 100%;
  max-height: calc(100dvh - 96px);
  overflow: auto;
}

.mermaid-wrap:fullscreen .mermaid svg {
  max-width: min(100%, 96vw);
  max-height: calc(100dvh - 120px);
  height: auto;
}

.bucket-files {
  display: flex;
  flex-direction: column;
  gap: 48px;
}

/* ---------- file article ---------- */

.file {
  border: 1px solid var(--border);
  border-radius: 8px;
  /* overflow must stay visible so .file-header sticky can stick to the viewport; clip lives on .file-body */
  background: var(--bg-raised);
  container-type: inline-size;
  /* collapsing scrolls an off-screen-above article back up (client.js) — to the line its header sticks at */
  scroll-margin-top: var(--sticky-top);
}

.file-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--bg-raised) 70%, black);
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  position: sticky;
  top: var(--sticky-top);
  z-index: 4;
}

.file-header-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.file-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  margin-left: auto;
}

.file.is-collapsed .file-header {
  /* Collapsed body is height 0 — disable sticky so the header scrolls away with the article */
  position: static;
  border-radius: 8px;
}

.file-collapse {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
}

.file-collapse::before {
  content: "";
  border-style: solid;
  border-width: 4px 0 4px 6px;
  border-color: transparent transparent transparent currentColor;
  rotate: 90deg;
  transition: rotate 150ms;
}

.file.is-collapsed .file-collapse::before {
  rotate: 0deg;
}

.file-path {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.copy-path {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  flex: none;
  padding: 2px;
  transition: color 100ms;
}

.copy-path:hover {
  color: var(--text);
}

.copy-path.copied {
  color: var(--add-fg);
}

.file-comment-link {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 12px;
  white-space: nowrap;
  text-decoration: none;
  transition: color 100ms;
}

.file-comment-link:hover {
  color: var(--text);
}

.file-stat {
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
  display: flex;
  gap: 6px;
}

.file-reviewed {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}

/* ---------- acted comments (Fix with Agent results, collapsed under the file header) ---------- */

.acted-comments {
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  font-size: 12.5px;
}

.acted-comments summary {
  cursor: pointer;
  padding: 8px 12px;
  color: var(--text-faint);
  list-style: none;
}

.acted-comments summary::-webkit-details-marker {
  display: none;
}

.acted-comment {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
}

.acted-comment-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.acted-comment-flag {
  color: var(--accent);
  font-weight: 600;
}

.acted-comment-range {
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 11.5px;
}

.acted-comment-body {
  color: var(--text-dim);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.acted-comment-reply {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
}

.acted-comment-reply-label {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

.acted-comment-reply-body {
  color: var(--text);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.btn-load-diff,
.btn-icon {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 12px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 100ms,
    border-color 100ms,
    color 100ms;
}

.btn-load-diff:hover,
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ---------- diff / hunks ---------- */

.file-body {
  height: auto;
  overflow: clip;
  border-radius: 0 0 8px 8px;
  transition: height 150ms;
}

/* chevron-driven AND reviewed auto-collapse both land here — client.js toggles one class */
.file.is-collapsed .file-body {
  height: 0;
}

.hunks {
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
}

body.soft-wrap .hunks {
  overflow-x: visible;
}

.hunk + .hunk,
.gap-row + .hunk {
  border-top: 1px solid var(--border);
}

.since-badge {
  padding: 2px 8px;
  color: var(--text-faint);
  font-size: 12px;
}

.since-badge[data-since="changed"] {
  color: var(--severity-review);
  font-weight: 600;
}

.syntax-badge {
  padding: 2px 8px;
  color: var(--text-faint);
  font-size: 12px;
}

.structure-note {
  padding: 4px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* An underline without a fill marks changed syntax, so the syntax colours stay readable over the line colour. */
.code-old mark.syntax-change {
  background: none;
  color: inherit;
  text-decoration: underline 1px color-mix(in srgb, var(--del-fg) 70%, transparent);
  text-underline-offset: 3px;
}

.code-new mark.syntax-change {
  background: none;
  color: inherit;
  text-decoration: underline 1px color-mix(in srgb, var(--add-fg) 70%, transparent);
  text-underline-offset: 3px;
}

/* template.ts gives a token that is hard to read on a deleted or an added line colour a readable colour for that line colour. The split layout paints the old cell of a changed pair red and the new cell green. */
.readable-token {
  color: var(--color);
}

:is(.line-del, .line-change .code-old) .readable-token {
  color: var(--deleted-line-color, var(--color));
}

:is(.line-add, .line-change .code-new) .readable-token {
  color: var(--added-line-color, var(--color));
}

.moved-badge {
  padding: 4px 12px;
  font-size: 11.5px;
  color: var(--severity-nit);
  background: color-mix(in srgb, var(--severity-nit) 12%, transparent);
}

.gap-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  margin: 0;
  cursor: pointer;
  color: var(--text-dim);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  border-block: 1px dashed var(--border-strong);
  text-align: left;
}

.gap-row:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.gap-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.gap-row[data-expanded="1"] {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.gap-row-rule {
  flex: 1;
  min-width: 24px;
  height: 0;
  border-top: 1px dashed var(--border-strong);
}

.gap-row-label {
  flex: none;
  white-space: nowrap;
}

.gap-row-trailing {
  display: none;
}

.gap-expanded {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}

/* Full-file mode: gaps are expanded in place; hide the cut bars so the file reads continuously with diffs. */
.file.is-showing-full-source .gap-row {
  display: none;
}

.file.is-showing-full-source .gap-expanded {
  border-block: none;
}

.btn-full-source {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  width: 28px;
  height: 28px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.btn-full-source:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.diff-line {
  display: flex;
  /* grow to the row's own content so the background covers it at any horizontal scroll offset, but never shrink below the viewport */
  width: max-content;
  min-width: 100%;
}

body.soft-wrap .diff-line {
  width: auto;
}

.diff-line.line-add {
  background: var(--add-bg);
}

.diff-line.line-del {
  background: var(--del-bg);
}

/* Inset shadows overlay selection on add/delete backgrounds without obscuring text. */
.diff-line.is-selected {
  box-shadow: inset 0 0 0 100vmax color-mix(in srgb, var(--accent) 22%, transparent);
}

/* del+add replacement: unified/mobile keep stacked rows; desktop split shows one combined row. */
.diff-pair {
  display: contents;
}

.diff-pair-side {
  display: none;
}

/* drag-selecting lines shouldn't select the underlying code text */
.file.range-selecting .hunks {
  user-select: none;
}

.gutter {
  flex: none;
  display: flex;
  /* opaque (not inherited/tinted) so code sliding under during horizontal scroll doesn't show through */
  background: var(--bg-raised);
}

/* ---------- unified vs split diff (toggle: #unified-toggle) ---------- */
/* Both layouts share old/new gutter and code cells; CSS chooses which cells to display. */

/* Unified layout: one sticky gutter and one code column. */
body.unified .gutter-old,
body.unified .gutter-new {
  position: sticky;
}

body.unified .gutter-old {
  left: 0;
  order: 1;
}

body.unified .gutter-new {
  left: 38px;
  order: 2;
}

body.unified .code-old {
  order: 3;
  display: none;
}

body.unified .code-new {
  order: 3;
}

body.unified .diff-line.line-del .code-old {
  display: initial;
}

body.unified .diff-line.line-del .code-new {
  display: none;
}

/* Desktop split layout: old gutter/code, new gutter/code. display: contents aligns cells across the hunk. */
@media (min-width: 769px) {
  body:not(.unified) .hunk,
  body:not(.unified) .gap-inline,
  body:not(.unified) .gap-expanded {
    display: grid;
    grid-template-columns: 38px 1fr 38px 1fr;
  }

  body:not(.unified) .hunk .diff-line,
  body:not(.unified) .gap-inline .diff-line,
  body:not(.unified) .gap-expanded .diff-line {
    display: contents;
  }

  /* Hide stacked del/add copies; show the combined side-by-side row instead. Must beat `body:not(.unified) .hunk .diff-line { display: contents }`. */
  body:not(.unified) .hunk .diff-line.diff-pair-stack {
    display: none;
  }

  body:not(.unified) .hunk .diff-line.diff-pair-side {
    display: contents;
  }

  /* Span non-cell rows across the split grid. Composers and comments set their spans in base rules. */
  body:not(.unified) .moved-badge,
  body:not(.unified) .since-badge,
  body:not(.unified) .syntax-badge,
  body:not(.unified) .line-threads,
  body:not(.unified) .gap-row {
    grid-column: 1 / -1;
  }

  body:not(.unified) .code-old,
  body:not(.unified) .code-new {
    min-width: 0;
    overflow-x: auto;
  }

  body:not(.unified) .code-old {
    border-right: 1px solid var(--border-strong);
  }

  /* display: contents drops the .diff-line box itself, so per-line tint/selection has to land on the four child cells directly instead of the row. */
  body:not(.unified) .diff-line.line-del .gutter-old,
  body:not(.unified) .diff-line.line-del .code-old,
  body:not(.unified) .diff-line.line-change .gutter-old,
  body:not(.unified) .diff-line.line-change .code-old {
    background: var(--del-bg);
  }

  body:not(.unified) .diff-line.line-add .gutter-new,
  body:not(.unified) .diff-line.line-add .code-new,
  body:not(.unified) .diff-line.line-change .gutter-new,
  body:not(.unified) .diff-line.line-change .code-new {
    background: var(--add-bg);
  }

  /* An added or deleted file has only one side, so that side takes the full width. */
  body:not(.unified) .file[data-status="added"] .hunk,
  body:not(.unified) .file[data-status="deleted"] .hunk {
    grid-template-columns: 38px 1fr;
  }

  body:not(.unified) .file[data-status="added"] :is(.gutter-old, .code-old),
  body:not(.unified) .file[data-status="deleted"] :is(.gutter-new, .code-new) {
    display: none;
  }

  body:not(.unified) .file[data-status="deleted"] .code-old {
    border-right: none;
  }

  /* The split grid is 38px 1fr 38px 1fr: old code starts at 38px and new code at 50% + 38px. A comment stays inside the pane of its side. */
  body:not(.unified)
  :is(
    .line-threads > :is(.review-thread, .gh-thread, .comment-composer),
    .hunks .comment-composer:not([data-pane=""]),
    .acted-comments > :is(.review-thread, .comment-composer):not([data-pane=""])
  ) {
    --comment-inset: 38px;
    --comment-end: calc(50% + 12px);
  }

  body:not(.unified)
    :is(
      .line-threads > :is(.review-thread, .gh-thread, .comment-composer),
      .hunks .comment-composer:not([data-pane=""]),
      .acted-comments > :is(.review-thread, .comment-composer):not([data-pane=""])
    )[data-pane="new"] {
    --comment-inset: calc(50% + 38px);
    --comment-end: 12px;
  }

  body:not(.unified)
    .file:is([data-status="added"], [data-status="deleted"])
    :is(
      .line-threads > :is(.review-thread, .gh-thread, .comment-composer),
      .hunks .comment-composer:not([data-pane=""]),
      .acted-comments > :is(.review-thread, .comment-composer):not([data-pane=""])
    ) {
    --comment-inset: 38px;
    --comment-end: 12px;
  }

  /* display: contents leaves no row box to shadow, so each cell carries it (see the unified rule above) */
  body:not(.unified) .diff-line.is-selected > * {
    box-shadow: inset 0 0 0 100vmax color-mix(in srgb, var(--accent) 22%, transparent);
  }
}

.line-num {
  appearance: none;
  background: transparent;
  border: none;
  width: 38px;
  padding: 0 8px;
  text-align: right;
  color: var(--text-faint);
  font: inherit;
  cursor: pointer;
  transition:
    background-color 100ms,
    border-color 100ms,
    color 100ms;
}

.line-num:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.line-num--empty {
  display: inline-block;
  width: 38px;
}

.line-add .line-num {
  color: color-mix(in srgb, var(--add-fg) 70%, var(--text-faint));
}

.diff-line.line-add .line-num:hover,
.diff-line.line-add .line-num--empty {
  background: var(--add-bg-strong);
}

.line-del .line-num {
  color: color-mix(in srgb, var(--del-fg) 70%, var(--text-faint));
}

.diff-line.line-del .line-num:hover,
.diff-line.line-del .line-num--empty {
  background: var(--del-bg-strong);
}

.line-code {
  white-space: pre;
  padding: 0 12px 0 4px;
  flex: 1;
}

body.soft-wrap .line-code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Shiki renders token colours inline for the selected theme. */

.file-diff-error {
  padding: 16px;
  color: var(--del-fg);
  font-size: 13px;
}

/* ---------- composer + pending comment (client.js-inserted) ---------- */

.comment-composer {
  grid-column: 1 / -1; /* spans the split-diff grid; the margins below place it beside its pane */
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 12px;
  max-inline-size: 720px;
  padding: 8px 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  height: auto;
  overflow: clip;
  transition:
    height 150ms,
    opacity 150ms;
}

@starting-style {
  .comment-composer {
    height: 0;
    opacity: 0;
  }
}

.comment-composer textarea {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px;
  font: 13px / 1.5 var(--sans);
}

.comment-composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.comment-composer-range {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--mono);
}

.comment-composer-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Compact buttons at their own height; the thread buttons below match them. */
.comment-composer-buttons .btn {
  min-height: 28px;
  padding: 3px 12px;
  font-size: 12.5px;
  line-height: 1.4;
}

/* A line comment, its replies, and a line composer sit beside the code of their pane with a readable width, also a resolved line comment under the file header. --comment-inset is where the code of that pane starts, and --comment-end keeps the surface inside the pane. Unified desktop shows two gutters. */
.line-threads > :is(.review-thread, .gh-thread, .comment-composer),
.hunks .comment-composer:not([data-pane=""]),
.acted-comments > :is(.review-thread, .comment-composer):not([data-pane=""]) {
  --comment-inset: 76px;
  --comment-end: 12px;
  margin-block: 4px;
  margin-inline: var(--comment-inset) var(--comment-end);
  max-inline-size: 720px;
}

/* ---------- review threads (reviewer + agent conversation, anchored to a line range or a file) ---------- */

/* One compact surface for each conversation, at a readable width. */
.review-thread {
  max-inline-size: 720px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius);
  font-size: 12.5px;
}

.review-thread + .review-thread {
  margin-top: 6px;
}

.review-thread.is-resolved {
  background: color-mix(in srgb, var(--text) 4%, var(--bg));
  border-color: var(--border);
}

.thread-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.thread-state {
  font-weight: 600;
  color: var(--accent);
}

.review-thread.is-resolved .thread-state {
  color: var(--text-faint);
}

/* An outdated discussion shows the code it started on, since no current line holds it. */
.thread-outdated {
  margin-bottom: 8px;
  color: var(--text-dim);
}

.thread-origin {
  font-family: var(--mono);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.thread-outdated-reason {
  margin-top: 2px;
  font-family: var(--sans);
}

.thread-quote {
  margin-top: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  font-family: var(--mono);
  white-space: pre;
  overflow-x: auto;
}

.outdated-discussions {
  margin-bottom: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

.outdated-discussions-heading {
  padding: 10px 16px 0;
  font-size: 15px;
}

.outdated-discussions-count {
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.outdated-discussions-note {
  padding: 4px 16px 10px;
  color: var(--text-dim);
  font-size: 12.5px;
}

.outdated-discussions .review-thread {
  margin: 0 16px 10px;
}

.acted-comments .review-thread {
  margin: 0 12px 8px;
}

.thread-message + .thread-message {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.thread-message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

/* Same severity palette as the section triangles — a finding says how much it wants your attention */
.thread-severity {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.thread-severity.severity-review {
  background: var(--severity-review);
}

.thread-severity.severity-nit {
  background: var(--severity-nit);
}

.thread-severity.severity-fyi {
  background: var(--severity-fyi);
}

.thread-author {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
}

.thread-message[data-author="agent"] .thread-author {
  color: var(--accent);
}

/* Restore markdown spacing and list markers after the reset. Comment prose uses sans; code keeps var(--mono). */
.thread-message-body {
  color: var(--text);
  font-family: var(--sans);
  font-size: 12.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.thread-message-body p,
.thread-message-body ul,
.thread-message-body ol,
.thread-message-body pre,
.thread-message-body blockquote,
.thread-message-body table {
  margin: 0 0 0.6em;
}

/* Bottom-only margins above, so the last block just drops its own gap and no `> :first-child` rule is needed to cancel a top one. */
.thread-message-body p:last-child,
.thread-message-body ul:last-child,
.thread-message-body ol:last-child,
.thread-message-body pre:last-child,
.thread-message-body blockquote:last-child,
.thread-message-body table:last-child {
  margin-bottom: 0;
}

.thread-message-body ul,
.thread-message-body ol {
  padding-left: 1.5em;
}

.thread-message-body ul {
  list-style: disc;
}

.thread-message-body ol {
  list-style: decimal;
}

.thread-message-body li + li {
  margin-top: 3px;
}

.thread-message-body h3,
.thread-message-body h4 {
  font-size: 12.5px;
  font-weight: 600;
  margin: 0 0 0.4em;
}

.thread-message-body code {
  font-family: var(--mono);
  font-size: 0.92em;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.thread-message-body pre {
  padding: 8px 10px;
  border-radius: 4px;
  overflow-x: auto;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border: 1px solid var(--border);
}

.thread-message-body pre code {
  padding: 0;
  background: none;
  font-size: 12px;
}

.thread-message-body a {
  color: var(--accent);
}

.thread-message-body blockquote {
  padding: 0 0.8em;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}

.thread-message-body table {
  border-collapse: collapse;
  font-size: 12px;
}

.thread-message-body th,
.thread-message-body td {
  border: 1px solid var(--border);
  padding: 4px 8px;
}

.thread-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.thread-reply,
.thread-resolve {
  min-height: 26px;
  padding: 3px 10px;
  line-height: 1.4;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
}

/* A touch screen keeps a larger hit target without the 44px square of the generic rule. */
@media (pointer: coarse) {
  .thread-reply,
  .thread-resolve,
  .comment-composer-buttons .btn {
    min-height: 36px;
  }
}

.thread-reply:hover,
.thread-resolve:hover {
  color: var(--text);
  border-color: var(--accent);
}

.pending-comment {
  grid-column: 1 / -1; /* full-width band in the split-diff grid; inert in unified/block layout */
  padding: 8px 12px 8px 76px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-block: 1px dashed color-mix(in srgb, var(--accent) 40%, transparent);
  font-size: 12.5px;
  color: var(--text-dim);
}

.pending-comment .pending-comment-flag {
  color: var(--accent);
  font-weight: 600;
  margin-right: 6px;
}

/* ---------- mobile ---------- */

@container (max-width: 520px) {
  .file-header {
    flex-direction: column;
    align-items: stretch;
  }

  .file-header-actions {
    margin-left: 0;
  }
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 15% 0 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0);
    /* the desktop resize/flow rules don't apply to the fixed drawer — it must scroll its own content */
    width: auto;
    max-width: none;
    resize: none;
    overflow-y: auto;
    /* clear the fixed nav-toggle, which floats above the drawer at top 8px */
    padding-top: 48px;
  }

  .main-col {
    grid-column: 1; /* desktop pins it to column 2; the single-column grid would otherwise leave column 1 as a dead strip */
  }

  body:has(#nav-toggle:checked) .sidebar {
    transform: translateX(0);
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.5);
  }

  .nav-toggle-label {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 31;
    width: 32px;
    height: 32px;
    font-size: 14px;
    background: var(--bg-raised);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 32px;
    min-width: 32px;
  }

  .main-col {
    padding: 44px 6px 68px;
  }

  /* clear the fixed nav-toggle (top 8px + 32px tall): sticky headers pin below it and collapses scroll to the same line */
  :root {
    --sticky-top: 44px;
  }

  .main-actions {
    display: none; /* mobile-bar owns Approve + Request changes */
  }

  /* Shrink chrome so code gets the viewport — headings, prose, buttons, checkboxes. Also beat the coarse-pointer 44px mins that otherwise dominate on phones. */
  button,
  .line-num,
  input[type="checkbox"] {
    min-height: 0;
    min-width: 0;
  }

  .review-header {
    gap: 28px;
    margin-bottom: 40px;
    padding-bottom: 24px;
  }

  .review-title {
    font-size: 16px;
    line-height: 1.25;
  }

  .review-header .review-summary {
    font-size: 15px;
    line-height: 24px;
  }

  .bucket {
    margin-bottom: 280px;
  }

  .bucket-heading {
    gap: 6px;
    padding: 2px 0;
  }

  .bucket-heading::before {
    border-width: 5px 0 5px 8px;
  }

  .bucket-heading h2 {
    font-size: 15px;
    line-height: 1.25;
  }

  .bucket-explanation {
    margin: 12px 0 80px;
    font-size: 15px;
    line-height: 24px;
  }

  .bucket-files {
    gap: 96px;
  }

  .btn {
    padding: 4px 8px;
    font-size: 11px;
  }

  .touch-target {
    min-height: 0;
  }

  button.touch-target,
  .btn.touch-target {
    min-height: 28px;
    min-width: 0;
  }

  input[type="checkbox"] {
    min-width: 14px;
    min-height: 14px;
    width: 14px;
    height: 14px;
  }

  .wrap-toggle-label,
  .theme-select-label {
    font-size: 11px;
    gap: 4px;
  }

  .theme-select-label select {
    padding: 2px 4px;
    font-size: 11px;
  }

  .mobile-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    z-index: 25;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border-strong);
  }

  .mobile-bar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: none;
  }

  .mobile-bar .btn {
    padding: 4px 8px;
    font-size: 11px;
    min-height: 28px;
  }

  .mobile-bar .mobile-home {
    flex: none;
    min-height: 28px;
    font-size: 12px;
  }

  .mobile-progress {
    font-size: 11px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    min-width: 0;
  }

  .reload-pill {
    bottom: calc(52px + env(safe-area-inset-bottom)); /* clear the fixed mobile bar */
  }

  /* Compact file chrome: path+copy on top, actions on a second row. */
  .file-header {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 4px 6px;
  }

  .file-header-top {
    gap: 4px;
  }

  .file-header-actions {
    margin-left: 0;
    padding-left: 22px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .file-collapse {
    width: 16px;
    height: 16px;
  }

  .file-path {
    font-size: 11px;
  }

  .copy-path {
    font-size: 12px;
  }

  .btn-full-source {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .file-comment-link {
    font-size: 11px;
  }

  .file-stat {
    font-size: 10px;
  }

  .file-reviewed {
    font-size: 10px;
    gap: 4px;
  }

  .gap-row {
    padding: 6px 8px;
    font-size: 11px;
    gap: 8px;
  }

  .hunks {
    font-size: 11px;
    line-height: 1.35;
  }

  /* One narrow line-number column — hide the unused side so gutters don't eat half the screen. Also beat the coarse-pointer 44px touch target on .line-num. */
  .line-num,
  .line-num--empty {
    width: 26px;
    min-width: 26px;
    min-height: 0;
    font-size: 9px;
    padding: 0 2px;
  }

  body.unified .gutter-old,
  body.unified .gutter-new,
  body:not(.unified) .gutter-old,
  body:not(.unified) .gutter-new {
    position: sticky;
    left: 0;
  }

  .diff-line.line-ctx .gutter-old,
  .diff-line.line-add .gutter-old {
    display: none;
  }

  .diff-line.line-del .gutter-new {
    display: none;
  }

  .pending-comment {
    padding-left: 30px;
  }

  /* One line-number column on a phone. */
  .line-threads > :is(.review-thread, .gh-thread, .comment-composer),
  .hunks .comment-composer:not([data-pane=""]),
  .acted-comments > :is(.review-thread, .comment-composer):not([data-pane=""]) {
    --comment-inset: 26px;
    --comment-end: 6px;
  }

  /* Split is unusable this narrow — force the unified layout regardless of #unified-toggle.
     The split-only rules above are already scoped to min-width: 769px, so nothing here needs
     to un-set a grid/contents layout; this just replicates the body.unified rules for
     body:not(.unified) too (same selector shape as those rules, so specificity doesn't fight). */
  body:not(.unified) .gutter-old,
  body:not(.unified) .gutter-new {
    position: sticky;
  }

  body:not(.unified) .gutter-old {
    left: 0;
    order: 1;
  }

  body:not(.unified) .gutter-new {
    left: 0;
    order: 2;
  }

  body:not(.unified) .code-old {
    order: 3;
    display: none;
  }

  body:not(.unified) .code-new {
    order: 3;
  }

  body:not(.unified) .diff-line.line-del .code-old {
    display: initial;
  }

  body:not(.unified) .diff-line.line-del .code-new {
    display: none;
  }
}
.review-live-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.review-live-notice .touch-target {
  min-height: 44px;
}

.review-action-status {
  margin: 0 0 20px;
  color: var(--text-dim);
  font-size: 13px;
}

.review-action-status h2 {
  font-size: 15px;
}

.review-action {
  margin: 8px 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  overflow-wrap: anywhere;
}

.review-action summary {
  min-height: 44px;
  align-content: center;
  cursor: pointer;
}

.review-action-state {
  color: var(--text);
  font-weight: 600;
}

.review-action-fields > div {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) minmax(0, 3fr);
  gap: 12px;
  margin: 8px 0;
}

.review-action-fields dd {
  margin: 0;
  color: var(--text);
}

[data-decision][aria-pressed="true"] {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.composer-error {
  margin: 8px 0;
  color: var(--text-dim);
}

.publication-status,
.publication-select {
  margin: 0 0 20px;
  color: var(--text-dim);
  font-size: 13px;
}

.publication-select h2 {
  font-size: 15px;
}

.publication-select,
.publication-batch {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  overflow-wrap: anywhere;
}

.publication-batch {
  margin: 8px 0;
}

.publication-title {
  min-height: 44px;
  align-content: center;
  margin: 0;
}

.publication-state {
  color: var(--text);
  font-weight: 600;
}

.publication-candidates,
.publication-items {
  list-style: none;
  margin: 8px 0;
  padding: 0;
}

.publication-candidate {
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.publication-choice {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--text);
  cursor: pointer;
}

.publication-choice input {
  width: 18px;
  height: 18px;
  flex: none;
}

.publication-body {
  margin: 4px 0 0 26px;
  color: var(--text);
  white-space: pre-wrap;
}

.publication-problem,
.publication-reason,
.publication-error {
  margin: 4px 0 0 26px;
}

.publication-reason,
.publication-error {
  margin-left: 0;
}

.publication-item {
  margin: 4px 0;
}

.publication-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.publication-controls .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.publication-link {
  display: inline-block;
  min-height: 44px;
  align-content: center;
}

/* Buttons and links here use display rules that would otherwise override the hidden attribute. */
.publication-status [hidden],
.publication-select [hidden] {
  display: none;
}

.publication-status a {
  color: var(--accent);
}

.btn-publish:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Coverage: each row keeps its own count and status. */
.coverage-status {
  margin: 0 0 32px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  font-size: 13px;
}

.coverage-status-heading {
  font-size: 15px;
}

.coverage-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(0, 5fr);
  gap: 12px;
  margin: 6px 0;
}

.coverage-row dt {
  color: var(--text-dim);
}

.coverage-row dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.coverage-row[data-status="incomplete"] .coverage-text,
.coverage-row[data-status="analyzed_with_skips"] .coverage-text {
  font-weight: 600;
}

.coverage-row[data-status="unknown"] .coverage-text,
.coverage-row[data-status="none"] .coverage-text {
  color: var(--text-dim);
}

.coverage-detail {
  display: block;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.coverage-detail:empty {
  display: none;
}

.coverage-reviewed-error {
  margin: 6px 0;
  color: var(--danger);
  font-weight: 600;
}

.coverage-items summary {
  min-height: 44px;
  align-content: center;
  cursor: pointer;
  color: var(--text-dim);
}

.coverage-item-list {
  margin: 0 0 8px;
  padding-left: 20px;
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.nav-bucket-count {
  flex: none;
  color: var(--text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.file-no-diff-reason {
  padding: 10px 16px;
  color: var(--text-dim);
  font-size: 13px;
}

@media (max-width: 768px) {
  .coverage-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
}

/* ---------- review home ---------- */
/* The index of stored reviews at `/`; home.js fills the list. */

.home-link {
  align-self: flex-start;
  font-size: 13px;
  color: var(--accent);
}

.home-link:hover {
  text-decoration: underline;
}

.home-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 32px 80px;
}

.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.home-title {
  font-size: 30px;
  font-weight: 600;
  line-height: 1.25;
}

.home-filters {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.home-filter {
  gap: 6px;
  padding: 0 12px;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
}

.home-filter[aria-current="page"] {
  border-bottom-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.home-filter-count {
  font-size: 12px;
  color: var(--text-faint);
}

.home-status,
.home-notice {
  color: var(--text-dim);
}

.home-status:empty {
  display: none;
}

.home-status[data-state="error"] {
  color: var(--danger);
}

.home-status .btn {
  margin-left: 8px;
}

.home-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.home-review {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

.home-review-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.home-review-title {
  font-size: 17px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.home-review-title:hover {
  text-decoration: underline;
}

.home-review-repo {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

.home-review-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.home-badge {
  padding: 1px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
}

.home-badge[data-kind="awaiting"] {
  border-color: var(--severity-review);
  color: var(--severity-review);
}

.home-review-actions {
  align-self: start;
}

.home-review-facts {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px 16px;
  font-size: 13px;
}

.home-review-facts dt {
  font-size: 12px;
  color: var(--text-faint);
}

.home-review-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.home-agent[data-status="working"] {
  color: var(--add-fg);
}

.home-agent[data-status="waiting_on_reviewer"] {
  color: var(--severity-review);
}

.home-more {
  align-self: center;
}

.home-more[hidden] {
  display: none;
}

.decision-status {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--add-fg);
  border-radius: var(--radius);
  background: var(--bg-raised);
  font-size: 14px;
}

.decision-status[data-pending-decision="request_changes"] {
  border-left-color: var(--severity-review);
}

.decision-status[hidden] {
  display: none;
}

.decision-status-heading {
  font-size: 15px;
  font-weight: 600;
}

.decision-status-publication,
.decision-status-resume {
  color: var(--text-dim);
}

.decision-status-prompt {
  font-family: var(--mono);
  font-size: 12.5px;
  overflow-wrap: anywhere;
  user-select: all;
}

.decision-status-error {
  color: var(--danger);
}

.archive-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 16px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

.archive-banner[hidden] {
  display: none;
}

.archive-banner-text {
  font-size: 14px;
  color: var(--text-dim);
}

@media (max-width: 768px) {
  .home-main {
    padding: 16px 12px 64px;
  }

  .home-title {
    font-size: 24px;
  }

  .home-review {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .home-review-facts {
    grid-template-columns: 1fr 1fr;
  }
}

/* Snapshot history and comparison */
.snapshot-history,
.snapshot-comparison {
  margin: 0 0 24px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  font-size: 13px;
}

.snapshot-history-heading,
.snapshot-comparison-heading {
  font-size: 15px;
}

.snapshot-comparison h3 {
  margin: 14px 0 4px;
  font-size: 13.5px;
}

.snapshot-history-note {
  margin: 6px 0;
  font-weight: 600;
}

.snapshot-history-form,
.snapshot-history-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 6px 0;
}

.snapshot-history-form label,
.since-focus-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
}

.snapshot-history-form select {
  max-width: 100%;
  min-height: 36px;
}

.snapshot-history-actions:empty {
  display: none;
}

.nav-comparison {
  display: block;
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
}

.comparison-files,
.comparison-discussions,
.comparison-groups,
.comparison-runs,
.comparison-needs-review {
  margin: 4px 0;
  padding: 0;
  list-style: none;
}

.comparison-file,
.comparison-discussion {
  padding: 6px 0;
  border-top: 1px solid var(--border);
  overflow-wrap: anywhere;
}

.comparison-file-heading {
  min-height: 32px;
  align-content: center;
  cursor: pointer;
}

.comparison-status {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
}

.comparison-status[data-status="changed"],
.comparison-status[data-status="new"],
.comparison-status[data-status="not_reviewed"],
.comparison-status[data-status="explanation_changed"],
.comparison-status[data-status="added"] {
  color: var(--severity-review);
}

.comparison-status[data-status="unchanged"],
.comparison-status[data-status="resolved"] {
  color: var(--text-dim);
}

.comparison-status[data-status="outdated"],
.comparison-status[data-status="left"],
.comparison-status[data-status="removed"] {
  color: var(--danger);
}

.comparison-path {
  font-family: var(--mono);
}

.comparison-detail,
.comparison-author {
  color: var(--text-faint);
}

.comparison-excerpt {
  margin: 2px 0;
}

.comparison-delta {
  margin: 6px 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
}

.comparison-line {
  display: grid;
  grid-template-columns: 4.5ch 4.5ch minmax(0, 1fr);
  gap: 8px;
}

.comparison-num {
  padding-right: 4px;
  color: var(--text-faint);
  text-align: right;
  user-select: none;
}

.comparison-code {
  white-space: pre;
}

.soft-wrap .comparison-code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.comparison-add {
  background: var(--add-bg);
}

.comparison-del {
  background: var(--del-bg);
}

.comparison-gap,
.comparison-more {
  padding: 0 8px;
  color: var(--text-faint);
}

/* The focus toggle hides hunks that repeat an unchanged change of the baseline, and file articles that show only such hunks. A hunk or file with an open discussion stays visible. */
.since-focus .hunk[data-since="unchanged"]:not(:has(.review-thread:not(.is-resolved))),
.since-focus
  .file:has(.hunk[data-since]):not(:has(.hunk[data-since="changed"])):not(
    :has(.review-thread:not(.is-resolved))
  ) {
  display: none;
}

/* An earlier snapshot is read-only: its controls that would change the review are hidden. */
.snapshot-read-only
:is(
  .main-actions,
  .mobile-bar-actions,
  .thread-actions,
  .file-reviewed,
  .bucket-reviewed,
  .file-comment-link,
  .archive-restore
) {
  display: none;
}

.snapshot-read-only .line-num {
  pointer-events: none;
}
