$dialog-close-height: 44px;

*:not(.is-dialog-open) {
  .dialog {
    .dialog_content {
      animation: dialogOut 300ms ease-in;
    }
  }
}

.dialog {
  -webkit-overflow-scrolling: touch; // sass-lint:disable-line no-vendor-prefixes

  &[aria-hidden='true'] {
    visibility: hidden;
    transition: visibility 300ms ease-out;
  }

  &:not([aria-hidden='true']) {
    visibility: visible;
    transition: visibility 300ms ease-out;
  }

  .dialog_header {
    border-bottom: 1px solid color(gray, plus3);
    align-items: center;
    justify-content: space-between;

    .dialog_title {
      font-weight: font-weight(normal);
      font-size: font-size(2);
    }
  }

  .dialog_body {
    overflow: auto;
  }

  .dialog_header,
  .dialog_buttons {
    display: flex;
    flex-shrink: 0;
  }

  .dialog_header,
  .dialog_body,
  .dialog_buttons {
    padding: ms(-5);
  }
}

.is-dialog-open {
  // Resolves iOS bug
  position: fixed;
  right: 0;
  left: 0;
  overflow: hidden;

  .dialog_blur {
    filter: blur(2px);
  }

  .dialog {
    .dialog_overlay {
      opacity: 1;
      transition: opacity 300ms ease-out;
    }

    .dialog_content {
      animation: dialogIn 500ms ease-out;
    }
  }
}

.dialog_overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  background-color: rgba(color(gray, plus4), 0.6);
  opacity: 0;
  transition: opacity 300ms ease-out;
}

.dialog_buttons {
  border-top: 1px solid color(gray, plus3);
  background: color(gray, plus5);
  justify-content: flex-end;
  align-items: center;
}

.dialog_content {
  @include z-depth(2);

  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 3;
  display: flex;
  overflow: hidden;
  overflow-y: auto;
  min-width: 95%;
  max-width: 990px;
  max-height: 90%;
  background-color: color(white);
  transform: translate(-50%, -50%);
  flex-flow: column;

  .dialog_close_container {
    flex-grow: 0;
    justify-content: center;
    align-items: center;
  }

  @include media('>=md') {
    min-width: 75%;
  }


  @include media('>=lg') {
    min-width: 40%;
  }
}

@keyframes dialogIn {
  from {
    opacity: 0;
    transform: translate(-50%, -70%);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

@keyframes dialogOut {
  from {
    opacity: 1;
    transform: translate(-50%, -50%);
  }

  to {
    opacity: 0;
    transform: translate(-50%, 0%);
  }
}

.dialog_close {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  padding: 0;
  width: $dialog-close-height;
  height: $dialog-close-height;
  border: none;
  background: transparent;
  cursor: pointer;
  justify-content: center;
  align-items: center;

  .icon {
    width: 1rem;
    height: 100%;
    color: color(black);
  }
}

.dialog_headerless {
  .dialog_header {
    @extend %visually-hidden;
  }

  .dialog_close {
    background: linear-gradient(to right, rgba(color(white), 0), color(white) 30%);
  }
}

.dialog_required {
  .dialog_close {
    display: none;
  }
}
