.gin-table-scroll-wrapper {
  clear: both;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  margin-block-start: calc(var(--gin-spacing-xs) * -1);
}

table.gin--sticky-table-header {
  visibility: hidden;
  z-index: 97;
  position: sticky;
  inset-block-start: calc(var(--gin-toolbar-y-offset) + var(--gin-height-sticky) - 1px);
  width: auto !important;
  margin-block-start: calc(var(--gin-spacing-xs) * -1);
  overflow: hidden;

  tr {
    display: block;
    width: max-content;
  }
}

.gin-horizontal-scroll-shadow {
  background-image:
    linear-gradient(to right, var(--gin-bg-layer), var(--gin-bg-layer)),
    linear-gradient(to right, var(--gin-bg-layer), var(--gin-bg-layer)),
    linear-gradient(to right, rgba(0, 0, 0, .125), rgba(255, 255, 255, 0)),
    linear-gradient(to left, rgba(0, 0, 0, .125), rgba(255, 255, 255, 0));
  background-position: left center, right center, left center, right center;
  background-repeat: no-repeat;
  background-color: var(--gin-bg-layer);
  background-size: 24px 100%, 24px 100%, 12px 100%, 12px 100%;
  background-attachment: local, local, scroll, scroll;
}

table.sticky-header {
  inset-inline-start: auto !important;
  min-width: 100%;
  max-width: fit-content;
  background: transparent;
}

table.position-sticky,
table.sticky-header {
  thead {
    position: static;
  }

  &.--is-processed thead {
    pointer-events: none;

    tr {
      border-color: transparent;

      .sortable-heading.is-active > a::before {
        display: none;
      }
    }
  }
}

table {
  thead {
    background: transparent;
    border-radius: var(--gin-border-m);

    tr {
      border-block-end: 2px solid var(--gin-border-color-table-header);

      &:hover {
        background: transparent;
      }
    }
  }

  th {
    font-size: var(--gin-font-size-s);
    font-weight: var(--gin-font-weight-bold);
    background: var(--gin-bg-layer);

    &, .form-item__label {
      color: var(--gin-color-title);
    }

    @include mq(medium) {
      height: auto;
      padding: var(--gin-spacing-m);
    }
  }

  tbody {
    tr {
      border-block-end: 1px solid var(--gin-border-color-table);
    }

    td {
      height: auto;
      padding: var(--gin-spacing-density-m) var(--gin-spacing-m);
    }
  }

  tr,
  tr:focus-within,
  .draggable-table.tabledrag-disabled tr {
    color: var(--gin-color-text);
    background-color: transparent;

    &:hover {
      color: var(--gin-color-text);
      background: var(--gin-bg-item);
    }

    &.selected:hover {
      background: transparent;
    }
  }

  tr.selected {
    .gin--dark-mode & {
      border-color: rgba(white, .2);
    }

    td {
      background-color: var(--gin-bg-item-hover);
    }
  }

  td {
    a {
      text-decoration: none;

      &:hover {
        text-decoration: underline;
        text-decoration-style: var(--gin-link-decoration-style);
      }
    }

    .group-label {
      color: var(--gin-color-title);
    }
  }
}

.sortable-heading {
  padding: var(--gin-spacing-xs) var(--gin-spacing-m);

  > a::before {
    inset-block-end: -2px;
  }

  > a::after {
    background: var(--gin-color-text-light);
    mask-image: icon('sort');
    mask-repeat: no-repeat;
    mask-position: center center;

    @media (forced-colors: active) {
      background: linktext;
    }
  }

  &.is-active > a::before,
  > a:hover::before {
    width: 100%;
    inset-inline-start: 0;
  }

  > a:hover::before {
    border-block-end-width: 3px;
  }

  &.is-active > a {
    &, &:hover, &:active {
      color: var(--gin-color-primary-active);
    }

    &::before {
      background-color: var(--gin-bg-item);
      border-start-start-radius: var(--gin-border-s);
      border-start-end-radius: var(--gin-border-s);
      border-block-end: .1875rem solid var(--gin-color-primary-active);
    }
  }
}

.tablesort {
  background-color: var(--gin-color-primary-active);
  background-image: none;
  mask-image: icon('sort');
  mask-repeat: no-repeat;
  mask-position: 0 50%;
}

.tablesort--asc,
[dir="rtl"] .tablesort--asc {
  mask-image: icon('sort-asc');

  @media (forced-colors: active) {
    background: linktext;
  }
}

.tablesort--desc,
[dir="rtl"] .tablesort--desc {
  mask-image: icon('sort-desc');

  @media (forced-colors: active) {
    background: linktext;
  }
}

.field-plugin-settings-edit-wrapper {
  float: inline-end;

  + a {
    float: inline-start;
  }
}

.region-title {
  border-block-end: 2px solid var(--gin-color-text);
}

td.webform-has-field-suffix > .form-item > .form-element {
  max-width: 100%;
  width: auto;
}

.field-multiple-table {
  th {
    padding-block: var(--gin-spacing-xs);
    padding-inline: var(--gin-spacing-l) var(--gin-spacing-m);
    border-block-end: 0;
    background: transparent;

    &.th__order {
      font-size: 0;
      padding: 0;
    }
  }

  thead {
    th {
      background: var(--gin-bg-header);

      &:first-of-type {
        border-start-start-radius: var(--gin-border-m);
        border-end-start-radius: var(--gin-border-m);
      }
    }

    &:not(:has(th:last-of-type:not([style*="display: none"]))) th:nth-last-of-type(2),
    th:last-of-type:not([style*="display: none"]) {
      border-start-end-radius: var(--gin-border-m);
      border-end-end-radius: var(--gin-border-m);
    }

    tr {
      border-block-end: 0;
    }

    .field-label .label,
    .form-item__label--multiple-value-form {
      display: inline-block;
      font-size: var(--gin-font-size-l);
      font-weight: var(--gin-font-weight-bold);
      letter-spacing: -0.025em;
      line-height: 1.33333em;
      color: var(--gin-color-primary-active);
      padding: var(--gin-spacing-xs) 0;
      margin: 0;
    }
  }

  tr .form-item:not(:last-of-type) {
    margin-block-end: var(--gin-spacing-m);
  }

  // Fixes paragraphs extending beyond layout
  .ck.ck-toolbar.ck-toolbar_grouping>.ck-toolbar__items {
    flex-wrap: wrap;
  }
}

.gin-layer-wrapper .views-table {
  margin-block-start: 0;
}

table td.field-plugin-summary-cell {
  vertical-align: middle;
}

table .views-field.views-field-operations {
  text-align: end;
}
