.uploader:not(.uploader-expanded) {
  display: inline-block;
  min-width: 8rem;
  max-width: 12rem;
  max-height: 5rem;
  text-align: center;

  transition: max-height 600ms ease(in-out-quad),
    max-width 400ms ease(in-out-quad);

  .uploader_form,
  progress,
  .uploader_thumbs {
    @extend %hidden-from-everything;
  }
}

.uploader {
  .uploader-expanded {
    .required-suppressed::after {
      content: '';
    }
  }
}

.uploader-expanded {
  .uploader_thumbs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;

    &:empty {
      + .uploader_file-label {
        @extend %hidden-from-everything;
      }
    }

    img {
      margin-right: 1rem;
      margin-bottom: 0.5rem;
      height: 120px;
      vertical-align: top;
      pointer-events: none;
      user-select: none;
      object-fit: contain;
    }
  }

  .uploader_thumbs_wrapper {
    display: inline-flex;
    margin-top: 10px;
    align-items: center;
  }
}

.uploader {
  $add-another-size: 120px;

  &:not(.uploader-expanded) {
    .uploader_file-label {
      @extend %hidden-from-everything;
    }
  }

  &:not(.uploader-has-thumbs) {
    .uploader_thumbs_wrapper,
    .uploader_thumbs {
      @extend %hidden-from-everything;
    }
  }

  .uploader_file-label {
    &[disabled] {
      box-shadow: none;
      cursor: default;
      pointer-events: none;
      user-select: none;
    }
  }

  .uploader_file-label:not(.button-link) {
    display: flex;
    flex-direction: column;
    padding: padding(1);
    min-width: $add-another-size;
    width: $add-another-size;
    height: $add-another-size;
    border-style: dashed;
    text-align: center;
    font-size: font-size(-2);
    order: 99;
    align-self: center;
    align-items: center;
    justify-content: center;

    .text-with-icon {
      display: flex;
      flex-direction: column-reverse;
      text-transform: capitalize;
      line-height: 1.25;
    }

    .icon {
      margin: 0.1rem;
      font-size: 2.4rem;
    }
  }
}

.uploader_thumbs_remove-button,
.uploader_thumbs_remove-button:focus {
  position: relative;
  top: -0.7rem;
  left: -1.65rem;
  padding: 0.125rem;
  width: 24px;
  height: 24px;
  border: 1px solid color(gray, plus4);
  border-radius: 50%;
  background: color(white);
  color: color(error, darker);
  line-height: 1;

  @include z-depth(1);

  &:hover {
    @include z-depth(2);
    color: color(error);
  }
}

