/* ============================================
   Component: SKU performance
   View: dashboards/sku_performance/show.html.erb, records.html.erb, record.html.erb, _words.html.erb
   Partials: parts/_figure.html.erb, parts/_table.html.erb, parts/_filter.html.erb
   Stimulus: none
   ============================================ */
/* SKU performance (#495) reads question first (D-139): the decision it serves, then each section under its question,
   its figure, then its words' tap, then its tables, each with its title and its line, and the ranking's counts' tap;
   and the records behind each number, with a SKU's page, laid out as Receiving and fulfilment's are. */

/* The decision the tab serves, above its first section. */
.sku-performance-decision {
  margin: var(--spacing-lg) 0 0;
  color: var(--color-muted);
}

/* Each section: its question, then its figure, its words' tap, the days of sales in the ranking's, its tables and the
   ranking's counts' tap, one beneath another, each starting at the section's left. */
.sku-performance-section {
  display: grid;
  gap: var(--spacing-md);
  margin-top: var(--spacing-lg);
}

.sku-performance-section > h3 { margin: 0; }

/* The section's answer, on a card's surface, the width of a row on a phone and of a column on a wide screen; it lays
   itself out by its own width. */
.sku-performance-section > .figure-container {
  justify-self: start;
  width: 100%;
  max-width: 40rem;
  padding: var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

/* A table's title, then the table, then its line directly under it. The table's box fits its table, and is never
   wider than the page: a wider table scrolls sideways in its own box, never the page. */
.sku-performance-table {
  display: grid;
  gap: var(--spacing-xs);
}

.sku-performance-table > .table-scroll {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}

/* A table's title above its box, in the caption's type (components/table.css), so it wraps within the page on a
   phone, where a caption inside a table wider than the screen scrolls with it and is cut at the box's edge (#651).
   The caption stays, for a screen reader and as the box's name, hidden from sight only by clipping, as the filter's
   radio input is (components/filter.css). */
.sku-performance-table-title {
  margin: 0;
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: 600;
}

.sku-performance-table .table-caption {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A column of figures' label, on the tab, its records pages and a SKU's page, may wrap onto lines of its own, as a
   column of words' label does, while its figures keep to one line (components/table.css): a table wider than its box
   is drawn at its least width, and a label such as "Stock at list price" on one line would set its column's width
   (#651). */
.sku-performance-section .table thead .table-number,
.sku-performance-records .table thead .table-number,
.sku-performance-record .table thead .table-number {
  white-space: normal;
}

/* On a phone, a table wider than its box shows that it scrolls: a fade over the box's right edge, which keeps to that
   edge as the table scrolls under it, so a figure the edge cuts reads as cut, not as a smaller figure (#651). The table
   keeps room of the fade's width after it, so once it fits its box, or is scrolled to its end, the fade lies over that
   room and covers no cell. The box lays the table and the fade in one cell of a grid. From 600px there is none, even
   where a table is wider than its box. The table part's own sign that a table scrolls, drawn for every tab, is
   #581's. */
.sku-performance-table > .table-scroll,
.sku-performance-records > .table-scroll,
.sku-performance-record > .table-scroll {
  display: grid;
}

.sku-performance-table > .table-scroll > .table,
.sku-performance-records > .table-scroll > .table,
.sku-performance-record > .table-scroll > .table {
  grid-area: 1 / 1;
  margin-right: var(--spacing-lg);
}

.sku-performance-table > .table-scroll::after,
.sku-performance-records > .table-scroll::after,
.sku-performance-record > .table-scroll::after {
  content: "";
  position: sticky;
  right: 0;
  z-index: 2;
  grid-area: 1 / 1;
  justify-self: end;
  width: var(--spacing-lg);
  background: linear-gradient(to right, transparent, var(--color-surface));
  pointer-events: none;
}

/* The rankings' first cells, in the two tables of the section labelled by the ranking's heading, as a rule takes no
   id selector (design › SOP 16): a SKU, then its product's name on the line under it (SoldLinesQuery::SKU_AND_PRODUCT).
   On a phone each row is those two lines, no more: the SKU, whole, then the name, cut with "…" at the edge of the
   column, which is at least the 12rem the table part gives a column of long text (#651). A word wider than the column
   widens it rather than breaking, so a SKU with no space or hyphen keeps to its line; one wider than the column that
   breaks at a space or a hyphen takes the name's line too, still whole. From 600px the name is whole, wrapping where
   it must. */
.sku-performance-section[aria-labelledby="sku-performance-ranking"] .table tbody th {
  min-width: 12rem;
}

.sku-performance-section[aria-labelledby="sku-performance-ranking"] .table tbody th .table-row-link {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  white-space: pre-line;
}

@media (min-width: 600px) {
  .sku-performance-table > .table-scroll,
  .sku-performance-records > .table-scroll,
  .sku-performance-record > .table-scroll {
    display: block;
  }

  .sku-performance-table > .table-scroll > .table,
  .sku-performance-records > .table-scroll > .table,
  .sku-performance-record > .table-scroll > .table {
    margin-right: 0;
  }

  .sku-performance-table > .table-scroll::after,
  .sku-performance-records > .table-scroll::after,
  .sku-performance-record > .table-scroll::after {
    content: none;
  }

  .sku-performance-section[aria-labelledby="sku-performance-ranking"] .table tbody th .table-row-link {
    display: block;
    -webkit-line-clamp: none;
    overflow: visible;
  }
}

/* What revenue and units sold count, in a line just above the columns that show them: on the tab, between the days of
   sales and the rankings, and on the records of the SKUs sold and of a SKU's sales, between the number and its
   records (#651). */
.sku-performance-basis {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--font-size-sm);
}

/* The table's line: its source, its date and its sentence, its parts apart, as the figure part's frame is. */
.sku-performance-table-frame {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--spacing-sm);
  margin: 0;
  color: var(--color-muted);
  font-size: var(--font-size-xs);
}

.sku-performance-table-frame > * + *::before {
  content: "· ";
}

.sku-performance-table-frame time { color: var(--color-text); }

/* What sits behind a tap: what the ranking counts and leaves out, and the words a section or a page uses. A <details>
   opens with no JavaScript and no hover, its summary at least the tap target's height, as the figure part's other
   ways are. */
.sku-performance-tap {
  color: var(--color-muted);
  font-size: var(--font-size-xs);
}

.sku-performance-tap > summary {
  display: flex;
  align-items: center;
  gap: 0 var(--spacing-sm);
  min-height: var(--tap-target);
  color: var(--color-link);
  cursor: pointer;
  list-style: none;
}

/* A flex summary loses its marker, so it draws its own: closed, then open */
.sku-performance-tap > summary::-webkit-details-marker { display: none; }

.sku-performance-tap > summary::before { content: "▸"; }

.sku-performance-tap[open] > summary::before { content: "▾"; }

.sku-performance-coverage { margin: 0; }

/* Each word, then its definition beneath it. */
.sku-performance-word-list {
  display: grid;
  gap: var(--spacing-xs);
  margin: 0;
}

.sku-performance-word-list > dt {
  color: var(--color-text);
  font-weight: 600;
}

.sku-performance-word-list > dd {
  margin: 0 0 var(--spacing-xs);
}

/* The records behind a number: the number, then its page of records with its line, then its words, one beneath
   another, each starting at the page's left; and a SKU's page, its product and its stock, then their words. A wider
   table scrolls sideways in its own box, never the page. */
.sku-performance-records,
.sku-performance-record {
  display: grid;
  gap: var(--spacing-md);
}

.sku-performance-records > .table-scroll,
.sku-performance-record > .table-scroll {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}

/* A SKU's sales: each line's date, its first cell, and when it was synced, its last (SoldLinesQuery::LINE_COLUMNS),
   each on one line, where a phone would draw the table at its least width and wrap a date or a time onto a line a
   word (#651). */
.sku-performance-sales .table tbody th,
.sku-performance-sales .table tbody td:last-child {
  white-space: nowrap;
}

/* The page's line, "Records 1 to 100 of 250", then its links to the pages before and after it, each as large as a
   tap; they wrap under the line on a phone. */
.sku-performance-records-pages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 var(--spacing-md);
  font-size: var(--font-size-sm);
}

.sku-performance-records-line { color: var(--color-muted); }

.sku-performance-records-previous,
.sku-performance-records-next {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
}

.sku-performance-back { margin-top: var(--spacing-lg); }
