@layer components {
  .report {
    display: grid;
    gap: 1.5rem;
  }

  .report__body {
    max-inline-size: 48rem;
  }

  .report__pending {
    display: grid;
    gap: 0.75rem;
    max-inline-size: 48rem;
  }

  /* A document to read: more room between blocks than a chat reply. */
  .report-markdown {
    display: grid;
    gap: 0.75rem;
    min-inline-size: 0;
    text-wrap: pretty;

    & > * {
      margin: 0;
    }

    h1 {
      font-size: var(--text-2xl);
      line-height: var(--text-2xl--line-height);
      font-weight: var(--font-weight-semibold);
    }

    h2 {
      margin-block-start: 0.75rem;
      font-size: var(--text-xl);
      line-height: var(--text-xl--line-height);
      font-weight: var(--font-weight-semibold);
    }

    :is(h3, h4, h5, h6) {
      margin-block-start: 0.5rem;
      font-size: var(--text-base);
      line-height: var(--text-base--line-height);
      font-weight: var(--font-weight-semibold);
    }

    :is(ul, ol) {
      display: grid;
      gap: 0.25rem;
      padding-inline-start: 1.25rem;
    }

    li:has(> input[type="checkbox"]) {
      list-style: none;
      margin-inline-start: -1.25rem;
    }

    input[type="checkbox"] {
      margin-inline-end: 0.375rem;
      accent-color: var(--primary);
      vertical-align: -0.125em;
    }

    blockquote {
      padding-inline-start: 0.75rem;
      border-inline-start: 2px solid var(--border);
      color: var(--muted-foreground);
    }

    hr {
      inline-size: 100%;
      border: 0;
      border-block-start: 1px solid var(--border);
    }

    a {
      text-decoration: underline;
      text-underline-offset: 2px;
    }

    :not(pre) > code {
      padding: 0.1em 0.3em;
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      font-size: 0.9em;
    }

    pre {
      overflow-x: auto;
      padding: 0.5rem 0.75rem;
      border: 1px solid var(--border);
      border-radius: var(--radius-md);
      overflow-wrap: normal;
    }

    table {
      display: block;
      overflow-x: auto;
      border-collapse: collapse;
      font-size: var(--text-sm);
      line-height: var(--text-sm--line-height);
      overflow-wrap: normal;
    }

    :is(th, td) {
      padding: 0.375rem 0.625rem;
      border: 1px solid var(--border);
      text-align: start;
    }

    th {
      background: var(--muted);
      font-weight: var(--font-weight-medium);
    }
  }

  .report-form {
    display: grid;
    gap: 1rem;
    max-inline-size: 48rem;
  }

  .report-form__body {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }

  .report-sources {
    display: grid;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--text-sm);
  }

  /* A report a conversation wrote, between its messages. */
  .report-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card);
  }

  .report-card__icon {
    display: grid;
    place-items: center;
    flex: none;
    inline-size: 2.25rem;
    block-size: 2.25rem;
    border-radius: var(--radius-md);
    background: var(--muted);
    color: var(--muted-foreground);
  }

  .report-card__text {
    display: grid;
    flex: 1;
    min-inline-size: 0;
  }

  .report-card__title {
    overflow: hidden;
    font-weight: var(--font-weight-semibold);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .report-card__meta {
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }

  .report-form__row {
    display: grid;
    align-items: start;
    gap: 1rem;

    @media (width >= 40rem) {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  /* A daily schedule has no weekday to pick. */
  .report-form:has(select[name="report_schedule[cadence]"] option[value="daily"]:checked) .field:has(select[name="report_schedule[weekday]"]) {
    display: none;
  }

  .report-schedules {
    display: grid;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .report-schedule {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
  }

  .report-schedule__text {
    display: grid;
    flex: 1;
    min-inline-size: 0;
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }

  .report-schedule__title {
    font-size: var(--text-base);
    font-weight: var(--font-weight-semibold);
  }

  /* A chart a report draws from its data (reports/_chart). */
  .report-chart {
    display: grid;
    gap: 0.5rem;
    margin: 0;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card);
  }

  .report-chart__title {
    font-weight: var(--font-weight-semibold);
  }

  .report-chart__plot {
    display: block;
    max-inline-size: 100%;
    block-size: auto;
    overflow: visible;
    font-size: 12px;
  }

  .report-chart__grid {
    stroke: var(--border);

    &.report-chart__grid--zero {
      stroke: var(--muted-foreground);
    }
  }

  .report-chart__tick,
  .report-chart__label {
    fill: var(--muted-foreground);
  }

  .report-chart__bar {
    fill: var(--chart-1);
    transition: opacity 150ms ease-out;
  }

  .report-chart__line {
    fill: none;
    stroke: var(--chart-1);
    stroke-width: 2;
    stroke-linejoin: round;
  }

  .report-chart__point {
    fill: var(--card);
    stroke: var(--chart-1);
    stroke-width: 2;
  }

  /* The hovered value stands out against the rest. */
  .report-chart__plot:has(:is(.report-chart__bar, .report-chart__point):is(:hover, :focus-visible)) .report-chart__bar:not(:hover, :focus-visible) {
    opacity: 0.5;
  }

  :is(.report-chart__bar, .report-chart__point):focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
  }

  .report-chart__sources,
  .report-chart__data {
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }

  .report-chart__sources {
    margin: 0;
  }

  .report-chart__data summary {
    cursor: pointer;
  }

  .report-chart__data table {
    margin-block-start: 0.5rem;
    color: var(--foreground);
  }

  .report-chart__error {
    color: var(--destructive);
    font-size: var(--text-sm);
  }

  @media (prefers-reduced-motion: reduce) {
    .report-chart__bar {
      transition: none;
    }
  }
}
