/* ==========================================================================
   sdatoken.org — tools.css
   Data-surface components: energy mix bars, big numbers, carbon scale,
   Europe map, sparklines, sliders bank, comparison strips.
   Requires tokens.css + site.css.
   ========================================================================== */

/* ── source colour mapping via data attribute ────────────────────────── */
[data-src='nuclear'] {
  --src: var(--src-nuclear);
}
[data-src='hydro'] {
  --src: var(--src-hydro);
}
[data-src='wind'],
[data-src='wind_onshore'],
[data-src='wind_offshore'] {
  --src: var(--src-wind);
}
[data-src='solar'] {
  --src: var(--src-solar);
}
[data-src='biomass'] {
  --src: var(--src-biomass);
}
[data-src='geothermal'] {
  --src: var(--src-geothermal);
}
[data-src='waste'] {
  --src: var(--src-waste);
}
[data-src='marine'] {
  --src: var(--src-marine);
}
[data-src='other_renewable'] {
  --src: var(--src-other-renewable);
}
[data-src='gas'] {
  --src: var(--src-gas);
}
[data-src='coal'] {
  --src: var(--src-coal);
}
[data-src='oil'] {
  --src: var(--src-oil);
}
[data-src='peat'] {
  --src: var(--src-peat);
}
[data-src='oil_shale'] {
  --src: var(--src-oil-shale);
}
[data-src='thermal'] {
  --src: var(--src-thermal);
}
[data-src='other'],
[data-src='other_fossil'] {
  --src: var(--src-other);
}

.src-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--src, var(--src-other));
  vertical-align: middle;
  margin-right: 6px;
}

/* ── carbon intensity scale ─────────────────────────────────────────── */
[data-ci='0'] {
  --ci: var(--scale-c0);
}
[data-ci='1'] {
  --ci: var(--scale-c1);
}
[data-ci='2'] {
  --ci: var(--scale-c2);
}
[data-ci='3'] {
  --ci: var(--scale-c3);
}
[data-ci='4'] {
  --ci: var(--scale-c4);
}
[data-ci='5'] {
  --ci: var(--scale-c5);
}
.ci-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--ci, var(--scale-c2));
  vertical-align: -2px;
  margin-right: 6px;
}
.ci-legend {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-ink-muted);
  font-weight: var(--weight-bold);
}
.ci-legend__bar {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    var(--scale-c0),
    var(--scale-c1),
    var(--scale-c2),
    var(--scale-c3),
    var(--scale-c4),
    var(--scale-c5)
  );
}
.ci-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 6px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  font-weight: var(--weight-black);
  font-variant-numeric: tabular-nums;
}
.ci-pill::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ci, var(--scale-c2));
}

