$card-padding: 16px !default;
$card-box-shadow: $whiteframe-shadow-1dp !default;

md-card {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  margin: $baseline-grid;

  box-shadow: $card-box-shadow;

  md-card-header {
    padding: $card-padding;
    display: flex;
    flex-direction: row;

    &:first-child {
      md-card-avatar {
       @include rtl-prop(margin-right, margin-left, 12px, auto);
      }
    }

    &:last-child {
      md-card-avatar {
        @include rtl-prop(margin-left, margin-right, 12px, auto);
      }
    }

    md-card-avatar {
      width: 40px;
      height: 40px;

      .md-user-avatar,
      md-icon{
        border-radius: 50%;
      }

      md-icon {
        padding: 8px;
        > svg {
          // Safari workaround for any SVG with padded parent
          height: inherit;
          width: inherit;
        }
      }

      & + md-card-header-text {
        max-height: 40px;

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

    md-card-header-text {
      display: flex;
      flex: 1;
      flex-direction: column;

      .md-subhead {
        font-size: 14px;
      }
    }
  }

  > img,
  > md-card-header img,
  md-card-title-media img {
    box-sizing: border-box;
    display: flex;
    flex: 0 0 auto;
    width: 100%;
    height: auto;
  }

  md-card-title {
    padding: 3 * $card-padding * 0.5 $card-padding $card-padding;
    display: flex;
    flex: 1 1 auto;
    flex-direction: row;

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

    md-card-title-text {
      flex: 1;
      flex-direction: column;
      display: flex;

      .md-subhead {
        padding-top: 0;
        font-size: 14px;
      }

      &:only-child {
        .md-subhead {
          padding-top: 3 * $card-padding * 0.25;
        }
      }
    }

    md-card-title-media {
      margin-top: - $card-padding * 0.5;

      .md-media-sm {
        height: 80px;
        width: 80px;
      }
      .md-media-md {
        height: 112px;
        width: 112px;
      }
      .md-media-lg {
        height: 152px;
        width: 152px;
      }
    }
  }

  md-card-content {
    display: block;
    padding: $card-padding;

    & > p {
      &:first-child {
        margin-top: 0;
      }

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

    .md-media-xl {
      height: 240px;
      width: 240px;
    }
  }

  md-card-actions {
    margin: $baseline-grid;

    &.layout-column {
      .md-button {
        &:not(.md-icon-button) {
          margin: $baseline-grid * 0.25 0;

          &:first-of-type {
            margin-top: 0;
          }

          &:last-of-type {
            margin-bottom: 0;
          }
        }

        &.md-icon-button {
          margin-top: 3 * $baseline-grid * 0.25;
          margin-bottom: 3 * $baseline-grid * 0.25;
        }
      }
    }

    md-card-icon-actions {
      flex: 1;
      justify-content: flex-start;
      display: flex;
      flex-direction: row;
    }

    &:not(.layout-column) .md-button {
      &:not(.md-icon-button) {
        margin: 0 $baseline-grid * .5;

        &:first-of-type {
          @include rtl-prop(margin-left, margin-right, 0, auto);
        }

        &:last-of-type {
          @include rtl-prop(margin-right, margin-left, 0, auto);
        }
      }

      &.md-icon-button {
        margin-left: 3 * $baseline-grid * 0.25;
        margin-right: 3 * $baseline-grid * 0.25;

        &:first-of-type {
          @include rtl-prop(margin-left, margin-right, 3 * $baseline-grid * 0.5, auto);
        }

        &:last-of-type {
          @include rtl-prop(margin-right, margin-left, 3 * $baseline-grid * 0.5, auto);
        }
      }

      & + md-card-icon-actions {
        flex: 1;
        justify-content: flex-end;
        display: flex;
        flex-direction: row;
      }
    }
  }

  md-card-footer {
    margin-top: auto;
    padding: $card-padding;
  }
}

@media screen and (-ms-high-contrast: active) {
  md-card {
    border: 1px solid #fff;
  }
}

.md-image-no-fill {
  > img {
    width: auto;
    height: auto;
  }
}

