table.quickgrid {
  --bs-table-bg: transparent;
  --bs-table-striped-bg: transparent;
  --bs-table-hover-bg: transparent;
  border-collapse: collapse;
}

.quickgrid th button {
  background: none;
  border: none;
  color: inherit;
  font-size: inherit;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.quickgrid th button:hover {
  color: var(--lightera-purple-1, #6f00d3);
}

.quickgrid .col-sort-indicator {
  color: var(--lightera-purple-1, #6f00d3);
  opacity: 0.55;
}

.quickgrid .col-sort-indicator.sorted {
  opacity: 1;
}

.quickgrid .col-options-button {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 0.125rem 0.25rem;
  border-radius: 3px;
  font-size: 0.8rem;
  transition: color 150ms ease, background-color 150ms ease;
}

.quickgrid .col-options-button:hover {
  color: var(--lightera-purple-1, #6f00d3);
  background-color: rgba(111, 0, 211, 0.07);
}

.quickgrid .col-options,
.col-options-popup {
  background-color: white;
  border: 1.5px solid rgba(111, 0, 211, 0.2);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(111, 0, 211, 0.15);
  padding: 0.75rem;
  min-width: 200px;
  z-index: 30;
}

.quickgrid .col-options input[type="text"],
.quickgrid .col-options input[type="search"],
.col-options-popup input[type="text"],
.col-options-popup input[type="search"] {
  display: block;
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
  color: #31312f;
  transition: border-color 150ms ease, box-shadow 150ms ease;
  background-color: white;
}

.quickgrid .col-options input[type="text"]:focus,
.quickgrid .col-options input[type="search"]:focus,
.col-options-popup input[type="text"]:focus,
.col-options-popup input[type="search"]:focus {
  outline: none;
  border-color: var(--lightera-purple-1, #6f00d3);
  box-shadow: 0 0 0 3px rgba(111, 0, 211, 0.12);
}

.quickgrid .col-options label,
.col-options-popup label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.375rem;
}

.grid-loading {
  position: relative;
}

.grid-loading::before {
  content: '';
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2rem;
  height: 2rem;
  border: 3px solid rgba(111, 0, 211, 0.2);
  border-top-color: var(--lightera-purple-1, #6f00d3);
  border-radius: 50%;
  animation: quickgrid-spin 700ms linear infinite;
  z-index: 10;
}

@keyframes quickgrid-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.quickgrid-empty,
.quickgrid tbody tr.no-data td {
  padding: 3rem 1rem;
  text-align: center;
  color: #9ca3af;
  font-size: 0.9375rem;
}

.quickgrid tbody tr:not(:has(td > *)) {
  height: 0;
  line-height: 0;
  border-bottom: none;
}

.quickgrid tbody tr:not(:has(td > *)) td {
  border: none !important;
  padding: 0 !important;
  height: 0;
  line-height: 0;
}

/* Bootstrap's .table-responsive sets overflow-x: auto, which implicitly creates a
   vertical scroll container and blocks viewport-level sticky on thead.
   overflow-y: clip creates a BFC without a scroll container, allowing sticky to
   propagate through to the viewport in the Y direction. */
/* PREVIOUS ATTEMPT (did not work — overflow-x: auto still makes it a scroll container):
.lightera-results-card .table-responsive {
    overflow-y: clip;
}
*/

/* Make .table-responsive the intentional scroll container so thead sticky works at top: 0.
   max-height = viewport minus topbar + search bar + paginator + card margins (~7.5rem). */
.lightera-results-card .table-responsive {
    /* overflow-y: clip; */ /* REVERT: restore this line and remove the two lines below */
    max-height: calc(100vh - var(--topbar-h, 4.5rem) - var(--grid-search-h, 3rem) - 5rem);
    overflow-y: auto;
}
/* REVERT: remove the rule above to roll back this fix */

/* ── Sticky column headers — sit below the sticky search bar ── */
.quickgrid thead th {
    position: sticky;
    /* top: calc(var(--topbar-h, 4.5rem) + var(--grid-search-h, 3rem)); */ /* REVERT: restore this and remove top: 0 below */
    top: 0; /* sticky within .table-responsive scroll container */
    z-index: 3;
    background-color: white; /* must be opaque so scrolling rows don't bleed through */
}

[data-bs-theme="dark"] .quickgrid thead th {
    background-color: #2a2a28;
}
/* REVERT: remove the two blocks above to roll back sticky column headers */

/* ── Column widths ── */
.quickgrid th.col-delivery,
.quickgrid td.col-delivery     { width: 5rem;  min-width: 5rem; }

.quickgrid th.col-customer-po,
.quickgrid td.col-customer-po  { width: 5.5rem; min-width: 5.5rem; }

.quickgrid th.col-part-number,
.quickgrid td.col-part-number  { width: 6.5rem; min-width: 6.5rem; }

.quickgrid th.col-qty-km,
.quickgrid td.col-qty-km       { width: 5rem;  min-width: 5rem; }

.quickgrid th.col-qty-km       { text-align: right; }

.quickgrid th.col-po-item,
.quickgrid td.col-po-item      { width: 3rem;  min-width: 3rem; }

.quickgrid th.col-part-desc,
.quickgrid td.col-part-desc    { width: 18rem; min-width: 12rem; }

@media (max-width: 767.98px) {
    .quickgrid td.col-checkbox::before     { content: ""; display: none; }
    .quickgrid td.col-container-id::before { content: "Container ID"; }
    .quickgrid td.col-min::before          { content: "MIN"; }
    .quickgrid td.col-delivery::before     { content: "Delivery Nbr"; }
    .quickgrid td.col-customer-po::before  { content: "Customer PO"; }
    .quickgrid td.col-part-number::before  { content: "Part Number"; }
    .quickgrid td.col-part-desc::before    { content: "Description"; }
    .quickgrid td.col-qty-km::before       { content: "Qty (km)"; }
    .quickgrid td.col-date::before         { content: "Created"; }
}

@media (forced-colors: active) {
  .lightera-card-header {
    forced-color-adjust: none;
    background-color: Highlight;
    color: HighlightText;
  }

  .quickgrid th {
    forced-color-adjust: none;
    background-color: ButtonFace;
    color: ButtonText;
    border-bottom: 2px solid ButtonText;
  }

  .quickgrid tbody tr:hover {
    forced-color-adjust: none;
    background-color: Highlight;
    color: HighlightText;
  }
}
