/* ============================================================
   mobile-grids.css  (mobilegrids-2026-11-21)
   Phone layout for every RadzenDataGrid, its pager/filters, dialogs
   and page toolbars. Loaded after mobile.css + compact-cards.css.

   EVERY rule is inside @media (max-width: 768px). Nothing here applies
   at desktop/tablet widths above 768px. Companion script
   js/mobile-grids.js only adds the mg-* classes below 768px.
   ============================================================ */

@media screen and (max-width: 768px) {

  /* ---- 1. Let the grid be no wider than the screen ----------------
     Flex items default to min-width:auto, so a 1,400px table pushes every
     RadzenRow/Column/Stack/Card above it wider than the phone and the page
     clips. Allow the ancestors of a grid to shrink; the grid then scrolls
     inside its own box. */
  .rz-body :where(div, section, article, form, fieldset, main):has(.rz-data-grid) {
    min-width: 0;
  }
  .rz-data-grid {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* ---- 2. Sideways scrolling inside the grid only ------------------
     The table scrolls inside .rz-data-grid-data; the pager (outside that
     box) stays put, the column header scrolls with its columns.
     overscroll-behavior-x keeps a sideways swipe from turning into a
     browser back-gesture. */
  .rz-data-grid .rz-data-grid-data {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    max-width: 100%;
  }
  /* mobile.css gives the OUTER box overflow-x:auto too, which produced a
     second scrollbar that moved the pager away. The inner box scrolls. */
  .rz-data-grid.rz-datatable-scrollable {
    overflow-x: visible !important;
  }

  /* ---- 3. Hint that there is more to the right ---------------------
     mobile-grids.js adds .mg-scroll-right while more columns are hidden. */
  .rz-data-grid.mg-scroll-right {
    position: relative;
  }
  .rz-data-grid.mg-scroll-right::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 18px;
    pointer-events: none;
    background: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.12));
    z-index: 3;
  }

  /* ---- 4. Sticky first column --------------------------------------
     Only when mobile-grids.js decided it is safe (.mg-sticky): the table
     really scrolls, the first column is at most ~45% of the visible width,
     and Radzen has not already frozen columns itself. */
  .rz-data-grid.mg-sticky .rz-grid-table > thead > tr > th:first-child,
  .rz-data-grid.mg-sticky .rz-grid-table > tbody > tr.rz-data-row > td:first-child,
  .rz-data-grid.mg-sticky .rz-grid-table > tfoot > tr > td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background-color: var(--rz-base-background-color, #fff);
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.12), 3px 0 4px -2px rgba(0, 0, 0, 0.10);
  }
  .rz-data-grid.mg-sticky .rz-grid-table > thead > tr > th:first-child {
    z-index: 4; /* above body cells when the header is also sticky */
    background-color: var(--rz-grid-header-background-color, #EEF6ED);
  }
  /* stripe colours can be translucent: paint the stripe over an opaque base so the
     columns scrolling underneath never show through */
  .rz-data-grid.mg-sticky .rz-grid-table-striped > tbody > tr.rz-data-row:nth-child(even) > td:first-child {
    background-color: var(--rz-base-background-color, #fff);
    background-image: linear-gradient(var(--rz-grid-stripe-background-color, transparent), var(--rz-grid-stripe-background-color, transparent));
  }

  /* ---- 5. Touch-friendly rows --------------------------------------- */
  .rz-data-grid .rz-grid-table > tbody > tr.rz-data-row > td {
    height: 44px; /* a table cell treats height as a minimum */
  }

  /* ---- 6. Pager: wraps, big enough to tap --------------------------- */
  .rz-data-grid .rz-pager,
  .rz-pager {
    flex-wrap: wrap !important;
    row-gap: 4px;
    justify-content: center;
    max-width: 100%;
  }
  .rz-pager .rz-pager-first,
  .rz-pager .rz-pager-prev,
  .rz-pager .rz-pager-next,
  .rz-pager .rz-pager-last,
  .rz-pager .rz-pager-page {
    min-width: 40px;
    min-height: 40px;
  }
  .rz-pager .rz-pager-summary {
    flex-basis: 100%;
    text-align: center;
  }

  /* ---- 7. Filters ----------------------------------------------------
     Header filter inputs fill their column; filter popups fit the screen. */
  .rz-data-grid .rz-cell-filter input,
  .rz-data-grid .rz-cell-filter .rz-textbox,
  .rz-data-grid .rz-cell-filter .rz-dropdown {
    min-width: 0;
    max-width: 100%;
  }
  .rz-grid-filter,
  .rz-overlaypanel,
  .rz-popup {
    max-width: calc(100vw - 16px) !important;
  }

  /* ---- 8. Dialogs fit the screen ------------------------------------
     mobile.css makes them 95vw at <=600px; this covers 601-768px and
     keeps tall dialogs scrollable inside instead of off the bottom. */
  .rz-dialog {
    max-width: calc(100vw - 16px) !important;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    display: flex;
    flex-direction: column;
  }
  .rz-dialog .rz-dialog-content {
    overflow: auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }
  .rz-dialog .rz-dialog-content .rz-data-grid {
    max-width: 100% !important;
  }

  /* ---- 9. Toolbars wrap ----------------------------------------------
     RadzenStack writes flex-wrap:nowrap inline, so a row of buttons and a
     search box runs off the screen. Wrap them (not inside grid cells, where
     wrapping would only make rows taller). */
  .rz-body .rz-stack.rz-flex-row:not(.rz-data-grid *),
  .rz-dialog .rz-stack.rz-flex-row:not(.rz-data-grid *) {
    flex-wrap: wrap !important;
  }
  .rz-body .rz-stack.rz-flex-row:not(.rz-data-grid *) > .rz-textbox,
  .rz-body .rz-stack.rz-flex-row:not(.rz-data-grid *) > .rz-dropdown,
  .rz-body .rz-stack.rz-flex-row:not(.rz-data-grid *) > .rz-datepicker,
  .rz-body .rz-stack.rz-flex-row:not(.rz-data-grid *) > input {
    max-width: 100%;
  }
}
