.sb-data-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-family: inherit;
}

.sb-data-grid__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sb-data-grid__title:empty {
  display: none;
}

.sb-data-grid__toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-left: auto;
}

.sb-data-grid__views {
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.375rem;
  font-size: 0.85rem;
  background: transparent;
  color: inherit;
}

.sb-dg-columns {
  position: relative;
}

.sb-dg-columns-popover {
  position: absolute;
  top: calc(100% + 0.25rem);
  right: 0;
  z-index: 20;
  min-width: 200px;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  color: #111;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.4rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 0.5rem;
}

.sb-dg-columns-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.3rem;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
}

.sb-data-grid__bulkbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid rgba(13, 110, 253, 0.25);
  background: rgba(13, 110, 253, 0.06);
  border-radius: 0.4rem;
  font-size: 0.85rem;
}

.sb-data-grid__bulkbar-count {
  font-weight: 600;
}

.sb-dg-bulk-edit-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex-basis: 100%;
  margin-top: 0.4rem;
}

.sb-dg-bulk-edit-form select,
.sb-dg-bulk-edit-form input {
  padding: 0.3rem 0.5rem;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.35rem;
  font-size: 0.85rem;
  background: transparent;
  color: inherit;
}

.sb-data-grid__row-select {
  width: 2rem;
  text-align: center;
}

.sb-data-grid__search {
  padding: 0.375rem 0.75rem;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.375rem;
  min-width: 220px;
  font-size: 0.9rem;
}

.sb-data-grid__body {
  position: relative;
  min-height: 120px;
  /* A grid with enough columns (a real prod spec hit 12 data columns + checkbox + actions)
     needs more width than its page container has - width: 100% on the table below then
     forces every column narrower than its content, and with no scroll container here the
     overflow (worst offender: the row-actions column, which is `white-space: nowrap`) just
     bleeds past the page's content column with nothing to scroll it back into view. Confirmed
     via a standalone repro of the real "orders" grid spec: table 1209px vs a 1140px container,
     overflow-x: visible (the default), zero way to reach the clipped content. overflow-x: auto
     here + max-content below (same fix already shipped for the CRUD Workspace's List.cshtml,
     minus the split sticky-header complexity - this table has no sticky header). */
  overflow-x: auto;
}

.sb-data-grid__table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.sb-data-grid__table th,
.sb-data-grid__table td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  text-align: left;
  vertical-align: middle;
}

.sb-data-grid__table th {
  font-weight: 600;
  opacity: 0.75;
}

.sb-dg-sort-th {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 600;
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.sb-dg-sort-th:hover {
  text-decoration: underline;
}

.sb-data-grid__table tbody tr:hover {
  background: rgba(0, 0, 0, 0.035);
}

.sb-data-grid__row-actions {
  text-align: right;
  white-space: nowrap;
}

.sb-data-grid__empty,
.sb-data-grid__unconfigured {
  padding: 2rem 1rem;
  text-align: center;
  opacity: 0.6;
  font-size: 0.9rem;
}

.sb-data-grid__loading {
  text-align: center;
  padding: 0.75rem;
  opacity: 0.6;
  font-size: 0.85rem;
  display: none;
}

.sb-data-grid__loading.is-visible {
  display: block;
}

.sb-data-grid__sentinel {
  height: 1px;
}

.sb-data-grid__overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 1050;
  padding: 3vh 1rem;
  overflow-y: auto;
}

.sb-data-grid__panel {
  background: #fff;
  color: #111;
  border-radius: 0.5rem;
  width: 100%;
  max-width: 720px;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
  .sb-data-grid__panel {
    background: #1e1e22;
    color: #eee;
  }

  .sb-data-grid__table th,
  .sb-data-grid__table td {
    border-bottom-color: rgba(255, 255, 255, 0.12);
  }

  .sb-data-grid__table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
  }

  .sb-data-grid__search {
    background: #2a2a2e;
    color: #eee;
    border-color: rgba(255, 255, 255, 0.2);
  }

  .sb-data-grid__views {
    background: #2a2a2e;
    color: #eee;
    border-color: rgba(255, 255, 255, 0.2);
  }

  .sb-dg-columns-popover {
    background: #1e1e22;
    color: #eee;
    border-color: rgba(255, 255, 255, 0.2);
  }

  .sb-data-grid__bulkbar {
    border-color: rgba(110, 168, 254, 0.35);
    background: rgba(110, 168, 254, 0.1);
  }

  .sb-dg-bulk-edit-form select,
  .sb-dg-bulk-edit-form input {
    border-color: rgba(255, 255, 255, 0.2);
  }
}

.sb-data-grid__panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.sb-data-grid__panel-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.sb-data-grid__panel-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
}

.sb-data-grid__panel-close:hover {
  opacity: 1;
}

.sb-data-grid__panel-body {
  padding: 1.1rem;
  overflow-y: auto;
}

.sb-data-grid__panel-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1.1rem;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.sb-data-grid__panel-footer-spacer {
  flex: 1 1 auto;
}

.sb-data-grid__panel-error {
  flex: 1 1 100%;
  order: -1;
  font-size: 0.85rem;
  font-weight: 600;
  color: #dc3545;
}

