/*  This file is part of the OmniDiff code diffing tool.
 *
 *  Copyright (C) 2026 Marko Ivankovic
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published
 *  by the Free Software Foundation, version 3 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #d8d8d8;
  --panel-bg: #fafafa;
  --unmarked: #6b6b6b;
  --matched: #0969da;
  --deleted: #cf222e;
  --inserted: #1a7f37;
  --update: #9a6700;
  --moved: #8250df;
  --selected-bg: #ffe58a;
  --selected-fg: #1a1a1a;
  --highlight-bg: #cfe6ff;
  --link: #0969da;
  --button-bg: #f0f0f0;
  --button-border: #c8c8c8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --fg: #e6edf3;
    --muted: #9aa4af;
    --border: #30363d;
    --panel-bg: #161b22;
    --unmarked: #9aa4af;
    --matched: #58a6ff;
    --deleted: #ff7b72;
    --inserted: #56d364;
    --update: #d29922;
    --moved: #a371f7;
    --selected-bg: #6b5900;
    --selected-fg: #f5e6a8;
    --highlight-bg: #16324a;
    --link: #58a6ff;
    --button-bg: #21262d;
    --button-border: #30363d;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 1rem 5rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
}

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

.page-header {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.page-header h1 {
  font-size: 1.1rem;
  margin: 0.25rem 0;
}

.back-link {
  font-size: 0.85rem;
}

.language-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
}

.source-link {
  display: inline-block;
  margin-left: 0.75rem;
  font-size: 0.8rem;
}

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0.5rem 0 0;
  padding: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.3em;
}

.fixture-table {
  border-collapse: collapse;
  max-width: 60rem;
  width: 100%;
}

.fixture-table th,
.fixture-table td {
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.fixture-table td:nth-child(n + 3),
.fixture-table th:nth-child(n + 3) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.fixture-table th {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.fixture-table th:hover {
  color: var(--fg);
}

.fixture-table th[aria-sort="ascending"],
.fixture-table th[aria-sort="descending"] {
  color: var(--matched);
}

.fixture-table th[aria-sort="ascending"]::after {
  content: " \25b4";
}

.fixture-table th[aria-sort="descending"]::after {
  content: " \25be";
}

.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

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

.panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  padding: 0.5rem 0.75rem;
  overflow-x: auto;
}

.panel[data-focused="true"] {
  border-color: var(--matched);
}

.panel h2 {
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tree {
  white-space: nowrap;
}

.node {
  display: block;
}

details.node {
  margin: 0;
}

details.node > summary {
  cursor: pointer;
  list-style: none;
}

details.node > summary::-webkit-details-marker {
  display: none;
}

details.node > summary::before {
  content: "\25b8";
  display: inline-block;
  width: 1em;
  color: var(--muted);
}

details.node[open] > summary::before {
  content: "\25be";
}

details.node > *:not(summary) {
  margin-left: 1.1em;
}

.node.leaf {
  padding-left: 1.1em;
}

.node.leaf,
details.node > summary {
  padding: 0.05rem 0.2rem;
  border-radius: 3px;
}

.node.leaf:hover,
details.node > summary:hover {
  background: color-mix(in srgb, var(--matched) 12%, transparent);
}

.status-unmarked {
  color: var(--unmarked);
}

.status-matched {
  color: var(--matched);
}

.status-deleted {
  color: var(--deleted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.status-inserted {
  color: var(--inserted);
}

/* A `status-matched` node that's a real edit (Update/MatchButNotIdentical), not a genuinely
   identical match - see `render_node`'s `changed_class` in generate_mapping_site.rs. Bold rather
   than a new color: it's still a "matched" pair (blue), just one the "hide identical matches"
   toggle below must never hide. */
.changed {
  font-weight: 700;
}

/* Which kind of matched pair this is - independent of `.changed` above, and overrides
   `.status-matched`'s plain blue (two classes beats one on specificity, so this wins regardless of
   the two rules' order in this file). `.op-update`: a leaf whose text changed (still `.changed` -
   yellow AND bold). `.op-moved`: a genuinely `Identical` pair - same content - that nonetheless
   sits at a different position than before (see `Caches::before_moved` in human_mapping.rs); never
   `.changed` and not bold, since nothing about its content differs, only where it is. */
.status-matched.op-update {
  color: var(--update);
}

.status-matched.op-moved {
  color: var(--moved);
}

/* Toggled on <body> by viewer.js's "hide identical matches" button/keybinding. Hides any node
   that's neither itself deleted/inserted/changed nor an ancestor of one (:has() finds a
   qualifying node at any depth, not just a direct child) - i.e. every genuinely-identical match
   and every never-annotated node, unless something interesting is nested underneath it. */
body.hide-identical .node:not(.status-deleted, .status-inserted, .changed):not(
    :has(.status-deleted, .status-inserted, .changed)
  ) {
  display: none;
}

