/* ==========================================================================
   TeamTrek — twelve weeks, and the week something changed
   --------------------------------------------------------------------------
   The hero figure on the productivity trends page: one figure drawn across
   twelve weeks, with a marker where a team changed something and the
   averages either side of it.

   A line, because a trend is a shape over time and nothing else shows it.
   The productivity tracking page draws a day and a week; this one draws the
   only question those cannot answer, which is whether a decision worked.

   1056 by 482, like every other hero figure on the site.

   The chart is an inline SVG on a 1000 by 250 viewBox. Strokes carry
   vector-effect so they stay one weight at every width, and the text
   outside it is HTML, so it scales with the page rather than with the box.
   ========================================================================== */

.trend {
  width: 100%; max-width: 66rem; margin-inline: auto;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--neutral-200); border-radius: var(--r-xl);
  background: #fff;
  /* Heavier than the shared shadow: the panel straddles the dark band and
     the dome, and a light shadow over the dark half disappears. */
  box-shadow: 0 30px 80px rgba(8, 40, 36, .28);
  text-align: left;
  display: flex; flex-direction: column;
}

/* ------------------------------------------------------------- the head */
.trend__head {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding-bottom: .875rem;
  border-bottom: 1px solid var(--neutral-200);
}
.trend__what { font-size: .9375rem; font-weight: 700; color: var(--neutral-900); }
.trend__span { font-size: .8125rem; color: var(--neutral-500); }
.trend__state {
  display: flex; align-items: center; gap: .5rem;
  font-size: .6875rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--primary-700);
}
.trend__now {
  margin-left: auto;
  font-size: .8125rem; color: var(--neutral-600); font-variant-numeric: tabular-nums;
}
.trend__now b { font-weight: 700; color: var(--neutral-900); }

/* ------------------------------------------------------------ the chart */
.trend__plot { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; }
.trend__svg { display: block; width: 100%; height: auto; overflow: visible; }

.trend__grid { stroke: var(--neutral-150); stroke-width: 1; vector-effect: non-scaling-stroke; }

/* The line itself. It is drawn rather than revealed: a trend that fades in
   is a picture of a trend, and a trend that draws left to right is time
   passing, which is what the figure is about. */
