.a11y-sortable-table {
  --a11y-sortable-table-border-color: hsl(220 13% 85%);
  --a11y-sortable-table-header-bg: hsl(220 20% 97%);
  --a11y-sortable-table-header-active-bg: hsl(220 95% 64%);
  --a11y-sortable-table-header-active-color: hsl(220 55% 13%);
  --a11y-sortable-table-state-accent-color: hsl(220 90% 38%);
  --a11y-sortable-table-row-hover-bg: hsl(42 45% 96%);
  --a11y-sortable-table-row-active-bg: hsl(220 45% 93%);
  --a11y-sortable-table-row-focus-bg: hsl(210 100% 93%);
  --a11y-sortable-table-row-selected-bg: hsl(154 46% 88%);
  --a11y-sortable-table-row-selected-focus-bg: hsl(154 52% 80%);
  --a11y-sortable-table-row-selected-accent-color: hsl(154 72% 24%);
  --a11y-sortable-table-cell-focus-bg: hsl(43 100% 88%);
  --a11y-sortable-table-cell-focus-ring: inset 0 0 0 3px hsl(220 90% 38%);
  --a11y-sortable-table-sort-active-cell-bg: hsl(220 95% 92%);
  --a11y-sortable-table-focus-ring: 3px solid hsl(220 90% 44%);
  --a11y-sortable-table-cell-padding: 0.75rem 1rem;
  --a11y-sortable-table-button-hover-bg: hsl(220 20% 92%);
  --a11y-sortable-table-sort-icon-color: hsl(220 80% 22%);

  --_border-color: var(--a11y-sortable-table-border-color);
  --_header-bg: var(--a11y-sortable-table-header-bg);
  --_header-active-bg: var(--a11y-sortable-table-header-active-bg);
  --_header-active-color: var(--a11y-sortable-table-header-active-color);
  --_state-accent-color: var(--a11y-sortable-table-state-accent-color);
  --_row-hover-bg: var(--a11y-sortable-table-row-hover-bg);
  --_row-active-bg: var(--a11y-sortable-table-row-active-bg);
  --_row-focus-bg: var(--a11y-sortable-table-row-focus-bg);
  --_row-selected-bg: var(--a11y-sortable-table-row-selected-bg);
  --_row-selected-focus-bg: var(--a11y-sortable-table-row-selected-focus-bg);
  --_row-selected-accent-color: var(--a11y-sortable-table-row-selected-accent-color);
  --_cell-focus-bg: var(--a11y-sortable-table-cell-focus-bg);
  --_cell-focus-ring: var(--a11y-sortable-table-cell-focus-ring);
  --_sort-active-cell-bg: var(--a11y-sortable-table-sort-active-cell-bg);
  --_focus-ring: var(--a11y-sortable-table-focus-ring);
  --_cell-padding: var(--a11y-sortable-table-cell-padding);
  --_button-hover-bg: var(--a11y-sortable-table-button-hover-bg);
  --_sort-icon-color: var(--a11y-sortable-table-sort-icon-color);

  width: 100%;
  border-collapse: collapse;
}

.a11y-sortable-table caption {
  margin-block-end: 0.75rem;
  font-weight: 700;
  text-align: start;
}

.a11y-sortable-table th,
.a11y-sortable-table td {
  padding: var(--_cell-padding);
  border-block-end: 1px solid var(--_border-color);
  text-align: start;
}

.a11y-sortable-table th {
  position: sticky;
  top: var(--_sticky-offset, 0px);
  z-index: 2;
  background: var(--_header-bg);
  font-weight: 700;
}

.a11y-sortable-table th[aria-sort="ascending"],
.a11y-sortable-table th[aria-sort="descending"] {
  color: var(--_header-active-color);
  background: var(--_header-active-bg);
  box-shadow: inset 0 -0.1875rem 0 var(--_sort-icon-color);
}

.a11y-sortable-table tbody tr:hover > * {
  background: var(--_row-hover-bg);
}

.a11y-sortable-table tbody tr:active > * {
  background: var(--_row-active-bg);
}

