/* The revenue chart's own two ramps, five steps each, drawn on the bars themselves.

   Half of these point at the brand tokens because they were the brand colours under different names;
   the rest are genuinely chart-specific shades with no counterpart in the palette, and inventing a
   colour-mix for them would give a muddier ramp than the ones chosen by hand. That is the reason the
   list looks half-tokenised: the tokenised half is the half a brand change should move. */
:root {
  /* The same hex as --looc-stream-produce-dark, which the sankey already draws its dark end with. */
  --color-green-darker: var(--looc-stream-produce-dark);
  --color-green-dark: #036351;
  /* The brand palette, reached through the tokens rather than restated: these three were the same
     hex codes as --looc-green, --looc-teal and --looc-orange under different names, so a brand change
     moved everything in the Portal except this chart. */
  --color-green-medium: var(--looc-green);
  --color-green-light: var(--looc-teal);
  --color-green-lighter: #e5f2e3;
  --color-orange-darker: #330900;
  --color-orange-dark: #632303;
  /* The same hex as --looc-stream-consume-brown. */
  --color-orange-medium: var(--looc-stream-consume-brown);
  --color-orange-light: var(--looc-orange);
  --color-orange-lighter: #f7a77e;
  --canvas-bg: var(--rz-base-background);
  --canvas-text: #28363c;
  --bar-height: 6em;
  --bar-half: calc(var(--bar-height) / 2);
  --bar-third: calc(var(--bar-height) / 3);
  --bar-quarter: calc(var(--bar-height) / 4);
  --bar-tenth: calc(var(--bar-height) / 10);
  --bar-text-left: 4em;
  --bar-text-right: 6em;
}

.barchart {
  position: relative;
}

.bar__wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.bar {
  height: var(--bar-height);
  position: relative;
}

  .bar::before,
  .bar::after {
    clip-path: polygon(0 0, calc(100% - var(--bar-quarter)) 0, 100% var(--bar-half), calc(100% - var(--bar-quarter)) 100%, 0 100%);
    content: '';
    height: var(--bar-height);
    left: 0;
    position: absolute;
  }

  .bar::before {
    right: 0;
  }

  .bar::after {
    right: var(--bar-tenth);
  }

.bar--subsidy {
  animation: growBarSubsidy 1500ms ease-out forwards;
  width: var(--subsidy-bar-length);
}

  .bar--subsidy::before {
    background: var(--color-green-light);
  }

  .bar--subsidy::after {
    background: linear-gradient(290deg, var(--color-green-dark) var(--bar-height), var(--color-green-light) calc(3 * var(--bar-height)));
    border: 1px solid var(--color-green-medium);
  }

.bar--regular {
  animation: growBarRegular 1500ms ease-out forwards;
  width: var(--regular-bar-length);
}

  .bar--regular::before {
    background: var(--color-orange-light);
  }

  .bar--regular::after {
    background: linear-gradient(290deg, var(--color-orange-dark) var(--bar-height), var(--color-orange-light) calc(3 * var(--bar-height)));
    border: 1px solid var(--color-orange-medium);
  }

.bar__text {
  display: flex;
  flex-direction: column;
  height: var(--bar-height);
  justify-content: center;
  position: absolute;
  z-index: 1;
  max-width: calc(var(--bar-text-left) + var(--bar-text-right));
}

.bar--subsidy .bar__text {
  left: max(10px, calc(100% - var(--bar-text-left) - var(--bar-text-right) - 60px));
}

.bar--regular .bar__text {
  left: max(10px, calc(100% - var(--bar-text-left) - var(--bar-text-right) - 60px));
}

.bar__paragraph {
  align-items: center;
  color: var(--rz-on-primary);
  display: flex;
  line-height: 1.2;
  gap: 10px;
  justify-content: space-between;
  margin: 0;
  text-shadow: 1px 1px 1px hsl(0 0% 0% / 0.4), 0 0 5px hsl(0 0% 0% / 0.3);
}

.bar--targetless .bar__paragraph {
  color: var(--rz-text-color);
  text-shadow: none;
}

.bar__label {
  flex: 1 0 var(--bar-text-left);
}

.bar__time,
.bar__currency {
  flex: 1 0 var(--bar-text-right);
}

.bar__time {
  text-align: right;
}

.bar__currency {
  text-align: right;
}

.bar--targetless .bar__currency {
    text-align: right;
}

.bar__percentage {
  font-weight: 600;
  font-size: 16px;
  padding: 0 0.5em;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translate(200%, 70%);
  /* LC-268: "under 1%" broke over two lines and ran into the text beside it. */
  white-space: nowrap;
}

