/*
 * The company page types' own chrome (companies/_chrome; tasks/redesign, D8,
 * from keystats.png).
 *
 *   .company-chrome             the header
 *   .company-chrome__utility    the breadcrumbs, then the date, Excel and
 *                               Print, over a hairline
 *   .company-chrome__title      the company's name in the serif, and the
 *                               ticker in a chip beside it
 *   .company-chrome__identity   the sector and industry in green small caps
 *   .company-chrome__lede       the standfirst — the sentence, the quarter's
 *                               figures, the tags — beside the price block,
 *                               side by side from 1024px
 *   .stat-bar                   seven figures under a double rule, scrolling
 *                               sideways on a phone
 *
 * Then the tab bar at every width, scrolling sideways on a phone
 * (components/tabs.css) — the one company navigation; and, below, the
 * statement pages' own arrangement. The pieces the pages are built from —
 * the keystats report and its cards, the statement's picture and table —
 * are components (components/keystats.css and its neighbours).
 */
@layer pages {
  .company-chrome {
    /* One line of the price at its hero size, and its "as of" under it: what
       the price frame reserves for its placeholder and keeps when it lands —
       or when a company has no price and the frame comes back empty. */
    --company-price-height: 4.25rem;

    display: grid;
    gap: var(--space-xs);
    margin-block-end: var(--space-sm);

    /* With `extended_hours` on, room for the pre-market or after-hours line
       under the price at every hour (companies/_extended_hours), so the poll
       never moves the page when a session starts or ends. */
    &.company-chrome--sessions {
      --company-price-height: 5.75rem;
    }

    /* With the reader's notebook slip, from 1024px, the header is two
       columns: the name, the identity line and the standfirst down the
       left, one after the other; the slip and, under it, the price with
       Follow and Alert down the right. The lede gives up its own box
       (`display: contents`) so its two halves can take a column each, and
       the flexible fourth row takes whatever one column needs past the
       other, so neither side leaves a gap in the middle of the other. */
    @media (width >= 1024px) {
      /* A class from the template, not `:has(.notebook-entry)`: that made
         the browser restyle the page after every element a chart added. */
      &.company-chrome--notebook {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: auto auto auto 1fr auto;
        column-gap: var(--space-2xl);

        & > * {
          grid-column: 1 / -1;
        }

        & > .company-chrome__utility {
          grid-row: 1;
        }

        & > .company-chrome__title,
        & > .company-chrome__identity {
          grid-column: 1;
          align-self: start;
        }

        & > .company-chrome__title {
          grid-row: 2;
        }

        & > .company-chrome__identity {
          grid-row: 3;
        }

        & > .company-chrome__lede {
          display: contents;
        }

        & .company-chrome__summary {
          grid-column: 1;
          grid-row: 4 / span 2;
          align-self: start;
          margin-block-start: var(--space-sm);
        }

        & .company-chrome__quote {
          grid-column: 2;
          grid-row: 5;
          align-self: end;
          margin-block-start: var(--space-md);
        }

        & > .notebook-entry-slot {
          grid-column: 2;
          grid-row: 2 / span 3;
          align-self: start;
          justify-content: flex-end;
          margin-block-start: var(--space-sm);
        }

        /* Under the quote whatever is beside it: placed by the grid, the
           stat bar took the summary's empty row when a company had none (a
           new listing, M33) and sat above the price, Follow and Alert. */
        & > .stat-bar {
          grid-row: 6;
        }
      }
    }
  }

  .company-chrome__utility {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2xs) var(--space-lg);
    padding-block-end: var(--space-xs);
    border-block-end: var(--rule-hairline);

    & .breadcrumbs {
      margin: 0;
    }
  }

  .company-chrome__tools {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2xs) var(--space-md);
    color: var(--color-ink-muted);
    font-size: var(--text-ui-sm);
  }

  .company-chrome__date {
    @media (width < 640px) {
      display: none;
    }
  }

  /* The overview's Print button: a word, in the link green; not on a phone,
     where there is rarely a printer, and not on the paper. */
  .company-chrome__print {
    display: none;
    color: var(--color-link);
    font-size: inherit;
    cursor: pointer;

    &:hover {
      text-decoration: underline;
    }

    @media (width >= 768px) {
      display: inline;
    }
  }

  /* The name and the ticker's chip on one line, the chip wrapping under a
     long name rather than squeezing it. */
  .company-chrome__title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2xs) var(--space-sm);
    margin-block-start: var(--space-sm);
  }

  .company-chrome__name {
    margin: 0;
    font-size: var(--text-h1);
    line-height: var(--leading-h1);
    letter-spacing: -0.01em;
  }

  .company-chrome__identity {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2xs) var(--space-xs);
    margin: 0;
    color: var(--color-ink-muted);
    font-size: var(--text-caps);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }

  .company-chrome__ticker {
    padding: var(--space-3xs) var(--space-xs);
    border: var(--rule-width) solid var(--color-rule);
    color: var(--color-ink);
    font-size: var(--text-caps);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-caps);
  }

  .company-chrome__segment {
    position: relative;
    color: var(--color-link);
    text-decoration: none;

    &:hover {
      text-decoration: underline;
    }
  }

  /* The two links are a line of text, and a 44px target on touch without
     making the line taller: the hit area reaches above and below it. The
     @media is on the outside: Chrome before 130 drops declarations in an
     @media nested inside a nested pseudo-element. */
  @media (pointer: coarse) {
    .company-chrome__segment::after {
      content: "";
      position: absolute;
      inset-block: calc((100% - var(--target-min)) / 2);
      inset-inline: 0;
    }
  }

  .company-chrome__lede {
    display: grid;
    gap: var(--space-md) var(--space-2xl);
    margin-block-start: var(--space-2xs);

    @media (width >= 1024px) {
      grid-template-columns: minmax(0, 1fr) auto;
      align-items: end;
    }
  }

  .company-chrome__summary {
    display: grid;
    grid-row: 1;
    gap: var(--space-sm);
    max-inline-size: 48rem;
  }

  .company-chrome__standfirst {
    max-inline-size: 48rem;
    margin: 0;
    font-family: var(--font-prose);
    font-size: var(--text-lead);
    line-height: var(--leading-lead);
    text-wrap: pretty;
  }

  /* The latest quarter against a year earlier (companies/_quarter_changes,
     M17-D3): caps labels over signed figures, then what they are measured
     against and the quarter's earnings digest. */
  .quarter-changes {
    display: grid;
    gap: var(--space-2xs);
  }

  .quarter-changes__figures {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2xs) var(--space-lg);
    margin: 0;

    & dd {
      margin: 0;
      font-weight: var(--weight-semibold);
    }
  }

  .quarter-changes__figure {
    display: grid;
    gap: var(--space-3xs);
  }

  .quarter-changes__note {
    margin: 0;
    color: var(--color-ink-muted);
    font-size: var(--text-ui-sm);
  }

  /* The sets of companies this one belongs to — indexes, then streaks — and
     on the overview its red flags (M12-D11): square tags in one wrapping row,
     each a link. A tag is a word, so a 44px target on touch comes from its
     padding. */
  .company-chrome__tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--text-ui-sm);
  }

  .company-chrome__tag {
    display: inline-flex;
    align-items: baseline;
    gap: var(--space-2xs);
    padding: var(--space-3xs) var(--space-sm);
    border: var(--rule-width) solid var(--color-rule);
    border-radius: var(--radius-md);
    color: var(--color-ink);
    text-decoration: none;

    &:hover {
      border-color: var(--color-link);
      color: var(--color-link);
    }

    @media (pointer: coarse) {
      min-block-size: var(--target-min);
      align-items: center;
    }
  }

  .company-chrome__tag-count {
    color: var(--color-gain);
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums lining-nums;
  }

  .company-chrome__quote {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-sm) var(--space-xl);

    @media (width >= 1024px) {
      grid-column: 2;
      grid-row: 1;
      justify-content: flex-end;
    }
  }

  .company-chrome__price {
    display: block;
    min-block-size: var(--company-price-height);
  }

  .company-price {
    display: grid;
    align-content: end;
    gap: var(--space-3xs);
    block-size: var(--company-price-height);
  }

  .company-price__figures {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2xs) var(--space-sm);
  }

  .company-price__change {
    display: inline-flex;
    align-items: baseline;
    gap: var(--space-2xs);

    & .figure {
      font-weight: var(--weight-semibold);
    }
  }

  /* "After hours 352.17 ▼ 1.41 −0.40% · 6:12pm ET": quieter than the price
     above it, in the UI face; the time wraps under the figures on a phone. */
  .company-price__session {
    font-family: var(--font-ui);
    font-size: var(--text-ui);
    line-height: var(--leading-ui);
  }

  .company-price__session-figures {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-3xs) var(--space-xs);
  }

  .company-price__session-time {
    color: var(--color-ink-subtle);
    font-size: var(--text-ui-sm);

    &::before {
      content: "· ";
    }
  }

  /* Follow at the size of the block it ends, Alert beside it, and for a
     reader with the notebook its button after them. No wider than the quote,
     so on a phone a third button wraps under the others rather than off the
     edge. */
  .company-chrome__follow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    max-inline-size: 100%;

    & .button {
      min-block-size: var(--control-height);
      padding-inline: var(--space-lg);
    }

    /* From a tablet up the buttons sit at the page's right edge, so the
       alert panel and the follow signup open leftward; on a phone they sit at the left and it opens
       rightward, as everywhere else. */
    @media (width >= 768px) {
      & .alert-panel,
      & .follow__signup-form {
        inset-inline: auto 0;
      }
    }
  }

  /* The stat bar: a double rule, then seven cells of a caps label over a
     serif figure, ending on a hairline. It scrolls sideways inside itself on
     a phone. */
  .stat-bar {
    display: grid;
    grid-auto-columns: minmax(7.5rem, 1fr);
    grid-auto-flow: column;
    gap: var(--space-lg);
    margin: var(--space-sm) 0 0;
    padding-block: calc(var(--rule-double-height) + var(--space-sm)) var(--space-sm);
    border-block-end: var(--rule-hairline);
    background: var(--rule-double) top / 100% var(--rule-double-height) no-repeat;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .stat-bar__cell {
    display: grid;
    gap: var(--space-3xs);
  }

  .stat-bar__label {
    white-space: nowrap;
  }

  /* The fiscal year an estimate is for, after its label: as the ratios
     card writes it, not in capitals. */
  .stat-bar__period {
    text-transform: none;
    letter-spacing: 0;
  }

  .stat-bar__value {
    margin: 0;
    white-space: nowrap;
  }

  /* The date a figure is as of, under it: the Stock analysis's snapshot
     (companies/articles/_snapshot), whose figures are not all as fresh. */
  .stat-bar__note {
    color: var(--color-ink-muted);
    font-size: var(--text-ui-sm);
    white-space: nowrap;
  }

  .stat-bar__link {
    color: inherit;
    text-decoration: none;

    &:hover {
      text-decoration: underline;
      text-decoration-thickness: 1px;
    }
  }

  .company-tabs {
    margin-block-end: var(--space-md);
  }
}

