/* ==========================================================================
   COMPONENTS · FACTOR INDEX SELECTOR — the instrument through which the whole
   matrix is interrogated. ONE 3-rung colouring lens (category → subcategory →
   factor) with progressive-disclosure browse + type-to-filter. The chosen lens
   names the dimension the map / rankings / compare colour by, and it TRAVELS:
   it is shareable URL state and is carried on every click-through.

   Two scales, one object:
     · default — a trigger button + a floated popover panel (used on the map,
       rankings header, compare header);
     · .op-selector--full — the same browser rendered inline and full-width,
       which IS the /rankings directory.

   Composes the search field drawing, .op-kicker, .op-btn, .op-chip.
   The .op-lens indicator (below) is the visible, travelling lens state.
   ========================================================================== */

.op-selector { position: relative; display: inline-block; }

/* — CLOSED: the trigger shows the current lens — */
.op-selector__trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  max-inline-size: 100%;
  padding: 0.5em 0.8em;
  background: var(--surface-raised);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-xs);
  box-shadow: var(--shadow-emboss);
  color: var(--text);
  cursor: pointer;
  text-align: start;
  transition: var(--transition-ink);
}
.op-selector__trigger:hover { border-color: var(--text); }
.op-selector__trigger:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.op-selector__trigger-label {
  font-family: var(--font-furniture);
  font-size: var(--text-3xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
.op-selector__trigger-value {
  font-family: var(--font-furniture);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text);
}
/* When a non-default lens is active, mark the trigger with a rubric tick */
.op-selector__trigger.is-active .op-selector__trigger-value::before {
  content: "";
  display: inline-block;
  inline-size: 0.55em;
  block-size: 0.55em;
  margin-inline-end: 0.5em;
  background: var(--accent);
  transform: rotate(45deg);
  box-shadow: var(--shadow-emboss);
}
.op-selector__caret {
  margin-inline-start: auto;
  color: var(--text-muted);
  font-family: var(--font-data);
  font-size: var(--text-xs);
}

/* — THE PANEL (popover) — */
.op-selector__panel {
  position: absolute;
  z-index: var(--z-popover);
  inset-block-start: calc(100% + var(--space-2xs));
  inset-inline-start: 0;
  inline-size: min(26rem, calc(100vw - 2 * var(--gutter)));
  background: var(--surface-raised);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  max-block-size: min(34rem, 80vh);
}
.op-selector__panel[hidden] { display: none; }

/* The filter row — the search-desk magnifier, reused */
.op-selector__filter {
  position: relative;
  display: flex;
  align-items: center;
  padding: var(--space-xs);
  border-bottom: 1px solid var(--rule);
}
.op-selector__filter svg {
  position: absolute;
  inset-inline-start: calc(var(--space-xs) + 0.7em);
  inline-size: 0.95em;
  block-size: 0.95em;
  color: var(--text-muted);
  pointer-events: none;
}
.op-selector__filter input {
  inline-size: 100%;
  padding: 0.55em 0.8em 0.55em 2.6em;
  font-size: var(--text-sm);
}

/* The rung breadcrumb — where in the 3 rungs you are; each is a climb-back */
.op-selector__rungs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4em;
  padding: var(--space-2xs) var(--space-sm);
  border-bottom: 1px solid var(--rule-faint);
  font-family: var(--font-furniture);
  font-size: var(--text-3xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
}
.op-selector__rung {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--text-secondary);
  cursor: pointer;
}
.op-selector__rung:hover { color: var(--accent); }
.op-selector__rung[aria-current="true"] { color: var(--text); cursor: default; }
.op-selector__rung + .op-selector__rung::before {
  content: "\203A";
  margin-inline-end: 0.4em;
  color: var(--rule-strong);
}

/* The scrolling option region */
.op-selector__scroll {
  overflow-y: auto;
  flex: 1 1 auto;
}

/* — THE COLUMNS: a two-frame click browser. At most TWO full columns show at
     once, and their frames NEVER resize — drilling past two levels parks the
     oldest level in a reserved thin rail on the left rather than squeezing a
     third column in. Click a row to commit that rung as the lens (the map
     recolours) AND reveal its children in the next frame; only a leaf factor
     closes the panel. Click the parked rail to step back up a level. — */
.op-selector__cols { display: flex; align-items: stretch; min-block-size: 15rem; }
.op-selector__cols[hidden] { display: none; }
.op-selector__col {
  flex: 1 1 0;                 /* the two full frames split the rest equally + stably */
  min-inline-size: 0;
  display: flex;
  flex-direction: column;
  border-inline-start: 1px solid var(--rule-faint);
  max-block-size: min(28rem, 70vh);
  overflow-y: auto;
}
.op-selector__col:first-child { border-inline-start: 0; }

