:root {
  --ink: #1b1b1b;
  --muted: #565656;
  --line: #e0ddd6;
  --bg: #ffffff;
  --panel: #f6f5f1;
  --accent: #166b4d;
  --accent-ink: #ffffff;
  --add: #e7f4ec;
  --del: #fbeae9;
  --radius: 8px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --ink: #ede9df;
  --muted: #a39d90;
  --line: #38352c;
  --bg: #171613;
  --panel: #201e19;
  --accent: #3fa377;
  --accent-ink: #0d1512;
  --add: #143326;
  --del: #3d1f1c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { font-size: 18px; font-weight: 700; }
.brand-mark {
  display: inline-block;
  width: 26px; height: 26px;
  line-height: 26px;
  text-align: center;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  margin-right: 6px;
}
.brand-sub { color: var(--muted); font-weight: 400; font-size: 13px; }

.topbar-right { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.repo-label { font-size: 13px; color: var(--muted); }
.auth-bar { display: flex; gap: 8px; align-items: center; }
.auth-form { display: flex; gap: 6px; align-items: center; }
.auth-form input { width: 110px; }
/* Author display rules (flex/grid above) beat the browser's built-in
   [hidden] handling, so re-assert it: hidden must always win. */
[hidden] { display: none !important; }

.health { font-size: 12px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 20px; }
.health.ok { color: var(--accent); border-color: var(--accent); }
.health.bad { color: #a02c22; border-color: #a02c22; }

.tabs { display: flex; gap: 4px; padding: 8px 18px 0; border-bottom: 1px solid var(--line); }
.tabs button {
  border: 1px solid transparent;
  border-bottom: none;
  background: none;
  padding: 8px 18px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  border-radius: var(--radius) var(--radius) 0 0;
}
.tabs button.active { color: var(--ink); font-weight: 600; background: var(--bg); border-color: var(--line); }

main { padding: 16px 18px 60px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

.controls { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.controls label { font-size: 13px; color: var(--muted); }

.columns { display: grid; grid-template-columns: 300px 320px 1fr; gap: 16px; align-items: start; }
.columns-split { grid-template-columns: 280px minmax(0, 1fr); }
.col h2 { font-size: 13px; text-transform: none; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.col h3 { font-size: 13px; color: var(--muted); margin: 14px 0 6px; }

.history, .tree, .comments, .treenode { list-style: none; margin: 0; padding: 0; }
.treenode { padding-left: 16px; }
.history li, .tree li {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  background: var(--bg);
  word-break: break-word;
}
.history li:hover, .tree li:hover { border-color: var(--accent); }
/* Row links: every revision, file, diff, and change row carries its own
   shareable URL. The link fills the row; plain clicks keep working. */
.rowlink { display: block; color: inherit; text-decoration: none; }
.history li.selected, .tree li.selected { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.history .rev-num { font-weight: 700; margin-right: 8px; }
.history .rev-date { display: block; font-size: 12px; color: var(--muted); }
.tree .dir { font-weight: 600; }
.tree .size { float: right; color: var(--muted); font-size: 12px; }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg);
  white-space: pre-wrap;
  word-break: break-word;
}

.fileview, .diff {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  overflow: auto;
  max-height: 60vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--bg);
  white-space: pre-wrap;
  word-break: break-word;
}
.diff .add { background: var(--add); display: block; }
.diff .del { background: var(--del); display: block; }

/* Review diff pane keeps one fixed size and scrolls: switching files
   must not move the page content below it. */
#review-diff {
  height: 60vh;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Stale-checkout banner: a behind-but-dirty working tree that auto-sync
   refuses to touch. Same red as .health.bad, bold text and a heavy
   border so it cannot be mistaken for the small sync line. */
.stale-banner {
  border: 2px solid #a02c22;
  border-radius: var(--radius);
  background: var(--del);
  color: var(--ink);
  font-weight: 600;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.stale-banner button { margin-left: 12px; border-color: #a02c22; }

button, select, input, textarea {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
  background: var(--bg);
  color: var(--ink);
}
button { cursor: pointer; background: var(--panel); }
button:hover { border-color: var(--accent); }
form.card button[type="submit"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); margin-top: 8px; }
form.card input, form.card textarea, form.card select { width: 100%; margin-top: 6px; display: block; }
form.card input:first-child { margin-top: 0; }

.comments li {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 8px;
}
.comments .who { font-weight: 600; font-size: 13px; }
.comments .when { color: var(--muted); font-size: 12px; margin-left: 8px; }
.comments .where { color: var(--muted); font-size: 12px; }
.comments .replies { margin-top: 8px; padding-left: 16px; }
.comments li.resolved { opacity: 0.75; }
.resolved-badge {
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 1px 8px;
  margin-left: 8px;
}
.comment-actions { margin-top: 6px; display: flex; gap: 8px; }
.comment-actions button { font-size: 12px; padding: 3px 10px; }
.reply-form { margin-top: 8px; display: flex; gap: 8px; }
.reply-form input { flex: 1; }

.toast {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  max-width: 80vw;
}

.skeleton {
  opacity: 0.7;
  animation: pulse 1.2s ease-in-out infinite;
}

.is-loading {
  opacity: 0.65;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.tabs button.has-update::after {
  content: " •";
  color: var(--accent);
}

.history li:focus-visible, .tree li:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.compare-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.jump-link {
  font-size: 12px;
  padding: 3px 10px;
}

details.compare-file {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg);
}

details.compare-file summary {
  cursor: pointer;
  padding: 8px 12px;
  font-weight: 600;
}

details.compare-file summary:hover {
  border-color: var(--accent);
}

details.compare-file pre.diff {
  border: none;
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  margin: 0;
}

.empty-state {
  cursor: default;
}

.empty-state button {
  margin-left: 8px;
}

@keyframes pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.8; }
}

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

@media (prefers-reduced-motion: reduce) {
  * { transition: none; animation: none; }
}