.a11y-sortable-table tbody td[data-sort-active='true'] {
  background: var(--_sort-active-cell-bg);
  box-shadow: inset 0.1875rem 0 0 var(--_sort-icon-color);
}

.a11y-sortable-table tbody tr:focus-within > * {
  background: var(--_row-focus-bg);
}

.a11y-sortable-table tbody tr:focus-within > :first-child {
  box-shadow: inset 0.25rem 0 0 var(--_state-accent-color);
}

.a11y-sortable-table tbody tr[aria-selected='true'] > *,
.a11y-sortable-table tbody tr[data-selected='true'] > *,
.a11y-sortable-table tbody tr[data-a11y-sortable-table-selected='true'] > *,
.a11y-sortable-table tbody tr.is-selected > *,
.a11y-sortable-table tbody tr:has(input[data-a11y-sortable-table-row-select]:checked) > * {
  background: var(--_row-selected-bg);
}

.a11y-sortable-table tbody tr[aria-selected='true'] > :first-child,
.a11y-sortable-table tbody tr[data-selected='true'] > :first-child,
.a11y-sortable-table tbody tr[data-a11y-sortable-table-selected='true'] > :first-child,
.a11y-sortable-table tbody tr.is-selected > :first-child,
.a11y-sortable-table tbody tr:has(input[data-a11y-sortable-table-row-select]:checked) > :first-child {
  box-shadow: inset 0.25rem 0 0 var(--_row-selected-accent-color);
}

.a11y-sortable-table tbody tr[aria-selected='true']:focus-within > *,
.a11y-sortable-table tbody tr[data-selected='true']:focus-within > *,
.a11y-sortable-table tbody tr[data-a11y-sortable-table-selected='true']:focus-within > *,
.a11y-sortable-table tbody tr.is-selected:focus-within > *,
.a11y-sortable-table tbody tr:has(input[data-a11y-sortable-table-row-select]:checked):focus-within > * {
  background: var(--_row-selected-focus-bg);
}

.a11y-sortable-table tbody tr[aria-selected='true'] td[data-sort-active='true'],
.a11y-sortable-table tbody tr[data-selected='true'] td[data-sort-active='true'],
.a11y-sortable-table tbody tr[data-a11y-sortable-table-selected='true'] td[data-sort-active='true'],
.a11y-sortable-table tbody tr.is-selected td[data-sort-active='true'],
.a11y-sortable-table tbody tr:has(input[data-a11y-sortable-table-row-select]:checked) td[data-sort-active='true'] {
  box-shadow:
    inset 0.1875rem 0 0 var(--_sort-icon-color),
    inset 0 -0.1875rem 0 var(--_row-selected-accent-color);
}

.a11y-sortable-table tbody th:focus-visible,
.a11y-sortable-table tbody td:focus-visible,
.a11y-sortable-table tbody td:focus-within {
  position: relative;
  z-index: 1;
  background: var(--_cell-focus-bg);
  box-shadow: var(--_cell-focus-ring);
}

.a11y-sortable-table__button:active {
  transform: translateY(1px);
}

.a11y-sortable-table [data-align='end'],
.a11y-sortable-table .a11y-sortable-table__cell--numeric {
  text-align: end;
}

.a11y-sortable-table th:has(.a11y-sortable-table__button) {
  padding: 0.25rem;
}

.a11y-sortable-table__button {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  cursor: pointer;
  text-align: start;
  white-space: nowrap;
  transition: background-color 160ms ease;
}

.a11y-sortable-table__button:hover {
  background: var(--_button-hover-bg);
}

.a11y-sortable-table th[aria-sort="ascending"] .a11y-sortable-table__button,
.a11y-sortable-table th[aria-sort="descending"] .a11y-sortable-table__button {
  background: transparent;
}

.a11y-sortable-table th[aria-sort="ascending"] .a11y-sortable-table__button:hover,
.a11y-sortable-table th[aria-sort="descending"] .a11y-sortable-table__button:hover {
  background: color-mix(in srgb, var(--_header-active-bg) 78%, white);
}

