data-table {
  width: 100%;
}

.table, table-body {
  width: 100%;
  display: table;
}

.table {
  margin-bottom: 0;

  th {
    @include brand-font-label();
    border-top: none;
    -webkit-font-smoothing: antialiased;
    text-transform: uppercase;
    padding: 0.45rem 0.75rem 0.25rem;
  }

  td, th {
    position: relative;

    &.hidden-column {
      display: none;
    }
  }

  td {
    padding: 0.75rem;
    font-size: 0.9rem;
  }

  thead th {
    border-bottom: none;
    font-family: $font-family-brand-light;
    font-size: 0.8125rem;
    white-space: nowrap;
  }

  tbody {
    tr:first-child td {
      padding-top: 0.75rem;
    }

    tr:last-child td {
      padding-bottom: 0.75rem;
    }

    tr:hover td {
      background: $gray-50;
    }

    tr {
      transition: transform ease-out 0.05s;
      position: relative;
    }

    tr.is-selected {
      transform: scale(1.025, 1.1);
      z-index: 100;
      box-shadow: inset 0 0 0 2px $blue-700;
      background-color: $white;

      &:hover td {
        background-color: transparent;
      }
    }
  }

  td, thead th {
    vertical-align: middle;

    i {
      font-size: 1.3em;
    }

    // This breaks tags inside of cells -- if it's needed, fix that too.
    // * {
    //   vertical-align: middle;
    // }
    &.hide-column {
      display: none;
    }
  }

  th:first-child, td:first-child {
    padding-left: 1.5rem;
  }

  &.is-scrolled {
    th:first-child, td:first-child {
      &:after {
        position: absolute;
        top: 0;
        right: 0;
        display: block;
        content: " ";
        width: 10px;
        height: 100%;
        box-shadow: 5px 0 8px 0 $shadow-lighter;
      }
    }
  }

  th:last-child, td:last-child {
    padding-right: 1.5rem;
  }
}

.table-container {
  margin: -2.8625rem -2.875rem 4rem;

  header {
    padding: 1.75rem 4rem 1.5rem;

    h2 {
      margin-bottom: 0.3em;
    }

    p {
      line-height: 1.5em;
      font-size: 0.875em;
      color: $gray-500;

      &:last-child {
        margin-bottom: 0;
      }
    }
  }

  td:first-child,
  th:first-child {
    padding-left: 4rem;
  }

  td:last-child,
  th:last-child {
    padding-right: 4rem;
  }

  footer {
    display: flex;
    padding: 1rem 2rem 1.25rem;
    background: $gray-25;
    border-top: solid 0.0625rem $gray-150;
    justify-content: space-between;
    align-items: center;
    min-height: 3.5rem;
    z-index: 4;

    p:last-child {
      margin-bottom: 0;
    }
  }
}

.table thead tr {
  background: $gray-100;

  a {
    color: $gray-700;
    text-decoration: none;

    .ico {
      font-size: 1.125em;
      color: $gray-500;
    }

    .ico.ico-caret-sort {
      color: $gray-300;
    }
  }
}

.table.cozy {
  td {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
  }
}

.table.compact {
  td {
    font-size: 90%;
    padding-top: 0.25rem !important;
    padding-bottom: 0.25rem !important;
  }
}

.table.spacious {
  td {
    padding-top: 1.125rem !important;
    padding-bottom: 1.125rem !important;
  }
}

selection-row input[type="checkbox"] {
  display: none;

  + label {
    display: block;

    &:before {
      content: "";
      width: 15px;
      height: 15px;
      display: block;
      border: solid 1px $gray-700;
      border-radius: 3px;
      margin: 0 auto;
      cursor: pointer;
      text-align: center;
    }
  }

  &:checked + label {
    &:before {
      content: "\2713";
      font-size: 13px;
      line-height: 14px;
      color: $white;
      background: $gray-500;
    }
  }
}

th input[type="checkbox"] {
  display: none;

  + label {
    display: block;

    &:before {
      content: "";
      width: 15px;
      height: 15px;
      display: block;
      border: solid 1px $gray-700;
      border-radius: 3px;
      margin: 0 auto;
      cursor: pointer;
      text-align: center;
    }
  }

  &:checked + label {
    &:before {
      content: "\2713";
      font-size: 13px;
      line-height: 14px;
      color: $white;
      background: $gray-500;
    }
  }
}

.tab-pane .table-container {
  margin-top: -2rem;
}

markdown table {
  @extend .table;
}

.card .table-container {
  margin: rem(-31) rem(-32) rem(-32);

  header, footer {
    padding-left: 2rem;
    padding-right: 2rem;
  }

  td:first-child,
  th:first-child {
    padding-left: 2.5rem;
  }

  td:last-child,
  th:last-child {
    padding-right: 2.5rem;
  }
};

td p, th p {
  margin-bottom: 0;
}

td ul, th ul {
  margin: 1rem 0;
}

.table-row-name {
  @extend .mb-0;
}

// Primary Column

.primary-column {
  padding-left: 0 !important;
  padding-right: 0 !important;

  .btn {
    padding: 3px;
  }
}

tr.is-disabled td {
  background-color: $gray-50;

  > *:not(.primary-column),
  .primary-column-text {
    opacity: .4;
  }

  .drag-drop-grip,
  .table-row-menu,
  .primary-column-menu {
    opacity: inherit;
  }

  .primary-column-menu {
    opacity: 0;
  }
}

