/* gyro-canonical.css - the four canonical screens of spec 28.3 and their states
 * (28.7), sprint 73 lane p8. Boards P0-082, P0-083, P0-085.
 *
 * Every rule here is keyed on a class a canonical builder in
 * app/Support/Ui/Canonical writes, never on a page: a list becomes canonical by
 * calling ExactCountPagination::apply(), a form by FormHeaderBlock::make(), a
 * report by wearing .gs-canon-report. So the next module copies a PHP call and
 * gets the layout with it, and nothing here can reach a screen that did not ask.
 *
 * Colours and sizes are tokens only (tokens.css). Class names were read off the
 * vendor's own views on the host (vendor/filament/tables/resources/views/
 * index.blade.php, summary/row.blade.php, support pagination/index.blade.php),
 * never guessed (CLAUDE.md rule 1), and every rule is MEASURED as computed
 * style in a browser before it is believed (rule 65).
 *
 * Unlayered, loaded after gyro-theme.css and gyro-chrome.css: it outranks every
 * @layer rule in Filament's app.css whatever the specificity.
 */

/* -----------------------------------------------------------------------
 * 1. THE LIST: a header that stays put and an exact count that stays on screen
 *
 * `.fi-ta-content-ctn` is `overflow-x: auto` in Filament's app.css, which makes
 * it a scroll container in BOTH axes - so a sticky `thead` sticks to a box that
 * never scrolls vertically and freezes nothing when the page scrolls. The
 * canonical list bounds that box to the window instead (Odoo's and ERPNext's
 * list scrolls inside the content area for the same reason): the header sticks
 * inside it, the last totals row sticks to its foot, and the pagination with
 * its "Showing 1 to 50 of N" sits under it and sticks to the bottom of the
 * window while the list is in view.
 * --------------------------------------------------------------------- */
.gs-canon-list {
  --gs-canon-list-chrome: 16rem; /* topbar, page header, toolbar and pagination, measured at 1280 */
}

.gs-canon-list .fi-ta-content-ctn {
  max-block-size: max(18rem, calc(100dvh - var(--gs-canon-list-chrome)));
  overflow: auto;
}

/* `.fi-ta-ctn:not(.fi-ta-ctn-with-header) { overflow: hidden }` (vendor) would
 * make the card itself a scroll container that never scrolls, and the sticky
 * pagination would stick to it rather than to the window. `clip` keeps the
 * rounded corners and creates no scroll container. */
.gs-canon-list .fi-ta-ctn {
  overflow: clip;
}

.gs-canon-list .fi-ta-content-ctn .fi-ta-table > thead > tr > th {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background-color: var(--color-bg-surface);
  box-shadow: inset 0 -1px 0 0 var(--color-border-hairline);
}

/* The whole-list totals row is the last row of the body; a grouped list's
 * per-group rows are left where they are. */
.gs-canon-list .fi-ta-content-ctn .fi-ta-table > tbody > .fi-ta-summary-row:last-child > td {
  position: sticky;
  inset-block-end: 0;
  z-index: 1;
  background-color: var(--color-bg-surface);
  box-shadow: inset 0 1px 0 0 var(--color-border-strong);
  font-variant-numeric: tabular-nums;
}

.gs-canon-list .fi-pagination {
  position: sticky;
  inset-block-end: 0;
  z-index: 3;
  padding-block: var(--space-2);
  padding-inline: var(--size-pad-cell-x);
  background-color: var(--color-bg-surface);
  border-block-start: 1px solid var(--color-border-hairline);
}

.gs-canon-list .fi-pagination-overview {
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

/* -----------------------------------------------------------------------
 * 2. THE FORM: the header block, the tabs, the totals bottom right
 * --------------------------------------------------------------------- */
.gs-canon-header {
  border-color: var(--color-border-strong);
}

.gs-canon-tabs {
  margin-block-start: var(--space-2);
}

.gs-canon-totals__figures {
  justify-self: end;
  inline-size: 100%;
  max-inline-size: 36rem;
}

/* The error summary. Empty and invisible until a save is refused; then a
 * bordered list, never a filled region (spec 28.5: semantic colour as text and
 * chips only). Its heading carries the danger ink AND says what it is, so the
 * colour is never the only signal (spec 28.10). */
.gs-canon-errors[data-count="0"] {
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
}

.gs-canon-errors:not([data-count="0"]) {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-status-danger-border);
  border-inline-start-width: var(--space-1);
  border-radius: var(--radius-control);
  background-color: var(--color-bg-surface);
  color: var(--color-text-primary);
}

.gs-canon-errors__heading {
  margin: 0 0 var(--space-1);
  font-weight: var(--type-weight-semibold);
  color: var(--color-status-danger-text);
}

.gs-canon-errors__list {
  margin: 0;
  padding-inline-start: var(--space-5);
  list-style: disc;
}

/* ONE FILLED BUTTON (spec 28.4, board P0-082 A5). On a canonical form the save
 * at the foot is the primary action; a header verb beside the ribbon - Delete,
 * on the invoice - is drawn as a ghost, its word and its colour kept, so the
 * page carries exactly one filled button. Scoped by :has() to pages that hold a
 * canonical header block, so no other screen changes. */