/* ── big number block ───────────────────────────────────────────────── */
.bignum {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bignum__value {
  font-size: clamp(2.5rem, 6vw, var(--text-4xl));
  font-weight: var(--weight-black);
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.bignum__unit {
  font-size: 0.4em;
  color: var(--color-ink-muted);
  font-weight: var(--weight-bold);
  margin-left: 4px;
  letter-spacing: 0;
}
.bignum__label {
  font-size: var(--text-sm);
  color: var(--color-ink-muted);
  font-weight: var(--weight-bold);
}
.bignum__sub {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  font-weight: var(--weight-black);
}

/* ── energy mix bars ────────────────────────────────────────────────── */
.mix {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mix__row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: var(--space-3);
  align-items: center;
  font-size: var(--text-sm);
}
.mix__icon {
  font-size: 20px;
  text-align: center;
}
.mix__track {
  position: relative;
  height: 24px;
  border-radius: 6px;
  background: var(--color-surface-2);
  overflow: hidden;
}
.mix__fill {
  height: 100%;
  width: var(--pct, 0%);
  background: var(--src, var(--src-other));
  border-radius: inherit;
  transition: width var(--dur-slow) var(--ease-out);
}
.mix__name {
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  font-weight: var(--weight-black);
  font-size: var(--text-xs);
  color: var(--color-ink);
  mix-blend-mode: normal;
  text-shadow: 0 0 2px var(--color-surface);
}
.mix__val {
  font-weight: var(--weight-black);
  font-variant-numeric: tabular-nums;
  min-width: 9ch;
  text-align: right;
}
.mix__val small {
  color: var(--color-ink-muted);
  font-weight: var(--weight-bold);
}
/* single stacked bar (compact) */
.stackbar {
  display: flex;
  height: 18px;
  border-radius: 9px;
  overflow: hidden;
  background: var(--color-surface-2);
}
.stackbar__seg {
  width: var(--pct, 0%);
  background: var(--src, var(--src-other));
  transition: width var(--dur-slow) var(--ease-out);
}
.stackbar__seg + .stackbar__seg {
  box-shadow: inset 1px 0 0 var(--color-surface);
}
.stackbar--lg {
  height: 28px;
  border-radius: 8px;
}

/* ── sparkline ──────────────────────────────────────────────────────── */
.spark {
  width: 100%;
  height: 56px;
}
.spark path.line {
  fill: none;
  stroke: var(--color-sky);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.spark path.area {
  fill: var(--color-sky-soft);
}
.spark .dot {
  fill: var(--color-sky);
  stroke: var(--color-surface);
  stroke-width: 2;
}

/* ── Europe map ─────────────────────────────────────────────────────── */
.eu-map {
  width: 100%;
  height: auto;
  display: block;
}
.eu-map .country {
  fill: var(--color-surface-2);
  stroke: var(--color-surface);
  stroke-width: 0.8;
  transition:
    fill var(--dur-slow),
    filter var(--dur-fast);
  cursor: pointer;
}
.eu-map .country[data-ci] {
  fill: var(--ci);
}
.eu-map .country:hover,
.eu-map .country.is-active {
  filter: brightness(1.12) saturate(1.1);
  stroke: var(--color-ink);
  stroke-width: 1.5;
}
.eu-map .country.is-dim {
  opacity: 0.35;
}
.eu-map .country.no-data {
  fill: var(--color-surface-2);
  cursor: default;
}
.map-tip {
  position: absolute;
  pointer-events: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-ink);
  color: var(--color-inverse);
  font-size: var(--text-xs);
  font-weight: var(--weight-black);
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
  z-index: 10;
}
.map-wrap {
  position: relative;
}

/* ── ticker ─────────────────────────────────────────────────────────── */
.ticker {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  border: var(--border-w) solid var(--color-border);
  overflow: hidden;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
}
.ticker__label {
  flex-shrink: 0;
  color: var(--color-primary-ink); /* 7:1 on white (was 4.15:1) */
}
.ticker__track {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  mask-image: linear-gradient(to right, transparent, #000 5%, #000 95%, transparent);
}
.ticker__items {
  display: inline-flex;
  gap: var(--space-8);
  padding-right: var(--space-8);
  animation: ticker 45s linear infinite;
}
.ticker:hover .ticker__items {
  animation-play-state: paused;
}
/* JS renders the items twice; scrolling by half loops seamlessly and starts visible */
@keyframes ticker {
  to {
    transform: translateX(-50%);
  }
}

/* ── slider bank (Race to Zero) ─────────────────────────────────────── */
.slider-bank {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.slider-row {
  display: grid;
  grid-template-columns: 36px 1fr 96px;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: var(--border-w) solid var(--color-border);
}
.slider-row.is-capped {
  border-color: var(--color-warn);
}
.slider-row.is-blocked {
  border-color: var(--color-danger);
}
.slider-row__icon {
  font-size: 22px;
  text-align: center;
}
.slider-row__main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.slider-row__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--text-sm);
}
.slider-row__name {
  font-weight: var(--weight-black);
}
.slider-row__tier {
  font-size: var(--text-xs);
  font-weight: var(--weight-black);
  color: var(--color-ink-faint);
}
.slider-row .range {
  --range-fill: var(--src, var(--color-primary));
  height: 28px;
}
.slider-row__value {
  text-align: right;
  font-weight: var(--weight-black);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.slider-row__value small {
  display: block;
  color: var(--color-ink-muted);
  font-weight: var(--weight-bold);
  font-size: var(--text-xs);
}
/* feasibility tier marks drawn under a slider */
.tier-marks {
  position: relative;
  height: 6px;
  margin: -6px 14px 0;
}
.tier-marks span {
  position: absolute;
  top: 0;
  width: 2px;
  height: 6px;
  background: var(--color-warn);
}
.tier-marks span.red {
  background: var(--color-danger);
}

/* ── before/after strip ─────────────────────────────────────────────── */
.compare {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--space-4);
  align-items: center;
}
.compare__vs {
  font-weight: var(--weight-black);
  color: var(--color-ink-faint);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
}
@media (max-width: 640px) {
  .compare {
    grid-template-columns: 1fr;
  }
  .compare__vs {
    text-align: center;
  }
}

/* ── country card (Battle, neighbours) ─────────────────────────────── */
.country-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: var(--border-w) solid var(--color-border);
}
.country-card__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-black);
  font-size: var(--text-lg);
}
.country-card__head .flag {
  font-size: 1.6em;
}
.country-card.is-winner {
  border-color: var(--color-primary);
  box-shadow: 0 4px 0 var(--color-primary);
}