/*
 * The statement pages: the period switcher, and the chart beside the
 * statement's description. The picture and the table are components
 * (components/statement-picture.css, components/statement-table.css).
 */
@layer pages {
  .periods {
    margin-block: calc(var(--space-xs) * -1) var(--space-lg);
  }

  /* The period switcher and "Download Excel" on one row. The
     tabs keep their own sideways scroll on a phone, so the row never grows
     wider than the page; the link drops under them when there is no room. */
  .statement-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs) var(--space-md);
    margin-block: calc(var(--space-xs) * -1) var(--space-lg);

    & > .tabs {
      flex: 1 1 20rem;
      min-inline-size: 0;
      margin-block: 0;
    }
  }

  /* "Download Excel": a caps text link in the green, not a button
     (tasks/redesign, D11). */
  .statement-toolbar__download {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--target-min);
    color: var(--color-link);
    font-size: var(--text-meta-xs);
    font-weight: var(--weight-medium);
    letter-spacing: var(--tracking-caps);
    text-decoration: none;
    text-transform: uppercase;

    &:hover {
      text-decoration: underline;
    }
  }

  .statement-overview {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-lg);
    margin-block-end: var(--space-lg);

    @media (width >= 768px) {
      grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    }

    @media (width >= 1024px) {
      grid-template-columns: minmax(0, 7fr) minmax(0, 3fr);
    }
  }

  /* A statement with no chart (Metrics & Ratios): the description alone, one
     full-width track at every width. */
  .statement-overview--no-chart {
    @media (width >= 768px) {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  .statement-description {
    display: grid;
    gap: var(--space-xs);
    align-content: start;
    font-size: var(--text-ui-sm);
    line-height: 1.55;
    color: var(--color-ink-soft);
  }

}
