:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2230;
  --border: #30363d;
  --border-strong: #444c56;
  --fg: #e6edf3;
  --fg-muted: #9198a1;
  --fg-dim: #6e7681;
  --accent: #2f81f7;
  --accent-fg: #ffffff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #a371f7;
  --flag: #db6d28;
  --focus: #58a6ff;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Light theme — GitHub-light palette. Applied when <html data-theme="light">;
   only the color tokens are overridden, so every component re-themes for free. */
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-elev-2: #eaeef2;
  --border: #d0d7de;
  --border-strong: #afb8c1;
  --fg: #1f2328;
  --fg-muted: #59636e;
  --fg-dim: #818b96;
  --accent: #0969da;
  --accent-fg: #ffffff;
  --green: #1a7f37;
  --red: #cf222e;
  --yellow: #9a6700;
  --purple: #8250df;
  --flag: #bc4c00;
  --focus: #0969da;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-radius: 3px;
}

a { color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

/* ---- AppShell ---------------------------------------------------------- */
#app { display: flex; flex-direction: column; height: 100vh; }

.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.5px;
  color: var(--fg);
  cursor: pointer;
  background: none; border: 0; padding: 0;
}
.env-indicator {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg-muted);
}
.appbar-right { display: inline-flex; align-items: center; gap: 12px; }
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 4px 7px;
}
.theme-toggle:hover { color: var(--fg); border-color: var(--border-strong); }

.screen { flex: 1 1 auto; overflow: auto; min-height: 0; }
.screen[hidden] { display: none; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev-2);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--fg-dim); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.btn-primary:hover { background: #1f6feb; }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  font-family: var(--mono);
  font-size: 13px;
}
.btn-danger { color: var(--red); border-color: var(--red); }
.kbd {
  display: inline-block;
  min-width: 1.1em;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-elev-2);
  font-family: var(--mono);
  font-size: 0.82em;
  line-height: 1.5;
  color: var(--fg-muted);
  text-align: center;
  text-decoration: none;
}

/* ---- Landing ----------------------------------------------------------- */
.landing-wrap { max-width: 760px; margin: 48px auto; padding: 0 20px; }
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.card h2 { margin: 0 0 16px; font-size: 18px; }
.load-row { display: flex; gap: 10px; align-items: center; }
.text-input {
  flex: 1 1 auto;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
}
.text-input.invalid { border-color: var(--red); }
.field-hint { margin-top: 8px; font-size: 12px; color: var(--fg-muted); }
.field-error { margin-top: 8px; font-size: 12px; color: var(--red); }
.field-error[hidden] { display: none; }
.btn[hidden] { display: none; }

