@use '../../00-settings/settings' as *;
@use '../../00-mixins/mixins' as *;

/* stylelint-disable no-descending-specificity */

div.responsive-table,
div.table-swiper-wrapper {
  position: relative;
  padding-bottom: 1.4rem;
  hyphens: auto;

  caption,
  .caption {
    @include theme('color', 'help-text-color', 'table-caption-color');
    @include small-text;
  }
}

div.responsive-table {
  @include focus-style;

  display: none;

  @include tablet {
    display: block;
    max-width: 100%;
  }

  table {
    caption-side: bottom;
    border-collapse: collapse;
    border-bottom: 1px solid coloring('gray', -5);

    th {
      @include semi-bold-text;

      font-size: .9rem;
    }

    td {
      font-size: .8rem;

      &:nth-of-type(n) {
        @include table-backgrounds;
      }
    }

    tr {
      &:nth-of-type(even) th:not([scope="col"]) th:not([scope="row"]),
      &:nth-of-type(even) td {
        @include theme('background-color', 'color-secondary-light', 'table-row-color');
      }

      &:nth-of-type(n) {
        @include table-backgrounds(td);
      }

      th {
        @include theme('background-color', 'color-secondary', 'table-header-color');
      }
    }

    // Tables with a thead should have the same color scheme.
    thead ~ tbody tr {
      [class*="cs--"] &:nth-of-type(even) th:not([scope="col"]),
      [class*="cs--"] &:nth-of-type(even) td {
        background-color: transparent;
      }

      &:nth-of-type(odd) th:not([scope="col"]),
      &:nth-of-type(odd) td {
        @include theme('background-color', 'color-secondary-light', 'table-row-color');
      }
    }

    th,
    td {
      @include theme('color', 'color-zero', 'table-content-color');

      padding: 20px;
      text-align: left;
    }

    caption {
      margin-top: 10px;
      text-align: right;
    }
  }
}

// Swiper styling for mobile.

$fixed-col-width: 130px;
$pag-nav-wrapper-size: 50px;

div.table-swiper-wrapper {
  display: block;
  width: 100%;

  @include tablet {
    display: none;
  }

  .table-swiper__fixed-column,
  .swiper-slide {
    padding-bottom: $pag-nav-wrapper-size;

    &::before,
    &::after {
      content: "";
      position: absolute;
      right: 0;
      left: 0;
      height: 1px;
      background-color: coloring('gray-light');
    }

    &::before {
      top: 0;
    }

    &::after {
      bottom: $pag-nav-wrapper-size;
    }
  }

  .table-swiper {
    display: flex;
    position: relative;
    width: 100%;
    overflow: hidden;

    dl,
    dt,
    dd {
      margin: 0;
    }

    dt,
    dd {
      display: block;
      width: 100%;
      padding: 20px;
    }

    .swiper {
      width: calc(100vw - #{$fixed-col-width} - 40px);
      margin-right: 0;
      margin-left: 0;
      padding-left: 0;
      overflow: hidden;
    }

    .swiper-wrapper {
      display: flex;
      box-sizing: border-box;
      width: 100%;
      margin: 0;
      padding: 0;
      gap: 0;
    }

    .swiper-slide {
      width: auto;
      max-width: 190px;  // = 360px - 2 x 20px - 130px (for fixed column).
      margin-right: -1px;
    }

    .swiper-pagination {
      top: calc(100% - $pag-nav-wrapper-size + 8px);
    }

    .swiper-pagination-bullet-active,
    .swiper-button-next,
    .swiper-button-prev {
      @include theme('color', 'color-primary');
    }

    .swiper-pagination-bullet {
      @include theme('background-color', 'bullet-inactive-color');

      width: 10px;
      height: 10px;
      margin: 0 7.5px;
      opacity: 1;
    }

    .swiper-pagination-bullet-active {
      @include theme('background-color', 'color-primary');
    }

    .swiper-button-next,
    .swiper-button-prev {
      top: calc(100% - $pag-nav-wrapper-size);
      height: $pag-nav-wrapper-size;
      margin-top: 0;

      &::after {
        display: none;
      }

      .icon {
        &::before {
          font-size: 1.6rem;
          line-height: $pag-nav-wrapper-size;
        }
      }
    }
  }

  .table-swiper__fixed-column {
    position: sticky;
    z-index: 2;
    left: 0;
    flex-shrink: 0;
    width: $fixed-col-width;
    pointer-events: none;

    &::after {
      content: "";
      position: absolute;
      z-index: 4;
      top: 0;
      bottom: $pag-nav-wrapper-size;
      left: 100%;
      width: 25px;
      height: auto;
      background: linear-gradient(90deg, rgba(2, 0, 36, .25) 0%, rgba(0, 0, 0, 0) 100%);
    }
  }

  dt {
    @include theme('background-color', 'color-secondary', 'table-header-color');
    @include theme('border-color', 'color-secondary', 'table-header-color');
    @include semi-bold-text;
  }

  dd {
    &:nth-of-type(n) {
      @include table-backgrounds;
    }
  }
}
