/* Shared chrome for list pages (Customers, Vendors, Products, ...) — the page shell,
   the scrolling table, and the pagination footer are all one shape; the listTable
   Kensington component (app/views/components/list-table.js) wires them together. */

/* The scrolling surface takes the leftover vertical space, pagination stays pinned
   below it, and the outer page never scrolls. The viewport-height shell itself is
   .cp-full-viewport-height-page in app-shell.css, which the page carries alongside
   .cp-list-page; only the colour is particular to a list. */

/* Opt out of the default --cp-canvas-bg (gray) for a --bs-body-bg (white). */
.cp-main:has(.cp-list-page) {
  background: var(--bs-body-bg);
}

.cp-list-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.cp-list-header  { flex: 0 0 auto; }
.cp-list-toolbar { flex: 0 0 auto; }

/* The toolbar's date range keeps its natural width. Sharing a flex row with the search box, it
   was otherwise squeezed until the date text clipped. The row wraps instead. */
.cp-list-toolbar cp-date-range { flex-shrink: 0; }

/* The scrolling surface: card with sticky-header table inside. min-height: 0 is what
   lets flex actually shrink the child below its content height.
   Borderless/square/flat, not .card's usual bordered, rounded, shadow-lifted
   look (theme.css's .card rule), a list-page table is meant to sit flush
   against the page, not read as a boxed-off card of its own. */
.cp-list-scroll {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.cp-list-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bs-body-bg);
}

.cp-list-pagination {
  flex: 0 0 auto;
  padding-top: .75rem;
}

/* One-line cells (nowrap) across every list table; vertical-align: middle
   already comes from .align-middle on the <table>.
   Row-hover styling is Bootstrap's own .table-hover. Apply it in the
   table's class list, not here. */
.cp-list-table :is(th, td) { white-space: nowrap; }

/* Body rows at the same size as everything around them. The headers carry
   Bootstrap's .small and the filter row is built from .form-select-sm, both
   of which land on 14px, while the rows themselves were inheriting the body's
   16px and reading a size larger than the page they sit in.

   On tbody alone: .small on the headers is an em, so sizing the whole table
   would shrink those a second time. One rule here reaches every list, since
   work orders, customers, vendors, products and invoices all render through
   listTable(). */
.cp-list-table tbody {
  font-size: .875rem;
}

/* A cell whose content has no natural width ceiling: free text, in practice.
   First used by the work order list's Description column, the only one of
   its sixteen with unbounded width, one long entry otherwise pushing the rest
   off the side. Named for what it does rather than for that one column, so
   the next free-text column a list needs reaches for this instead of a
   second copy of the same rule.

   clamp rather than a fixed cap, so the column grows on a wide monitor and
   gives way on a narrow one, which is when the space it takes actually costs
   something. The floor is wide enough to be worth reading; the ceiling stops
   it from becoming the page's main column on a 1400px screen.

   What the ellipsis defers stays reachable by opening the row, which every
   list built on listTable() already does on click.

   Exempting the printed sheet, which shares this table's class. Paper has
   neither a scrollbar nor a tooltip, so an ellipsis there loses the text
   rather than deferring it. Scoped to the print TABLE rather than to print
   media, so the print page reads the same on screen as it comes out: a
   preview that truncates what the paper will not is its own small lie. */

/* Wrapping is the right trade on paper, against the nowrap every cell in this
   table gets: a taller row costs a sheet, and text running off the edge
   costs the answer someone printed the list for. Ahead of the screen rule
   below only to keep specificity ascending, which stylelint enforces. */
.cp-print-table td.cp-truncated-cell {
  white-space: normal;
}