.section-title { margin: 28px 0 10px; font-size: 13px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.section-title-row { display: flex; align-items: baseline; justify-content: space-between; }
.section-title-row .section-title { margin: 28px 0 10px; }
.link-btn {
  background: none;
  border: 0;
  color: var(--fg-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.link-btn:hover { color: var(--fg); }
.resume-list { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.resume-empty { padding: 16px; color: var(--fg-muted); }
.resume-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 0;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.resume-row:last-child { border-bottom: 0; }
.resume-row-main {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 12px 14px;
  background: none;
  border: 0;
  color: var(--fg);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13px;
}
.resume-row:hover { background: var(--bg-elev-2); }
.resume-ref { font-weight: 600; min-width: 160px; }
.resume-meta { color: var(--fg-muted); margin-left: auto; }
.resume-arrow { color: var(--fg-dim); }
.resume-archive-btn {
  flex-shrink: 0;
  margin-right: 12px;
  padding: 6px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg-muted);
  font-size: 12px;
  cursor: pointer;
}
.resume-archive-btn:hover { color: var(--fg); border-color: var(--fg-dim); }

/* ---- Badges / glyphs --------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 12px;
}
.badge-viewed { color: var(--green); }
.badge-flagged { color: var(--flag); }
.badge-done {
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 999px;
  padding: 1px 8px;
}
.glyph-pass { color: var(--green); }
.glyph-fail { color: var(--red); }
.glyph-pending { color: var(--yellow); }
.glyph-none { color: var(--fg-dim); }
.glyph-approved { color: var(--green); }
.glyph-changes { color: var(--red); }
.glyph-merged { color: var(--purple); }

/* ---- Review layout (three-region grid) --------------------------------- */
.review-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "summary summary"
    "files detail";
  height: 100%;
}

/* pr-summary */
.pr-summary {
  grid-area: summary;
  padding: 12px 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.pr-summary .ps-title { font-size: 15px; font-weight: 600; }
.pr-summary .ps-title .ps-ref { color: var(--fg-muted); font-family: var(--mono); font-weight: 400; }
.pr-summary .ps-title a.ps-ref-link { text-decoration: none; cursor: pointer; }
.pr-summary .ps-title a.ps-ref-link:hover { color: var(--accent); text-decoration: underline; }
.pr-summary .ps-title a.ps-ref-link::after { content: " \2197"; font-size: 0.85em; opacity: 0.7; }
.pr-summary .ps-meta { color: var(--fg-muted); font-family: var(--mono); font-size: 13px; }
.pr-summary .ps-meta .ps-branch { color: var(--fg); }
.pr-summary .ps-meta .ps-excl-tests { opacity: 0.7; }
.pr-summary .ps-status-row { display: flex; align-items: center; gap: 22px; margin-top: 4px; font-family: var(--mono); font-size: 13px; }
.pr-summary .ps-status-row .submit-entry { margin-left: auto; }
.ps-adds { color: var(--green); }
.ps-dels { color: var(--red); }

.drawer-toggle { display: none; }

/* ---- nav-tabs (Review / Repowise) in the pr-summary status row --------- */
.nav-tabs { display: inline-flex; gap: 2px; align-items: stretch; }
.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px 5px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13px;
  border-bottom-width: 2px;
}
.nav-tab:first-child { border-radius: 6px 0 0 6px; }
.nav-tab:last-child { border-radius: 0 6px 6px 0; }
.nav-tab + .nav-tab { border-left: 0; }
.nav-tab:hover { color: var(--fg); }
.nav-tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.nav-tab .nav-tab-mark { color: var(--accent); width: 0.9em; display: inline-block; }
.nav-tabs-hint { margin-left: 4px; align-self: center; }

/* file-list */
.file-list {
  grid-area: files;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  overflow: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
}
.fl-progress { padding: 0 14px 10px; }
.fl-progress-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 5px; }
.fl-head-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-left: auto; min-width: 0; }
.fl-progress .fl-count { font-family: var(--mono); font-size: 12px; color: var(--fg-muted); }
.ai-engine-select {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  color: var(--fg-muted);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.ai-engine-select:disabled { opacity: 0.55; cursor: default; }

.fl-order-select {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  color: var(--fg-muted);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.fl-order-select:hover, .fl-order-select:focus-visible { color: var(--fg); }
.fl-group-toggle, .fl-behavior-name { font-family: var(--mono); font-size: 11px; padding: 2px 7px; }
.fl-group-toggle[aria-pressed="true"] { color: var(--fg); border-color: var(--border); }
.fl-behavior {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  padding: 6px 8px 4px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-muted);
  border-top: 1px solid var(--border);
}
/* min-width:0 is what lets this shrink at all: a flex item's automatic minimum
   is its content width, so without it a long title widens the row instead. */
.fl-behavior-caret {
  flex: 1 1 100%;
  min-width: 0;
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.45;
  padding-left: 1.6em;
  text-indent: -1.6em;
}
.fl-behavior-meta { flex: 0 1 auto; margin-right: auto; color: var(--fg-dim); min-width: 0; }
.fl-behavior-noise { opacity: 0.65; }
.fl-behavior-comment { padding: 0 4px; }
.fl-also-in { font-family: var(--mono); font-size: 10px; color: var(--fg-dim); flex: 0 0 auto; white-space: nowrap; }
.fl-tests-toggle { font-family: var(--mono); font-size: 11px; padding: 2px 7px; }
.fl-tests-toggle[aria-pressed="true"] { color: var(--fg); border-color: var(--border); }
.fl-empty { padding: 14px; font-family: var(--mono); font-size: 12px; color: var(--fg-dim); }
.progress-track { height: 6px; background: var(--bg-elev-2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--green); transition: width 0.2s; }

.fl-rows { flex: 1 1 auto; }
.fl-row {
  display: grid;
  grid-template-columns: 16px 1fr auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 6px 14px;
  background: none;
  border: 0;
  color: var(--fg);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12.5px;
}
.fl-row:hover { background: var(--bg-elev-2); }
.fl-row.current { background: var(--bg-elev-2); box-shadow: inset 3px 0 0 var(--accent); }
.fl-marker { color: var(--accent); width: 16px; }
.fl-name { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
/* Basename wins the row: truncating it to `chan…` costs the only part that identifies the file. */
.fl-base { flex: 0 0 auto; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); }
.fl-dir { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-dim); font-size: 11px; min-width: 0; }
.fl-counts { color: var(--fg-muted); }
.fl-counts .ps-adds, .fl-counts .ps-dels { margin-left: 4px; }
.fl-badges { display: inline-flex; gap: 4px; min-width: 14px; }
.fl-legend { padding: 12px 14px 4px; font-family: var(--mono); font-size: 11px; color: var(--fg-dim); border-top: 1px solid var(--border); }
.fl-legend span { margin-right: 12px; }

