/* Opportunity districts page. Loaded after styles.css and app.css (palette, top bar,
   buttons, page header, footer). */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.provisional {
  margin: 0 0 1.75rem;
  padding: 0.9rem 1.1rem;
  border-left: 6px solid var(--red);
  background: var(--accent-soft);
  max-width: 62rem;
  font-size: 0.98rem;
}

/* ---------- filters ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
}
.filters__field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 9rem;
}
.filters__field span {
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.filters select,
.filters input {
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--black);
  border-radius: 0;
}
.filters select:focus,
.filters input:focus {
  outline: 3px solid var(--black);
  outline-offset: 1px;
}
/* the multiselects (chamber, party, political alignment): a dropdown (details) that looks like the selects beside it,
   with a panel of checkboxes under it */
.filters__multi {
  /* a fixed width: the closed text of a long selection is cut with an ellipsis (its full text is the
     tooltip) instead of widening the field and pushing the next one onto a second row */
  flex: 0 0 16rem;
  width: 16rem;
  min-width: 0;
}
.multi {
  position: relative;
}
.multi summary {
  padding: 0.55rem 2rem 0.55rem 0.7rem;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--black);
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
}
.multi summary::-webkit-details-marker {
  display: none;
}
.multi summary::after {
  content: "";
  position: absolute;
  right: 0.75rem;
  top: 50%;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid var(--black);
  border-bottom: 2px solid var(--black);
  transform: translateY(-70%) rotate(45deg);
}
.multi[open] summary::after {
  transform: translateY(-30%) rotate(-135deg);
}
.multi summary:focus-visible {
  outline: 3px solid var(--black);
  outline-offset: 1px;
}
.multi__panel {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 30;
  min-width: 100%;
  padding: 0.4rem 0.7rem;
  background: var(--paper);
  border: 2px solid var(--black);
  border-top-width: 0;
}
.multi__panel label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.multi__panel label[hidden] {
  display: none; /* a flex label would otherwise ignore the hidden attribute */
}
/* a filter that does not apply at the chosen level (party and alignment for a county or town) */
.multi.is-disabled summary {
  color: var(--muted);
  background: transparent;
  border-style: dashed;
  cursor: not-allowed;
}
.multi.is-disabled summary::after {
  opacity: 0.4;
}
.filters .multi__panel input {
  width: 1.05rem;
  height: 1.05rem;
  padding: 0;
  accent-color: var(--black);
}
/* the collapsed "More filters" area under the main filters, full width */
.filters-more {
  flex: 1 0 100%;
  border-top: 2px solid var(--line);
  padding-top: 0.6rem;
}
/* only the area's own summary (">"): the dropdowns inside it have summaries of their own (.multi summary) */
.filters-more > summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
}
.filters-more > summary::-webkit-details-marker {
  display: none;
}
/* a chevron that points right when closed and down when open */
.filters-more > summary::before {
  content: "";
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--black);
  border-bottom: 2px solid var(--black);
  transform: rotate(-45deg);
  transition: transform 0.12s ease;
}
.filters-more[open] > summary::before {
  transform: rotate(45deg);
}
/* a faint note, only while it is closed */
.filters-more__hint {
  font-weight: 400;
  font-size: 0.85rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
  opacity: 0.8;
}
.filters-more[open] .filters-more__hint {
  display: none;
}
.filters-more > summary:focus-visible {
  outline: 3px solid var(--black);
  outline-offset: 2px;
}
.filters-more__body {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.9rem 2rem;
  margin-top: 0.6rem;
}
.filters-more__group {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.9rem 1.1rem;
  position: relative;
  padding-top: 1.35rem;
}
.filters-more__legend {
  position: absolute;
  top: 0;
  left: 0;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.filters-more .filters__field--grow {
  min-width: 18rem;
}
.filters-more select:disabled,
.filters-more input:disabled {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}
.filters__field--sort {
  min-width: 16rem;
  max-width: 24rem;
}
#f-state {
  width: 5.5rem;
  text-transform: uppercase;
}
#f-margin {
  width: 8rem;
}