.node.placeholder {
  font-style: italic;
  opacity: 0.75;
}

/* A multi-map group member's badge - see `render_node`'s `group_badge` in
   generate_mapping_site.rs. `.group-any`: one of several valid pairings is shown, so it stays
   muted. `.group-all`: every counterpart is real and `data-match` lists them all, so it takes the
   matched color to say so. Never bold and never struck through, whatever the node's own status. */
.group-badge {
  display: inline-block;
  font-size: 0.7em;
  font-weight: 400;
  line-height: 1.3;
  padding: 0 0.4em;
  border-radius: 0.7em;
  border: 1px solid var(--muted);
  color: var(--muted);
  text-decoration: none;
  vertical-align: middle;
}

.group-badge.group-all {
  border-color: var(--matched);
  color: var(--matched);
}

.node.selected > summary,
.node.leaf.selected {
  background: var(--selected-bg) !important;
  color: var(--selected-fg) !important;
}

.node.counterpart > summary,
.node.leaf.counterpart {
  background: var(--highlight-bg) !important;
}

.page-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

#file-issue,
#toggle-identical,
#toggle-reviewed,
#random-unreviewed {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
}

#file-issue[aria-disabled="true"] {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

#toggle-identical[aria-pressed="true"] {
  background: var(--matched);
  color: #fff;
  border-color: var(--matched);
}

/* Set by reviewed.js. A stale mark (the mapping changed since it was made) keeps the button in
 * its unpressed shape but says so in the label; the colour is the "needs work" one. */
#toggle-reviewed[aria-pressed="true"] {
  background: var(--inserted);
  color: #fff;
  border-color: var(--inserted);
}

#toggle-reviewed[data-state="stale"] {
  border-color: var(--update);
  color: var(--update);
}

/* The index page's own review controls: a progress line and the random-fixture button, above the
 * table rather than in a fixed footer, which the index does not have. */
.review-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.fixture-table td.reviewed {
  text-align: center;
}

.fixture-table input.reviewed-mark {
  cursor: pointer;
}

#status-line {
  color: var(--muted);
  font-size: 0.8rem;
}

#help-overlay {
  position: fixed;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  max-width: 30rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

#help-overlay.hidden {
  display: none;
}

#help-overlay dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1rem;
  margin: 0.5rem 0 0;
}

#help-overlay dt {
  font-weight: bold;
  color: var(--matched);
}

#help-overlay dd {
  margin: 0;
  color: var(--fg);
}

#search-prompt {
  position: fixed;
  bottom: 3.2rem;
  left: 1rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  z-index: 10;
}

#search-prompt.hidden {
  display: none;
}

#search-prompt input {
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--button-border);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
}

/* ---------------------------------------------------------------- code panels
 * The rendered-source counterpart to the tree panels. Uses the same four operation colors as the
 * tree, but as backgrounds rather than text color: code has its own reasons to want the foreground
 * (and a whole line tinted is what makes a change findable while scrolling), so each operation gets
 * a muted background token alongside the strong foreground one it already had.
 */

:root {
  --deleted-bg: #ffd7d5;
  --inserted-bg: #cdf3d5;
  --update-bg: #f7e6bd;
  --moved-bg: #e6dbfb;
  --deleted-row-bg: #ffefee;
  --inserted-row-bg: #eaf9ee;
  --update-row-bg: #fbf4e2;
  --moved-row-bg: #f3eefc;
  --counterpart-outline: #0969da;
}

@media (prefers-color-scheme: dark) {
  :root {
    --deleted-bg: #67282c;
    --inserted-bg: #1f5c30;
    --update-bg: #5c4409;
    --moved-bg: #402e63;
    --deleted-row-bg: #2b1b1d;
    --inserted-row-bg: #172a1d;
    --update-row-bg: #2a2413;
    --moved-row-bg: #221c2f;
    --counterpart-outline: #58a6ff;
  }
}

.code-panels {
  margin-bottom: 1rem;
}

.code {
  white-space: pre;
  line-height: 1.45;
}

.cl {
  display: flex;
  align-items: flex-start;
}

.cl .ln {
  flex: 0 0 4ch;
  text-align: right;
  padding-right: 1ch;
  color: var(--muted);
  user-select: none;
}

.cl .lt {
  flex: 1 1 auto;
  min-width: 0;
}

.cl.fold {
  color: var(--muted);
  font-style: italic;
  border-top: 1px dashed var(--border);
  border-bottom: 1px dashed var(--border);
  margin: 0.15rem 0;
}

.cl.row-cd-delete {
  background: var(--deleted-row-bg);
}
.cl.row-cd-insert {
  background: var(--inserted-row-bg);
}
.cl.row-cd-update {
  background: var(--update-row-bg);
}
.cl.row-cd-move {
  background: var(--moved-row-bg);
}

.cd {
  border-radius: 2px;
  cursor: pointer;
}

