/* The explorer (/explore/). One real <table>: grid rows on a desktop, stacked
   entries on a phone. Rows are laid out with a fixed track list (no content-sized
   tracks), so every row lines up without table auto-layout, and each row can use
   content-visibility: auto. Money has no hue; color only for a verdict and focus. */

.page-explore {
  --xt-ref: color-mix(in srgb, var(--ink-3) 62%, transparent);
  --xt-zone: color-mix(in srgb, var(--range) 9%, transparent);
  --x-bar: 0px;
}

/* ------------------------------------------------------------ head */

.xhead { padding-top: var(--s6); }
.xhead__title { margin-top: var(--s2); }
.xhead__summary { margin-top: var(--s3); max-width: 60ch; min-height: 56px; }
@media (min-width: 768px) {
  .xhead { padding-top: var(--s7); }
  .xhead__summary { font-size: 20px; line-height: 30px; }
}

/* ------------------------------------------------------------ controls */

html:not(.js) .xctl { display: none; }
.xctl { margin-top: var(--s5); }

.xtools { display: flex; align-items: center; gap: var(--s2); }
.xtools__sort { display: flex; align-items: center; gap: 10px; min-width: 0; }
.xtools__label {
  font-size: var(--t-micro);
  line-height: var(--lh-micro);
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
  font-weight: 650;
  color: var(--ink-3);
  white-space: nowrap;
}
.xtools__select { width: auto; min-width: 0; font-size: var(--t-small); }
.xtools__filters { padding: 0 14px; gap: 8px; }
.xtools__count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--page);
  font-size: var(--t-micro);
  line-height: 1;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.xf { display: grid; gap: var(--s3) var(--s3); }
.xf .select, .xf .input { font-size: var(--t-small); min-height: 40px; }
.xf .input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.xf__f--open { display: flex; align-items: flex-end; }
.xf__f--open .check { min-height: 40px; white-space: nowrap; }

.xbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.xbar__csv { min-height: 40px; padding: 0 14px; white-space: nowrap; }

.xchips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); min-width: 0; }
.xchips:empty { display: none; }
.xchip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--axis);
  border-radius: var(--r-chip);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--t-small);
  line-height: 1;
  font-weight: 500;
}
.xchip::before { content: ""; position: absolute; inset: -6px -2px; }
.xchip:hover { border-color: var(--ink-3); }
.xchip__k { color: var(--ink-3); font-weight: 450; }
.xchip__x { position: relative; width: 10px; height: 10px; flex: none; }
.xchip__x::before, .xchip__x::after {
  content: "";
  position: absolute;
  left: 4.25px; top: -1px;
  width: 1.5px; height: 12px;
  border-radius: 1px;
  background: var(--ink-2);
  transform: rotate(45deg);
}
.xchip__x::after { transform: rotate(-45deg); }
.xchips__clear {
  min-height: 32px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: var(--t-small);
  font-weight: 560;
  text-decoration: underline;
  text-decoration-color: var(--axis);
  text-underline-offset: 0.2em;
}
.xchips__clear:hover { color: var(--ink); text-decoration-color: currentColor; }