/* the reserved ancestor rail — a fixed thin gutter that holds the parked level */
.op-selector__col--rail { flex: 0 0 2.25rem; overflow: hidden; border-inline-start: 0; }
.op-selector__rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  inline-size: 100%;
  block-size: 100%;
  padding: var(--space-xs) 0;
  background: var(--surface-sunken);
  border: 0;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-ink);
}
.op-selector__rail-btn:hover { color: var(--accent); background: var(--accent-wash); }
.op-selector__rail-back { font-family: var(--font-data); font-size: var(--text-md); line-height: 1; }
.op-selector__rail-name {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  min-block-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-furniture);
  font-size: var(--text-3xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.op-selector__col-head {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
  padding: var(--space-xs) var(--space-sm) var(--space-3xs);
  background: var(--surface-raised);
  font-family: var(--font-furniture);
  font-size: var(--text-3xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--rule-faint);
}
.op-selector__col-list { list-style: none; margin: 0; padding: 0; }
/* in a column, name sits left; count + chevron group at the right */
.op-selector__col .op-selector__pick { justify-content: flex-start; }
.op-selector__col .op-selector__count { margin-inline-start: auto; }
/* the previewed (hovered) row in a column — a quiet wash so the path reads */
.op-selector__option.is-open > .op-selector__pick { background: var(--accent-wash); }
.op-selector__option.is-open .op-selector__chev { color: var(--accent); }

/* the cascade chevron on rows that have a deeper column */
.op-selector__chev {
  flex: none;
  margin-inline-start: var(--space-2xs);
  color: var(--text-muted);
  font-family: var(--font-data);
}

/* the empty second frame's prompt (shown before any specialty is hovered) */
.op-selector__hint {
  padding: var(--space-md) var(--space-sm);
  font-family: var(--font-furniture);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: var(--text-muted);
}
.op-selector__group-label {
  display: block;
  padding: var(--space-xs) var(--space-sm) var(--space-3xs);
  font-family: var(--font-furniture);
  font-size: var(--text-3xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
.op-selector__group-label [data-numeric] {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--text-secondary);
}

.op-selector__list { list-style: none; margin: 0; padding: 0; }
.op-selector__option {
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--rule-faint);
}
.op-selector__option:first-child { border-top: 0; }

/* The pick — selects this rung's row AS the lens (recolours the surface) */
.op-selector__pick {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  min-inline-size: 0;
  padding: 0.6em var(--space-sm);
  background: none;
  border: 0;
  text-align: start;
  cursor: pointer;
  color: var(--text);
  transition: var(--transition-ink);
}
.op-selector__pick:hover { background: var(--accent-wash); }
.op-selector__pick:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

.op-selector__name {
  font-family: var(--font-furniture);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  min-inline-size: 0;
}
.op-selector__count {
  flex: none;
  font-family: var(--font-data);
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--text-muted);
}

/* The drill — goes one rung deeper (browse). Absent on terminal factor rows. */
.op-selector__drill {
  flex: none;
  inline-size: 2.6em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  border-inline-start: 1px solid var(--rule-faint);
  color: var(--text-muted);
  font-family: var(--font-data);
  cursor: pointer;
  transition: var(--transition-ink);
}
.op-selector__drill:hover { color: var(--accent); background: var(--accent-wash); }
.op-selector__drill:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* The active lens row — a leading rubric lozenge + ink it up */
.op-selector__option.is-active .op-selector__pick { color: var(--accent); }
.op-selector__option.is-active .op-selector__name { font-weight: var(--weight-semibold); }
.op-selector__option.is-active .op-selector__name::before {
  content: "";
  display: inline-block;
  inline-size: 0.5em;
  block-size: 0.5em;
  margin-inline-end: 0.5em;
  background: var(--accent);
  transform: rotate(45deg);
  vertical-align: middle;
}

/* — FILTER RESULTS: a flat list with the full path shown + a <mark> hit — */
.op-selector__path {
  display: block;
  font-family: var(--font-furniture);
  font-size: var(--text-3xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.15em;
}
.op-selector mark {
  background: var(--highlight);
  color: inherit;
  border-radius: var(--radius-xs);
  padding: 0 0.1em;
}

/* — NO-MATCH: never a dead end — explain + offer a way back to browse — */
.op-selector__nomatch {
  padding: var(--space-lg) var(--space-md);
  text-align: center;
}
.op-selector__nomatch-line {
  font-family: var(--font-reading);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-2xs);
}
.op-selector__nomatch-line [data-q] {
  font-family: var(--font-data);
  color: var(--text);
}
.op-selector__nomatch-hint {
  font-family: var(--font-furniture);
  font-size: var(--text-2xs);
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

/* — THE FOOT: the default-reset + a doorway to the full index — */
.op-selector__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  border-top: 1px solid var(--rule);
  background: var(--surface-sunken);
}
.op-selector__reset {
  background: none;
  border: 0;
  padding: 0;
  font-family: var(--font-furniture);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-secondary);
  cursor: pointer;
}
.op-selector__reset:hover { color: var(--accent); }
.op-selector__reset:disabled { color: var(--text-muted); cursor: default; opacity: 0.6; }
.op-selector__foot-link {
  font-family: var(--font-furniture);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--link-underline);
}
.op-selector__foot-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ==========================================================================
   --full — the same browser, inline and full-width: the /rankings directory.
   The panel sheds its float and shadow and lays its rungs out as columns.
   ========================================================================== */
