.table-wrapper {
  width: 100%;

  .scroll-table {
    overflow-x: auto;
    width: 100%;
    padding: 0 4px 10px;
    margin: 0 -4px;
  }

  table {
    width: 100%;
    background-color: white;
    border-radius: 10px;
    border-collapse: collapse;
    box-shadow: 0px 2px 4px 0px var(--shadow);
    position: relative;

    &.actions {
      th:last-child, td:last-child {
        width: 40px;
        text-align: right;
        padding-right: 30px;
      }
    }
  }

  th {
    background-color: #F9FAFB;
    color: var(--text-dark);
    text-transform: uppercase;
    text-align: left;
    padding: 17px 30px;
    font-weight: 500;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;

    &:after {
      content: '';
      display: inline-block;
      width: 0;
      height: 0;
      margin-left: 5px;
      border-right: 6px solid transparent;
      border-left: 6px solid transparent;
    }

    &:first-child {
      border-top-left-radius: 10px;
    }

    &:last-child {
      border-top-right-radius: 10px;
    }

    &.asc, &.desc {
      color: var(--primary);
    }


    &[data-datasource-target="orderable"] {
      cursor: pointer;
      &.asc:after {
        content: "";
        display: inline-block;
        width: 0;
        height: 0;
        margin-left: 5px;
        vertical-align: middle;
        position: relative;
        bottom: 2px;
        border-top: 6px solid var(--primary);
      }

      &.desc:after {
        content: "";
        display: inline-block;
        width: 0;
        height: 0;
        margin-left: 5px;
        vertical-align: middle;
        position: relative;
        bottom: 2px;
        border-bottom: 6px solid var(--primary);
      }
    }

    &[data-sort-column] {
      cursor: pointer;

      &:hover {
        color: var(--primary);
      }

      &:after {
        content: '';
        display: inline-block;
        width: 0;
        height: 0;
        margin-left: 5px;
        vertical-align: middle;
        position: relative;
        bottom: 2px;
      }

      &.desc:after {
        border-top: 6px solid var(--primary);
      }

      &.asc:after {
        border-bottom: 6px solid var(--primary);
      }

    }
  }

  tr {
    &:hover {
      td {
        background-color: #F9FAFB;

        & > a {
          color: var(--primary);
        }
      }
    }
  }

  tr:last-child {
    td {
      &:first-child {
        border-bottom-left-radius: 10px;
      }

      &:last-child {
        border-bottom-right-radius: 10px;
      }
    }
  }

  td {
    border: none;
    border-top: 1px solid var(--gray-lightest);

    & > a, & > span {
      display: block;
      padding: 17px 30px;
      color: var(--text-dark); 
      text-decoration: none;
    }
  }

  footer {
    display: flex;
    justify-content: space-between;
  }

  nav.pagination {
    background-color: white;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--shadow);
    display: flex;
    gap: 4px;
    justify-content: space-between;

    .first, .last {
      display: none;
    }

    &.all-controls {
      .first, .last {
        display: flex;
      }
    }

    .page {
      a {
        width: 20px;
        display: block;
        text-align: center;
        color: var(--text-dark);
        border-radius: 5px;

        &:hover {
          background-color: var(--gray-lightest);
        }
      }
    }

    .page.current {
      min-width: 20px;
      padding: 0px 2px;
      display: block;
      text-align: center;
      background-color: var(--primary);
      color: white;
      border-radius: 5px;
      box-sizing: border-box;
    }

    .prev, .next {
      width: 18px;
      height: 18px;
      background-color: white;
      display: flex;
      border-radius: 3px;
      position: relative;

      a {
        flex: 1;
      }

      &:hover {
        background-color: var(--gray-lightest);
      }

      &:after {
        content: '';
        display: block;
        width: 7px;
        height: 7px;
        transform: rotate(-45deg);
        margin-top: 5px;
        margin-left: 5px;
        border-left: 1px solid var(--text-dark);
        border-top: 1px solid var(--text-dark);
        position: absolute;
        pointer-events: none;
        left: 2px;
      }

      &:empty {
        pointer-events: none;

        &:after {
          opacity: 0.2;
        }
      }
    }

    .next {
      &:after {
        transform: rotate(135deg);
        left: -2px;
      }
    }

    .last, .first {
      width: 18px;
      height: 18px;
      background-color: white;
      display: flex;
      border-radius: 3px;
      position: relative;

      a {
        flex: 1;
      }

      &:hover {
        background-color: var(--gray-lightest);
      }

      &:after, &:before {
        content: '';
        display: block;
        width: 7px;
        height: 7px;
        transform: rotate(-45deg);
        margin-top: 5px;
        margin-left: 5px;
        border-left: 1px solid var(--text-dark);
        border-top: 1px solid var(--text-dark);
        position: absolute;
        pointer-events: none;
        left: 4px;
      }

      &:before {
        transform: rotate(-45deg);
        left: 0px;
      }

      &:empty {
        pointer-events: none;

        &:after, &:before {
          opacity: 0.2;
        }
      }
    }

    .last {
      &:after, &:before {
        transform: rotate(135deg);
      }
      &:after {
        left: -4px;
      }
      &:before {
        left: 0px;
      }
    }
  }
}

[data-datasource-target~="table"] {
  &:empty {
    box-shadow: 0px 2px 4px 0px var(--shadow);
    background-color: white;
    padding: 50px 75px 35px;
    border-radius: 15px;
    display: block;
    margin-bottom: 50px;

    &:before {
      content: 'Select a table above to get started';
      display: block;
      padding: 0 0 15px;
      color: var(--text-lighter);
      font-style: italic;
      text-align: center;
    }
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

turbo-frame.table {
  position: relative;

  &[busy]:empty {
    width: 100%;
    background-color: white;
    border-radius: 10px;
    border-collapse: collapse;
    overflow: hidden;
    box-shadow: 0px 2px 4px 0px var(--shadow);
    min-height: 106px;
    display: block;
    background-image: linear-gradient(#F9FAFB 0%, #F9FAFB 52px, var(--gray-lightest) 53px, white 54px);

    &:after {
      opacity: 1 !important;
    }
  }

  &[busy] table {
    width: 100%;
    background-color: white;
    border-radius: 10px;
    border-collapse: collapse;
    overflow: hidden;
    box-shadow: 0px 2px 4px 0px var(--shadow);
    min-height: 106px;
    background-image: linear-gradient(#F9FAFB 0%, #F9FAFB 52px, var(--gray-lightest) 53px, white 54px);

    &:after {
      opacity: 1;
    }
  }

  table:after, &[busy]:empty:after {
    content: '';
    display: block;
    position: absolute;
    top: 12px;
    right: 12px;
    margin-left: -15px;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    border: 3px solid var(--text-lighter);
    border-top-color: transparent;
    animation: spin 1s linear infinite;
    transform: rotate(0deg);
    opacity: 0;
    transition: opacity 0.3s;
  }

}