$modal-icon-size: 6rem !default;
$modal-icon-animations: true !default;
$modal-icon-svg: true !default;
$modal-icon-font-family: inherit !default;
$modal-icon-font-size: $modal-icon-size * 0.6 !default;
$modal-icon-border-size: $modal-icon-size * 0.075 !default;
$modal-success: $green-500 !default;
$modal-error: $red-500 !default;
$modal-warning: $orange-500 !default;
$modal-info: $cyan-500 !default;
$modal-question: $teal-500 !default;
$modal-animation-delay: 0.5s !default;

// @link https://www.potlabicons.com/
$modal-success-icon: 'url("data:image/svg+xml,<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><style>@keyframes check {to {stroke-dashoffset:0;}}</style><circle cx="12" cy="12" r="8" stroke="#{$modal-success}" opacity="0.2" stroke-width="1.5"/><path stroke="#{$modal-success}" stroke-linecap="round" stroke-width="1.5" d="M9.215 12.052l1.822 1.805 3.748-3.714" style="animation:check 2s #{$modal-animation-delay} infinite cubic-bezier(.99,-.1,.01,1.02) alternate" stroke-dashoffset="100" stroke-dasharray="100"/></svg>")';
$modal-question-icon: 'url("data:image/svg+xml,<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><style>@keyframes jello {0%,to{transform:scale3d(1,1,1)}15%{transform:scale3d(1.25,.75,1)}20%{transform:scale3d(.75,1.25,1)}25%{transform:scale3d(1.15,.85,1)}32%{transform:scale3d(.95,1.05,1)}37%{transform:scale3d(1.05,.95,1)}}</style><circle cx="12" cy="12" r="8" stroke="#{$modal-question}" opacity="0.2" stroke-width="1.5"/><path fill="#{$modal-question}" d="M14.325 9.956c0 .298-.103.605-.308.924a3.726 3.726 0 01-.68.786c-.657.566-.987.983-.987 1.252 0 .595-.233.892-.7.892a.688.688 0 01-.531-.233c-.135-.156-.202-.365-.202-.627s.064-.506.191-.732c.135-.234.294-.44.478-.616.184-.184.368-.361.552-.531.453-.41.68-.782.68-1.115a.627.627 0 00-.277-.53.957.957 0 00-.615-.213.943.943 0 00-.606.212c-.17.135-.332.273-.488.414a.738.738 0 01-.51.202.614.614 0 01-.467-.19.68.68 0 01-.18-.468c0-.333.23-.669.69-1.009a2.47 2.47 0 011.518-.52c.722 0 1.31.202 1.763.605.452.404.679.903.679 1.497zm-2.697 4.449c.248 0 .443.081.584.244.142.156.213.35.213.584a.959.959 0 01-.245.637.787.787 0 01-.615.276.721.721 0 01-.574-.244.903.903 0 01-.201-.595c0-.234.078-.442.233-.626a.776.776 0 01.605-.276z" style="animation:jello 1.5s #{$modal-animation-delay} both infinite cubic-bezier(.69,.34,.09,.6);transform-origin:center"/></svg>")';
$modal-info-icon: 'url("data:image/svg+xml,<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><style>@keyframes info{0%,45%,68%,84%,100%{transform: translateY( 0% ) translateZ(0);animation-timing-function: cubic-bezier(.26,.77,.5,1);}60%{transform: translateY( -2px ) translateZ(0); animation-timing-function: cubic-bezier(.35,.02,.63,.7);}76%{transform: translateY( -0.5px ) translateZ(0);animation-timing-function: cubic-bezier(.35,.02,.63,.7);}92%{transform: translateY( -0.3px );animation-timing-function: cubic-bezier(.35,.02,.63,.7);}}</style><circle cx="12" cy="11" r="8" stroke="#{$modal-info}" opacity="0.2" stroke-width="1.5"/><circle r="0.8" cx="12" cy="8" fill="#{$modal-info}" style="animation:info 2s ease infinite both"/><path fill="#{$modal-info}" d="M12.9 15.1h.7l.2.2v.6l-.2.2h-2.7a.2.2 0 0 1-.2-.2v-.6l.2-.2h.7v-3.8H11a.2.2 0 0 1-.2-.2v-.6l.2-.2h1.7l.2.2v4.6z"/></svg>")';
$modal-warning-icon: 'url("data:image/svg+xml,<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><style>@keyframes warn{0%,to{transform:rotate(0deg);transform-origin:center}10%,90%{transform:rotate(2deg)}20%,40%,60%{transform:rotate(-6deg)}30%,50%,70%{transform:rotate(6deg)}80%{transform:rotate(-2deg)}}</style><path stroke="#{$modal-warning}" opacity="0.2" stroke-width="1.5" d="M11.134 6.844a1 1 0 011.732 0l5.954 10.312a1 1 0 01-.866 1.5H6.046a1 1 0 01-.866-1.5l5.954-10.312z"/><g style="animation:warn .8s #{$modal-animation-delay} cubic-bezier(.455,.03,.515,.955) both infinite"><path stroke="#{$modal-warning}" stroke-linecap="round" stroke-width="1.5" d="M12 10.284v3.206"/><circle cx="12" cy="15.605" r=".832" fill="#{$modal-warning}"/></g></svg>")';
$modal-error-icon: 'url("data:image/svg+xml,<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><style>@keyframes cross{90%,to{stroke-dashoffset:0;}}@keyframes cross2{0%,10% {stroke-dashoffset:100;}to{stroke-dashoffset:0;}}</style><line x1="9.5" y1="9.5" x2="14.5" y2="14.5" stroke="#{$modal-error}" stroke-width="1.5" stroke-linecap="round" style="animation:cross2 2s #{$modal-animation-delay} infinite cubic-bezier(.99,-.1,.01,1.02) alternate" stroke-dashoffset="100" stroke-dasharray="100"/><line x1="14.5" y1="9.5" x2="9.5" y2="14.5" stroke="#{$modal-error}" stroke-width="1.5" stroke-linecap="round" style="animation:cross 2s #{$modal-animation-delay} infinite cubic-bezier(.99,-.1,.01,1.02) alternate" stroke-dashoffset="100" stroke-dasharray="100"/><path stroke="#{$modal-error}" opacity="0.2" stroke-width="1.5" stroke-linecap="round" d="M19.994 14.753a1 1 0 01-.282.712l-4.007 4.134a1 1 0 01-.702.304l-5.756.09a1 1 0 01-.712-.281l-4.134-4.007a1 1 0 01-.304-.702l-.09-5.756a1 1 0 01.281-.712l4.007-4.134a1 1 0 01.702-.304l5.756-.09a1 1 0 01.712.281l4.134 4.007a1 1 0 01.304.702l.09 5.756z"/></svg>")';
@keyframes modal-animate-circle-icon {
  from {
    transform: scale(0);
  }
  to {
    transform: scale(1);
  }
}