.a11y-sortable-table__button:focus-visible {
  outline: var(--_focus-ring);
  outline-offset: 0.125rem;
}

.a11y-sortable-table__icon {
  flex: 0 0 auto;
  inline-size: 1.25em;
  color: var(--_sort-icon-color);
  text-align: center;
}

.a11y-sortable-table__icon::before {
  content: "\2195";
}

.a11y-sortable-table th[aria-sort="ascending"] .a11y-sortable-table__icon::before {
  content: "\2191";
}

.a11y-sortable-table th[aria-sort="descending"] .a11y-sortable-table__icon::before {
  content: "\2193";
}

.a11y-sortable-table th[aria-sort="none"] .a11y-sortable-table__icon {
  opacity: 0.55;
}


@media (prefers-reduced-motion: reduce) {
  .a11y-sortable-table__button {
    transition: none;
  }

  .a11y-sortable-table__button:active {
    transform: none;
  }
}

@media (forced-colors: active) {
  .a11y-sortable-table th[aria-sort='ascending'],
  .a11y-sortable-table th[aria-sort='descending'],
  .a11y-sortable-table tbody td[data-sort-active='true'] {
    forced-color-adjust: none;
    background: Highlight;
    box-shadow: none;
    color: HighlightText;
  }

  .a11y-sortable-table__button:focus-visible {
    outline-color: ButtonText;
  }
}

/* ==========================================================================
   Sticky header — applied to <th> cells for consistent browser behaviour
   ========================================================================== */

.a11y-sortable-table th {
  position: sticky;
  top: var(--_sticky-offset, 0px);
  z-index: 2;
}

/* ==========================================================================
   Table wrapper — scroll container for sticky headers + responsive layout
   Public API:  --a11y-table-wrapper-*
   Internals:   --_*
   ========================================================================== */
.a11y-table-wrapper {
  --a11y-table-wrapper-max-height: 32rem;
  --a11y-table-wrapper-min-width: 42rem;
  --a11y-table-wrapper-border-color: hsl(220 13% 85%);
  --a11y-table-wrapper-radius: 0.5rem;
  --a11y-table-wrapper-shadow: none;
  --a11y-table-wrapper-background: Canvas;
  --a11y-table-sticky-offset: 0px;

  --_max-height: var(--a11y-table-wrapper-max-height);
  --_min-width: var(--a11y-table-wrapper-min-width);
  --_border-color: var(--a11y-table-wrapper-border-color);
  --_radius: var(--a11y-table-wrapper-radius);
  --_shadow: var(--a11y-table-wrapper-shadow);
  --_wrapper-bg: var(--a11y-table-wrapper-background);
  --_sticky-offset: var(--a11y-table-sticky-offset);

  max-width: 100%;
  max-height: var(--_max-height);
  overflow: auto;
  border: 1px solid var(--_border-color);
  border-radius: var(--_radius);
  background:
    linear-gradient(to right, var(--_wrapper-bg) 30%, hsl(0 0% 100% / 0%)),
    linear-gradient(to right, hsl(0 0% 100% / 0%), var(--_wrapper-bg) 70%) 100% 0,
    radial-gradient(farthest-side at 0 50%, hsl(220 13% 18% / 18%), transparent),
    radial-gradient(farthest-side at 100% 50%, hsl(220 13% 18% / 18%), transparent) 100% 0;
  background-attachment: local, local, scroll, scroll;
  background-repeat: no-repeat;
  background-size: 2rem 100%, 2rem 100%, 0.75rem 100%, 0.75rem 100%;
  box-shadow: var(--_shadow);
  -webkit-overflow-scrolling: touch;
}

.a11y-table-wrapper:focus-visible {
  outline: var(--_focus-ring, 3px solid currentColor);
  outline-offset: 0.25rem;
}

.a11y-table-wrapper .a11y-sortable-table {
  min-width: var(--_min-width);
  border: 0;
}

.a11y-table-wrapper .a11y-sortable-table th {
  --_sticky-offset: var(--_sticky-offset, 0px);
}