.uploader {
  $scrim-icon-fill: color(brand, catskillBlue);

  &.uploader-expanded {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: padding(3);
    min-height: 8rem;
    max-width: 100%;
    max-height: 100%;
    border: 2px dashed color(brand);
    border-radius: 3px;
    text-align: left;
    transition: border 600ms linear, max-height 600ms ease(in-out-quad),
      max-width 400ms ease(in-out-quad);
    justify-content: center;
    align-items: flex-start;

    .uploader_cta {
      @extend %hidden-from-everything;
    }

    .uploader_text {
      margin: 0;
      white-space: normal;
      animation: uploaderTextFadeIn 600ms linear;
    }

    @keyframes uploaderTextFadeIn {
      0% {
        width: 100vw;
        white-space: nowrap;
        opacity: 0;
      }
      1% {
        display: inherit;
        visibility: visible;
      }
      100% {
        width: auto;
        white-space: normal;
        opacity: 1;
      }
    }

    .scrim,
    .scrim_icon {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      z-index: -1;
      opacity: 0;
    }

    &.uploader-dragged-on {
      border: solid 2px color(brand, columbiaBlue);
      transition: border 300ms linear infinite;

      * {
        // Prevents dragover JS event from being fired nonstop.
        // See https://medium.com/@reiberdatschi/common-pitfalls-with-html5-drag-n-drop-api-9f011a09ee6c
        pointer-events: none;
      }

      .scrim {
        z-index: 1;
        background-color: rgba(color(brand, catskillBlue), 1);
        opacity: 1;
        animation: pulseOpacity 750ms ease(in-out-quad) infinite;
        animation-direction: alternate;
      }

      .scrim_icon {
        $icon-size: 8rem;

        z-index: 1;
        background-color: rgba(color(brand, catskillBlue), 0.6);
        background-image: url("data:image/svg+xml,%3Csvg width='276' height='226' viewBox='0 0 276 226' version='1' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23e8edf3' fill-rule='evenodd'%3E%3Cpath d='M190 33l31-12 55 151-150 54-5-12-14 7-7-15 9-5 3 7 125-64-65-124-17 9-6-9 28-14 13 27zm-60 176l2 5 131-48-48-132-20 8 55 107-120 60z'/%3E%3Cpath d='M78 129c-4 3-5 9-2 13l4 8 5 5-2 1c-2 1-5 0-7-2l-19-27a5 5 0 0 1 1-7l7-4c2-2 6-1 7 2l6 11zm82-18l-1-6-5-8c-3-5-8-6-13-4l-7-11c-1-3 0-6 2-7l7-4a5 5 0 0 1 7 2l14 31c1 2 0 5-2 6l-2 1zm-23-17l-55 32-6-11c-3-4-8-5-12-3L52 93c-2-3-1-6 1-8l62-36a6 6 0 0 1 8 3l10 20c-3 2-5 8-2 12l6 10zM0 80L138 0l80 139-138 80L0 80zm13 4l70 121 121-70-70-121L13 84zm71 5a3 3 0 1 0-3-6 3 3 0 0 0 3 6zm19-12a3 3 0 1 0-2-6 3 3 0 0 0 2 6zm8 17a3 3 0 1 0-2-6 3 3 0 0 0 2 6zm-17 10a3 3 0 1 0-2-6 3 3 0 0 0 2 6zm-12 27l59-34c3-2 7-1 8 2l5 9c2 3 1 6-2 8l-59 34c-3 2-7 1-8-2l-5-9c-2-3-1-6 2-8zm72-11l5-3 11 11a2 2 0 0 1-1 3c-1 1-3 1-4-1l-11-10zm-58 33l3 15c1 2 0 4-2 4a2 2 0 0 1-3-1l-3-15 5-3z'/%3E%3C/g%3E%3C/svg%3E");
        background-position: center center;
        background-size: $icon-size;
        background-repeat: no-repeat;
        content: '';
        opacity: 1;
        transition: opacity 300ms linear;
      }
    }

    &.uploader-max-files {
      .scrim_icon {
        background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg aria-labelledby='awrb-icon-circle-slash-desc awrb-icon-circle-slash-title' xmlns='http://www.w3.org/2000/svg' style='fill: %23e8edf3%3B' viewBox='0 0 16 16'%3E%3Ctitle id='awrb-icon-circle-slash-title'%3ECircle Slash%3C/title%3E%3Cdesc id='awrb-icon-circle-slash-desc'%3EA circle with a diagonal line through it%3C/desc%3E%3Cpath d='M8 14.868a6.823 6.823 0 01-4.526-1.717l9.573-9.794A6.838 6.838 0 0114.867 8 6.876 6.876 0 018 14.868M1.134 8A6.875 6.875 0 018 1.132c1.736 0 3.32.653 4.531 1.72l-9.574 9.795A6.834 6.834 0 011.133 8M8 .411C3.816.411.412 3.815.412 8c0 4.184 3.404 7.589 7.588 7.589S15.588 12.184 15.588 8C15.588 3.815 12.185.411 8 .411' fill-rule='evenodd'/%3E%3C/svg%3E");
      }
    }

    input {
      &[type='file'] {
        display: none;
      }
    }
  }

  &.uploader-has-thumbs {
    border-style: solid;
  }

  progress {
    &:not([value]),
    &[value='0'] {
      display: none;
      visibility: hidden;
    }

    &[value]:not([value='0']) {
      position: absolute;
      right: 0;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 10px;
      border: none;
      border-radius: 0;
      background-color: color(gray, plus3);
      color: color(brand, columbiaBlue);
      appearance: none;

      &::-webkit-progress-bar, // sass-lint:disable-line no-vendor-prefixes
      &::-moz-progress-bar {
        // sass-lint:disable-line no-vendor-prefixes
        background-color: color(gray, plus3);
      }

      &::-webkit-progress-value {
        // sass-lint:disable-line no-vendor-prefixes
        background-color: color(brand, catskillBlue);
        transition: width 500ms ease(out-quad);
      }
    }

    &[value='100'] {
      &::after {
        $color-fill: color(success);
        $icon-size: 2rem;

        position: absolute;
        top: -1 * $icon-size;
        right: 4px;
        display: block;
        width: $icon-size;
        height: $icon-size;
        background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg aria-labelledby='aprb-icon-check-desc aprb-icon-check-title' xmlns='http://www.w3.org/2000/svg' style='fill: %233d7733%3B' viewBox='0 0 16 16'%3E%3Ctitle id='aprb-icon-check-title'%3ECheck%3C/title%3E%3Cdesc id='aprb-icon-check-desc'%3EA check mark%3C/desc%3E%3Cpath d='M5.417 13a.44.44 0 01-.317-.134L1.129 8.782a.457.457 0 01.003-.64.441.441 0 01.63.005l3.66 3.763 8.821-8.78a.439.439 0 01.63.006.456.456 0 01-.006.638l-9.138 9.097a.439.439 0 01-.312.129' fill-rule='evenodd'/%3E%3C/svg%3E");
        background-position: center center;
        background-size: $icon-size;
        background-repeat: no-repeat;
        content: '';
      }

      &::-webkit-progress-value {
        // sass-lint:disable-line no-vendor-prefixes
        background-color: color(success);
        transition: background-color 200ms linear;
      }
    }
  }
}

.uploader.uploader-mobile {
  .uploader_thumbs {
    img {
      height: 64px;
    }

    .uploader_file-label {
      padding: 0.2rem;
      min-width: 72px;
      width: 72px;
      height: 72px;

      .icon {
        display: none;
        visibility: hidden;
      }
    }
  }
}

@keyframes pulseOpacity {
  from {
    opacity: 0.8;
  }

  to {
    opacity: 0.4;
  }
}
