@layer km-base {
  .km-page--trend {
    color: var(--km-color-body);
    font-size: var(--km-font-body);
  }


  .km-page--trend #historyRecords {
    overflow-x: hidden;
  }

  .km-page--trend #historyRecords .history-item {
    border-bottom: 1px solid var(--km-color-border);
    display: grid;
    align-items: center;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    padding: var(--km-space-sm) 0;
    column-gap: 0;
    row-gap: 0;
    overflow: visible;
    text-align: left;
  }

  .km-page--trend #historyRecords .history-overall-row {
    grid-template-columns:
      var(--km-history-date-width)
      var(--km-history-date-to-content-gap)
      var(--km-history-face-size)
      var(--km-history-grid-gap)
      var(--km-history-percent-width)
      var(--km-history-grid-gap)
      minmax(0,1fr);
  }

  .km-page--trend #historyRecords .history-single {
    grid-template-columns:
      var(--km-history-date-width)
      var(--km-history-date-to-content-gap)
      max-content
      var(--km-history-grid-gap)
      minmax(0,1fr);
  }

  .km-page--trend #historyRecords .history-compare,
  .km-page--trend #historyRecords .history-context {
    grid-template-columns:
      var(--km-history-date-width)
      var(--km-history-date-to-content-gap)
      max-content
      var(--km-history-grid-gap)
      var(--km-history-separator-width)
      var(--km-history-grid-gap)
      max-content
      var(--km-history-grid-gap)
      minmax(0,1fr);
  }

  .km-page--trend #historyRecords .history-overall-row > .history-date,
  .km-page--trend #historyRecords .history-analysis-row > .history-date { grid-column: 1; }
  .km-page--trend #historyRecords .history-overall-row > .history-face-cell { grid-column: 3; }
  .km-page--trend #historyRecords .history-overall-row > .history-percent { grid-column: 5; }
  .km-page--trend #historyRecords .history-overall-row > .history-note { grid-column: 7; }
  .km-page--trend #historyRecords .history-single > .history-metric-group { grid-column: 3; }
  .km-page--trend #historyRecords .history-single > .history-note { grid-column: 5; }
  .km-page--trend #historyRecords .history-compare > .history-metric-group--a,
  .km-page--trend #historyRecords .history-context > .history-metric-group--a { grid-column: 3; }
  .km-page--trend #historyRecords .history-compare > .history-group-sep,
  .km-page--trend #historyRecords .history-context > .history-group-sep { grid-column: 5; }
  .km-page--trend #historyRecords .history-compare > .history-metric-group--b,
  .km-page--trend #historyRecords .history-context > .history-context-value { grid-column: 7; }
  .km-page--trend #historyRecords .history-compare > .history-note,
  .km-page--trend #historyRecords .history-context > .history-note { grid-column: 9; }

  .km-page--trend #historyRecords .history-date {
    width: var(--km-history-date-width);
    min-width: var(--km-history-date-width);
    max-width: var(--km-history-date-width);
    margin: 0;
    padding: 0;
    white-space: nowrap;
    text-align: left;
  }

  .km-page--trend #historyRecords .history-face-cell {
    width: var(--km-history-face-size);
    min-width: var(--km-history-face-size);
    max-width: var(--km-history-face-size);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
  }

  .km-page--trend #historyRecords .history-percent {
    width: var(--km-history-percent-width);
    min-width: var(--km-history-percent-width);
    max-width: var(--km-history-percent-width);
    margin: 0;
    padding: 0;
    text-align: left;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .km-page--trend #historyRecords .history-metric-group {
    display: grid;
    grid-template-columns: max-content var(--km-history-score-width);
    column-gap: var(--km-history-metric-gap);
    align-items: center;
    width: max-content;
    min-width: 0;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .km-page--trend #historyRecords .history-metric-name {
    display: block;
    width: auto;
    min-width: 0;
    max-width: none;
    margin: 0;
    padding: 0;
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
  }

  .km-page--trend #historyRecords .history-score {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--km-history-score-width);
    min-width: var(--km-history-score-width);
    max-width: var(--km-history-score-width);
    margin: 0;
    padding: 0;
    text-align: center;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .km-page--trend #historyRecords .history-group-sep {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--km-history-separator-width);
    min-width: var(--km-history-separator-width);
    max-width: var(--km-history-separator-width);
    margin: 0;
    padding: 0;
    color: var(--km-color-muted);
    line-height: 1;
  }

  .km-page--trend #historyRecords .history-context-value {
    display: block;
    width: max-content;
    min-width: 0;
    max-width: none;
    margin: 0;
    padding: 0;
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
  }

  .km-page--trend #historyRecords .history-note {
    width: auto;
    min-width: 0;
    max-width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
  }

  .km-page--trend #historyRecords .trend-history-face {
    display: inline-block;
    width: var(--km-history-face-size);
    height: var(--km-history-face-size);
    vertical-align: middle;
    margin: 0 var(--km-space-xs);
  }

  .km-page--trend #historyRecords .history-clickable {
    cursor: pointer;
    border-radius: 0;
  }

  .km-page--trend #historyRecords .history-clickable:hover {
    background: var(--km-color-bg-soft);
  }

  .km-page--trend #historyRecords .history-clickable:focus {
    outline: 2px solid var(--km-color-primary-hover);
    outline-offset: 2px;
  }

  @media (max-width:600px) {
    .km-page--trend #historyRecords .history-item {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: var(--km-space-xs) var(--km-space-sm);
      padding: var(--km-space-sm) 0;
    }

    .km-page--trend #historyRecords .history-item > * {
      grid-column: auto;
    }

    .km-page--trend #historyRecords .history-date {
      width: var(--km-history-date-width-mobile);
      min-width: var(--km-history-date-width-mobile);
      max-width: var(--km-history-date-width-mobile);
    }

    .km-page--trend #historyRecords .history-item > :nth-child(2) {
      margin-left: calc(var(--km-history-date-to-content-gap) - var(--km-history-grid-gap));
    }

    .km-page--trend #historyRecords .history-face-cell {
      width: var(--km-face-history-mobile);
      min-width: var(--km-face-history-mobile);
      max-width: var(--km-face-history-mobile);
    }

    .km-page--trend #historyRecords .trend-history-face {
      width: var(--km-face-history-mobile);
      height: var(--km-face-history-mobile);
    }

    .km-page--trend #historyRecords .history-percent {
      width: auto;
      min-width: 0;
      max-width: none;
    }

    .km-page--trend #historyRecords .history-metric-group {
      display: inline-grid;
      grid-template-columns: max-content var(--km-history-score-width);
      column-gap: var(--km-history-metric-gap);
      align-items: center;
      width: max-content;
      min-width: 0;
      max-width: none;
      margin: 0;
      padding: 0;
    }

    .km-page--trend #historyRecords .history-metric-name {
      display: inline-block;
      width: auto;
      min-width: 0;
      max-width: 110px;
    }

    .km-page--trend #historyRecords .history-context-value {
      display: inline-block;
      width: auto;
      min-width: 0;
      max-width: 100%;
      white-space: normal;
      overflow-wrap: anywhere;
    }

    .km-page--trend #historyRecords .history-score {
      display: inline-flex;
      width: 2.6ch;
      min-width: 2.6ch;
      max-width: 2.6ch;
    }

    .km-page--trend #historyRecords .history-group-sep {
      display: inline-flex;
      width: auto;
      min-width: 0;
      max-width: none;
    }

    .km-page--trend #historyRecords .history-note {
      flex: 0 0 100%;
      width: 100%;
      white-space: normal;
      text-overflow: clip;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      line-height: 1.45;
    }
  }
}

@layer km-pages {
  /* Compare legend is outside the horizontal chart scroller so it stays visible at every scroll position. */
  .km-page--trend .trend-compare-legend {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--km-space-sm) var(--km-space-lg);
    margin: 0 0 var(--km-space-sm);
    min-width: 0;
    font-size: var(--km-font-meta);
    font-weight: var(--km-weight-regular);
    line-height: 1.5;
  }

  .km-page--trend .trend-compare-legend.hidden {
    display: none;
  }

  .km-page--trend .trend-compare-legend-item {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    white-space: nowrap;
  }

  .km-page--trend .trend-compare-legend-item--a {
    color: var(--km-color-body);
  }

  .km-page--trend .trend-compare-legend-item--b {
    color: var(--km-color-muted);
  }
}
