// 888             888      888
// 888             888      888
// 888             888      888
// 888888  8888b.  88888b.  888  .d88b.  .d8888b
// 888        "88b 888 "88b 888 d8P  Y8b 88K
// 888    .d888888 888  888 888 88888888 "Y8888b.
// Y88b.  888  888 888 d88P 888 Y8b.          X88
//  "Y888 "Y888888 88888P"  888  "Y8888   88888P'

table {
  border-collapse: collapse;
  border-spacing: 0;
}

.hover-row {
  &:active,
  &:focus,
  &:hover {
    td,
    th {
      background-color: color(cyan, 80);
      cursor: pointer;
    }
  }
}

.table {
  font-variant-numeric: tabular-nums;
  width: 100%;

  tbody th {
    vertical-align: middle;
  }

  thead th {
    vertical-align: bottom;
  }

  th {
    text-align: left;
  }

  th,
  td {
    padding: $space-s;

    &.padding {
      padding: $space-m !important;
    }

    &.text-center,
    &.text-left,
    &.text-right {
      display: table-cell;
    }

    &.text-center {
      text-align: center;
    }

    &.text-right {
      text-align: right;
    }
  }
}

.table-bordered {
  th,
  td {
    border: $border-base;
  }
}

.table-button-cell {
  button,
  .button {
    border-color: color(white);
  }
}

.table-data {
  table-layout: fixed;

  th,
  td {
    border: $border-base;
  }

  thead {
    display: none;

    @include breakpoint(s) {
      display: table-header-group;
    }
  }

  tbody {
    tr {
      display: block;
      margin-bottom: $space-m;

      @include breakpoint(s) {
        display: table-row;
        margin-bottom: 0;
      }

      &:nth-child(even) {
        td,
        th {
          @include breakpoint(s) {
            background-color: $color-theme-base-background;
          }
        }
      }

      &:nth-child(odd) {
        td,
        th {
          @include breakpoint(s) {
            background-color: color(grey, 95);
          }
        }
      }

      &:active,
      &:focus,
      &:hover {
        &,
        &:nth-child(even),
        &:nth-child(odd) {
          td,
          th {
            background-color: color(cyan, 80);
            cursor: pointer;
          }

          th:first-child {
            background-color: $color-theme-dark-background-alt;

            @include breakpoint(s) {
              background-color: color(cyan, 80);
            }
          }
        }
      }

      &.has-warning {
        td,
        th {
          background-color: $color-state-warning-background;
          font-style: italic;
        }

        th:first-child {
          background-color: $color-state-warning-accent;

          @include breakpoint(s) {
            background-color: $color-state-warning-background;
          }
        }

        &:active,
        &:focus,
        &:hover {
          td,
          th {
            background-color: color(orange, 80);
          }

          th:first-child {
            background-color: $color-state-warning-accent;

            @include breakpoint(s) {
              background-color: color(orange, 80);
            }
          }
        }
      }
    }

    td,
    th {
      border-bottom-width: 0;
      border-top-width: 0;
      display: block;
      padding-top: 0;

      @include breakpoint(s) {
        border-bottom-width: 1px;
        border-top-width: 1px;
        display: table-cell;
        padding-top: $space-s;
      }

      &:first-child {
        border-top-width: 1px;
        padding-top: $space-s;
      }

      &:last-child {
        border-bottom-width: 1px;
      }
    }

    th:first-child {
      background-color: $color-theme-dark-background-alt;
      color: $color-theme-dark-text;
      padding-bottom: $space-s;

      @include breakpoint(s) {
        background-color: inherit;
        color: $color-theme-base-text;
      }

      + td {
        padding-top: $space-s;
      }
    }
  }

  .table-data-cell-s {
    @include breakpoint(s) {
      width: $space-xl;
    }
  }

  .table-data-cell-m {
    @include breakpoint(s) {
      width: $space-xxxl;
    }
  }

  .table-data-cell-l {
    @include breakpoint(s) {
      width: $space-xxxxxl;
    }
  }

  .table-data-cell-xl {
    @include breakpoint(s) {
      width: $space-xxxxxxl;
    }
  }

  .table-data-cell-xxl {
    @include breakpoint(s) {
      width: $space-xxxxxxxl;
    }
  }
}

.table-striped {
  tbody tr:nth-child(odd) {
    th,
    td {
      background-color: color(grey, 95);
    }
  }
}

.table-responsive {
  thead {
    display: none;
  }

  th,
  td {
    display: block;
    padding: $space-xs $space-s !important;
    text-align: left;
  }

  th {
    border-bottom-width: 0;
    margin-top: $space-s;
  }

  td {
    word-break: break-word;
  }

  @include breakpoint(s) {
    thead {
      display: table-header-group;
    }

    th,
    td {
      display: table-cell;

      &:first-child {
        padding-left: 0;
      }

      &:last-child {
        padding-right: 0;
      }
    }

    th {
      border-bottom-width: 1px;
    }
  }

  &.table-searches {
    th.table-spinner:last-child {
      padding: 0 !important;
    }
  }
}

.table-results-all {
  + .table-results-all {
    margin-top: $space-l;
  }

  table {
    border-bottom: $border-base;
  }
}