.status {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.status--error {
  color: var(--red-dark);
  font-weight: 700;
}

/* ---------- ranked table ---------- */

.table-scroll {
  overflow-x: auto;
  border: 2px solid var(--black);
}
table.opps {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
table.opps thead th {
  padding: 0.6rem 0.8rem;
  text-align: left;
  background: var(--black);
  color: var(--paper);
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
/* A sortable header is a plain-looking button; the current sort shows an arrow. */
table.opps .th-sort {
  padding: 0;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
table.opps .th-sort:hover,
table.opps .th-sort:focus-visible {
  text-decoration: underline;
}
table.opps .opp__sortval-head {
  white-space: normal;
  min-width: 9rem;
}
/* The Sanders-vs-Clinton/Biden margin is the headline of its column; like the score, it is not a
   party colour. */
.opp__margin {
  display: block;
  font-weight: 800;
  white-space: nowrap;
}
.opp__appetite .opp__sub {
  white-space: nowrap;
}
.opp__sortval {
  font-weight: 700;
  white-space: nowrap;
}
table.opps td {
  padding: 0.65rem 0.8rem;
  vertical-align: top;
  border-top: 1px solid var(--line);
}
tr.opp:first-child td {
  border-top: none;
}
.opp__rank {
  font-weight: 900;
  font-size: 1.1rem;
  width: 3rem;
}
.opp__sub {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}
.opp__score {
  white-space: nowrap;
  min-width: 8rem;
}
.opp__num {
  font-weight: 800;
  margin-left: 0.4rem;
}
.scorebar {
  display: inline-block;
  width: 4.5rem;
  height: 0.6rem;
  vertical-align: middle;
  background: var(--wash);
  border: 1px solid var(--black);
}
/* The score is not a party colour: neutral ink, never red (Republican) or blue (Democratic). */
.scorebar i,
.factor__bar i {
  display: block;
  height: 100%;
  background: var(--black);
}
.opp__lean {
  font-weight: 800;
  white-space: nowrap;
}
.opp__more {
  text-align: right;
  white-space: nowrap;
}
tr.opp:hover td {
  background: #fafafa;
}

/* ---------- the "why" panel ---------- */

tr.opp-detail td {
  background: var(--wash);
  padding: 1.1rem 1.25rem 1.4rem;
  border-top: none;
}
.detail__why {
  margin: 0 0 1rem;
  max-width: 60rem;
  font-size: 1rem;
}
.factors {
  list-style: none;
  margin: 0 0 1.1rem;
  padding: 0;
  display: grid;
  gap: 0.55rem;
  max-width: 62rem;
}
.factor {
  display: grid;
  grid-template-columns: 12rem 7rem 6rem 1fr;
  gap: 0.2rem 0.9rem;
  align-items: center;
  font-size: 0.9rem;
}
.factor__label {
  font-weight: 800;
}
.factor__bar {
  display: block;
  height: 0.6rem;
  background: var(--paper);
  border: 1px solid var(--black);
}
.factor__pts {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.factor__reason {
  color: var(--muted);
}
.factor--nodata .factor__label,
.factor--nodata .factor__pts {
  color: var(--muted);
  font-weight: 700;
}
.factor--nodata .factor__bar {
  border-style: dashed;
  border-color: #999;
}
@media (max-width: 760px) {
  .factor {
    grid-template-columns: 1fr 5rem;
  }
  .factor__bar {
    grid-column: 1 / -1;
    order: 3;
  }
  .factor__reason {
    grid-column: 1 / -1;
  }
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.7rem 1.25rem;
  margin: 0 0 1.1rem;
}
.facts div {
  border-top: 2px solid var(--black);
  padding-top: 0.3rem;
}
.facts dt {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.facts dd {
  margin: 0.1rem 0 0;
  font-weight: 700;
}
.detail__links {
  margin: 0;
}

.more {
  margin: 1.25rem 0 0;
}

/* ---------- the incumbent: conservative-establishment / progressive / dsa ---------- */
/* Not party colours (red and blue are the parties): plain ink, filled for the target. */

.badge {
  /* always on its own line under the officeholder's name (beside it, a short name pulled it up to the right) */
  display: block;
  width: fit-content;
  margin: 0.3rem 0 0;
  padding: 0.05rem 0.45rem;
  border: 2px solid var(--black);
  font-weight: 800;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: help;
}
.badge--conservative_establishment {
  background: var(--black);
  color: var(--paper);
}
.badge--progressive,
.badge--dsa {
  background: var(--wash);
  color: var(--muted);
  border-color: var(--muted);
}
.opp__appetite {
  white-space: nowrap;
  font-weight: 700;
}
/* the progressive-appetite cell: Bernie's average, then DSA's signals as small neutral badges under it */
.opp__dsa {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.3rem;
}
.dsa {
  display: inline-block;
  padding: 0 0.4rem;
  border: 1px solid var(--black);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.5;
  white-space: nowrap;
  cursor: help;
}
.dsa--electeds {
  background: var(--black);
  color: var(--paper);
}
/* the hover card of the DSA electeds badge (js/dsa-tip.js): fixed, so the table's scroll box does not clip it */
.dsa-tip {
  position: fixed;
  z-index: 50;
  max-width: 24rem;
  padding: 0.6rem 0.8rem;
  border: 2px solid var(--black);
  background: var(--paper);
  color: var(--black);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.35;
  white-space: normal;
  box-shadow: 4px 4px 0 var(--black);
  pointer-events: none;
}
.dsa-tip ul {
  margin: 0.3rem 0;
  padding-left: 1.1rem;
}
.dsa-tip__note {
  display: block;
  font-weight: 400;
  color: var(--muted);
}
.dsa--none,
.dsa--unknown {
  border-color: var(--muted);
  color: var(--muted);
  font-weight: 700;
}
.dsa--unknown {
  border-style: dashed;
}
.opp__sub-inline {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}
/* the alignment slider: a neutral track (red and blue are the parties), Socialist on the left, conservative on the right */
.align {
  max-width: 34rem;
  margin: 0 0 1.1rem;
}
.align__title {
  display: block;
  margin-bottom: 0.45rem;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.align__track {
  position: relative;
  height: 10px;
  border: 2px solid var(--black);
  background: linear-gradient(to right, #ffffff, #bdbdbd 55%, #111111);
}
.align__marker {
  position: absolute;
  top: -8px;
  width: 0;
  height: 0;
  margin-left: -7px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 12px solid var(--black);
  filter: drop-shadow(0 0 0 #fff) drop-shadow(0 1px 0 #fff);
}
/* the small one in the table's "Held by" cell */
.align--mini {
  display: block;
  /* one width for every row: sized by this, never by the length of the incumbent's name beside it */
  width: 9.5rem;
  max-width: 100%;
  margin: 0.4rem 0 0;
}
.align--mini .align__track {
  display: block;
  height: 6px;
  border-width: 1px;
}
.align--mini .align__marker {
  top: -7px;
  margin-left: -5px;
  border-left-width: 5px;
  border-right-width: 5px;
  border-top-width: 9px;
}
.align__ends {
  display: flex;
  justify-content: space-between;
  margin-top: 0.3rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}
.detail__dsa {
  margin: 0 0 1rem;
  max-width: 60rem;
  font-size: 0.95rem;
}
.detail__incumbent {
  margin: 0 0 1rem;
  max-width: 60rem;
  font-size: 0.95rem;
  color: var(--muted);
}
/* A county's or town's folded officeholders: the toggle reads inline, the list opens under it. */
.detail__holders-more {
  display: inline;
}
.detail__holders-more > summary {
  display: inline;
  cursor: pointer;
  text-decoration: underline dotted;
}

/* ---------- Sanders margin colours ----------
   The Bernie vs. Hillary / Biden number is always Sanders's margin: + he led, - he trailed.
   Green (led) and purple (trailed), in three soft tiers by size, because red and blue are the
   parties. The sign is in the text too, so colour is never the only signal. */
.m {
  display: inline-block;
  padding: 0 0.4em;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}
.m--even   { background: #efefef; color: #555555; }
.m--up-1   { background: #eaf4ee; color: #1f5c3a; }
.m--up-2   { background: #cfe7d8; color: #174d30; }
.m--up-3   { background: #a9d3ba; color: #0f3d24; }
.m--down-1 { background: #f1e9f4; color: #5b2f6d; }
.m--down-2 { background: #e0d0e8; color: #4a2459; }
.m--down-3 { background: #cdb2db; color: #3a1a47; }

.opp__appetite .opp__sub .m {
  font-weight: 700;
}
.key {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.key .m {
  font-size: 0.85rem;
}

/* a member of Congress's portrait beside the incumbent (linked from unitedstates/images, not hosted here) */
.opp__who {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.opp__portrait {
  flex: none;
  width: 36px;
  height: 44px;
  object-fit: cover;
  object-position: top;
  background: var(--wash);
  border: 2px solid var(--black);
}
.opp__whotext {
  flex: 1 1 auto;
  min-width: 0;
}
