//
// Base styles
//

.card {
  position: relative;
  display: block;
  margin-bottom: $card-spacer-y;
  background-color: $card-bg;
  border-radius: $card-border-radius;

  &.card-shadow {
    box-shadow: $card-box-shadow;
  }

  &.card-border {
    border: $card-border-width solid $card-border-color;
  }
}

.card-block {
  @include clearfix;
  padding: $card-padding;
  color: $gray-darker;

  & ~ .card-footer {
    padding-top: 0;
  }
}

.card-title {
  margin-bottom: $card-spacer-y;
}

.card-subtitle {
  margin-top: -($card-spacer-y / 2);
  margin-bottom: 0;
}

.card-text:last-child {
  margin-bottom: 0;
}

.card-link {
  + .card-link {
    margin-left: $card-spacer-x;
  }
}

//
// Optional textual caps
//

.card-header {
  @include clearfix;
  margin: 0;
  padding: $card-spacer-y $card-spacer-x;
  color: $card-cap-color;
  font-size: $card-cap-font-size;
  font-weight: $card-cap-font-weight;

  &:first-child {
    @include border-radius(
      $card-border-radius-inner $card-border-radius-inner 0 0
    );
  }
  & ~ .card-block {
    padding-top: 0;
  }
}

.card-footer {
  @include clearfix;
  margin: 0;
  padding: $card-spacer-y $card-spacer-x;
  color: $card-cap-color;
  font-size: $font-size-h6;
  font-weight: $card-cap-font-weight;

  &:last-child {
    @include border-radius(
      0 0 $card-border-radius-inner $card-border-radius-inner
    );
  }
}

//
// Header navs
//

.card-header-tabs {
  margin-right: -($card-spacer-x / 2);
  margin-bottom: -$card-spacer-y;
  margin-left: -($card-spacer-x / 2);
  border-bottom: 0;

  .nav-item {
    margin-bottom: 0;
  }
}

.card-header-pills {
  margin-right: -($card-spacer-x / 2);
  margin-left: -($card-spacer-x / 2);
}

// Remove all backgrounds
.card-outline-primary {
  @include card-outline-variant($btn-primary-bg);
}

.card-outline-secondary {
  @include card-outline-variant($btn-secondary-border);
}

//
// Blockquote
//

.card-blockquote {
  padding: 0;
  margin-bottom: 0;
  border-left: 0;
}

// Card image
.card-img {
  max-width: 100%;

  @include border-radius(0.25rem);
}

.card-img-overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1.25rem;
}

// Card image caps
.card-img-top {
  max-width: 100%;

  @include border-radius(
    $card-border-radius-inner $card-border-radius-inner 0 0
  );
}

.card-img-bottom {
  max-width: 100%;

  @include border-radius(
    0 0 $card-border-radius-inner $card-border-radius-inner
  );
}

//
// Card set
//

@if $enable-flex {
  @include media-breakpoint-up(sm) {
    .card-deck {
      display: flex;
      flex-flow: row wrap;
      margin-right: -$card-deck-margin;
      margin-left: -$card-deck-margin;

      .card {
        flex: 1 0 0;
        margin-right: $card-deck-margin;
        margin-left: $card-deck-margin;
      }
    }
  }
} @else {
  @include media-breakpoint-up(sm) {
    $space-between-cards: (2 * $card-deck-margin);

    .card-deck {
      display: table;
      table-layout: fixed;
      border-spacing: $space-between-cards 0;

      .card {
        display: table-cell;
        width: 1%;
        vertical-align: top;
      }
    }

    .card-deck-wrapper {
      margin-right: (-$space-between-cards);
      margin-left: (-$space-between-cards);
    }
  }
}

//
// Card groups
//

@include media-breakpoint-up(sm) {
  .card-group {
    @if $enable-flex {
      display: flex;
      flex-flow: row wrap;
    } @else {
      display: table;
      width: 100%;
      table-layout: fixed;
    }

    .card {
      @if $enable-flex {
        flex: 1 0 0;
      } @else {
        display: table-cell;
        vertical-align: top;
      }

      + .card {
        margin-left: 0;
        border-left: 0;
      }

      // Handle rounded corners
      &:first-child {
        @include border-right-radius(0);

        .card-img-top {
          border-top-right-radius: 0;
        }

        .card-img-bottom {
          border-bottom-right-radius: 0;
        }
      }

      &:last-child {
        @include border-left-radius(0);

        .card-img-top {
          border-top-left-radius: 0;
        }

        .card-img-bottom {
          border-bottom-left-radius: 0;
        }
      }

      &:not(:first-child):not(:last-child) {
        border-radius: 0;

        .card-img-top,
        .card-img-bottom {
          border-radius: 0;
        }
      }
    }
  }
}

//
// Card
//

@include media-breakpoint-up(sm) {
  .card-columns {
    column-count: 3;
    column-gap: $card-columns-sm-up-column-gap;

    .card {
      display: inline-block;
      width: 100%; // Don't let them exceed the column width
    }
  }
}
