/*
 * The filing reader (tasks/growth/milestones/35): a 10-K, 10-Q or 8-K read
 * back from the SEC's HTML into the site's type, at
 * /:ticker/filings/:accession/document. Its markup is Filings::ReadableDocument's
 * and Filings::ReadableTable's, drawn by companies/filing_documents/_document.
 *
 * Prose is set like an article — the serif at the reading measure — and each
 * Item opens on a heavy rule, as a section does. Tables run the page's full
 * width in the data face: figures right-aligned and tabular, a total ruled
 * above and a grand total heavy-ruled below where the filer ruled them, and the
 * row label pinned while a wide table scrolls. A table kept with the filer's
 * own grid says "As filed" over it, its spacer cells closed up; one of words
 * stays in the serif.
 *
 * It is a component rather than a page's stylesheet so /styleguide#filing-document
 * can draw it.
 */
@layer components {
  .filing-contents {
    margin-block: var(--space-md) var(--space-xl);
    padding-block-start: var(--space-xs);
    border-block-start: var(--rule-heavy);
  }

  .filing-contents__list {
    columns: 2 18rem;
    column-gap: var(--space-xl);
    margin: 0;
    padding: 0;
    list-style: none;
    font-family: var(--font-ui);
    font-size: var(--text-ui);
    line-height: var(--leading-ui);

    & li {
      break-inside: avoid;
      padding-block: var(--space-3xs);
      border-block-end: var(--rule-hairline);
    }
  }

  .filing-document {
    color: var(--color-ink);
    font-family: var(--font-prose);
    font-size: var(--text-prose);
    line-height: var(--leading-prose);
    text-wrap: pretty;

    & :is(p, ul, ol, h3, h4) {
      max-inline-size: var(--measure);
    }

    & p {
      margin-block: 0 1em;
    }

    & a {
      color: var(--color-link);
    }

    & sup,
    & sub {
      line-height: 0;
    }
  }

  .filing-document__item {
    margin-block: var(--space-2xl) var(--space-sm);
    padding-block-start: var(--space-xs);
    border-block-start: var(--rule-heavy);
    font-size: var(--text-h2);
    line-height: var(--leading-h2);
    font-weight: var(--weight-semibold);
    scroll-margin-block-start: var(--space-md);
  }

  .filing-document__heading {
    margin-block: 1.5em 0.4em;
    font-size: var(--text-h4);
    line-height: var(--leading-h4);
    font-weight: var(--weight-semibold);

    &:is(h4) {
      font-size: var(--text-prose);
      font-style: italic;
      font-weight: var(--weight-regular);
    }
  }

  .filing-document__centred {
    margin-inline: auto;
    text-align: center;
  }

  .filing-document__figure img {
    max-inline-size: 100%;
    block-size: auto;
  }

  /* The filer's lists, and its tables of bullets read as one: the reset
     strips list markers, and a filing's lists are read by them. */
  .filing-document :is(ul, ol),
  .filing-document__list {
    padding-inline-start: var(--space-lg);
    list-style: disc;
  }

  .filing-document ol {
    list-style: decimal;
  }

  .filing-document__note {
    color: var(--color-ink-muted);
    font-size: var(--text-meta-xs);
  }

  .filing-document__plain-text {
    overflow-x: auto;
    font-family: var(--font-data);
    font-size: var(--text-data);
    line-height: var(--leading-data);
    white-space: pre;
  }

  .filing-document__source {
    margin-block-start: var(--space-xl);
    padding-block-start: var(--space-xs);
    border-block-start: var(--rule-hairline);
  }

  .filing-table-scroll {
    margin-block: var(--space-sm) var(--space-lg);
  }

  .filing-table {
    border-collapse: separate;
    border-spacing: 0;
    font-family: var(--font-prose);
    font-size: var(--text-prose-sm);
    line-height: var(--leading-prose-sm);

    & :is(th, td) {
      padding: 0.3125rem var(--space-xs);
      border-block-end: var(--rule-hairline);
      text-align: start;
      vertical-align: top;
    }

    & thead th {
      color: var(--color-ink-muted);
      font-family: var(--font-data);
      font-size: var(--text-table-head);
      line-height: var(--leading-table-head);
      font-weight: var(--weight-medium);
      text-align: end;
      vertical-align: bottom;
      min-inline-size: 5rem;
    }

    & thead th[colspan] {
      text-align: center;
    }

    & thead th:first-child {
      text-align: start;
    }

    & thead tr:last-child th {
      border-block-end: var(--rule-width) solid var(--color-rule-strong);
    }
  }

  .filing-table--figures {
    inline-size: 100%;
    font-family: var(--font-data);
    font-size: var(--text-data);
    line-height: var(--leading-data);
    font-variant-numeric: tabular-nums lining-nums;

    & td {
      vertical-align: bottom;
    }

    & td:not(.filing-table__label) {
      text-align: end;
      white-space: nowrap;
    }

    & tr.is-subtotal td {
      font-weight: var(--weight-semibold);
    }

    & tr.has-rule td:not(:first-child) {
      border-block-start: var(--rule-width) solid var(--color-rule-strong);
    }

    /* The filer's double rule under a grand total is the heavy rule here:
       the double rule is the masthead's alone (agents/DESIGN.md §5). */
    & tr.has-double-rule td:not(:first-child) {
      border-block-end: var(--rule-heavy);
    }
  }

  /* The filer's own grid: its empty spacer cells take no room, so a figure
     sits beside its `$` and its `)` as it was filed. */
  .filing-table--as-filed :is(td, th):empty {
    padding-inline: 0;
  }

  .filing-table__label {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    min-inline-size: 9rem;
    max-inline-size: 11rem;
    padding-inline-start: calc(var(--indent, 0) * var(--space-sm));
    background-color: var(--color-surface);
    white-space: normal;

    @media (width >= 768px) {
      min-inline-size: 16rem;
      max-inline-size: 28rem;
    }
  }

  .filing-table__figure {
    white-space: nowrap;
  }

  .filing-table__caption {
    caption-side: top;
    padding-block-end: var(--space-3xs);
    text-align: start;
  }
}
