/* ---------------------------------------------------------------------------
 * DataGrid (Components/DataGrid.razor): Microsoft's QuickGrid in the design
 * system.
 * ---------------------------------------------------------------------------
 * QuickGrid ships its own look as scoped CSS. Since 2026-10-04 the hosts link
 * the scoped-CSS bundle (index.html: OSM.Platform.Client.styles.css), which
 * brings that look with it - so every rule QuickGrid's markup needs is here, in
 * theme tokens, and the end of this file takes back what QuickGrid's own sheet
 * would otherwise draw (its literal colours, its sort arrow). The table also
 * carries osm-table, so it already has the list density (~36px rows), the
 * sticky header, row hover and the selected row (material.css). This file adds the grid's own parts: the sort and filter
 * buttons in the headings, the filter pop-over, the Columns menu, widths, and
 * the stacked card layout on phones.
 *
 * No colour is written here - only tokens (the colour guard enforces it).
 * The icons are masks: their shape comes from the SVG, their colour from the
 * token behind them.
 */

.osm-dg { --osm-dg-icon-sort: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 5l7 10H5z'/%3E%3C/svg%3E");
          --osm-dg-icon-either: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2l6 8H6zM12 22l-6-8h12z'/%3E%3C/svg%3E");
          --osm-dg-icon-filter: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 4h18l-7 8.5V19l-4 2v-8.5z'/%3E%3C/svg%3E"); }

/* ---- The bar above the grid: filter chips on the left, tools on the right ---- */
.osm-dg-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin-bottom: 8px;
}
/* With the page's ListToolbar in it: one row, the grid's tools after the
   toolbar's own (count, Export). */
.osm-dg-bar.has-toolbar { align-items: flex-start; margin-bottom: 12px; }
.osm-dg-bar.has-toolbar > .osm-list-toolbar { flex: 1 1 560px; min-width: 0; margin-bottom: 0; }
.osm-dg-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 8px; }
.osm-dg-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 10px; border-radius: 999px;
  background: var(--osm-accent-soft); color: var(--osm-ink);
  font-size: 0.8125rem;
}
.osm-dg-chip-remove {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; padding: 0; border: 0; border-radius: 999px;
  background: transparent; color: var(--osm-ink-soft);
}
.osm-dg-chip-remove:hover { background: var(--osm-surface); color: var(--osm-ink); }
.osm-dg-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }

/* ---- Columns menu ---- */
.osm-dg-menu-anchor { position: relative; }
.osm-dg-backdrop { position: fixed; inset: 0; z-index: 1059; background: transparent; }
.osm-dg-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 1060;
  width: min(320px, calc(100vw - 32px));
  max-height: min(70vh, 520px); overflow: auto;
  padding: 12px; border-radius: var(--osm-radius);
  background: var(--osm-surface); color: var(--osm-ink);
  border: var(--osm-border-width) solid var(--osm-rule-strong);
  box-shadow: var(--osm-shadow-lg);
}
.osm-dg-menu-head { margin-bottom: 8px; }
.osm-dg-menu-list { list-style: none; margin: 0; padding: 0; }
.osm-dg-menu-list > li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 2px 0; border-bottom: 1px solid var(--osm-rule);
}
.osm-dg-menu-list > li:last-child { border-bottom: 0; }
.osm-dg-menu-check { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; padding: 4px 0; cursor: pointer; }
.osm-dg-menu-check .osm-check { margin: 0; flex: none; }
.osm-dg-menu-move { display: inline-flex; flex: none; }
.osm-dg-menu-move .mud-icon-button { padding: 4px; color: var(--osm-ink-soft); }
.osm-dg-menu-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.osm-dg-menu-source { margin-top: 8px; }
.osm-dg-menu-org { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 6px; }
.osm-dg-menu-message { margin-top: 6px; }

/* ---- The table: QuickGrid's headings ---- */
.osm-grid { --osm-dg-gap: 4px; }
.osm-grid > thead th { text-align: start; }
.osm-grid > thead th.col-justify-end { text-align: end; }
.osm-grid .col-header-content { display: flex; align-items: center; gap: var(--osm-dg-gap); min-width: 0; }
.osm-grid th.col-justify-end .col-header-content { flex-direction: row-reverse; }
.osm-grid th.col-justify-center .col-header-content { justify-content: center; }

