/* ============================================================
   Cases / Deals (desk/staff) list pages.
   Structure in @layer layout, paint in @layer design.
   The caseload table, its cells and its pager are design-system
   components now. This sheet keeps the filter chips and search box that
   other desk lists still share, a case's slat on the caseload,
   and the placement of each page's own search form.
   ============================================================ */

@layer layout {
  /* Filter chips: a row of plain links carrying counts. */
  .filter-bar { display: flex; flex-wrap: wrap; gap: var(--mea-space-2); margin: 0; padding: 0; }
  .filter-chip { display: inline-flex; align-items: center; gap: var(--mea-space-2);
                 min-height: var(--t-target-min, 44px);
                 padding: var(--mea-space-2) var(--mea-space-4); border: 0;
                 border-radius: var(--mea-radius-pill); cursor: pointer; white-space: nowrap; }

  /* Search box: a field and a button in one row. */
  .search-box { flex: 1; min-inline-size: 12rem; display: flex; align-items: center; gap: var(--mea-space-2);
                margin: 0; padding: var(--mea-space-2) var(--mea-space-3);
                border-radius: var(--mea-radius-md); }
  .search-box__input { flex: 1; min-height: var(--t-target-min, 44px);
                       border: 0; background: transparent; padding: 0; }

  /* A link straight under the page (Back to caseload) keeps its own width,
     as it did before, rather than stretching across the grid. */
  :is(.deals-page, .caseload-search-page) > a { justify-self: start; }

  /* A case's three groups: who it is, the plan, where it stands. Who it is
     takes the most room. In a wide list the status group lines up at the
     right edge, as a table's last column would. */
  .case-slats { --slat-columns: minmax(0, 2fr) minmax(0, 1.5fr) minmax(0, 1fr); }
  @container (inline-size >= 36rem) {
    .case-slats .group.status { justify-items: end; text-align: end; }
  }
  /* The overdue mark is an icon the size of the text it leads. */
  .case-slats .overdue svg { inline-size: 1.15em; block-size: 1.15em;
                             vertical-align: -0.2em; margin-inline-end: var(--t-space-1); }

  /* Bulk form: the table and the ticked-row controls stack in one POST form. */
  .deals-page .deals-bulk-form { display: grid; gap: var(--t-space-4); }

  /* The controls card appears once at least one row is ticked, with no script. */
  .deals-page .deals-bulk-card { display: none; }
  .deals-page .deals-bulk-form:has(input[name="deal_ids"]:checked) .deals-bulk-card { display: grid; }

  /* The fieldset carries no frame of its own; the pane around it is the card. */
  .deals-page .deals-bulk-actions { display: grid; gap: var(--t-space-3);
                                    margin: 0; padding: 0; border: 0;
                                    justify-items: start; }
  .deals-page .deals-bulk-actions > .field { inline-size: 100%; }
  .deals-page .deals-bulk-actions > legend { padding: 0; font-size: var(--t-font-size-md);
                                             font-weight: var(--t-font-weight-bold); }

  /* The caseload search page stacks its heading, form, results and pager like
     the caseload list it is refined from. */
  .caseload-search-page { display: grid; gap: var(--t-space-5); }

  /* Each page places its own search form. */
  .deals-page .deals-search .field { flex: 1 1 16rem; }
  .caseload-search-page .search { display: flex; flex-wrap: wrap; align-items: end;
                                  gap: var(--t-space-3); }
  .caseload-search-page .search .field { flex: 1 1 16rem; }

  /* The sort row: a label, then one chip per column the list sorts by. The
     current chip's arrow is the size of its text. */
  .deals-page .caseload-sort__label { font-size: var(--t-font-size-sm);
                                   font-weight: var(--t-font-weight-semibold); }
  .deals-page .caseload-sort .chip svg { inline-size: 1em; block-size: 1em;
                                      vertical-align: -0.125em; }

  /* The caseload pages left .app-screen behind, and with it the desk
     gutter, so on a computer they sat closer to the menu and the window's
     edge than every other desk page. They take the same room here. */
  @media (min-width: 48rem) {
    body.desk-portal :is(.deals-page, .caseload-search-page, .deal-detail-page) {
      padding: var(--mea-space-6) var(--mea-gutter-desktop) var(--mea-space-12);
    }
  }
}

@layer design {
  /* A triage value nobody has recorded yet: the page's dash, quieter than
     a value. */
  .case-slats :is(.muted, .unknown) { color: var(--c-surface-text-color-muted); }
  .case-slats .overdue { color: var(--c-surface-text-color-error); }

  /* Filter chips. .is-active is toggled by the controller. */
  .filter-chip { background: var(--t-bg-recessed); color: var(--t-text-secondary);
                 font-size: var(--mea-text-sm); font-weight: var(--mea-w-semibold);
                 transition: background var(--mea-dur-fast), color var(--mea-dur-fast); }
  .filter-chip:hover { background: var(--t-bg-active); }
  .filter-chip.is-active { background: var(--t-accent); color: var(--t-accent-text); }

  .search-box { background: var(--t-bg-elevated); color: var(--t-text); border: 1px solid var(--t-border); }
  .search-box__icon { color: var(--t-text-muted); }
  .search-box__input { color: var(--t-text); font-size: var(--mea-text-md); }
  .search-box__input::placeholder { color: var(--t-text-muted); }
  .search-box:focus-within { border-color: var(--t-border-focus); }

}
