.constituent-matches {
  display: grid;
  gap: var(--space-4);
  min-inline-size: 0;
  overflow-wrap: anywhere;
}

.constituent-matches__scope {
  margin: 0;
}

.constituent-matches__scope {
  color: var(--fg2);
  max-inline-size: 70ch;
}

/* The tally: three numbers that say how much of the pile is easy. */
.match-tally {
  display: grid;
  gap: var(--space-2);
}

.match-tally__total {
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
}

.match-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
  min-inline-size: 0;
}

.match-toolbar__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-inline-size: 0;
}

.match-batch {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  max-inline-size: 100%;
}

.match-batch:has(.match-batch__dialog--in-place) {
  display: flex;
  flex-basis: 100%;
}

.match-batch__dialog {
  inline-size: min(38rem, calc(100% - 2rem));
  max-inline-size: 100%;
}

.match-batch__dialog--in-place {
  position: static;
  margin-block-start: var(--space-3);
  inline-size: 100%;
}

.match-batch__body {
  display: grid;
  gap: var(--space-3);
  min-inline-size: 0;
}

.match-batch__summary,
.match-batch__audit-note {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.match-batch__summary {
  color: var(--fg1);
}

.match-batch__audit-note {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--tone-good-line);
  border-radius: var(--radius-sm);
  background: var(--tone-good-bg);
  color: var(--tone-good-fg);
}

.match-batch__list {
  display: grid;
  gap: var(--space-2);
  max-block-size: 15rem;
  margin: 0;
  padding: var(--space-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  list-style: none;
  overflow: auto;
}

.match-batch__item {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  min-inline-size: 0;
}

.match-batch__pair {
  color: var(--fg1);
  font-size: var(--text-sm);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.match-batch__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  color: var(--fg2);
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
}

.match-batch__form {
  display: grid;
  gap: var(--space-3);
  max-inline-size: none;
  margin: 0;
}

.match-batch__form .field {
  margin: 0;
}

.match-batch__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.match-shortcuts__toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-block-size: var(--target-min);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--fg2);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
}

.match-shortcuts__toggle:hover {
  border-color: var(--rule-strong);
  background: var(--surface-sunken);
  color: var(--fg1);
}

.match-shortcuts__toggle[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.match-shortcuts__panel {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.match-shortcuts__panel[hidden] { display: none; }

.match-shortcuts__heading {
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.match-shortcuts__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: 0;
}

.match-shortcuts__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.match-shortcuts__item dd {
  margin: 0;
  color: var(--fg1);
}

.match-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: 1.5rem;
  padding: 0.1rem var(--space-1);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--fg1);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.2;
}

.match-search {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-inline-size: 0;
}

.match-search__field {
  flex: 1 1 14rem;
  min-inline-size: 0;
  max-inline-size: 26rem;
}

.match-search__input {
  inline-size: 100%;
  min-block-size: var(--target-min);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  color: var(--fg1);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}

.match-search__input::placeholder { color: var(--fg3); }

.tform.match-toolbar__action {
  container-type: normal;
  display: inline-flex;
  inline-size: auto;
  max-inline-size: 100%;
  margin: 0;
}

.constituent-matches .btn {
  max-inline-size: 100%;
  white-space: normal;
  overflow-wrap: normal;
  text-align: center;
}

.match-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.match-filter {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-block-size: var(--target-min);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--fg1);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
}

.match-filter:hover {
  border-color: var(--rule-strong);
  background: var(--surface-sunken);
}

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

.match-filter__count {
  color: var(--fg2);
  font-variant-numeric: tabular-nums;
}

.match-triage {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

.match-triage__summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  margin: 0;
  color: var(--fg1);
  font-size: var(--text-sm);
}

.match-triage__confidence,
.match-triage__target {
  color: var(--fg2);
}

.match-triage .match-pair__signals li {
  border: 1px solid var(--rule);
  background: var(--surface-raised);
}

.match-tally__counts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: var(--space-2);
  margin: 0;
}

.match-tally__count {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.match-tally__count dt {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--fg2);
  font-size: var(--text-sm);
}