.osm-grid .col-title {
  display: inline-flex; align-items: center; gap: var(--osm-dg-gap);
  min-width: 0; flex: 0 1 auto; padding: 0; margin: 0;
  color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; text-align: inherit;
}
.osm-grid button.col-title { border: 0; background: transparent; cursor: pointer; border-radius: 3px; }
.osm-grid button.col-title:hover { color: var(--osm-ink); }
.osm-grid th.col-justify-end .col-title { flex-direction: row-reverse; }
.osm-grid .col-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The sort arrow: the current column's in the accent; a faint up-and-down on
   the others when the pointer is over them, so it is clear they sort. */
.osm-grid .sort-indicator { flex: none; width: 12px; height: 12px; }
.osm-grid th.col-sort-asc .sort-indicator,
.osm-grid th.col-sort-desc .sort-indicator {
  background-color: var(--osm-accent);
  -webkit-mask: var(--osm-dg-icon-sort) center / contain no-repeat;
          mask: var(--osm-dg-icon-sort) center / contain no-repeat;
}
.osm-grid th.col-sort-desc .sort-indicator { transform: rotate(180deg); }
.osm-grid th:not(.col-sort-asc):not(.col-sort-desc) button.col-title:is(:hover, :focus-visible) .sort-indicator {
  background-color: var(--osm-ink-mute);
  -webkit-mask: var(--osm-dg-icon-either) center / contain no-repeat;
          mask: var(--osm-dg-icon-either) center / contain no-repeat;
}

/* The filter button (QuickGrid's "column options"). */
.osm-grid th .col-options-button {
  position: relative; flex: none;
  width: 22px; height: 22px; padding: 0; border: 0; border-radius: 4px;
  background: transparent; cursor: pointer; opacity: 0.6;
}
.osm-grid .col-options-button::before {
  content: ""; position: absolute; inset: 4px;
  background-color: var(--osm-ink-soft);
  -webkit-mask: var(--osm-dg-icon-filter) center / contain no-repeat;
          mask: var(--osm-dg-icon-filter) center / contain no-repeat;
}
.osm-grid th:hover .col-options-button, .osm-grid .col-options-button:focus-visible { opacity: 1; }
.osm-grid .col-options-button:hover { background: var(--osm-surface); opacity: 1; }
.osm-grid th.has-filter .col-options-button { opacity: 1; }
.osm-grid th.has-filter .col-options-button::before { background-color: var(--osm-accent); }

/* The filter pop-over. Inside the heading, so it undoes the heading's type. */
.osm-grid .col-options {
  position: absolute; top: 100%; left: 0; z-index: 20;
  min-width: 240px; max-width: min(320px, calc(100vw - 32px));
  margin-top: 2px; padding: 10px 12px;
  background: var(--osm-surface); color: var(--osm-ink);
  border: var(--osm-border-width) solid var(--osm-rule-strong);
  border-radius: var(--osm-radius); box-shadow: var(--osm-shadow-md);
  font-size: 0.875rem; font-weight: 400; letter-spacing: normal; text-transform: none;
  white-space: normal; text-align: start; cursor: default;
}
.osm-grid th.col-justify-end .col-options { left: auto; right: 0; }
/* The list's card scrolls (and so clips) on a desk: while a filter is open it
   lets the pop-over out, so a short list does not cut it off. */
.osm-dg-scroll.osm-panel.osm-table-scroll:has(.col-options) { overflow: visible; max-height: none; }
.osm-dg-filter-title { font-size: 0.75rem; font-weight: 600; color: var(--osm-ink-soft); margin-bottom: 6px; }
.osm-dg-filter-choices { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow: auto; }
.osm-dg-filter-choices .osm-dg-choice { margin: 0; display: flex; gap: 8px; align-items: center; padding-left: 0; cursor: pointer; }
.osm-dg-filter-dates { display: grid; grid-template-columns: auto 1fr; gap: 6px 8px; align-items: center; }
.osm-dg-filter-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }

/* A column edge can be dragged: a hairline shows where to grab. */
.osm-grid > thead th.osm-dg-col { background-clip: padding-box; }
.osm-grid > thead th.osm-dg-col:hover { box-shadow: inset -2px 0 0 var(--osm-rule-strong); }

/* ---- The table: cells and rows ---- */
.osm-grid > tbody > tr > td.col-justify-end { text-align: end; }
.osm-grid > tbody > tr > td.col-justify-center { text-align: center; }
.osm-grid th.osm-dg-select, .osm-grid td.osm-dg-select { width: 2.25rem; }
.osm-grid td.osm-dg-select .osm-check, .osm-grid th.osm-dg-select .osm-check { margin: 0; vertical-align: middle; }