/* LC-268: a bar too short to carry its text (set in RevenueBarBoiler) puts the text beside the bar on a plate of its
   own, in the page's text colour: in white on the light gradient behind the bar it could hardly be read. The share of
   the maximum heads the plate instead of floating beside it. */
.bar--short .bar__text {
  background: color-mix(in srgb, var(--rz-base-background-color) 92%, transparent);
  border-radius: var(--looc-radius-sm);
  /* A size down, so the plate with the share on top stays within the bar's height. */
  font-size: 0.875em;
  height: auto;
  left: max(10px, calc(100% + 0.5em));
  max-width: none;
  padding: 0.125em 0.625em;
  top: 50%;
  transform: translateY(-50%);
}

.bar--short .bar__paragraph {
  color: var(--rz-text-color);
  text-shadow: none;
}

.bar--short .bar__percentage {
  font-size: 1em;
  order: -1;
  padding: 0;
  position: static;
  transform: none;
}

.bar--subsidy .bar__percentage {
  color: var(--color-green-dark);
}

.bar--regular .bar__percentage {
  color: var(--color-orange-dark);
}

.marker__wrapper {
  position: initial;
}

.marker {
  bottom: 0;
  display: block;
  left: 0;
  position: absolute;
  top: 0;
}

.marker__arrow {
  clip-path: polygon(0 0, calc(100% - var(--bar-quarter)) 0, 100% var(--bar-half), calc(100% - var(--bar-quarter)) 100%, 0 100%);
  content: '';
  height: var(--bar-height);
  left: 0;
  position: absolute;
  right: 0;
}

.marker--subsidy {
  border-right: 2px solid var(--color-green-medium);
  right: calc(100% - var(--bar-max-percentage) * var(--subsidy-bar-max));
}

  .marker--subsidy .marker__arrow {
    background: var(--color-green-lighter);
    background: linear-gradient(100deg, var(--color-green-dark) 0, var(--color-green-lighter) calc(3 * var(--bar-height)));
    opacity: 0.5;
  }

.marker--regular {
  border-right: 2px solid var(--color-orange-medium);
  right: calc(100% - var(--bar-max-percentage) * var(--regular-bar-max));
}

  .marker--regular .marker__arrow {
    background: var(--color-orange-lighter);
    background: linear-gradient(100deg, var(--color-orange-dark) 0, var(--color-orange-lighter) calc(3 * var(--bar-height)));
    bottom: 0;
    opacity: 0.2;
  }

.marker__text {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  padding: 0 0.5em;
  position: absolute;
  right: 0;
}

.marker--subsidy .marker__text {
  color: var(--color-green-dark);
  transform: translate(100%, 0);
  top: 0;
}

.marker--regular .marker__text {
  color: var(--color-orange-medium);
  text-align: right;
  transform: translate(0, -100%);
  top: 50%;
}

@keyframes growBarSubsidy {
  from {
    width: 0;
  }
  30% {
    width: 0;
  }
  to {
    width: var(--subsidy-bar-length);
  }
}

@keyframes growBarRegular {
  from {
      width: 0;
  }
  30% {
    width: 0;
  }
  to {
    width: var(--regular-bar-length);
  }
}

/* Device sections */
.device-section {
  border-bottom: 1px solid hsl(0 0% 92%);
  margin-bottom: 1rem;
  padding-bottom: 1rem;
}

.device-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

/* Device header */
.device-header {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem 0.5rem;
  margin-bottom: 0.5rem;
}

.device-header__name {
  color: var(--rz-text-color);
  font-size: 1rem;
  font-weight: 600;
}

/* LC-268: what the card comes to, at the end of its head, before the posts explain it. */
.device-header__result {
  font-size: 1.125rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin-left: auto;
  white-space: nowrap;
}

/* LC-268: in which of the totals at the top the card counts. */
.revenue-badge {
  background: color-mix(in srgb, var(--looc-green) 14%, transparent);
  border-radius: var(--looc-radius-sm);
  color: var(--color-green-dark);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  white-space: nowrap;
}

.revenue-badge--passive {
  background: var(--rz-base-200);
  color: var(--rz-text-secondary-color);
}

/* Revenue summary card */
.revenue-summary {
  border: 1px solid hsl(0 0% 90%);
  border-radius: 10px;
  margin-bottom: 0.5rem;
  padding: 0.875rem 1rem;
}

