.meter {
  display: block;
  position: relative;
  isolation: isolate;
  height: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--line);
  overflow: hidden;
}

.meter::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fill, 0%);
  border-radius: inherit;
  background: var(--accent);
}

.meter::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 auto 0 var(--band-start, 0%);
  width: calc(var(--band-end, 0%) - var(--band-start, 0%));
  background: var(--good-soft);
}

.meter-good::before {
  background: var(--good);
}

.meter-caution::before {
  background: var(--caution);
}

.meter-danger::before {
  background: var(--danger);
}

/* One grid for the whole list: every row is a subgrid over its columns, so
   the labels, tracks, values and bands of all rows start and end together.
   The label column takes the widest label up to 14rem. Below 34rem a label
   spans the first two columns and the track takes a line of its own. */
.meter-list {
  container-type: inline-size;
  display: grid;
  grid-template-columns: fit-content(14rem) minmax(0, 1fr) auto auto;
  gap: var(--space-2) var(--space-2);
}

/* Set columns, for lists stacked under separate headings: each list is its
   own grid, so only set widths make their tracks start and end together.
   The widths hold a percentage row: "100%" and "at most 20%". */
.meter-list-aligned {
  grid-template-columns: 9rem minmax(0, 1fr) 3rem 6rem;
}

/* The same, for a value and a target said in words: "3.6 per week" against
   "at most 3 per week". */
.meter-list-aligned-wide {
  grid-template-columns: 11rem minmax(0, 1fr) 7rem 7.5rem;
}

.meter-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  grid-template-areas:
    "label label value band"
    "meter meter meter meter";
  row-gap: var(--space-1);
  align-items: center;
}

.meter-row-label {
  grid-area: label;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
}

.meter-row-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 2px;
}

.meter-row-link:hover {
  text-decoration-color: currentColor;
}

.meter-row-meter {
  grid-area: meter;
  min-width: 0;
}

.meter-row-value {
  grid-area: value;
  font-size: var(--text-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.meter-row-band {
  grid-area: band;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* 34rem: a half-width analytics panel on a 1280px laptop is about 37rem
   inside, and one-line meters are the point of putting it on the grid. */
@container (min-width: 34rem) {
  .meter-row {
    grid-template-areas: "label meter value band";
  }

  .meter-row-bare {
    grid-template-areas: "label label value band";
  }
}