/* On a desk the label is the heading, and the value is just the cell. */
.osm-dg-label { display: none; }
.osm-dg-value { display: contents; }

.osm-grid.is-activatable > tbody > tr[aria-rowindex] { cursor: pointer; }
.osm-grid > tbody > tr[aria-rowindex]:focus-visible { outline: 2px solid var(--osm-accent); outline-offset: -2px; }
.osm-grid > tbody > tr > td.grid-cell-placeholder::after { content: "\2026"; color: var(--osm-ink-mute); }

/* Widths the person dragged: the table keeps them exactly (and scrolls
   sideways inside its card if they add up to more than the screen). */
.osm-grid.is-sized > thead th.osm-dg-col { width: 9rem; }
.osm-grid.is-sized > tbody > tr > td.osm-dg-col { overflow: hidden; text-overflow: ellipsis; }
.osm-grid.is-sized td.osm-truncate { max-width: none; }

.osm-dg-none {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin-top: 8px; padding: 10px 12px; border-radius: var(--osm-radius);
  background: var(--osm-sunk); color: var(--osm-ink-soft); font-size: 0.875rem;
}

/* The phone's "Sort by" list stands in for the headings: a Material select. */
.osm-dg-phone-sort.mud-input-control { width: auto; min-width: 14rem; max-width: 100%; flex: 1 1 14rem; margin: 0; }
@media (min-width: 768px) {
  .osm-dg-phone-sort, .osm-dg-phone-sort.mud-input-control { display: none; }
}

/* A row's check box: the box is Material's size, the label around it is the
   target - 40px on a desk, 44px on a phone or touch screen. */
.osm-dg-check {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; min-height: 32px; margin: -6px; padding: 0; cursor: pointer;
  border-radius: 50%;
}
.osm-dg-check:hover { background: color-mix(in srgb, var(--osm-ink) 7%, transparent); }
.osm-dg-check .osm-check { margin: 0; flex: none; }

/* ---- Phones: each row a card of "label: value" lines ---- */
@media (max-width: 767.98px) {
  .osm-dg-scroll.osm-table-scroll, .osm-dg-scroll.osm-panel {
    overflow: visible; max-height: none;
    border: 0; border-radius: 0; background: transparent; box-shadow: none;
  }
  .osm-grid, .osm-grid > tbody, .osm-grid > tbody > tr, .osm-grid > tbody > tr > td { display: block; width: 100%; }
  .osm-grid > thead { display: none; }
  .osm-grid { table-layout: auto !important; }
  .osm-grid > tbody > tr[aria-rowindex] {
    margin-bottom: 8px; padding: 6px 12px;
    background: var(--osm-surface);
    border: var(--osm-border-width) solid var(--osm-rule); border-radius: var(--osm-radius);
  }
  .osm-grid > tbody > tr:not([aria-rowindex]) { display: none; }
  .osm-grid > tbody > tr > td,
  .osm-table.osm-grid > :not(caption) > * > * {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    padding: 4px 0; border: 0; text-align: end; max-width: none; white-space: normal;
  }
  .osm-grid > tbody > tr > td.osm-truncate { max-width: none; }
  .osm-grid > tbody > tr > td + td { border-top: 1px solid var(--osm-rule); }
  .osm-grid > tbody > tr > td.osm-dg-select { justify-content: flex-start; width: auto; }
  .osm-dg-label {
    display: block; flex: 0 0 auto; max-width: 45%;
    color: var(--osm-ink-soft); font-size: 0.75rem; font-weight: 600; text-align: start;
    letter-spacing: var(--osm-label-tracking); text-transform: var(--osm-label-transform);
  }
  .osm-dg-value { display: block; min-width: 0; overflow-wrap: anywhere; text-align: end; }
  .osm-dg-tools { margin-left: 0; width: 100%; }
}

/* Touch: the headings are buttons a finger presses (sort, filter), and the
   check boxes' labels grow to 44px. Phones in portrait have no headings (the
   rows are cards), but a phone turned sideways or a tablet shows the table.
   "Touch" is below 1024px or a coarse pointer, as in material.css. */