/* file-detail */
.file-detail {
  grid-area: detail;
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.fd-scroll {
  flex: 1 1 auto;
  overflow: auto;
  min-height: 0;
  padding: 16px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
/* Children size to content and never shrink — otherwise the flex column would
   collapse the overflow:hidden diff region (min-height:0) to fit and clip it,
   instead of letting .fd-scroll scroll. */
.fd-scroll > * { flex: 0 0 auto; }
.fd-empty { color: var(--fg-muted); margin: auto; font-family: var(--mono); }
.fd-header { display: flex; align-items: baseline; gap: 14px; font-family: var(--mono); }
.fd-header .fd-name { font-size: 15px; font-weight: 600; overflow-wrap: break-word; }
/* Diff / Full-file toggle in the file header. Both never shrink below their
   natural width — a long filename wraps instead, rather than squeezing these
   buttons until their label text wraps onto two lines. */
.fd-view-seg { margin-left: auto; flex-shrink: 0; display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; align-self: center; }
.fd-view-btn { background: none; border: 0; color: var(--fg-muted); font-size: 12px; font-family: var(--mono); white-space: nowrap; padding: 5px 12px; line-height: 1.3; cursor: pointer; transition: background-color 0.12s, color 0.12s; }
.fd-view-btn:hover:not(.is-active) { color: var(--fg); background: var(--bg-elev-2); }
.fd-view-btn.is-active { background: var(--accent); color: #fff; }
.fd-view-btn + .fd-view-btn { border-left: 1px solid var(--border); }
.fd-wrap-btn { flex-shrink: 0; border: 1px solid var(--border); border-radius: 6px; align-self: center; }
/* Whole-file view: line-numbered table, added lines highlighted. */
.diff-region .fullfile { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; line-height: 1.6; }
.diff-region .fullfile td.ff-num { width: 1%; text-align: right; padding: 0 12px 0 10px; color: var(--fg-dim); user-select: none; white-space: nowrap; border-right: 1px solid var(--border); }
.diff-region .fullfile td.ff-code { padding: 0 12px; color: var(--fg); white-space: pre; tab-size: 4; }
.diff-region .fullfile tr.ff-added td.ff-code { background: rgba(46, 160, 67, 0.13); }
.diff-region .fullfile tr.ff-added td.ff-num { background: rgba(46, 160, 67, 0.13); color: var(--green); }
/* Wrap-long-lines mode: toggled by #wrap-toggle, persisted via data-wrap on <html>.
   Diff2html's line content is normally `white-space: pre` inside a horizontally
   scrolling container; flip both to pre-wrap / visible so long lines break instead. */
html[data-wrap="on"] .diff-region .d2h-code-line-ctn,
html[data-wrap="on"] .diff-region .d2h-code-side-line .d2h-code-line-ctn {
  white-space: pre-wrap;
  word-break: break-all;
}
html[data-wrap="on"] .diff-region .d2h-file-diff,
html[data-wrap="on"] .diff-region .d2h-file-side-diff {
  overflow-x: visible;
}
html[data-wrap="on"] .diff-region .fullfile td.ff-code {
  white-space: pre-wrap;
  word-break: break-all;
}

/* A fixed-height row beneath the scrolling .fd-scroll region (not in the scroll
   flow), so it never overlaps the diff and the last diff line is always visible. */
.action-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.action-bar .ab-label { color: var(--fg-muted); font-size: 13px; margin-right: 4px; }

/* ---- AI panel ---------------------------------------------------------- */
.ai-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  padding: 12px 14px;
}
.ai-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ai-head .ai-title { font-family: var(--mono); font-size: 13px; color: var(--fg-muted); }
/* Long AI responses scroll inside the panel instead of pushing the diff down. */
.ai-body { font-size: 13.5px; line-height: 1.55; max-height: 320px; overflow-y: auto; }
.ai-qa { max-height: 280px; overflow-y: auto; }
.ai-body p { margin: 0 0 10px; }
.ai-body > :last-child { margin-bottom: 0; }
.ai-body ul { margin: 0 0 10px; padding-left: 20px; }
.ai-body li { margin: 2px 0; }
.ai-body code { font-family: var(--mono); font-size: 0.9em; background: var(--bg-elev-2); padding: 1px 5px; border-radius: 4px; }
.ai-body strong { color: var(--fg); font-weight: 600; }
.ai-body hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.ai-body .ai-md-h { font-weight: 600; margin: 8px 0 4px; }
.ai-loading { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 13px; color: var(--fg-muted); }
.ai-error { color: var(--red); display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 13px; }
.ai-divider { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.ai-ask-row { display: flex; gap: 8px; align-items: center; }
.ai-ask-row .text-input { font-family: var(--sans); }
.ai-progress-track { flex: 1 1 auto; height: 6px; background: var(--bg-elev-2); border-radius: 3px; overflow: hidden; position: relative; }
.ai-progress-indef { position: absolute; height: 100%; width: 30%; background: var(--accent); animation: indef 1.2s ease-in-out infinite; }
@keyframes indef { 0% { left: -30%; } 100% { left: 100%; } }
.ai-qa { font-size: 13px; }
.ai-qa .ai-q { color: var(--fg-muted); }

.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner-sm { width: 11px; height: 11px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Diff -------------------------------------------------------------- */
/* position:relative makes this the containing block for diff2html's absolutely
   positioned line-number gutter, so the gutter scrolls with the code inside
   .fd-scroll instead of anchoring to the viewport and staying frozen. */
.diff-region { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; position: relative; }
/* diff2html dark scheme (enabled in JS) provides the palette. Tune for legibility
   WITHOUT touching the horizontal box: diff2html positions the line number
   absolutely and reserves space for it via the code line's left padding
   (padding: 0 4.5em). Overriding that padding clips the code under the gutter,
   so here we only adjust line-height / colors — never horizontal padding. */
.diff-region .d2h-wrapper { font-size: 13px; font-family: var(--mono); }
.diff-region .d2h-code-line,
.diff-region .d2h-code-side-line { line-height: 1.6; color: var(--fg); }
/* Code text must be selectable for the "explain selection" feature — diff2html
   marks side-by-side lines user-select:none; force text-selectable on the code
   content (line-number gutters stay unselectable). */
.diff-region .d2h-code-line,
.diff-region .d2h-code-side-line,
.diff-region .d2h-code-line-ctn { -webkit-user-select: text; user-select: text; }
/* Scroll horizontally so long lines stay reachable (no content cut off) — in both
   line-by-line (.d2h-file-diff) and side-by-side (.d2h-file-side-diff) layouts. */
.diff-region .d2h-file-diff,
.diff-region .d2h-file-side-diff { overflow-x: auto; }
.diff-region .d2h-code-side-linenumber { color: var(--fg-dim); border-color: var(--border); }
/* Soften the per-line add/del wash so changed *words* stand out, not whole rows. */
.diff-region .d2h-ins { background: rgba(46, 160, 67, 0.13); }
.diff-region .d2h-del { background: rgba(248, 81, 73, 0.13); }
.diff-region .d2h-ins ins { background: rgba(46, 160, 67, 0.40); text-decoration: none; border-radius: 2px; }
.diff-region .d2h-del del { background: rgba(248, 81, 73, 0.40); text-decoration: none; border-radius: 2px; }
.diff-region .d2h-info { background: var(--bg-elev); color: var(--fg-muted); }
/* The filename already shows in .fd-header above the panel — hide diff2html's
   own per-file header to avoid showing it twice. */
.diff-region .d2h-file-header { display: none; }
/* Syntax highlighting (vendored highlight.js) — GitHub's own token palette, so
   a highlighted diff here matches what reviewers already know from github.com.
   Backgrounds stay whatever the diff/full-file row already set (added/removed
   wash, etc.) — these rules only ever set foreground color. Base values are
   GitHub's dark palette (the app's default theme); the light override below
   swaps in GitHub's light palette, same pattern as the rest of the theme. */
.diff-region .hljs-comment, .diff-region .hljs-quote { color: var(--fg-muted); }
.diff-region .hljs-keyword, .diff-region .hljs-selector-tag, .diff-region .hljs-subst { color: #ff7b72; }
.diff-region .hljs-number, .diff-region .hljs-literal, .diff-region .hljs-variable,
.diff-region .hljs-template-variable, .diff-region .hljs-tag .hljs-attr,
.diff-region .hljs-built_in, .diff-region .hljs-builtin-name { color: #79c0ff; }
.diff-region .hljs-string, .diff-region .hljs-doctag, .diff-region .hljs-regexp,
.diff-region .hljs-link { color: #a5d6ff; }
.diff-region .hljs-title, .diff-region .hljs-section, .diff-region .hljs-selector-id,
.diff-region .hljs-symbol, .diff-region .hljs-bullet { color: #d2a8ff; }
.diff-region .hljs-type, .diff-region .hljs-class .hljs-title { color: #ffa657; }
.diff-region .hljs-tag, .diff-region .hljs-name, .diff-region .hljs-attribute { color: #7ee787; }
.diff-region .hljs-meta { color: var(--fg-muted); }
.diff-region .hljs-emphasis { font-style: italic; }
.diff-region .hljs-strong { font-weight: 700; }
:root[data-theme="light"] .diff-region .hljs-keyword,
:root[data-theme="light"] .diff-region .hljs-selector-tag,
:root[data-theme="light"] .diff-region .hljs-subst { color: #cf222e; }
:root[data-theme="light"] .diff-region .hljs-number,
:root[data-theme="light"] .diff-region .hljs-literal,
:root[data-theme="light"] .diff-region .hljs-variable,
:root[data-theme="light"] .diff-region .hljs-template-variable,
:root[data-theme="light"] .diff-region .hljs-tag .hljs-attr,
:root[data-theme="light"] .diff-region .hljs-built_in,
:root[data-theme="light"] .diff-region .hljs-builtin-name { color: #0550ae; }
:root[data-theme="light"] .diff-region .hljs-string,
:root[data-theme="light"] .diff-region .hljs-doctag,
:root[data-theme="light"] .diff-region .hljs-regexp,
:root[data-theme="light"] .diff-region .hljs-link { color: #0a3069; }
:root[data-theme="light"] .diff-region .hljs-title,
:root[data-theme="light"] .diff-region .hljs-section,
:root[data-theme="light"] .diff-region .hljs-selector-id,
:root[data-theme="light"] .diff-region .hljs-symbol,
:root[data-theme="light"] .diff-region .hljs-bullet { color: #8250df; }
:root[data-theme="light"] .diff-region .hljs-type,
:root[data-theme="light"] .diff-region .hljs-class .hljs-title { color: #953800; }
:root[data-theme="light"] .diff-region .hljs-tag,
:root[data-theme="light"] .diff-region .hljs-name,
:root[data-theme="light"] .diff-region .hljs-attribute { color: #116329; }
.diff-placeholder { padding: 24px; text-align: center; color: var(--fg-muted); font-family: var(--mono); }
.diff-loading { padding: 24px; text-align: center; color: var(--fg-muted); }

/* ---- File comments (bubbles in the reviewed file) ---------------------- */
.fd-comments { display: flex; flex-direction: column; gap: 8px; }
.fd-comments[hidden] { display: none; }
.fd-comments-title { font-family: var(--mono); font-size: 12px; color: var(--fg-muted); }
.comment-bubble {
  align-self: flex-start;
  max-width: 80%;
  padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 3px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Inline line-anchored comment row injected into the diff table. */
.diff-region tr.comment-row > td { padding: 6px 12px 6px 4.5em; background: var(--bg-elev); border-top: 1px solid var(--border); }
.diff-region tr.comment-row .comment-bubble { max-width: 90%; margin: 2px 0; }
.diff-region tr.comment-row .fd-comments-title { margin-bottom: 4px; }

/* ---- Inline "explain selection" --------------------------------------- */
.sel-explain-btn {
  position: fixed;
  z-index: 50;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--fg);
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.sel-explain-btn:hover { border-color: var(--accent); }
.sel-popover {
  position: fixed;
  z-index: 60;
  width: 420px;
  max-width: calc(100vw - 24px);
  max-height: 320px;
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.sel-pop-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--fg-muted);
}
.sel-pop-close { background: none; border: 0; color: var(--fg-muted); cursor: pointer; font-size: 13px; }
.sel-pop-close:hover { color: var(--fg); }
.sel-pop-body { padding: 12px; }

/* ---- Modal ------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(1, 4, 9, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 560px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-weight: 600;
}
.modal-close { background: none; border: 0; color: var(--fg-muted); cursor: pointer; font-size: 16px; font-family: var(--mono); }
.modal-body { padding: 16px; }
.modal-body label { display: block; margin-bottom: 6px; color: var(--fg-muted); font-size: 13px; }
.textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
}
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.modal-existing-note { background: var(--bg-elev-2); border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; font-family: var(--mono); font-size: 13px; color: var(--fg-muted); }

/* ---- Submit review ----------------------------------------------------- */
.submit-wrap { max-width: 880px; margin: 28px auto; padding: 0 20px; }
.submit-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.submit-head h2 { margin: 0; font-size: 18px; }
.counts-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
.count-cell { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.count-cell .cc-label { color: var(--fg-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.count-cell .cc-value { font-size: 22px; font-weight: 700; font-family: var(--mono); }
.comments-line { font-family: var(--mono); color: var(--fg-muted); margin-bottom: 18px; }

.flagged-table { width: 100%; border-collapse: collapse; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 18px; }
.flagged-table th, .flagged-table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: 13px; }
.flagged-table th { color: var(--fg-muted); font-weight: 600; background: var(--bg-elev); }
.flagged-table td:first-child { color: var(--flag); white-space: nowrap; }
.flagged-empty { color: var(--fg-muted); font-family: var(--mono); margin-bottom: 18px; }

.decision-group { display: flex; gap: 22px; margin: 12px 0 18px; flex-wrap: wrap; }
.decision-opt { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-family: var(--mono); font-size: 14px; }
.unviewed-warn { color: var(--yellow); font-family: var(--mono); font-size: 13px; margin-bottom: 14px; }
.unviewed-warn[hidden] { display: none; }
.submit-actions { display: flex; justify-content: flex-end; gap: 12px; }

/* ---- screen:repowise --------------------------------------------------- */
.repowise-grid {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-areas: "summary" "region";
  height: 100%;
}
#pr-summary-repowise { grid-area: summary; }
.repowise-region {
  grid-area: region;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* component:repowise-prepare */
.rw-prepare {
  flex: 1 1 auto;
  overflow: auto;
  min-height: 0;
  padding: 24px 28px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.rw-prepare-title { font-family: var(--mono); font-size: 14px; color: var(--fg); margin-bottom: 18px; }
.rw-steps { list-style: none; margin: 0 0 20px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.rw-step { display: grid; grid-template-columns: 18px 1fr; gap: 10px; align-items: baseline; font-family: var(--mono); font-size: 13px; }
.rw-step-glyph { width: 18px; text-align: center; }
.rw-step-glyph .spinner { vertical-align: -1px; }
.rw-step-label { color: var(--fg); }
.rw-step-sub { color: var(--fg-muted); font-size: 12px; margin-top: 2px; }
.rw-step.is-pending .rw-step-label { color: var(--fg-dim); }
.rw-step.is-skipped .rw-step-label { color: var(--fg-muted); }
.rw-prepare-progress { display: flex; align-items: center; gap: 12px; font-family: var(--mono); font-size: 12px; color: var(--fg-muted); margin-bottom: 18px; }
.rw-prepare-foot { display: flex; justify-content: flex-end; }

/* component:repowise-embed */
.rw-embed { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.rw-embed-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--fg-muted);
}
.rw-embed-bar .rw-bar-ctx { color: var(--fg); }
.rw-embed-bar .rw-bar-mark { color: var(--accent); }
.rw-embed-bar .rw-bar-actions { margin-left: auto; display: inline-flex; gap: 8px; }
.rw-embed-frame {
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 12px;
  overflow: hidden;
}
.rw-embed-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

/* Complete/Diff mode toggle + the prview-native diff-associations panel. */
.rw-mode-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.rw-mode-btn { background: none; border: 0; color: var(--fg-muted); font-size: 12px; padding: 4px 10px; cursor: pointer; font-family: var(--mono); }
.rw-mode-btn:hover { color: var(--fg); }
.rw-mode-btn.is-active { background: var(--accent); color: #fff; }
.rw-embed-frame.rw-diff-panel { overflow: auto; padding: 14px 16px; background: var(--bg-elev); }
.rw-diff-loading, .rw-diff-error { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 13px; color: var(--fg-muted); padding: 16px; }
.rw-diff-error { color: var(--red); }
.rw-diff-head { font-family: var(--mono); font-size: 14px; color: var(--fg); margin-bottom: 12px; }
.rw-diff-section { margin-bottom: 16px; }
.rw-diff-title { font-family: var(--mono); font-size: 12px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.rw-diff-empty { color: var(--fg-dim); font-size: 12px; font-family: var(--mono); padding: 2px 0; }
.rw-diff-row { display: flex; align-items: baseline; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.rw-diff-path { flex: 1 1 auto; font-family: var(--mono); font-size: 13px; color: var(--fg); word-break: break-all; }
.rw-diff-tag { flex: 0 0 auto; font-family: var(--mono); font-size: 11px; color: var(--fg-muted); }
.rw-docgen-status { margin-top: 10px; font-family: var(--mono); font-size: 12px; color: var(--fg-muted); white-space: pre-wrap; }

/* component:repowise-link-fallback */
.rw-fallback {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 32px;
}
.rw-fallback-mark { font-size: 18px; color: var(--fg); font-family: var(--mono); }
.rw-fallback-mark .rw-bar-mark { color: var(--accent); }
.rw-fallback-text { color: var(--fg-muted); max-width: 460px; line-height: 1.55; }
.rw-fallback .btn-primary { padding: 10px 22px; font-size: 15px; }
.rw-url-row { display: inline-flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 13px; color: var(--fg-muted); }
.rw-url-row .rw-url { color: var(--fg); }

/* component:repowise-error (reuses .ai-error / .ai-body code) */
.rw-error { flex: 1 1 auto; overflow: auto; min-height: 0; padding: 24px 28px; max-width: 760px; width: 100%; margin: 0 auto; }
.rw-error .ai-error { margin: 6px 0 4px; }
.rw-error-hint { color: var(--fg-muted); font-family: var(--mono); font-size: 12px; margin: 0 0 16px 24px; }
.rw-error-hint code { font-family: var(--mono); background: var(--bg-elev-2); padding: 1px 6px; border-radius: 4px; color: var(--fg); }
.rw-error-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.rw-stderr {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg-muted);
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
}

/* ---- screen:overview ---------------------------------------------------- */
.overview-grid {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-areas: "summary" "region";
  height: 100%;
}
#pr-summary-overview { grid-area: summary; }
.overview-region {
  grid-area: region;
  overflow-y: auto;
  min-height: 0;
  padding: 24px 28px;
}
.ov-toolbar { display: flex; gap: 10px; justify-content: flex-end; margin-bottom: 14px; }
.ov-loading { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; padding: 32px 0; }
.ov-body { max-width: 980px; margin: 0 auto; max-height: none; overflow-y: visible; }
.ai-md-pre {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.35;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 12px;
  white-space: pre;
}

/* ---- Toast ------------------------------------------------------------- */
.toast-stack { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--green);
  border-radius: 6px;
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: toast-in 0.18s ease-out;
}
.toast.toast-error { border-left-color: var(--red); }
.toast-link { color: inherit; text-decoration: underline; margin-left: 8px; white-space: nowrap; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Narrow-screen fallback (drawer + unified diff) -------------------- */
@media (max-width: 860px) {
  .review-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "summary"
      "detail";
  }
  .drawer-toggle { display: inline-flex; }
  .file-list {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 84%;
    max-width: 340px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 18px rgba(0,0,0,0.5);
  }
  body.drawer-open .file-list { transform: none; }
  .counts-grid { grid-template-columns: repeat(2, 1fr); }

  /* pr-summary stacks; nav-tabs wrap below the status text */
  .pr-summary .ps-status-row { flex-wrap: wrap; gap: 12px; }
  .pr-summary .ps-status-row .submit-entry { margin-left: 0; }
  /* The ☰ Files drawer toggle is meaningless on the Repowise tab (no file list) */
  #pr-summary-repowise .drawer-toggle { display: none; }
  .rw-embed-frame { margin: 6px; }
}

/* Local AI review: menu, run status, staged drafts */
.review-menu .skill-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.skill-row { display: flex; gap: 10px; align-items: baseline; text-align: left; width: 100%; }
.skill-row.skill-misfit { opacity: 0.55; }
.skill-name { font-weight: 600; }
.skill-note { font-size: 0.85em; opacity: 0.75; }
#review-status {
  position: fixed; bottom: 12px; left: 12px; z-index: 40;
  display: flex; gap: 10px; align-items: center;
  padding: 6px 10px; border: 1px solid currentColor; border-radius: 4px;
  background: var(--bg, #111); font-size: 0.85em;
}
.comment-bubble.comment-draft { border-left: 3px dashed currentColor; }
.draft-badges { display: flex; gap: 6px; margin-bottom: 4px; }
.badge {
  font-size: 0.72em; letter-spacing: 0.04em; padding: 1px 6px;
  border-radius: 3px; border: 1px solid currentColor;
}
.badge-fix { font-weight: 700; }
.draft-actions { display: flex; gap: 8px; margin-top: 4px; }
.review-panel { grid-column: 1 / -1; padding: 10px 14px; }
.run-row { display: flex; gap: 12px; align-items: baseline; margin-bottom: 6px; }
.staged-summary { margin: 12px 0; padding: 10px 12px; border: 1px solid currentColor; border-radius: 4px; }
.staged-summary h4 { margin: 8px 0 2px; font-size: 0.9em; }
.staged-summary ul { margin: 0; padding-left: 20px; font-size: 0.88em; }