/* The filter form inside the phone sheet. */
.sheet .xf { padding-top: var(--s4); grid-template-columns: 1fr; }
.sheet .xf .select, .sheet .xf .input { min-height: var(--touch); font-size: var(--t-body); }
.xsheet__foot {
  position: sticky;
  bottom: calc(-1 * (var(--s5) + env(safe-area-inset-bottom)));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-top: var(--s5);
  padding: var(--s3) 0 calc(var(--s3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
  background: var(--surface);
}
.xsheet__show { flex: 1; }

/* ------------------------------------------------------------ notes */

.xnotes { margin-top: var(--s5); display: grid; gap: 4px; }
.xnotes .note, .xfoot .note { max-width: 96ch; }
.xlegend { margin-top: var(--s2); }
.xfoot { margin-top: var(--s5); display: grid; gap: 6px; }
.xfoot a { color: var(--ink-2); }

/* ------------------------------------------------------------ the table */

.xtable-wrap { margin-top: var(--s3); }
.xt { display: block; width: 100%; }
.xt > thead, .xt > tbody { display: block; }
.xt tr { display: grid; }
.xt th, .xt td { display: block; min-width: 0; padding: 0; border: 0; }

.xt > thead {
  position: sticky;
  top: var(--x-bar);
  z-index: 3;
  background: var(--page);
}
.xt thead th { white-space: normal; overflow-wrap: normal; }
.xt thead th.num { text-align: right; }
.xt thead .sort {
  display: inline;
  min-height: 0;
  max-width: 100%;
  padding: 4px 0;
  text-align: inherit;
  white-space: normal;
  text-wrap: balance;
  border-radius: 2px;
}
/* The arrow shows on the sorted column, and on hover or focus elsewhere. */
.xt thead .sort::after {
  display: inline-block;
  margin-left: 5px;
  vertical-align: 2px;
  opacity: 0;
  transition: opacity var(--motion) var(--ease);
}
.xt thead th[aria-sort] .sort::after { opacity: 1; }
.xt thead .sort:hover::after, .xt thead .sort:focus-visible::after { opacity: 0.8; }
.xt thead .sort:hover { color: var(--ink-2); }
html:not(.js) .xt .sort { cursor: default; pointer-events: none; }
.xt__rlabel { display: block; margin-bottom: 6px; }
.xt thead .axis { text-transform: none; letter-spacing: 0; font-weight: 450; }

/* A row. */
.xt > tbody > tr {
  content-visibility: auto;
  contain-intrinsic-size: auto 57px;
  border-bottom: 1px solid var(--hairline);
}
.xt > tbody > tr:not(.is-median):not(.is-group):hover { background: color-mix(in srgb, var(--ink) 2.5%, transparent); }

/* Person: portrait, name and party, the office line under it. */
.xp { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.xp > .portrait { margin-top: 2px; }
.xp__text { display: grid; min-width: 0; }
.xp__name {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-size: 16px;
  line-height: 20px;
  font-weight: 560;
  color: var(--ink);
}
.xp__name > a { text-decoration: none; }
.xp__name > a:hover { text-decoration: underline; text-decoration-color: var(--axis); }
.xp__name .party { margin-left: 6px; vertical-align: 1px; }
.xp__name .tag { margin-left: 6px; }
.xp__office { font-size: var(--t-micro); line-height: var(--lh-micro); color: var(--ink-3); margin-top: 1px; }

.xt td.c-rank { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.xt td.c-mid { font-weight: 600; color: var(--ink); }
.xv__pre { display: block; font-size: var(--t-micro); line-height: var(--lh-micro); font-weight: 450; color: var(--ink-3); }
/* The range cell is a named container, so the words beside a published estimate
   can step aside when the column is too narrow to hold them on either side of
   the diamond. The amount stays, the legend names the mark, and a screen reader
   still gets the words. */
.xr { position: relative; container: xrange / inline-size; }
@container xrange (max-width: 321px) {
  .xpub__word {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
  }
}
.xpub {
  position: absolute;
  top: -2px;
  font-size: var(--t-micro);
  line-height: var(--lh-micro);
  color: var(--ink-2);
  white-space: nowrap;
  pointer-events: none;
}
.xt td.c-low, .xt td.c-high { color: var(--ink-2); }
.xlimit { color: var(--ink-3); font-weight: 450; }
/* "or less" and "or more" sit under the counted figure in the narrow Lowest and
   Highest columns (DESIGN 13.2). "nothing listed" sits under its $0 the way the
   open markers sit above theirs (DESIGN 13.3). */
.xt td.c-low .xlimit, .xt td.c-high .xlimit { display: block; font-size: var(--t-micro); line-height: var(--lh-micro); }
.xv__post { display: block; font-size: var(--t-micro); line-height: var(--lh-micro); font-weight: 450; color: var(--ink-3); }
.xt td.c-chg .verdict { font-size: var(--t-small); }
/* A reason in place of a verdict ("Nothing to compare yet") wraps inside its column. */
.xt td.c-chg .verdict--none { white-space: normal; max-width: 100%; align-items: flex-start; }
.xt td.c-chg .verdict--none > .glyph { flex: none; margin-top: 4px; }
.xc__sub { display: block; margin-top: 1px; padding-left: 19px; font-size: var(--t-micro); line-height: var(--lh-micro); color: var(--ink-3); }
.xc__amt { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
/* A share ("now about 15% of the starting figure") wraps inside the column. */
.xc__mult { white-space: normal; }
.xbg { color: var(--ink-2); }
.xbg__more { color: var(--ink-3); white-space: nowrap; }
.xnofig { font-size: var(--t-small); line-height: var(--lh-small); font-style: italic; color: var(--ink-3); }

.xsrc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  color: var(--ink-2);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.xsrc::before {
  content: "";
  width: 10px;
  height: 12px;
  flex: none;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 12'%3E%3Cpath d='M1.5.5h5l2.5 2.5v8.5h-7.5z M6.5.5v2.5h2.5 M3 6h4 M3 8h4' fill='none' stroke='%23000' stroke-width='1' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 12'%3E%3Cpath d='M1.5.5h5l2.5 2.5v8.5h-7.5z M6.5.5v2.5h2.5 M3 6h4 M3 8h4' fill='none' stroke='%23000' stroke-width='1' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.xsrc:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.xsrc__dated {
  display: block;
  font-size: var(--t-micro);
  line-height: var(--lh-micro);
  color: var(--ink-3);
}

/* The median row and the group label row. */
.xt > tbody > tr.is-median {
  border-top: 1px solid var(--axis);
  border-bottom: 1px solid var(--axis);
  background: color-mix(in srgb, var(--range) 12%, transparent);
  content-visibility: visible;
}
.xm { display: grid; padding-left: 38px; }
.xm__label { font-size: var(--t-small); line-height: var(--lh-small); font-weight: 650; color: var(--ink); }
.xm__sub { font-size: var(--t-micro); line-height: var(--lh-micro); color: var(--ink-3); }
.xt tr.is-median td { border-bottom: 0; }
.xt tr.is-median td.c-mid { color: var(--ink); }
.xt > tbody > tr.is-group { content-visibility: visible; border-bottom-color: var(--axis); }
.xt tr.is-group td { padding-top: var(--s5); }
.xt td.c-group { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; padding-bottom: 8px; }
.xg__title { font-size: var(--t-small); line-height: var(--lh-small); font-weight: 650; color: var(--ink); }
.xg__sub { font-size: var(--t-micro); line-height: var(--lh-micro); color: var(--ink-3); }

.xempty { padding: var(--s6) 0; display: grid; justify-items: start; gap: var(--s3); color: var(--ink-2); }

/* ------------------------------------------------------------ desktop: grid rows */

@media (min-width: 900px) {
  .xctl {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "f f f" "chips sort csv";
    align-items: center;
    gap: var(--s3) var(--s4);
  }
  .xtools, .xbar { display: contents; }
  .xtools__filters { display: none; }
  .xtools__sort { grid-area: sort; }
  .xbar__csv { grid-area: csv; }
  .xchips { grid-area: chips; }
  .xf-home { grid-area: f; }
  .xf { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); align-items: end; }
  .xf__f--name { grid-column: span 2; }

  .xt { --cols: 30px 196px minmax(0, 1fr) 76px 124px 44px 56px; }
  /* "open both ways" sits on its own lines above the figure, so the dot that joins
     the two on a card is not drawn here. */
  .xt td.c-mid .xv__pre { white-space: normal; }
  .xv__dot { display: none; }
  .xt tr { grid-template-columns: var(--cols); column-gap: 12px; padding-inline: 4px; }
  .xt td { align-self: center; padding-block: 10px; }
  .xt thead tr { align-items: end; border-bottom: 1px solid var(--axis); }
  .xt thead th { padding-block: 10px 8px; }
  .xt thead th.c-range { padding-bottom: 0; }
  .xt thead th.c-rank { padding-bottom: 14px; }
  .xt .c-low, .xt .c-high, .xt .c-since, .xt .c-bg { display: none; }
  .xt td.c-grade, .xt th.c-grade { text-align: center; }
  .xt thead th.c-grade .sort { margin-inline: auto; }
  .xt td.c-range {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .xt tr.is-group td.c-range { background: none; }
  .xt tr.is-group td.c-group { grid-column: 1 / -1; }
}
@media (min-width: 1100px) {
  .xt { --cols: 30px 196px minmax(0, 1fr) 76px 64px 60px 124px 44px 56px; }
  .xt .c-low, .xt .c-high { display: block; }
}
@media (min-width: 1264px) {
  .xf { grid-template-columns: minmax(0, 1.5fr) repeat(6, minmax(0, 1fr)) auto; }
  .xf__f--name { grid-column: auto; }
  .xt { --cols: 30px 196px minmax(0, 1fr) 76px 64px 60px 116px 52px 92px 44px 56px; }
  .xt .c-since, .xt .c-bg { display: block; }
}

/* ------------------------------------------------------------ cards: phone and tablet */

/* Below the width where the table fits (900px) every row is a card, and the card
   is one deliberate grid at every width from a small phone to a tablet:

     rank | name, party, office              | value
          | the range bar, full width
          | verdict and change               | filing
          | in office since · background     | grade

   The background rides in the same cell as "in office since" here (a copy that
   only a card shows), so the two read as one run of text and wrap as one.

   The toolbar (Filters and Sort) is pinned to the top of the window while the
   cards scroll, and the range header sticks right under it. The pinned height
   is measured by explore.js (--x-bar-h), so the header's offset always matches
   what is actually pinned. With JavaScript off the toolbar is not shown and
   the header sticks at the top. */
@media (min-width: 900px) { .xsince__bg { display: none; } }
@media (max-width: 899.98px) {
  .page-explore { --x-bar: 0px; }
  .js .page-explore { --x-bar: var(--x-bar-h, 60px); }
  /* The controls box dissolves, so the pinned toolbar's containing block is the
     whole page column and it stays pinned for the length of the table. */
  .js .xctl { display: contents; }
  .xtools {
    position: sticky;
    top: 0;
    z-index: 4;
    margin-top: var(--s5);
    margin-inline: calc(-1 * var(--gutter));
    padding: 8px var(--gutter);
    background: var(--page);
    justify-content: space-between;
  }
  .xtools__sort { flex: 0 1 auto; }
  .xtools__select { max-width: 62vw; min-height: 44px; }
  .xf-home { display: none; }
  .xbar { margin-top: var(--s2); }
  .xbar__csv {
    margin-left: auto;
    min-height: 36px;
    padding: 0 2px;
    border: 0;
    background: none;
    color: var(--ink-2);
    font-weight: 560;
    text-decoration: underline;
    text-decoration-color: var(--axis);
    text-underline-offset: 0.2em;
  }

  .xt > thead { border-bottom: 1px solid var(--axis); }
  .xt thead tr { display: block; padding-top: 4px; }
  .xt thead th:not(.c-range) { display: none; }
  .xt thead th.c-range { display: block; padding-left: calc(var(--pl-rank) + var(--pl-gap)); }

  /* A card is the Ladder's person line (DESIGN 10, item 3): rank, 32px portrait,
     name and value, the office line, then the bar on the same spacing, then two
     quiet lines of details that share one left edge. */
  .xt > tbody > tr {
    grid-template-columns: var(--pl-rank) minmax(0, 1fr) auto;
    grid-template-areas:
      "rank person mid"
      ". range range"
      ". chg src"
      ". since grade";
    column-gap: var(--pl-gap);
    align-items: start;
    padding: 10px 0 12px;
    contain-intrinsic-size: auto 132px;
  }
  .xt td.c-rank { grid-area: rank; text-align: right; font-size: var(--t-small); line-height: 22px; color: var(--ink-3); font-weight: 600; }
  .xt td.c-person { grid-area: person; }
  .xt .xp { gap: var(--pl-gap); }
  .xt .xp > .portrait--xs { --pw: 32px; }
  .xt .xp__name { font-size: 17px; line-height: 22px; }
  .xp__office { font-size: var(--t-small); line-height: var(--lh-small); color: var(--ink-2); }
  .xt td.c-mid { grid-area: mid; justify-self: end; font-size: var(--t-small); line-height: 22px; font-weight: 650; white-space: nowrap; }
  .xv__pre { display: inline; font-size: var(--t-small); line-height: inherit; font-weight: 450; color: var(--ink-3); }
  .xv__post { display: inline; font-size: var(--t-small); line-height: inherit; }
  /* A rank of 100 or more is set smaller, so three digits stay inside the rank
     column. On a small phone the column is also a little wider than the Ladder's. */
  .xt td.c-rank.is-wide { font-size: 12px; }
  @media (max-width: 479px) {
    .page-explore { --pl-rank: 24px; }
    .xt td.c-rank.is-wide { font-size: 11px; }
    .xt td.c-mid:has(.xv__pre) { white-space: normal; max-width: 8.5em; text-align: right; }
  }
  .xt td.c-range { grid-area: range; margin-top: 8px; }
  .xt tr.is-nofig td.c-range { margin-top: 6px; }
  .xt td.c-low, .xt td.c-high { display: none; }

  /* Line one of the details: the verdict and the change at left, the filing at
     right. Line two: in office since and the background at left, the grade at
     right. The right column is as wide as the value above it, so a name keeps
     the rest of the card. */
  .xt td.c-chg {
    grid-area: chg;
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 6px;
    color: var(--ink-2);
    font-size: var(--t-small);
    line-height: var(--lh-small);
  }
  .xt td.c-chg:has(.verdict--none) { color: var(--ink-3); }
  .xc__sub { display: inline; padding-left: 0; font-size: inherit; line-height: inherit; color: var(--ink-3); }
  .xc__since { flex-basis: 100%; font-size: var(--t-micro); line-height: var(--lh-micro); }
  .xt td.c-grade, .xt td.c-src {
    justify-self: end;
    font-size: var(--t-micro);
    line-height: var(--lh-small);
    color: var(--ink-3);
    white-space: nowrap;
  }
  .xt td.c-src { grid-area: src; margin-top: 8px; }
  .xt td.c-src .xsrc { min-height: var(--lh-small); }
  .xsrc__dated { display: inline; margin-left: 6px; }
  .xt td.c-grade { grid-area: grade; margin-top: 2px; display: inline-flex; align-items: center; min-height: var(--lh-small); }
  .xt td.c-grade:has(.grade:not(.grade--none))::before { content: "Grade"; margin-right: 5px; }
  .xt td.c-grade:has(.grade--none) { display: none; }
  .xt td.c-chg:empty, .xt td.c-src:empty { display: none; }

  /* Line two: in office since, then the background, one run of text. */
  .xt td.c-since {
    grid-area: since;
    margin-top: 2px;
    font-size: var(--t-micro);
    line-height: var(--lh-small);
    color: var(--ink-3);
    text-align: left;
    white-space: normal;
  }
  .xsince::before { content: "In office since "; }
  .xsince + .xsince__bg::before { content: " · "; white-space: pre; }
  .xt td.c-since:empty, .xt td.c-bg { display: none; }

  /* The median row and the group label row. */
  .xt > tbody > tr.is-median {
    grid-template-areas:
      "rank person mid"
      ". range range"
      ". chg chg";
    padding: 10px 0;
  }
  .xm { padding-left: calc(32px + var(--pl-gap)); }
  .xt tr.is-median td.c-low, .xt tr.is-median td.c-high, .xt tr.is-median td.c-since, .xt tr.is-median td.c-bg,
  .xt tr.is-median td.c-grade, .xt tr.is-median td.c-src { display: none; }
  .xt tr.is-median td.c-chg:empty, .xt tr.is-median td.c-range:empty { display: none; }
  .xt > tbody > tr.is-group { display: block; padding: 0; }
  .xt td.c-group { padding-top: var(--s3); }
}

@media (forced-colors: active) {
  .xt td.c-range { background-image: none !important; }
  .xt td.c-range .rb__zero, .xt td.c-range .rb__ref { display: block !important; }
  .xchip { border-color: CanvasText; }
}

@media print {
  .xctl { display: none !important; }
  .xt > thead { position: static; }
  .xt > tbody > tr { content-visibility: visible; break-inside: avoid; }
}