// Without svg, we need dedicated animations
@if not $modal-icon-svg {
  // Question mark animation
  @keyframes modal-animate-question-mark {
    0% {
      transform: rotateY(-360deg);
    }

    100% {
      transform: rotateY(0);
    }
  }

  // Info and Warning mark animation
  @keyframes modal-animate-i-mark {
    0% {
      transform: rotateZ(45deg);
      opacity: 0;
    }

    25% {
      transform: rotateZ(-25deg);
      opacity: 0.4;
    }

    50% {
      transform: rotateZ(15deg);
      opacity: 0.8;
    }

    75% {
      transform: rotateZ(-5deg);
      opacity: 1;
    }

    100% {
      transform: rotateX(0);
      opacity: 1;
    }
  }

  // Error icon animations
  @keyframes modal-animate-error-x-mark {
    0% {
      margin-top: 1.625em;
      transform: scale(0.4);
      opacity: 0;
    }

    50% {
      margin-top: 1.625em;
      transform: scale(0.4);
      opacity: 0;
    }

    80% {
      margin-top: -0.375em;
      transform: scale(1.15);
    }

    100% {
      margin-top: 0;
      transform: scale(1);
      opacity: 1;
    }
  }

  @keyframes modal-animate-error-icon {
    0% {
      transform: rotateX(100deg);
      opacity: 0;
    }

    100% {
      transform: rotateX(0deg);
      opacity: 1;
    }
  }

  // Success icon animations
  @keyframes modal-animate-success-v-mark {
    0% {
      transform: scale(3);
      opacity: 0;
    }
    25% {
      transform: scale(2);
      opacity: 0.5;
    }
    100% {
      transform: scale(1);
      opacity: 1;
    }
  }
}