/* ── verified feed badge ────────────────────────────────────────────── */
.verified {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-black);
  color: var(--color-sky-strong);
}
.verified::before {
  content: '✔';
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-sky);
  color: #fff;
  font-size: 10px;
}

/* ── leaflet overrides (Solar Studio) ──────────────────────────────── */
.leaflet-container {
  border-radius: var(--radius-lg);
  border: var(--border-w) solid var(--color-border);
  font-family: var(--font-sans);
}

/* ---------- day-ahead price lens (Europe Live) ---------- */
.price-legend {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-ink-muted);
  font-weight: var(--weight-bold);
}
.price-legend__bar {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    var(--scale-c0),
    var(--scale-c1),
    var(--scale-c2),
    var(--scale-c3),
    var(--scale-c4),
    var(--scale-c5)
  );
}
.pricebars {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 140px;
  overflow-x: auto;
}
.pricebars__axis {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.pricebar {
  flex: 1 0 4px;
  min-width: 3px;
  height: var(--h, 4%);
  border-radius: 2px 2px 0 0;
  background: var(--ci, var(--color-primary));
  opacity: 0.85;
}
.pricebar.is-now {
  outline: 2px solid var(--color-ink);
  outline-offset: 1px;
  opacity: 1;
}
.pricebar.is-cheapest {
  box-shadow: 0 0 0 2px var(--scale-c0) inset;
  opacity: 1;
}
.pricebar.is-negative {
  background: repeating-linear-gradient(
    45deg,
    var(--color-info, #2563eb),
    var(--color-info, #2563eb) 3px,
    #fff 3px,
    #fff 5px
  );
  border-bottom: 3px solid var(--color-info, #2563eb);
}
#price-rank tr.is-stale td {
  opacity: 0.75;
}
#price-rank tr.rank-sep td {
  background: var(--color-surface-2);
  font-weight: var(--weight-bold);
}
.price-cell {
  line-height: 1.25;
}
.price-cell small {
  display: block;
  font-size: var(--text-xs);
  font-weight: 400;
}
#price-rank td small.faint {
  display: block;
  font-weight: 400;
}

/* ---------- household bill breakdown (Europe Live, price lens) ---------- */
.billbar {
  display: flex;
  height: 34px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface-2);
}
.billbar__seg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-black);
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
}
.billbar__seg[data-part='energy_supply'] {
  background: #16a34a;
}
.billbar__seg[data-part='network'] {
  background: #2563eb;
}
.billbar__seg[data-part='taxes_levies'] {
  background: #b45309;
}
.billbar__seg[data-part='vat'] {
  background: #7c3aed;
}
.billlegend {
  list-style: none;
  margin: var(--space-3) 0 0;
  padding: 0;
  display: grid;
  gap: var(--space-1) var(--space-5);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  font-size: var(--text-sm);
}
.billlegend li {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-variant-numeric: tabular-nums;
}
.billlegend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}
.billlegend .billlegend__val {
  margin-left: auto;
  font-weight: var(--weight-black);
}
.billlegend li.is-rebate .billlegend__val {
  color: var(--color-primary-strong);
}
.billlegend li.is-total {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-1);
  grid-column: 1 / -1;
  font-weight: var(--weight-black);
}