// Icons in tables
.cell-with-icon {
  display: flex;
  flex-direction: row;

  .cell-icon {
    width: 2.75rem;
    flex: 1 0 2.75rem;
  }

  .cell-content {
    flex: 1 0 25.25rem;
    padding-top: 0.5rem;
    padding-bottom: 0.75rem;

    .badge {
      padding: 0.25rem 0.625rem 0.15rem;
      background-color: $gray-100;
    }
  }
}

// table-row-menu

.table-row-menu {
  opacity: 0;
  height: 2rem;

  .ico {
    font-size: 0.75rem;
  }
}

tr:hover .table-row-menu {
  opacity: 1;
}

// Extended Labels
td .extended-label {
  padding-top: 0.75rem;

  label {
    display: block;
    padding-left: 0;
  }

  strong {
    display: block;
  }
}


// Cursors
th.sortable {
  cursor: pointer;
}

// RESPONSIVE TABLE
@include media-breakpoint-down(xxs) {
  .table-container {
    footer {

      .table-pagination {

        .pagination-arrows,
        .pagination-counter {
          margin-left: 0;
        }

        .pagination-arrows {
          white-space: nowrap;
        }
      }
    }
  }
}

@include media-breakpoint-down(sm) {
  .table-container {

    footer {
      display: block;

      > div {
        max-width: 100%;
      }
    }
  }
}

@include media-breakpoint-between(sm, sm) {
  .table-container .responsive-table {
    overflow: auto;

    table {
      tr {
        position: relative;

        &:hover {
          td:first-child {
            background: $gray-50;
          }
        }
      }

      th, td {
        white-space: nowrap;
      }

      th:first-child, td:first-child {
        background: inherit;
        left: 0;
        position: absolute;
        min-width: 14rem;
        z-index: 2;
      }

      th:first-child label {
        padding: 0;
      }

      td:first-child {
        background: $white;
        height: 2.8rem;

        &:hover {
          background: $gray-50;
        }
      }

      td:nth-child(2),
      th:nth-child(2) {
        padding-left: 15rem;
        z-index: 1;
      }
    }

    .hidden-row {
      th:first-child, td:first-child {
        position: relative;
      }
    }
  }

  .table.compact td:first-child {
    height: 1.8rem !important;
  }

  .table.spacious td:first-child {
    height: 3.4rem !important;
  }
}

// Drop shadow stylings
.is-scrolled {
  th:first-child, td:first-child {
    &:after {
      position: absolute;
      top: 0;
      right: 0;
      display: block;
      content: " ";
      width: 10px;
      height: 100%;
      box-shadow: 5px 0 8px 0 $shadow-lighter;
    }
  }
}


@include media-breakpoint-down(xs) {
  thead.original-table-header {
    > tr {
      position: absolute;
      top: -9999px;
      left: -9999px;

      > th {
        position: absolute;
        top: -9999px;
        left: -9999px;
      }
    }
  }

  .sticky-table-header {
    th {
      border: none;
      border-bottom: 1px solid $gray-100;
      position: relative;
      padding-left: 50% !important;
      white-space: normal;
      text-align: left;
      display: block;
      -webkit-box-sizing: content-box;
      -moz-box-sizing: content-box;
      box-sizing: content-box;
      min-height: 1em;
    }
  }

  .responsive-table {

    > table {
      > thead {
        > tr {
          > th {
            position: absolute;
            top: -9999px;
            left: -9999px;
          }
        }
      }

      > tbody {
        background-color: $body-bg;

        > tr {
          display: block;
          font-size: 1rem;
          margin: 2rem 1rem 0;

          &.hidden-row {
            margin-top: 0;
          }

          > td {
            @include clearfix;
            border: none;
            position: relative;
            padding-left: 32% !important;
            white-space: normal;
            text-align: left;
            display: block;
            box-sizing: content-box;
            min-height: 1em;
            overflow: hidden;
            text-overflow: ellipsis;

            &:first-child a {

              text-decoration: none;
            }

            &::before {
              @include brand-font-label();
              line-height: 1.57rem;
              color: $gray-500;
              content: attr(data-column);
              position: absolute;
              left: 6px;
              width: 25%;
              word-wrap: break-word;
              text-align: right;
            }
          }
        }
      }

      .table {
        &.cozy {
          td {
            min-height: 32px;
            padding-top: 0;
            padding-bottom: 0;
          }
        }
      }
    }
  }
}

.table-pagination {
  .input-group i {
    font-size: 0.5rem;
  }

  .pagination-select {
    label {
      display: inline;
    }

    select {
      display: inline;
      min-width: 4rem;

      &.form-control {
        width: auto;
      }
    }
  }

  .pagination-counter {
    margin-left: 2rem;
    font-size: 0.875em;
  }

  .pagination-arrows {
    display: inline;
    margin-left: 2rem;

    a {
      color: $gunmetal;
      padding: 2rem 0.5rem;

      i {
        font-size: 0.875rem;
      }
    }

    select {
      display: inline;
      min-width: 3.5rem;
      margin-right: 0.35rem;

      &.form-control {
        width: auto;
      }
    }
  }
}

table-card .card.table-container {
  margin: 0;

  header h3 {
    padding-top: 0.5rem;
    margin-bottom: 0.5rem;
  }
}

td .row-select {
  position: absolute;
  left: 37px;
}

th input.row-select--select-all {
  position: absolute;
  display: block;
  left: 37px;
}