.modal-icon {
  --modal-color: #666;
  display: flex;
  position: relative;
  justify-content: center;
  width: $modal-icon-size;
  height: $modal-icon-size;
  margin: 0 auto;
  font-family: $modal-icon-font-family;
  line-height: $modal-icon-size;
  cursor: default;
  user-select: none;

  @if $modal-icon-svg {
    background-position: center;
    background-size: 120%; // Fix svg sizing
    border-radius: 0;
    border: 0;

    &.modal-icon-show {
      @if $modal-icon-animations {
        animation: modal-animate-circle-icon 0.5s;
      }
    }
  } @else {
    opacity: 0;

    &:before {
      border: $modal-icon-border-size solid transparent;
      border-radius: 50%;
      border-color: var(--modal-color);
      content: "";
      width: 100%;
      height: 100%;
      position: absolute;
      opacity: 0.2;
    }

    &:after {
      display: flex;
      align-items: center;
      font-size: $modal-icon-font-size;
      color: var(--modal-color);
    }

    &.modal-icon-show {
      opacity: 1;
    }
  }

  &.modal-error {
    --modal-color: #{$modal-error};
    @if $modal-icon-svg {
      &.modal-icon-show {
        background-image: escape-svg($modal-error-icon);
      }
    } @else {
      &:after {
        content: "✕";
      }

      // Error icon animation
      &.modal-icon-show {
        @if $modal-icon-animations {
          animation: modal-animate-error-icon 0.5s;

          &:after {
            animation: modal-animate-error-x-mark 0.5s;
          }
        }
      }
    }
  }

  &.modal-warning {
    --modal-color: #{$modal-warning};
    @if $modal-icon-svg {
      &.modal-icon-show {
        background-image: escape-svg($modal-warning-icon);
      }
    } @else {
      &:after {
        content: "!";
      }

      // Warning icon animation
      &.modal-icon-show {
        @if $modal-icon-animations {
          animation: modal-animate-error-icon 0.5s;

          &:after {
            animation: modal-animate-i-mark 0.5s;
          }
        }
      }
    }
  }

  &.modal-info {
    --modal-color: #{$modal-info};
    @if $modal-icon-svg {
      &.modal-icon-show {
        background-image: escape-svg($modal-info-icon);
      }
    } @else {
      &:after {
        content: "i";
      }

      // Info icon animation
      &.modal-icon-show {
        @if $modal-icon-animations {
          animation: modal-animate-error-icon 0.5s;

          &:after {
            animation: modal-animate-i-mark 0.8s;
          }
        }
      }
    }
  }

  &.modal-question {
    --modal-color: #{$modal-question};
    @if $modal-icon-svg {
      &.modal-icon-show {
        background-image: escape-svg($modal-question-icon);
      }
    } @else {
      &:after {
        content: "?";
      }
      &.modal-icon-show {
        @if $modal-icon-animations {
          animation: modal-animate-error-icon 0.5s;

          &:after {
            animation: modal-animate-question-mark 0.8s;
          }
        }
      }
    }
  }

  &.modal-success {
    --modal-color: #{$modal-success};
    @if $modal-icon-svg {
      &.modal-icon-show {
        background-image: escape-svg($modal-success-icon);
      }
    } @else {
      &:after {
        content: "✓";
      }

      // Success icon animation
      &.modal-icon-show {
        @if $modal-icon-animations {
          animation: modal-animate-circle-icon 0.5s;

          &:after {
            animation: modal-animate-success-v-mark 0.5s;
          }
        }
      }
    }
  }
}

.modal-dialog.modal-dialog-centered {
  // Centered modals should not fade down but scale instead
  .modal.fade & {
    transform: scale(0.8);
  }
  .modal.show & {
    transform: scale(1);
  }
  .modal.modal-static & {
    transform: $modal-scale-transform;
  }
}