@media (max-width: 1023.98px), (pointer: coarse) {
  .osm-grid button.col-title { min-height: 44px; }
  .osm-grid th .col-options-button { width: 44px; height: 44px; }
  .osm-grid .col-options-button::before { inset: 13px; }
  .osm-dg-check { min-width: 44px; min-height: 44px; margin: -10px; }
  .osm-dg-chip-remove { width: 32px; height: 32px; }
  .osm-dg-menu-check { min-height: 44px; }
}

/* QuickGrid's own scoped sheet (linked with the bundle): its sort arrow is a
   black picture and its pop-over white with a silver edge. The arrow is ours
   (a mask in the accent, above) and so is the pop-over; nothing of QuickGrid's
   colours shows in any theme or in dark mode. */
.osm-grid th.col-sort-asc .sort-indicator, .osm-grid th.col-sort-desc .sort-indicator { background-image: none; }
.osm-grid th.col-sort-asc .sort-indicator { transform: none; }
.osm-grid th .col-options-button { background: transparent; align-self: center; }
.osm-grid th .col-width-draghandle::after { border-color: var(--osm-rule-strong); }

/* ---- Group by (Columns menu): a heading row per value, folded from it ----
   The heading sits in the row's first cell and runs over the empty cells
   beside it, so it never widens the first column. */
.osm-dg-menu-group { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--osm-rule); }
.osm-dg-menu-group .osm-dg-group-choice { min-height: 40px; }
.osm-grid > tbody > tr.osm-dg-group-row > td {
  position: relative; height: 2.5rem; overflow: visible;
  background: var(--osm-sunk); border-top: 1px solid var(--osm-rule-strong);
}
.osm-grid.is-sized > tbody > tr.osm-dg-group-row > td.osm-dg-col,
.osm-grid > tbody > tr.osm-dg-group-row > td.osm-truncate { overflow: visible; max-width: none; }
.osm-dg-group-head { position: absolute; top: 0; bottom: 0; left: 0.25rem; z-index: 1; display: flex; align-items: center; white-space: nowrap; }
.osm-dg-group-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 10px 0 6px;
  border: 0; border-radius: var(--osm-radius); background: transparent; color: var(--osm-ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
.osm-dg-group-toggle:hover { background: color-mix(in srgb, var(--osm-ink) 7%, transparent); }
.osm-dg-group-toggle:focus-visible { outline: 2px solid var(--osm-accent); outline-offset: 1px; }
.osm-dg-group-chevron {
  width: 0.5rem; height: 0.5rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg); margin: 0 4px 3px 4px; transition: transform 0.15s;
}
.osm-dg-group-row.is-collapsed .osm-dg-group-chevron { transform: rotate(-45deg); margin-bottom: 0; }

/* ---- A phone's short card: the PhoneSummary columns, the rest behind "More" ---- */
.osm-dg-more {
  display: none; min-height: 44px; min-width: 44px; padding: 0 12px;
  border: 1px solid var(--osm-rule-strong); border-radius: var(--osm-radius);
  background: transparent; color: var(--osm-accent); font: inherit; font-weight: 600; cursor: pointer;
}
.osm-dg-more:focus-visible { outline: 2px solid var(--osm-accent); outline-offset: 1px; }
@media (max-width: 767.98px) {
  .osm-grid > tbody > tr.osm-dg-group-row {
    display: block; margin: 12px 0 6px; padding: 0; border: 0; background: transparent;
  }
  .osm-grid > tbody > tr.osm-dg-group-row > td { display: none; height: auto; background: transparent; border: 0; }
  .osm-grid > tbody > tr.osm-dg-group-row > td:has(.osm-dg-group-head) { display: block; padding: 0; }
  .osm-dg-group-head { position: static; }
  .osm-dg-group-toggle { min-height: 44px; }

  .osm-grid.has-phone-summary > tbody > tr[aria-rowindex]:not(.osm-dg-group-row) { display: flex; flex-wrap: wrap; column-gap: 8px; }
  .osm-grid.has-phone-summary > tbody > tr > td { flex: 1 1 100%; min-width: 0; }
  .osm-grid.has-phone-summary > tbody > tr > td.osm-dg-phone-extra { display: none; order: 3; }
  .osm-grid.has-phone-summary > tbody > tr.is-expanded > td.osm-dg-phone-extra { display: flex; }
  .osm-grid.has-phone-summary > tbody > tr > td.osm-dg-phone-line .osm-dg-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .osm-grid.has-phone-summary > tbody > tr > td:has(> .osm-dg-more) { align-items: center; }
  .osm-dg-more { display: inline-flex; align-items: center; justify-content: center; flex: none; }
}
