/* ==========================================================================
   Datatables on phones (portrait < 768px, or a landscape phone: coarse
   pointer and under 500px tall). Desktop and tablets are untouched.

   - No pinned columns: the shared .fixed-table-header rules, page-level
     sticky-col variants and DataTables FixedColumns all stop pinning, so
     columns scroll normally. Header rows still stay at the top of their own
     scroll box (that pins rows, not columns).
   - Each table scrolls sideways inside its own box; the page never does.
     public/js/datatable-mobile.js adds a .dt-hscroll box around tables that
     have none, turns FixedColumns off/on across the breakpoint and keeps
     row action menus from being clipped by that box.
   - Search, length, buttons, info and paging stack full width and wrap.

   The media query must match MOBILE_QUERY in datatable-mobile.js.
   ========================================================================== */

@media (max-width: 767.98px), (pointer: coarse) and (max-height: 500px) {

  /* ---- 1. No pinned columns ------------------------------------------- */

  /* custom.css pins the first four body cells (left + top) from 740px. */
  .fixed-table-header tbody tr td:nth-child(-n+4),
  .fixed-table-header tbody tr th:nth-child(-n+4) {
    position: static !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    z-index: auto !important;
    box-shadow: none !important;
  }

  /* Header cells stay sticky to the top of the scroll box but lose their
     left offsets, so they scroll sideways with the body. One z-index for
     every header cell: above the body, below menus and modals. */
  .fixed-table-header thead tr th,
  .roster_rep_tbl thead tr th {
    left: auto !important;
    right: auto !important;
    z-index: 2 !important;
    box-shadow: none !important;
  }

  .fixed-table-header {
    max-height: min(500px, 75vh);
  }

  /* Page-level pinned-column classes (sticky-col, col-sticky-left, ...).
     !important also beats the inline left: offsets some sheets print. */
  td.sticky-col, td.sticky-column, td.sticky-left, td.col-sticky-left, td.col-summary,
  td.asp-sn-col, td.asp-sticky-col, td.asp-sticky-col-2,
  td.dtfc-fixed-left, td.dtfc-fixed-right,
  th.dtfc-fixed-left, th.dtfc-fixed-right {
    position: static !important;
    left: auto !important;
    right: auto !important;
    z-index: auto !important;
    box-shadow: none !important;
  }

  th.sticky-col, th.sticky-column, th.sticky-left, th.col-sticky-left, th.col-summary,
  th.asp-sn-col, th.asp-sticky-col, th.asp-sticky-col-2 {
    left: auto !important;
    right: auto !important;
    box-shadow: none !important;
  }

  .dtfc-fixed-left::after, .dtfc-fixed-right::after,
  .dtfc-fixed-start::after, .dtfc-fixed-end::after {
    display: none !important;
  }

  /* FixedColumns 4/5 corner blockers and FixedColumns 3 cloned tables. */
  div[class*="dtfc-"][class*="-blocker"],
  .DTFC_LeftWrapper, .DTFC_RightWrapper {
    display: none !important;
  }

  /* ---- 2. Scroll inside the table box, never the page ------------------ */

  .dataTables_wrapper,
  .table-responsive,
  .dt-hscroll {
    max-width: 100%;
    min-width: 0;
  }

  .dt-hscroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .dataTables_wrapper .dataTables_scroll,
  .dataTables_wrapper .dataTables_scrollBody {
    max-width: 100%;
  }

  /* ---- 3. Toolbar: length, search, buttons, info, paging ----------------- */

  .dataTables_wrapper::after {
    content: "";
    display: table;
    clear: both;
  }

  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    float: none !important;
    width: 100%;
    margin: 0 0 8px;
    padding: 0 !important;
    text-align: left;
  }

  .dataTables_wrapper .dataTables_length label,
  .dataTables_wrapper .dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin: 0;
    white-space: nowrap;
  }

  .dataTables_wrapper .dataTables_filter input {
    flex: 1 1 auto;
    min-width: 0;
    width: auto !important;
    height: 34px;
    margin: 0 !important;
  }

  .dataTables_wrapper .dataTables_length select {
    height: 34px;
    margin: 0 !important;
  }

  .dataTables_wrapper .dt-buttons {
    float: none !important;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 8px;
  }

  .dataTables_wrapper .dt-buttons .dt-button,
  .dataTables_wrapper .dt-buttons .btn {
    margin: 0 !important;
    min-height: 34px;
  }

  .dataTables_wrapper .dataTables_info {
    font-size: 12px;
    line-height: 1.4;
    white-space: normal !important;
  }

  .dataTables_wrapper .dataTables_paginate {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }

  .dataTables_wrapper .dataTables_paginate > span {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }

  .dataTables_wrapper .dataTables_paginate .paginate_button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
    margin: 0 !important;
    padding: 4px 8px !important;
  }

  .dataTables_wrapper .dataTables_paginate .ellipsis {
    padding: 0 2px;
  }

  /* ---- 4. Cells -------------------------------------------------------- */

  table.dataTable > thead > tr > th,
  table.dataTable > thead > tr > td,
  table.dataTable > tbody > tr > td,
  table.dataTable > tfoot > tr > td,
  table.dataTable > tfoot > tr > th {
    padding: 6px 8px;
    font-size: 12.5px;
    line-height: 1.35;
  }

  /* Text wraps at spaces; a single word (date, code, amount) never breaks,
     so its column keeps its full width and the table scrolls instead. */
  table.dataTable > tbody > tr > td {
    overflow-wrap: break-word;
  }

  table.dataTable td.dt-right, table.dataTable td.dt-body-right,
  table.dataTable td.text-right, table.dataTable td.num {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  /* Cells holding several action buttons keep them on one line. */
  table.dataTable td:has(> .btn ~ .btn),
  table.dataTable td:has(> a ~ a > .fa) {
    white-space: nowrap;
  }

  table.dataTable td > .btn,
  table.dataTable td > .btn-group > .btn {
    min-width: 30px;
    min-height: 30px;
  }

  table.dataTable td input[type="checkbox"],
  table.dataTable th input[type="checkbox"] {
    width: 18px;
    height: 18px;
  }

  /* ---- 5. Loading / empty states --------------------------------------- */

  /* A wide table centres its message across every column, off screen. */
  table.dataTable td.dataTables_empty {
    text-align: left !important;
    padding: 16px 8px;
  }

  .dataTables_wrapper .dataTables_processing {
    left: 50%;
    width: auto;
    max-width: calc(100% - 16px);
    margin-left: 0;
    transform: translateX(-50%);
  }
}