.cd-delete {
  background: var(--deleted-bg);
}
.cd-insert {
  background: var(--inserted-bg);
}
.cd-update {
  background: var(--update-bg);
}
.cd-move {
  background: var(--moved-bg);
}

/* A zero-width placeholder range: the side with nothing to show for an insert/delete still gets a
 * range at the position the other side's text belongs (see TextRange's doc comment). Drawn as a
 * caret between two characters - it is the only thing marking, say, where a deleted function used
 * to be on the after side. Clickable like any other span, and its counterpart is the real text. */
.cd.cd-gap {
  display: inline-block;
  width: 0;
  background: none;
  border-left: 2px solid var(--deleted);
  margin: 0 -1px;
}

.cd.cd-gap.cd-insert {
  border-left-color: var(--inserted);
}

.cl.row-gap .ln {
  border-right: 2px solid var(--muted);
}

.cd.selected {
  outline: 2px solid var(--selected-fg);
  outline-offset: -1px;
}

.cd.counterpart {
  outline: 2px dashed var(--counterpart-outline);
  outline-offset: -1px;
}

/* Only the tree panels carry the "hide identical matches" behaviour and the keyboard cursor; the
 * view switch below is what hides one half or the other wholesale. */
body[data-view="code"] .tree-panels,
body[data-view="tree"] .code-panels {
  display: none;
}

.view-switch {
  display: inline-flex;
  gap: 0;
  margin-top: 0.5rem;
}

.view-switch button {
  font: inherit;
  padding: 0.15rem 0.6rem;
  background: var(--button-bg);
  color: var(--fg);
  border: 1px solid var(--button-border);
  cursor: pointer;
}

.view-switch button:first-child {
  border-radius: 4px 0 0 4px;
}

.view-switch button:last-child {
  border-radius: 0 4px 4px 0;
}

.view-switch button + button {
  border-left: none;
}

.view-switch button[aria-pressed="true"] {
  background: var(--matched);
  border-color: var(--matched);
  color: var(--bg);
}

.notice {
  margin: 0 0 0.75rem;
  padding: 0.4rem 0.6rem;
  border-left: 3px solid var(--update);
  background: var(--panel-bg);
  color: var(--muted);
}

/* The tree legend names foreground dot colors, the code legend background swatches - the same four
 * operations, but a reader comparing them side by side would be comparing two different palettes,
 * so each view shows only its own. */
body[data-view="tree"] .code-legend,
body[data-view="code"] .legend:not(.code-legend) {
  display: none;
}

.cd-inserted-swatch {
  display: inline-block;
  width: 1.2em;
  height: 0.85em;
  cursor: default;
}

/* ---------------------------------------------------------------- code renderings
 *
 * A fixture page stacks every account of the same edit as code - the node mapping projected to
 * text, plus one panel per human painting - and viewer.js shows one at a time. They are stacked
 * rather than laid out side by side on purpose: the two are compared by flipping between them
 * with the rows in identical positions, which is also why generate_mapping_site.rs folds every
 * rendering on the same row set. */
.code-panels.hidden {
  display: none;
}

.painting-switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.painting-switch-label {
  color: var(--muted);
}

/* Same segmented-control treatment as the view switch, so the two read as the same kind of
 * control - one chooses which half of the page you see, the other which answer it shows. */
.painting-switch button {
  font: inherit;
  padding: 0.15rem 0.6rem;
  background: var(--button-bg);
  color: var(--fg);
  border: 1px solid var(--button-border);
  cursor: pointer;
}

.painting-switch button:first-of-type {
  border-radius: 4px 0 0 4px;
}

.painting-switch button:last-of-type {
  border-radius: 0 4px 4px 0;
}

.painting-switch button + button {
  border-left: none;
}

.painting-switch button[aria-pressed="true"] {
  background: var(--matched);
  border-color: var(--matched);
  color: var(--bg);
}

/* The switch belongs to the code view, so it goes wherever the code panels go. */
body[data-view="tree"] .painting-switch,
body[data-view="tree"] .painting-notice {
  display: none;
}

.fixture-table td.paintings {
  color: var(--muted);
}

/* ---------------------------------------------------------------- provenance and notes
 *
 * What a fixture is (its description.md) and where it came from (the upstream commit it was
 * sampled from) - both previously visible only in src/test/data/diffs.csv. */
.description {
  margin: 0 0 0.75rem;
  padding: 0.4rem 0.6rem;
  border-left: 3px solid var(--matched);
  background: var(--panel-bg);
  white-space: pre-wrap;
}

.source-path {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}

/* Second line of the fixture-name cell, not a column: free prose has no fixed width, and it should
 * read as a subtitle of the name above it rather than compete with the counts beside it. */
.fixture-note {
  color: var(--muted);
  font-size: 0.9em;
  margin-top: 0.15rem;
  max-width: 60ch;
}