.fi-page:has(.gs-canon-header) .fi-header .fi-btn:not(.fi-outlined) {
  background-color: transparent;
  color: var(--color-text-primary);
  box-shadow: inset 0 0 0 1px var(--color-border-strong);
}

/* A danger verb keeps its colour as INK, never as a fill - and its word. */
.fi-page:has(.gs-canon-header) .fi-header .fi-btn.fi-color-danger:not(.fi-outlined) {
  color: var(--color-status-danger-text);
}

.fi-page:has(.gs-canon-header) .fi-header .fi-btn:not(.fi-outlined):hover {
  background-color: var(--color-bg-hover);
}

/* -----------------------------------------------------------------------
 * 3. THE STATES: skeleton rows shaped like the table (P0-083 A2)
 * --------------------------------------------------------------------- */
.gs-canon-skeleton .gyro-skeleton-cell[data-align="end"] {
  flex: 0 0 var(--space-7);
  margin-inline-start: auto;
}

.gs-canon-skeleton .gyro-skeleton-cell[data-align="end"] ~ .gyro-skeleton-cell[data-align="end"] {
  margin-inline-start: 0;
}

/* -----------------------------------------------------------------------
 * 4. THE REPORT: one filter panel, results drawn like the list (P0-082 A4)
 *
 * The report partials print their own <style> in the body, after this sheet,
 * so every rule here carries the .gs-canon-report scope and wins on
 * specificity rather than on order.
 * --------------------------------------------------------------------- */
.gs-canon-report__filter-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
}

.gs-canon-report__filter-label {
  margin: 0 0 var(--space-1);
  font-size: var(--type-size-small);
  line-height: var(--type-line-small);
  font-weight: var(--type-weight-semibold);
  color: var(--color-text-secondary);
}

/* The results box scrolls in both axes like the canonical list's, so its
 * heading row stays put; it is focusable (tabindex in the view) and so draws
 * the focus ring every other control does. */
.gs-canon-report .gs-canon-table__box {
  max-block-size: max(18rem, calc(100dvh - 18rem));
  overflow: auto;
  border: 1px solid var(--color-border-hairline);
  border-radius: var(--radius-control);
}

.gs-canon-report .gs-canon-table__box:focus-visible {
  outline: 2px solid var(--color-accent-ring);
  outline-offset: 2px;
}

/* The list's own heading: sentence case, small, semibold, the secondary ink -
 * not the report partial's spaced capitals, which made a report a second
 * table to learn. */
.gs-canon-report .gs-canon-table > thead > tr > th {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
  block-size: var(--size-row-table);
  padding-block: var(--size-pad-cell-y);
  padding-inline: var(--size-pad-cell-x);
  font-size: var(--type-size-small);
  line-height: var(--type-line-small);
  font-weight: var(--type-weight-semibold);
  letter-spacing: normal;
  text-transform: none;
  color: var(--color-text-secondary);
  background-color: var(--color-bg-surface);
  border-block-end: 0;
  box-shadow: inset 0 -1px 0 0 var(--color-border-hairline);
}

.gs-canon-report .gs-canon-table > tbody > tr > th,
.gs-canon-report .gs-canon-table > tbody > tr > td {
  block-size: var(--size-row-table);
  padding-block: var(--size-pad-cell-y);
  padding-inline: var(--size-pad-cell-x);
  font-size: var(--type-size-base);
  font-weight: var(--type-weight-normal);
  color: var(--color-text-primary);
}

.gs-canon-report .gs-canon-table > tbody > tr > th.gs-report__name {
  text-align: start;
  font-weight: var(--type-weight-medium);
}

.gs-canon-report .gs-canon-table td.gs-report__num,
.gs-canon-report .gs-canon-table th.gs-report__num {
  text-align: end;
  font-variant-numeric: tabular-nums;
}

.gs-canon-report .gs-canon-table td.gs-report__muted {
  color: var(--color-text-secondary);
}

/* The totals row, as the list's: last, stuck to the foot of its box. */
.gs-canon-report .gs-canon-table__totals > th,
.gs-canon-report .gs-canon-table__totals > td {
  position: sticky;
  inset-block-end: 0;
  text-align: start;
  font-weight: var(--type-weight-semibold);
  color: var(--color-text-primary);
  background-color: var(--color-bg-surface);
  border-block-start: 0;
  box-shadow: inset 0 1px 0 0 var(--color-border-strong);
}

.gs-canon-report .gs-canon-table__totals > td.gs-report__num {
  text-align: end;
}

/* -----------------------------------------------------------------------
 * 5. MOTION. Nothing above animates; this keeps it that way for anything a
 *    canonical screen inherits (spec 28.10).
 * --------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .gs-canon-list *,
  .gs-canon-report *,
  .gs-canon-tabs * {
    transition-duration: var(--motion-reduced-duration) !important; /* !important: the vendor sets durations on components this cannot name one by one */
    animation: none !important; /* !important: same reason */
  }
}
