@import '../../core/stylesheets/variables.scss';
@import '../../core/stylesheets/mixins.scss';

$card-radius: 2px;

.md-card {
  overflow: auto;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  border-radius: $card-radius;
  box-shadow: $material-shadow-2dp;

  &.md-with-hover {
    cursor: pointer;
    transition: $swift-ease-out;
    transition-property: box-shadow;

    &:hover {
      z-index: 2;
      box-shadow: $material-shadow-8dp;
    }
  }

  .md-card-media {
    position: relative;

    &.md-16-9 {
      @include image-aspect-ratio(16, 9);
    }

    &.md-4-3 {
      @include image-aspect-ratio(4, 3);
    }

    &.md-1-1 {
      @include image-aspect-ratio(1, 1);
    }

    + .md-card-header {
      padding-top: 24px;
    }

    + .md-card-content:last-child {
      padding-bottom: 16px;
    }

    img {
      width: 100%;
    }
  }

  .md-card-header {
    padding: 16px;

    &:first-child {
      > .md-title:first-child,
      > .md-card-header-text > .md-title:first-child {
        margin-top: 8px;
      }
    }

    &:last-child {
      margin-bottom: 8px;
    }

    &.md-card-header-flex {
      display: flex;
      justify-content: space-between;
    }

    + .md-card-content {
      padding-top: 0;
    }

    + .md-card-actions:not(:last-child) {
      padding: 0 8px;
    }

    .md-avatar {
      margin-right: 16px;
      float: left;

      ~ .md-title {
        font-size: 14px;
      }

      ~ .md-title,
      ~ .md-subhead {
        font-weight: 500;
        line-height: 20px;
      }
    }

    .md-button {
      margin: 0;

      &:last-child {
        margin-right: -4px;
      }

      + .md-button {
        margin-left: 8px;
      }
    }

    .md-card-header-text {
      flex: 1;
    }

    .md-card-media {
      $size: 80px;

      width: $size;
      flex: 0 0 $size;
      height: $size;
      margin-left: 16px;

      &.md-medium {
        $size: 120px;

        width: $size;
        flex: 0 0 $size;
        height: $size;
      }

      &.md-big {
        $size: 160px;

        width: $size;
        flex: 0 0 $size;
        height: $size;
      }
    }
  }

  .md-subhead,
  .md-title,
  .md-subheading {
    margin: 0;
    font-weight: 400;
  }

  .md-subhead {
    opacity: .54;
    font-size: 14px;
    letter-spacing: .01em;
    line-height: 20px;

    + .md-title {
      margin-top: 4px;
    }
  }

  .md-title {
    font-size: 24px;
    letter-spacing: 0;
    line-height: 32px;
  }

  .md-card-media-actions {
    padding: 16px;
    display: flex;
    justify-content: space-between;

    .md-card-media {
      $size: 240px;

      max-width: $size;
      max-height: $size;
      flex: 1;
    }

    .md-card-actions {
      margin-left: 16px;
      flex-direction: column;
      justify-content: flex-start;
      align-items: center;

      .md-button + .md-button {
        margin: 8px 0 0;
      }
    }
  }

  .md-card-content {
    padding: 16px;
    font-size: 14px;
    line-height: 22px;

    &:last-child {
      padding-bottom: 24px;
    }
  }

  .md-card-actions {
    padding: 8px;
    display: flex;
    justify-content: flex-end;
    align-items: center;

    .md-button {
      margin: 0;

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

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

      + .md-button {
        margin-left: 4px;
      }
    }
  }

  .md-card-area {
    position: relative;
  }

  > .md-card-area:not(:last-child) {
    position: relative;

    &:after {
      height: 1px;
      position: absolute;
      bottom: 0;
      content: " ";
    }

    &:not(.md-inset):after {
      right: 0;
      left: 0;
    }

    &.md-inset:after {
      right: 16px;
      left: 16px;
    }
  }

  .md-card-media-cover {
    position: relative;
    color: #fff;

    &.md-text-scrim {
      .md-card-backdrop {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1;
      }
    }

    .md-card-area {
      position: absolute;
      right: 0;
      bottom: 0;
      left: 0;
      z-index: 2;
    }

    .md-card-header + .md-card-actions {
      padding-top: 0;
    }

    .md-subhead {
      opacity: 1;
    }
  }

  .md-card-expand {
    overflow: hidden;

    &.md-active {
      [md-expand-trigger] {
        transform: rotateZ(180deg) translate3D(0, 0, 0);
      }

      .md-card-content {
        margin-top: 0 !important;
        opacity: 1;
      }
    }

    .md-card-actions {
      padding-top: 0;
      position: relative;
      z-index: 2;
    }

    [md-expand-trigger] {
      transition: $swift-ease-out;
      will-change: transform;
    }

    .md-card-content {
      padding-top: 4px;
      position: relative;
      z-index: 1;
      opacity: 0;
      transform: translate3D(0, 0, 0);
      transition: $swift-ease-out;
      will-change: margin;
    }
  }
}
