/* Rankings (templates/rankings.html, static/js/pages/rankings.js). Uses the tokens of app.css. */

.rk-head {
  padding-bottom: var(--s-3);
}

/* the sentence builder: "Rank [cantons] by [electric share]" */

.rk-builder {
  padding: var(--s-4) var(--s-5) var(--s-5);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  background: var(--surface);
}

.rk-sentence {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  font-size: clamp(1.35rem, 1rem + 1.6vw, 2rem);
  font-weight: 750;
  letter-spacing: -0.02em;
}

.rk-sentence__word {
  color: var(--text-2);
}

/* native selects with a drawn chevron (follows the theme) */

.rk-select {
  position: relative;
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
}

.rk-select select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 0 30px 0 10px;
  border: 1px solid var(--border-control);
  border-radius: var(--r-s);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  text-overflow: ellipsis;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.rk-select select:hover {
  border-color: var(--text-3);
}

.rk-select select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.rk-select::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 12px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-2);
  border-bottom: 2px solid var(--text-2);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.rk-select--big select {
  min-height: 52px;
  padding: 0 44px 0 14px;
  border: 2px solid var(--accent);
  border-radius: var(--r-m);
  background: var(--accent-soft);
  color: var(--text);
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
}

.rk-select--big::after {
  right: 18px;
  width: 10px;
  height: 10px;
  border-color: var(--accent-text);
  border-width: 0 3px 3px 0;
}

.rk-select--big select:hover {
  border-color: var(--accent-strong);
}

@media (pointer: coarse) {
  .rk-select select {
    min-height: 44px;
  }
}

/* filter row */

.rk-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--s-3) var(--s-4);
  margin-top: var(--s-4);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
}

.rk-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.rk-field__label {
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.rk-years {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rk-years__dash {
  color: var(--text-3);
}

.rk-field--actions {
  display: flex;
  gap: var(--s-2);
  margin-left: auto;
}

@media (max-width: 600px) {
  .rk-builder {
    padding: var(--s-4);
  }

  .rk-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .rk-field--years,
  .rk-field--actions {
    grid-column: 1 / -1;
  }

  .rk-field--actions {
    margin-left: 0;
  }
}

/* preset questions */

.rk-presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: var(--s-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.rk-presets > li {
  display: flex;
}

.rk-preset {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--r-m);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

.rk-preset:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-1);
  transform: translateY(-1px);
}

.rk-preset[aria-current="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: var(--accent-soft);
}

.rk-preset__tag {
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.rk-preset__q {
  font-weight: 650;
  line-height: 1.3;
}

/* result */

.rk-result {
  transition: opacity 0.18s ease;
}

.rk-result.is-refreshing .rk-layout,
.rk-result.is-refreshing .rk-headline {
  opacity: 0.5;
}

.rk-headline {
  max-width: 62ch;
  margin-bottom: var(--s-4);
  color: var(--text-2);
  font-size: clamp(1.1rem, 0.95rem + 0.8vw, 1.45rem);
  line-height: 1.35;
}

.rk-headline:empty {
  display: none;
}

.rk-headline strong {
  color: var(--text);
  font-weight: 750;
}

.rk-layout {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  transition: opacity 0.18s ease;
}

@media (min-width: 1100px) {
  .rk-layout:has(> .rk-map:not([hidden])) {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  }

  .rk-map {
    position: sticky;
    top: calc(var(--topbar-h) + var(--s-4));
  }
}

.rk-table {
  min-width: 0;
}

.rk-table-wrap {
  max-height: none;
}

.rk-tbl th,
.rk-tbl td {
  vertical-align: middle;
}

.rk-tbl tbody th {
  font-weight: 500;
}

.rk-col-rank {
  width: 3em;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.rk-row--top1 .rk-col-rank,
.rk-row--top2 .rk-col-rank,
.rk-row--top3 .rk-col-rank {
  color: var(--accent-text);
  font-weight: 750;
}

.rk-col-label {
  max-width: 22rem;
}

.rk-label-wrap {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}

.rk-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

a.rk-label:hover .rk-label__text {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.rk-label__text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.rk-label--ref {
  color: var(--text-2);
  font-style: italic;
}

.rk-profile {
  flex: none;
  color: var(--text-3);
  font-size: var(--fs-xs);
}

.rk-col-measure {
  width: 42%;
  min-width: 11rem;
}

.rk-measure {
  display: grid;
  grid-template-columns: minmax(4.5rem, auto) minmax(3rem, 1fr);
  align-items: center;
  gap: var(--s-3);
}

.rk-measure__value {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.rk-measure__sub {
  color: var(--text-3);
  font-weight: 500;
}

.rk-bar {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: var(--surface-3);
}

.rk-bar__fill {
  display: block;
  width: var(--w, 0%);
  height: 100%;
  border-radius: 5px;
  background: var(--data);
  transition: width 0.4s ease;
}

.rk-row--top1 .rk-bar__fill {
  background: var(--accent);
}

/* national reference: a tick in every bar, and its own row */

.rk-bar::after {
  content: "";
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: var(--ref, -10px);
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--text-2);
  opacity: 0.7;
}

.rk-bar:not([style*="--ref"])::after {
  display: none;
}

.rk-bar--ref .rk-bar__fill {
  background: repeating-linear-gradient(135deg, var(--text-3) 0 4px, transparent 4px 7px);
}

.rk-ref td,
.rk-ref th {
  background: var(--surface-2);
}

.rk-more {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-3);
}

.rk-map {
  gap: var(--s-2);
}

@media (max-width: 560px) {
  .rk-col-measure {
    min-width: 8rem;
  }

  .rk-measure {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

  .rk-measure__value {
    text-align: left;
  }

  .rk-measure__sub,
  .rk-profile {
    display: none;
  }

  .rk-tbl th,
  .rk-tbl td {
    padding: 8px;
    white-space: normal;
  }

  .rk-col-rank {
    width: 2em;
  }

  .rk-label {
    gap: 6px;
  }
}

/* phones: the name gets the room of the plate badge */
@media (max-width: 420px) {
  .rk-tbl th,
  .rk-tbl td {
    padding-inline: 6px;
  }

  .rk-col-measure {
    width: 28%;
    min-width: 5.5rem;
  }

  .rk-label {
    font-size: 0.9rem;
  }

  .rk-label .plate {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rk-preset:hover {
    transform: none;
  }
}

/* longer German texts: field labels, preset cards, headers and the headline wrap cleanly */

.rk-field__label,
.rk-preset__tag,
.rk-preset__q,
.rk-headline {
  overflow-wrap: anywhere;
  -webkit-hyphens: auto;
  hyphens: auto;
}

/* In the table, words break at hyphenation points only: "anywhere" would let the browser shrink
   a column to one letter per line. */
.rk-tbl thead th,
.rk-label__text {
  overflow-wrap: break-word;
  -webkit-hyphens: auto;
  hyphens: auto;
}

@media (max-width: 600px) {
  .rk-field .rk-select,
  .rk-field .rk-select select {
    width: 100%;
  }

  .rk-field--actions {
    flex-wrap: wrap;
  }
}