.op-selector--full { display: block; }
.op-selector--full .op-selector__panel {
  position: static;
  inline-size: 100%;
  max-block-size: none;
  box-shadow: var(--shadow-raised);
  border-radius: var(--radius-sm);
}
.op-selector--full .op-selector__scroll { overflow: visible; }
@media (min-width: 56.25rem) {
  .op-selector--full .op-selector__list { columns: 2; column-gap: var(--space-xl); }
  .op-selector--full .op-selector__option { break-inside: avoid; }
}

/* ==========================================================================
   --footer — the dropdown sat in a figure's caption shelf, right-aligned. Its
   panel anchors to the trigger's right edge and opens UPWARD, so it rises over
   the plate above rather than pushing the page content below it down.
   ========================================================================== */
.op-selector--footer .op-selector__panel {
  inset-block-start: auto;
  inset-block-end: calc(100% + var(--space-2xs));
  inset-inline-start: auto;
  inset-inline-end: 0;
  inline-size: min(34rem, calc(100vw - 2 * var(--gutter)));
}

/* ==========================================================================
   COMPONENTS · LENS — the visible, travelling lens state. A labelled indicator
   that says what dimension a data surface is currently coloured by, with the
   rung it belongs to and a one-click return to the default (Country overall).
   Sits in the trigger, and as a banner above the map / rankings / compare.
   ========================================================================== */
.op-lens {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0.35em 0.7em;
  background: var(--accent-wash);
  border: 1px solid var(--accent-keyline);
  border-radius: var(--radius-xs);
}
.op-lens__label {
  font-family: var(--font-furniture);
  font-size: var(--text-3xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
.op-lens__rung {
  font-family: var(--font-data);
  font-size: var(--text-3xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--accent);
  padding: 0.1em 0.4em;
  border: 1px solid var(--accent-keyline);
  border-radius: var(--radius-xs);
}
.op-lens__value {
  font-family: var(--font-furniture);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text);
}
.op-lens__clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 1.5em;
  block-size: 1.5em;
  margin-inline-start: 0.1em;
  font-family: var(--font-data);
  font-size: var(--text-sm);
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-radius: var(--radius-xs);
  cursor: pointer;
}
.op-lens__clear:hover { color: var(--accent); background: color-mix(in oklab, var(--accent) 16%, transparent); }
.op-lens__clear:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* The banner form — full width, sat above a data surface, carries the share */
.op-lens--banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  inline-size: 100%;
  background: var(--surface-sunken);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: var(--space-xs) var(--space-md);
}
.op-lens--banner .op-lens__share {
  margin-inline-start: auto;
  font-family: var(--font-data);
  font-size: var(--text-2xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums lining-nums;
}
.op-lens--banner .op-lens__share a {
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 1px solid var(--link-underline);
}
.op-lens--banner .op-lens__share a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* The family ladder — the three zoom levels (overall · specialty · factor) made
   reciprocal doors, shared by the three country leaderboards. The current rung is
   marked; the other two are links one step up or down the ladder. A pure extension
   of .op-lens, so the family reads as one component, not new chrome. */
.op-lens__ladder {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2xs);
}
.op-lens__step {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45em;
  padding: 0.15em 0.55em;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  text-decoration: none;
  color: var(--text-secondary);
}
a.op-lens__step:hover { color: var(--accent); border-color: var(--accent-keyline); }
a.op-lens__step:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.op-lens__step--current {
  background: var(--accent-wash);
  border-color: var(--accent-keyline);
}
.op-lens__step-rung {
  font-family: var(--font-data);
  font-size: var(--text-3xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
}
.op-lens__step--current .op-lens__step-rung { color: var(--accent); }
.op-lens__step-name {
  font-family: var(--font-furniture);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: inherit;
}
.op-lens__step--current .op-lens__step-name { color: var(--text); }
.op-lens__step-sep {
  font-family: var(--font-data);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  color: var(--accent);
}