/* A small key dot matching the pair badges; the label carries the meaning. */
.match-tally__count dt::before {
  content: "";
  inline-size: 0.5rem;
  block-size: 0.5rem;
  border-radius: 50%;
  background: var(--rule-strong);
}

.match-tally__count[data-suggestion="likely_same"] dt::before { background: var(--tone-good-fg); }
.match-tally__count[data-suggestion="unclear"] dt::before { background: var(--tone-warn-fg); }

.match-tally__count dd {
  margin: 0;
  color: var(--fg1);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-variant-numeric: lining-nums tabular-nums;
  line-height: 1.1;
}

/* One pair: a head line, the evidence in words, a side-by-side table, then the decision. */
.match-list {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.match-pair {
  display: grid;
  gap: var(--space-3);
  min-inline-size: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.match-pair[data-active="true"] {
  border-color: var(--accent);
  box-shadow: var(--ring-accent);
}

.match-pair__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.match-pair__name {
  margin: 0;
  font-size: var(--text-lg);
}

.match-pair__number {
  color: var(--fg3);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.match-pair__ltv {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem var(--space-2);
  border: 1px solid var(--tone-accent-line);
  border-radius: var(--radius-sm);
  background: var(--tone-accent-bg);
  color: var(--tone-accent-fg);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.match-pair__source {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target-min);
  margin-inline-start: auto;
  color: var(--accent-text);
  font-size: var(--text-sm);
  font-weight: 600;
}

.match-pair__signals {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.match-pair__signals li {
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--fg1);
  font-size: var(--text-sm);
}

.match-compare {
  inline-size: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: var(--text-sm);
}

.match-compare col.match-compare__label { inline-size: 8.5rem; }

.match-compare th,
.match-compare td {
  padding: var(--space-1) var(--space-2);
  border-block-start: 1px solid var(--rule);
  text-align: start;
  vertical-align: top;
}

.match-compare thead th {
  border-block-start: 0;
  color: var(--fg2);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.match-compare thead td { border-block-start: 0; }

.match-compare tbody th {
  color: var(--fg2);
  font-weight: 500;
}

.match-compare td { color: var(--fg1); }
.match-compare__muted,
.match-compare__note { color: var(--fg3); }
.match-compare__note { font-size: var(--text-xs); }
.match-compare td[data-state="agrees"] { color: var(--tone-good-fg); font-weight: 600; }
.match-compare td[data-state="differs"] { color: var(--tone-warn-fg); font-weight: 600; }

.match-pair__body {
  display: grid;
  gap: var(--space-3);
  min-inline-size: 0;
}

.match-pair__decide {
  display: grid;
  gap: var(--space-2);
  align-content: start;
  max-inline-size: none;
  padding-block-start: var(--space-3);
  border-block-start: 1px solid var(--rule);
}

.match-pair__decide .field { margin: 0; }
.match-pair__decide textarea { min-block-size: calc(var(--target-min) * 1.6); }

/* Wide screens put the decision beside the evidence, so a pair reads in one glance. */
@media (width >= 64rem) {
  .match-pair__body { grid-template-columns: minmax(0, 3fr) minmax(16rem, 2fr); align-items: start; }

  .match-pair__decide {
    padding-block-start: 0;
    padding-inline-start: var(--space-4);
    border-block-start: 0;
    border-inline-start: 1px solid var(--rule);
  }
}


.match-pair__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.constituent-matches__pages {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

/* At phone width the two systems stack under each field instead of sharing a row. */
@media (width < 40rem) {
  .match-pair { padding: var(--space-3); }
  .match-pair__source { margin-inline-start: 0; }
  .match-compare thead { display: none; }

  .match-compare,
  .match-compare tbody,
  .match-compare tr,
  .match-compare th,
  .match-compare td {
    display: block;
  }

  .match-compare tr {
    padding-block: var(--space-2);
    border-block-start: 1px solid var(--rule);
  }

  .match-compare th,
  .match-compare td {
    padding: 0;
    border: 0;
  }

  .match-compare col.match-compare__label { inline-size: auto; }

  .match-compare td[data-label]::before {
    content: attr(data-label);
    margin-inline-end: var(--space-2);
    color: var(--fg3);
  }
}