.revenue-summary__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.revenue-summary__label {
  color: var(--rz-text-secondary-color);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.revenue-summary__amount {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.revenue-summary__amount--positive {
  color: var(--color-green-dark);
}

.revenue-summary__amount--negative {
  color: hsl(0 65% 45%);
}

.revenue-summary__footer {
  border-top: 1px solid hsl(0 0% 92%);
  color: var(--rz-text-secondary-color);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.8125rem;
  gap: 0.375rem;
  margin-top: 0.75rem;
  padding-top: 0.625rem;
}

/* LC-268: the key figures as chips; as a line of small grey text they were hardly read. */
.revenue-summary__footer > span {
  background: var(--rz-base-100);
  border-radius: var(--looc-radius-sm);
  color: var(--rz-text-color);
  padding: 0.1875rem 0.5rem;
}

/* LC-265: the year over every device, split into steerable and passive. */
.revenue-totals {
  display: grid;
  gap: 0.75rem 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  margin-bottom: 1rem;
}

.revenue-totals__part {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.revenue-totals__amount {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.revenue-totals__note {
  font-size: 0.8125rem;
  margin: 0 0 1rem;
}

/* LC-268: a device type's posts, one row each, with a bar from a zero line in the middle: income to the right in
   green, a cost to the left in red, the amount beside it. The net result ends the rows as an arrow, in the style of the
   arrow before LC-265. */
.revenue-rows {
  /* Measured against the card rather than the window: beside the Portal's sidebar a card is narrow long before the
     window is. */
  container-type: inline-size;
  display: grid;
  gap: 0.25rem;
  margin: 0;
}

.revenue-row {
  align-items: center;
  display: grid;
  font-size: 0.875rem;
  gap: 1rem;
  grid-template-columns: minmax(8rem, 14rem) minmax(0, 1fr);
}

.revenue-row__label {
  color: var(--rz-text-secondary-color);
  font-weight: 500;
}

.revenue-row__value {
  align-items: center;
  display: grid;
  /* Wide enough for "−€ 12.345,67 cost" in the net result's bold. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 10.5rem;
  margin: 0;
}

.revenue-row__side {
  align-items: center;
  display: flex;
  height: 1.25rem;
}

/* The zero line: the cost half ends on it and the gain half starts from it. */
.revenue-row__side--cost {
  border-right: 1px solid var(--rz-base-400);
  justify-content: flex-end;
}

.revenue-row__bar {
  animation: revenueBarGrow 800ms cubic-bezier(0.22, 1, 0.36, 1) both;
  height: 0.75rem;
  min-width: 2px;
}

.revenue-row__bar--gain {
  background: var(--color-green-medium);
  border-radius: 0 3px 3px 0;
  transform-origin: left center;
}

.revenue-row__bar--cost {
  background: var(--rz-danger);
  border-radius: 3px 0 0 3px;
  transform-origin: right center;
}

.revenue-row__amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.revenue-row--sum {
  border-top: 1px solid hsl(0 0% 85%);
  font-size: 1rem;
  margin-top: 0.25rem;
  padding-top: 0.5rem;
}

.revenue-row--sum .revenue-row__label {
  color: var(--rz-text-color);
  font-weight: 600;
}

.revenue-row--sum .revenue-row__side {
  height: 2rem;
}

.revenue-row--sum .revenue-row__amount {
  font-weight: 700;
}

.revenue-row--part {
  font-size: 0.8125rem;
}

.revenue-row--part .revenue-row__label {
  padding-left: 1rem;
}

.revenue-row__note {
  margin: 0;
  text-align: right;
}

.revenue-arrow {
  --arrow-tip: 0.75rem;
  animation: revenueBarGrow 800ms cubic-bezier(0.22, 1, 0.36, 1) both;
  height: 1.75rem;
  min-width: calc(var(--arrow-tip) + 2px);
}

.revenue-arrow--gain {
  background: linear-gradient(90deg, var(--color-green-light) 0%, var(--color-green-medium) 45%, var(--color-green-dark) 100%);
  clip-path: polygon(0 0, calc(100% - var(--arrow-tip)) 0, 100% 50%, calc(100% - var(--arrow-tip)) 100%, 0 100%);
  transform-origin: left center;
}

.revenue-arrow--cost {
  background: linear-gradient(270deg, var(--rz-danger-lighter) 0%, var(--rz-danger) 45%, var(--rz-danger-dark) 100%);
  clip-path: polygon(var(--arrow-tip) 0, 100% 0, 100% 100%, var(--arrow-tip) 100%, 0 50%);
  transform-origin: right center;
}

@keyframes revenueBarGrow {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .revenue-row__bar,
  .revenue-arrow,
  .bar--subsidy,
  .bar--regular {
    animation: none;
  }
}

/* On a narrow card the label takes its own line above the bar and the amount. */
@container (max-width: 36rem) {
  .revenue-row {
    gap: 0.125rem;
    grid-template-columns: minmax(0, 1fr);
  }

  .revenue-row__value {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 9.5rem;
  }
}