.sb-data-grid__panel-error:empty {
  display: none;
}

.sb-dg-field {
  margin-bottom: 0.85rem;
}

.sb-dg-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.7;
  margin-bottom: 0.25rem;
}

.sb-dg-field input,
.sb-dg-field select {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.35rem;
  font-size: 0.9rem;
  background: transparent;
  color: inherit;
}

.sb-dg-required {
  color: #dc3545;
  margin-left: 0.15rem;
}

.sb-dg-fk {
  position: relative;
  /* Inside a child-table <td> a flex item with no floor can be squeezed to near-zero
     width by the browser's table layout, which combined with overflow-wrap: anywhere
     used to wrap every character onto its own line instead of just truncating. */
  min-width: 160px;
}

.sb-dg-fk-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sb-dg-fk-text {
  flex: 1 1 auto;
  font-size: 0.9rem;
  padding: 0.4rem 0;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-dg-fk-picker {
  margin-top: 0.4rem;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.35rem;
  overflow: hidden;
}

.sb-dg-fk-picker-search {
  display: block;
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.15);
  font-size: 0.85rem;
  background: transparent;
  color: inherit;
}

.sb-dg-fk-picker-search:focus {
  outline: none;
}

.sb-dg-fk-picker-list {
  max-height: 220px;
  overflow-y: auto;
}

.sb-dg-fk-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.6rem;
  border: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  background: transparent;
  color: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.sb-dg-fk-option:last-child {
  border-bottom: none;
}

.sb-dg-fk-option:hover,
.sb-dg-fk-option:focus {
  background: rgba(13, 110, 253, 0.12);
  outline: none;
}

@media (prefers-color-scheme: dark) {
  .sb-dg-fk-picker {
    border-color: rgba(255, 255, 255, 0.2);
    background: #2a2a2e;
  }

  .sb-dg-fk-picker-search {
    border-bottom-color: rgba(255, 255, 255, 0.15);
  }

  .sb-dg-fk-option {
    border-bottom-color: rgba(255, 255, 255, 0.08);
  }

  .sb-dg-fk-option:hover,
  .sb-dg-fk-option:focus {
    background: rgba(255, 255, 255, 0.08);
  }
}

.sb-dg-child-section {
  margin-top: 1.25rem;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  padding-top: 0.9rem;
}

@media (prefers-color-scheme: dark) {
  .sb-data-grid__panel-header,
  .sb-data-grid__panel-footer,
  .sb-dg-child-section {
    border-color: rgba(255, 255, 255, 0.12);
  }

  .sb-dg-field input {
    border-color: rgba(255, 255, 255, 0.2);
  }
}

.sb-dg-child-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sb-dg-child-table-scroll {
  /* Many/wide columns (e.g. several FK pickers) would otherwise force the browser's table
     layout to compress columns toward zero width - scroll horizontally instead. */
  overflow-x: auto;
  margin-bottom: 0.5rem;
}

.sb-dg-child-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.sb-dg-child-table th,
.sb-dg-child-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  white-space: nowrap;
}

.sb-dg-child-table input,
.sb-dg-child-table select {
  width: 100%;
  min-width: 110px;
  padding: 0.3rem 0.45rem;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.3rem;
  font-size: 0.85rem;
  background: transparent;
  color: inherit;
}

@media (prefers-color-scheme: dark) {
  .sb-dg-child-table th,
  .sb-dg-child-table td {
    border-bottom-color: rgba(255, 255, 255, 0.1);
  }

  .sb-dg-child-table input,
  .sb-dg-child-table select {
    border-color: rgba(255, 255, 255, 0.2);
  }
}

.sb-dg-child-row.is-deleted {
  opacity: 0.4;
  text-decoration: line-through;
}

.sb-dg-icon-btn {
  background: none;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.3rem;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: inherit;
}

@media (prefers-color-scheme: dark) {
  .sb-dg-icon-btn {
    border-color: rgba(255, 255, 255, 0.25);
  }
}

/* Active-customer scope banner (grids that declare CustomerKeyColumn, e.g. schedule-events).
   Mirrors the CRUD Workspace .crm-scope-banner look but self-contained - published pages
   don't load crm-shell.css. */
.sb-data-grid__scope {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  padding: 0.5rem 0.9rem;
  border: 1px solid #6366f1;
  border-radius: 0.5rem;
  background: #eef2ff;
  font-size: 0.85rem;
  color: #1f2430;
}

.sb-data-grid__scope--muted {
  border-color: #d9dee7;
  background: #f5f6f8;
}

.sb-data-grid__scope button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 700;
  color: #4f46e5;
  white-space: nowrap;
  cursor: pointer;
}

.sb-data-grid__scope button:hover {
  text-decoration: underline;
}

@media (prefers-color-scheme: dark) {
  .sb-data-grid__scope {
    border-color: #4c4fb0;
    background: rgba(99, 102, 241, 0.12);
    color: #e6e8f0;
  }
  .sb-data-grid__scope--muted {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.05);
  }
  .sb-data-grid__scope button {
    color: #a5b4fc;
  }
}