.trend__line {
  fill: none;
  stroke: var(--primary-500); stroke-width: 2.5;
  stroke-linecap: round; stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.trend__dot { fill: #fff; stroke: var(--primary-500); stroke-width: 2; vector-effect: non-scaling-stroke; }
.trend__dot--last { fill: var(--primary-600); stroke: #fff; stroke-width: 3; }

/* Where the team changed something. A dashed rule rather than a block,
   because it marks a moment and not a period. */
.trend__cut {
  stroke: var(--neutral-400); stroke-width: 1.5; stroke-dasharray: 5 5;
  vector-effect: non-scaling-stroke;
}
/* The average either side of it. Flat, so the step between them is the
   thing the eye lands on. */
.trend__mean { stroke-width: 2; stroke-dasharray: 2 6; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.trend__mean--before { stroke: var(--neutral-400); }
.trend__mean--after { stroke: var(--primary-700); }

/* ------------------------------------------------------------ the foot */
/* The two averages and the difference between them, which is the sentence
   the picture is making. */
.trend__sums {
  flex: none;
  margin: .875rem 0 0; padding: 0; list-style: none;
  padding-top: .875rem;
  border-top: 1px solid var(--neutral-200);
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}
.trend__sum b {
  display: block;
  font-size: 1.25rem; font-weight: 800; letter-spacing: -.02em;
  color: var(--neutral-900); font-variant-numeric: tabular-nums;
}
.trend__sum span { display: block; margin-top: .125rem; font-size: .8125rem; color: var(--neutral-500); }
.trend__sum--key b { color: var(--primary-700); }
.trend__note { margin-left: auto; }

/* ------------------------------------------------------------------ sizes */
@media (min-width: 860px) {
  /* The figure every other hero on the site carries. */
  .trend { height: 482px; }
}

@media (max-width: 859px) {
  .trend { padding: 1.125rem 1.25rem; }
  /* Two across. Four figures in a 700px panel leave each one 160px, which
     is not enough for "22h 34m" over "average after the change". */
  .trend__sums { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .875rem 1rem; }
  .trend__sum b { font-size: 1.125rem; }
}

@media (max-width: 599px) {
  .trend { padding: 1rem; }
  /* The two averages and the difference. How many weeks are on the chart is
     the one a phone can do without, and the chart is right above it. */
  .trend__sum:nth-child(4) { display: none; }
}

/* --------------------------------------------------------------------------
   One week against the weeks around it
   --------------------------------------------------------------------------
   Section 04's figure: this week's figure as a mark on the range the last
   eight weeks covered, with their average on it too.

   The restraint the rest of the site promises, drawn rather than asserted.
   A week that is down on the last one still sits inside the band, and the
   band is what says whether anything has actually happened.
   -------------------------------------------------------------------------- */
.range {
  margin-top: 2.5rem; padding: 1.5rem;
  border: 1px solid var(--neutral-200); border-radius: var(--r-lg);
  background: #fff;
}

.range__row {
  display: grid; grid-template-columns: 11rem minmax(0, 1fr) 7rem;
  align-items: center; gap: .75rem;
  padding: 1.25rem 0;
}
.range__row + .range__row { border-top: 1px solid var(--neutral-150); }
.range__name { margin: 0; font-size: .875rem; font-weight: 700; color: var(--neutral-900); }
.range__sub { display: block; font-size: .75rem; font-weight: 400; color: var(--neutral-500); }

.range__track {
  position: relative; height: 2.5rem;
  border-radius: var(--r-sm);
  background: var(--neutral-50);
  box-shadow: inset 0 0 0 1px var(--neutral-150);
}
/* The span the last eight weeks covered. */
.range__band {
  position: absolute; top: 5px; bottom: 5px;
  left: calc(var(--from) * 1%); right: calc(100% - var(--to) * 1%);
  border-radius: var(--r-xs);
  background: var(--primary-100, var(--neutral-100));
  box-shadow: inset 0 0 0 1px var(--primary-200);
}
/* Their average, and this week. The average is a hairline because it is
   context; this week is solid because it is the subject. */
.range__mean {
  position: absolute; top: 2px; bottom: 2px;
  left: calc(var(--at) * 1%);
  width: 1px; margin-left: -.5px;
  background: var(--neutral-400);
}
.range__mark {
  position: absolute; top: 0; bottom: 0;
  left: calc(var(--at) * 1%);
  width: 4px; margin-left: -2px;
  border-radius: 2px;
  background: var(--primary-600);
}
.range__mark b {
  position: absolute; left: 50%; top: -1.25rem; transform: translateX(-50%);
  font-size: .6875rem; font-weight: 700; color: var(--primary-700); white-space: nowrap;
}

.range__out {
  text-align: right;
  font-size: .9375rem; font-weight: 800; color: var(--neutral-900);
  font-variant-numeric: tabular-nums;
}
.range__out span { display: block; font-size: .75rem; font-weight: 400; color: var(--neutral-500); }

.range__axis {
  display: grid; grid-template-columns: 11rem minmax(0, 1fr) 7rem;
  gap: .75rem;
  font-size: .75rem; color: var(--neutral-500);
  font-variant-numeric: tabular-nums;
}
.range__ticks { position: relative; display: block; height: 1.0625rem; }
.range__ticks b {
  position: absolute; top: 0;
  left: calc(var(--at) * 1%); transform: translateX(-50%);
  font-weight: inherit; white-space: nowrap;
}
.range__ticks b:first-child { transform: none; }
.range__ticks b:last-child { transform: translateX(-100%); }

@media (max-width: 859px) {
  .range { padding: 1.25rem; }
  .range__row,
  .range__axis { grid-template-columns: minmax(0, 1fr) 6rem; row-gap: .5rem; }
  .range__track { grid-column: 1 / -1; }
  .range__axis > span:first-child { display: none; }
}

/* The marker and the second average arrive when the line reaches them, so
   the chart is never claiming a result it has not drawn yet.

   Hidden by a class the script adds, not by a default in here. A figure
   whose parts are invisible until JavaScript runs is a figure that is
   wrong whenever it does not. */
.trend__cut,
.trend__mean--after,
.trend__dot--last {
  transition: opacity var(--dur-ui) var(--ease-ui);
}
.trend.is-drawing .trend__cut,
.trend.is-drawing .trend__mean--after,
.trend.is-drawing .trend__dot--last { opacity: 0; }
