/*
 * The sideways scroller under every wide admin table (public/js/tableScroll.js).
 *
 * The browser's own thin bar under a .table-responsive is hidden and replaced by
 * the theme's: a rounded track between two arrow buttons, pinned to the bottom of
 * the screen while any of the table is in view, so a long list scrolls sideways
 * without first scrolling down to its last row. Each edge of the table fades while
 * there are more columns that way.
 *
 * Loaded after style.css, whose .scroll-sm bar this takes over.
 */

.table-scroll {
  --table-scroll-shade: rgba(17, 24, 39, 0.12);
  --table-scroll-bar-height: 2.25rem;
  --table-scroll-bar-gap: 0.625rem;
  position: relative;
}

[data-theme=dark] .table-scroll {
  --table-scroll-shade: rgba(0, 0, 0, 0.45);
}

/* The native bar goes; a trackpad, Shift + wheel and touch still scroll the table.
   A box that also scrolls up and down (a max-height list) keeps the browser's. */
.table-scroll:not(.is-native) > .table-responsive {
  scrollbar-width: none;
}

.table-scroll:not(.is-native) > .table-responsive::-webkit-scrollbar {
  display: none;
}

/* ---- Edge fades: shown only on a side that has more columns ---- */
.table-scroll::before,
.table-scroll::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 2;
  width: 1.75rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.table-scroll.has-bar::before,
.table-scroll.has-bar::after {
  bottom: calc(var(--table-scroll-bar-height) + var(--table-scroll-bar-gap));
}

.table-scroll::before {
  left: 0;
  border-radius: 8px 0 0 8px;
  background: linear-gradient(to right, var(--table-scroll-shade), transparent);
}

.table-scroll::after {
  right: 0;
  border-radius: 0 8px 8px 0;
  background: linear-gradient(to left, var(--table-scroll-shade), transparent);
}

.table-scroll.can-scroll-start::before,
.table-scroll.can-scroll-end::after {
  opacity: 1;
}

/* ---- The bar ---- */
.table-scroll__bar {
  position: sticky;
  bottom: 0.75rem;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--table-scroll-bar-height);
  margin-top: var(--table-scroll-bar-gap);
  padding: 0 4px;
  background-color: var(--white);
  border: 1px solid var(--neutral-200);
  border-radius: 999px;
  user-select: none;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.table-scroll__bar[hidden] {
  display: none;
}

/* Pinned over the rows rather than sitting under the table: lift it off them. */
.table-scroll__bar.is-floating {
  border-color: var(--neutral-300);
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.16);
}

.table-scroll__btn {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text-secondary-light);
  background-color: transparent;
  border: 0;
  border-radius: 50%;
  transition: background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.table-scroll__btn:hover:not([aria-disabled='true']) {
  color: var(--primary-600);
  background-color: var(--primary-50);
}

.table-scroll__btn[aria-disabled='true'] {
  opacity: 0.35;
  cursor: default;
}

.table-scroll__btn:focus-visible {
  outline: 2px solid var(--primary-600);
  outline-offset: 2px;
}

/* The track fills the pill's height, so its ring is drawn inside the pill. */
.table-scroll__track:focus-visible {
  outline: 2px solid var(--primary-600);
  outline-offset: -2px;
}

/* The whole bar height takes clicks and drags; the rail drawn in it is thin. */
.table-scroll__track {
  position: relative;
  flex: 1 1 auto;
  align-self: stretch;
  min-width: 0;
  border-radius: 999px;
  cursor: pointer;
  touch-action: none;
}

.table-scroll__track::before {
  content: '';
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  height: 6px;
  margin-top: -3px;
  background-color: var(--neutral-200);
  border-radius: 999px;
}

.table-scroll__thumb {
  position: absolute;
  top: 50%;
  left: 0;
  height: 6px;
  margin-top: -3px;
  background-color: var(--primary-600);
  border-radius: 999px;
  cursor: grab;
  transition: height 0.15s ease, margin-top 0.15s ease;
}

.table-scroll__track:hover .table-scroll__thumb,
.table-scroll.is-dragging .table-scroll__thumb {
  height: 10px;
  margin-top: -5px;
}

.table-scroll.is-dragging .table-scroll__thumb {
  cursor: grabbing;
}
