/*
 * Tables
 * @see https://designsystem.digital.gov/components/tables/
 * @source https://github.com/uswds/uswds/blob/develop/src/stylesheets/elements/_table.scss
 */

table {
  @include panel-margin;

  min-width: 100%;

  @include ie-only {
    border-collapse: separate;
  }

  th,
  td {
    &.table-cell--align-right {
      text-align: right;
    }

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

    &.table-cell--shrink {
      width: 1%;
    }

    &.table-cell--expand {
      width: 100%;
    }

    &.table-cell--hide-small {
      display: none;

      @include media($medium-screen) {
        display: table-cell;
      }
    }
  }

  thead {
    tr th {
      .sorting-direction {
        position: inherit;
        margin-right: -16px;
        width: 16px;

        .icon {
          height: 14px;
          width: 16px;
          margin: 0;
        }
      }
    }
  }

  tbody {
    tr {
      th,
      td {
        @include block-list-item;

        display: table-cell;
        white-space: nowrap;
        border-bottom-style: dashed;
        border-top: none;

        &:last-child {
          border-bottom-style: dashed;
        }
      }

      &:last-child {
        td,
        th {
          border-bottom-style: solid;
        }
      }
    }
  }

  thead {
    tr {
      th,
      td {
        @include block-list-header;

        display: table-cell;
        white-space: nowrap;
      }
    }
  }

  @at-root .panel #{&} {
    tr:last-child td {
      border-bottom: 0;
    }

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

.responsive-table-wrapper {
  overflow-x: auto;

  @include panel-margin;

  .responsive-table-wrapper__header {
    @include panel-base;
    @include panel-theme-default;

    border-top: none;
    border-bottom: 0;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    padding: $gap * 2;

    .responsive-table-wrapper__title {
      @include h4;

      font-size: $lead-font-size;
      justify-content: space-between;
      flex: 2;
    }
  }

  table {
    margin-bottom: 0;
  }

  @at-root .panel #{&} {
    tr:last-child td {
      border-bottom: 0;
    }

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

.fixed-table-wrapper {
  width: 100%;

  table {
    max-width: 100%;
    table-layout: fixed;

    th,
    td {
      white-space: normal;
    }
  }
}