.cp-list-table:not(.cp-print-table) td.cp-truncated-cell {
  max-width: clamp(12ch, 18vw, 40ch);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* An abbreviated header keeps Bootstrap's dotted underline, which is the cue
   that there is something to hover for, but not its cursor: help. Most of
   these headers are sort links, and help over a control that navigates on
   click describes the wrong thing. inherit rather than pointer so a header
   without a sort key still gets the ordinary arrow. */
.cp-list-table thead abbr[title] { cursor: inherit; }

/* The store colour band down a row's leading edge (ported from the prototype's rule of the
   same name, first used by the dashboard's Open orders by store table). A marking on the row,
   not a column of its own, so it carries no padding and only enough width to be seen.

   ::after is load-bearing, not decoration. The cell is empty, and an empty cell with no
   padding collapses to zero in an auto-layout table, which takes the store colour with it: a
   width on a table cell is a suggestion the layout algorithm is free to ignore, but content
   inside it is not. The prototype hit exactly this and fixed it the same way.

   Specificity, not !important: Bootstrap paints cell padding through
   `.table > :not(caption) > * > *`, so a bare .cp-store-strip would lose. Naming the table and
   the cell beats it outright and leaves the rule overridable. */
.cp-list-table :is(th, td).cp-store-strip {
  width: 4px;
  padding: 0;
}

.cp-list-table .cp-store-strip::after {
  content: "";
  display: block;
  width: 4px;
}

/* The store's LOC chip (ported from the prototype's rule of the same name): the store code on a
   fixed-height rounded chip, tinted per row with the store's colour inline. Stands in for the
   strip above on the work order list, as the prototype's list pages do. */
.cp-loc {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  color: var(--cp-on-dark);
  font-size: .75rem;
  font-weight: 600;
  line-height: 1;
}

/* Affordance belongs to <cp-click-nav>, not to the table: scoping it here means a table
   whose rows aren't actually wired up doesn't advertise a click that does nothing. */
cp-click-nav [data-href] { cursor: pointer; }

/* List-page toolbar strip: bleeds edge-to-edge against the page section's own p-4 padding
   (cancel + re-add) so its border-bottom spans the full content width instead of stopping
   at the section's padding. */
.cp-list-controls {
  margin: -1.5rem -1.5rem 0;
  padding: 1.5rem 1.5rem 0;
  border-bottom: var(--bs-border-width) solid var(--bs-border-color);

  /* Pill-shaped filter chrome, ported from the prototype's [data-cp-list] rules. The band above
     a list reads as a row of chips rather than a row of form fields, which is what separates
     "narrow what you are looking at" from "fill this in".

     Scoped here rather than globally so a control inside the table keeps square corners: in a
     row, a rounded select reads as a chip that has escaped the grid rather than as a cell.
     theme.css sets --bs-border-radius-sm to 0, so without this every one of them is square. */
  & .form-select {
    border-radius: 50rem;
    padding-left: .85rem;
  }

  /* A select is sized to about a pixel more than its widest option, which is
     enough for most of this row and not enough for the longest label on it:
     "All Prod. Statuses" measures 114.4px inside 115.4px, so the final glyph
     goes to subpixel rounding. Measured in Chrome at the .875rem these run at.

     A min-width on this one control rather than on every select: the row
     wraps, and padding the other seven out to the longest one's width would
     cost a whole column of space to fix a single label. */
  & .cp-filter-roomy {
    min-width: 11rem;
  }

  & .input-group > :first-child {
    border-top-left-radius: 50rem;
    border-bottom-left-radius: 50rem;
  }

  & .input-group > :last-child {
    border-top-right-radius: 50rem;
    border-bottom-right-radius: 50rem;
  }

  /* A range's leading label ("Due Date", "Paid") sits inside the curve, so it needs the matching
     inset or its first letter rides the radius. */
  & .input-group > .input-group-text:first-child {
    padding-left: .85rem;
  }

  /* Each date input .25rem narrower than input-group-sm's .5rem-a-side padding makes it. Taken
     from the padding rather than set as a width because a date input sizes itself to its
     browser's own date format, which differs between Chrome and Safari, so a fixed width would
     clip one of them. */
  & cp-date-range input[type="date"] {
    padding-inline: .375rem;
  }
}

/* Bulk-actions row: dimmed while no rows are selected (controls are also disabled via JS).
   Class-scoped, not id-scoped, so any future list page's bulk actions bar can reuse it. */
.cp-bulk-off { opacity: .55; }

/* Checkbox column: strip the <td>'s own padding so the <label> inside fills every pixel,
   which is what gives the whole cell a working hit target without the surrounding row-click
   firing (cp-click-nav ignores clicks on <label>, see cp-click-nav.js). The <th> is covered
   by the same selector so the "select all" cell behaves the same way. */
.cp-list-table :is(th, td).cp-bulk-select-cell { padding: 0; }

.cp-bulk-select-cell-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: .5rem .25rem;
  cursor: pointer;
}

/* The same chevron Bootstrap draws on <select class="form-select"> (identical SVG, position
   and size), for a button that opens a dropdown menu rather than posting straight away: it reads
   as one more select in the bar rather than as a different kind of control that happens to sit
   next to them. */
.cp-select-chevron {
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  background-size: 16px 12px;
}

/* Split-page master/detail: three (or more) columns each with their own vertical
   scrollbar, sitting inside a viewport-height shell so the page itself never
   scrolls. Same shape as .cp-list-page above: :has() scopes the viewport cap so
   other pages keep the default content-driven height. */
.cp-main:has(.cp-split-page) {
  height: 100vh;
  overflow: hidden;

  & > main {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }
}

.cp-split-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.cp-split-header { flex: 0 0 auto; }

.cp-split-columns {
  display: flex;
  flex: 1 1 auto;
  gap: 1rem;
  min-height: 0;
  align-items: stretch;
}

/* Each column is its own scrolling region. flex parents lay them out; the
   scroll comes from overflow-y here, and min-height:0 lets the column shrink
   below its content so overflow actually engages. Default: don't shrink
   (fixed-width nav rails and lists stay put); add .cp-split-column-grow
   to the pane that should expand into the leftover width. */
.cp-split-column {
  overflow-y: auto;
  min-height: 0;
  max-height: 100%;
  flex-shrink: 0;
}

.cp-split-column-grow {
  flex: 1 1 0;
  min-width: 0;
}

/* A list's search box on a row of its own, above the filters rather than beside them. Capped
   rather than full-width: stretched across a 1400px list it reads as the page's main input, which
   it is not. Paired with .cp-pill-search for the rounded ends. */
.cp-list-search {
  max-width: 320px;
}

/* Soft-deleted work orders, listed only when an admin turns on Show deleted.
   Muted and struck through so they never read as live orders. From the
   prototype (.ui-spec/docs/prototype/styles.css, .cp-row-deleted); the store
   strip keeps its color so the row still says which store it was, and the
   Status cell's Restore button stays a live-looking control. */
.cp-row-deleted > td {
  opacity: 0.6;
  text-decoration: line-through;

  &:has(button),
  &.cp-store-strip,
  &.cp-bulk-select-cell {
    opacity: 1;
    text-decoration: none;
  }
}