.a11y-table-scroll-hint {
  margin-block-end: 0.5rem;
  font-size: 0.875rem;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (min-width: 48rem) {
  .a11y-table-scroll-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .a11y-sortable-table *,
  .a11y-sortable-table *::before,
  .a11y-sortable-table *::after {
    animation-duration: 0.001ms;
    animation-iteration-count: 1;
    scroll-behavior: auto;
    transition-duration: 0.001ms;
  }
}

@media (forced-colors: active) {
  .a11y-sortable-table {
    --a11y-sortable-table-border-color: CanvasText;
    --a11y-sortable-table-header-bg: Canvas;
    --a11y-sortable-table-header-active-bg: Highlight;
    --a11y-sortable-table-header-active-color: HighlightText;
    --a11y-sortable-table-state-accent-color: ButtonText;
    --a11y-sortable-table-row-hover-bg: Canvas;
    --a11y-sortable-table-row-active-bg: Canvas;
    --a11y-sortable-table-row-focus-bg: Canvas;
    --a11y-sortable-table-row-selected-bg: Highlight;
    --a11y-sortable-table-row-selected-focus-bg: Highlight;
    --a11y-sortable-table-row-selected-accent-color: HighlightText;
    --a11y-sortable-table-cell-focus-bg: Canvas;
    --a11y-sortable-table-cell-focus-ring: inset 0 0 0 3px ButtonText;
    --a11y-sortable-table-sort-active-cell-bg: Highlight;
    --a11y-sortable-table-button-hover-bg: ButtonFace;
    --a11y-sortable-table-sort-icon-color: ButtonText;
  }

  .a11y-sortable-table th[aria-sort="ascending"],
  .a11y-sortable-table th[aria-sort="descending"],
  .a11y-sortable-table__button:hover,
  .a11y-sortable-table th[aria-sort="ascending"] .a11y-sortable-table__button,
  .a11y-sortable-table th[aria-sort="descending"] .a11y-sortable-table__button {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }

  .a11y-sortable-table tbody tr[aria-selected='true'] > *,
  .a11y-sortable-table tbody tr[data-selected='true'] > *,
  .a11y-sortable-table tbody tr[data-a11y-sortable-table-selected='true'] > *,
  .a11y-sortable-table tbody tr.is-selected > *,
  .a11y-sortable-table tbody tr:has(input[data-a11y-sortable-table-row-select]:checked) > * {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }

  .a11y-sortable-table tbody td[data-sort-active='true'] {
    forced-color-adjust: none;
    background: Highlight;
    box-shadow: inset 0.1875rem 0 0 HighlightText;
    color: HighlightText;
  }

  .a11y-sortable-table tbody tr:focus-within > :first-child,
  .a11y-sortable-table tbody tr[aria-selected='true'] > :first-child,
  .a11y-sortable-table tbody tr[data-selected='true'] > :first-child,
  .a11y-sortable-table tbody tr[data-a11y-sortable-table-selected='true'] > :first-child,
  .a11y-sortable-table tbody tr.is-selected > :first-child,
  .a11y-sortable-table tbody tr:has(input[data-a11y-sortable-table-row-select]:checked) > :first-child {
    box-shadow: inset 0.25rem 0 0 ButtonText;
  }

  .a11y-sortable-table tbody th:focus-visible,
  .a11y-sortable-table tbody td:focus-visible,
  .a11y-sortable-table tbody td:focus-within {
    forced-color-adjust: none;
    background: Canvas;
    box-shadow: inset 0 0 0 3px ButtonText;
    color: CanvasText;
  }

  .a11y-sortable-table__button:focus-visible,
  .a11y-table-wrapper:focus-visible {
    outline-color: CanvasText;
  }
}

@media print {
  .a11y-table-wrapper {
    max-height: none;
    overflow: visible;
    border: 0;
  }

  .a11y-table-wrapper .a11y-sortable-table,
  .a11y-sortable-table {
    min-width: 0;
  }

  .a11y-sortable-table th {
    position: static;
  }
}
