// File Upload
//================================================== //
.field-fileupload {
  input[type='text'] {
    padding-right: 56px;
    text-overflow: ellipsis;
  }

  .trigger,
  .trigger-close {
    cursor: pointer;
    display: inline-block;
    margin-left: -35px;
    outline: 0;
    text-align: center;
    width: 35px;

    &.trigger-close {
      color: $ids-color-palette-white;
      display: none;
      margin-left: -60px;
      border-radius: 8px;
      height: 28px;
      width: 28px;
      position: relative;
      top: -3px;

      &.is-visible {
        display: inline-block;
      }
    }

    &.trigger {
      height: 28px;
      width: 28px;
      border-radius: 8px;
      position: relative;
      top: 0;
    }

    .icon {
      color: $trigger-icon-fill-color;
      height: 18px;
      top: 5px;
      vertical-align: baseline;
      width: 18px;
      border-radius: 5px;
    }

    &:hover {
      .icon {
        background-color: transparent;
        color: $button-color-tertiary-hover-text-new;
      }
    }

    &:focus {
      outline: 1px solid $fileupload-border-focus-color;
    }

    &:active .icon {
      color: $trigger-active-color;
    }
  }

  .trigger-close .icon {
    height: 15px;
    top: 6px;
  }

  label {
    &.fileupload {
      display: inline-block;
    }
  }

  // Allows fileupload to be readonly without textarea readonly styling
  input {
    &.fileupload-background-transparent {
      background-color: $input-color-initial-background;
      border: 1px solid $input-default-border-color;
      color: $input-color;
      padding-right: 56px;
      text-overflow: ellipsis;

      &:focus {
        border-color: $ids-color-palette-azure-60;
      }

      &.readonly {
        background-color: $input-color-readonly-background;
        color: $input-readonly-color;
      }

      &[disabled] {
        background-color: $input-color-disabled-background;
        border-color: $input-disabled-color;
        color: $input-disabled-color;
      }
    }
  }

  // Make this flow offscreen
  label.fileupload input[type='file'],
  input.fileupload[type='file'] {
    left: 0;
    opacity: 0;
    position: absolute;
    z-index: -1;

    &:disabled + span:not(.audible),
    &:disabled + label.fileupload {
      svg {
        color: $input-color-disabled-border;
      }

      &:hover {
        svg {
          color: $input-color-disabled-border;
        }
      }
    }

    &:disabled + .trigger {
      cursor: default;
    }
  }
}

// File Upload Advanced
//================================================== //
.fileupload-wrapper {
  min-width: 335px;

  @include respond-to(phone) {
    min-width: inherit;

    &.standalone {
      border: 0;
      padding: 0;
    }

    .drop-area {
      text-align: center;

      .icon {
        display: block;
        float: none !important;
        margin: 0 auto !important;
      }
    }
  }

  &.standalone {
    padding: 25px 20px;
  }

  &.is-disabled {
    .container {
      border: 1px dashed $fileupload-disabled-border-color;

      &.drop-area {
        background-color: $fileupload-disabled-bg-color;
        color: $fileupload-disabled-color;

        .hyperlink,
        .fileupload-adv-browse-lbl {
          color: $fileupload-disabled-color;
          cursor: default;
        }

        .icon {
          color: $fileupload-disabled-icon-color;
          cursor: default;
        }

        &:hover {
          background-color: $fileupload-disabled-bg-color;
          border: 1px dashed $fileupload-disabled-border-color;
          color: $fileupload-disabled-color;

          .icon {
            color: $fileupload-disabled-icon-color;
            cursor: default;
          }
        }
      }
    }
  }

  .container {
    border: 1px dashed $fileupload-border-color;
    border-radius: 2px;
    margin-bottom: 10px;

    .btn-icon {
      height: 26px;
      margin-right: 4px;
      min-height: 26px;
      min-width: 26px;
      top: -2px;
      width: 26px;

      .icon {
        height: 13px;
        width: 13px;
      }
    }

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

    &::before,
    &::after {
      content: ' ';
      display: table;
    }

    &::after {
      clear: both;
    }

    &.drop-area {
      background-color: $fileupload-droparea-bg-color;
      color: $fileupload-droparea-color;
      padding: 25px 30px;
      text-align: center;

      .fileupload-adv-browse-lbl {
        color: $fileupload-primary-color;

        input[type='file'] {
          height: 0.1px;
          opacity: 0;
          overflow: hidden;
          width: 0.1px;
          z-index: -1;
        }
      }

      .icon {
        color: $fileupload-droparea-color;
      }

      p {
        color: $fileupload-primary-color;
        padding-top: 5px;
      }

      &:hover {
        background-color: $fileupload-droparea-hover-bg-color;
        color: $fileupload-droparea-hover-color;

        .icon {
          color: $fileupload-droparea-hover-icon-color;
        }
      }

      &.hover {
        background-color: $fileupload-droparea-dd-hover-bg-color;
        border-color: $fileupload-droparea-dd-hover-border-color;
        color: $fileupload-droparea-dd-hover-color;

        .icon {
          color: $fileupload-droparea-dd-hover-color;
        }
      }
    }

    .file-row,
    .progress-row {
      .status-icon,
      .description,
      .size,
      .action,
      .progress,
      .progress-bar {
        display: inline-block;
      }

      .description,
      .size {
        color: $fileupload-secondary-color;
        font-size: $ids-size-font-base;
        height: 34px;
        line-height: 34px;
        overflow: hidden;
        -o-text-overflow: ellipsis;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .status-icon {
        background-color: $fileupload-cancel-bg-color;
        border-radius: 50%;
        float: left;
        height: 16px;
        margin: 10px 10px 0;
        width: 16px;

        .btn-icon {
          height: 18px;
          left: -1px;
          margin: 0;
          min-height: 18px;
          min-width: 18px;
          top: -1px;
          width: 18px;

          .icon {
            margin-top: -3px;
          }
        }

        .icon {
          color: $fileupload-status-color;
          height: 10px !important;
          left: 3px;
          top: 2px;
          width: 10px;

          &.icon-error {
            top: -3px;
            left: 0;
            height: 18px !important;
            width: 18px;
          }
        }

        &:hover {
          background-color: $fileupload-cancel-hover-bg-color;
        }
      }

      .description {
        color: $fileupload-primary-color;
        max-width: calc(100% - 185px);
      }

      .size {
        color: $fileupload-secondary-color;
        line-height: 36px;
        margin-right: 42px;
        max-width: 115px;

        .percent {
          color: $fileupload-progress-color;
          font-weight: 800;
        }
      }

      .action {
        margin: 0 5px 0 10px;
        width: 16px;
      }

      &.file-row {
        .status-icon.file-error {
          background-color: transparent;
        }

        .l-pull-right .action {
          float: right;
          height: 16px;
          margin-top: 7px;

          .icon {
            color: $fileupload-secondary-color;
          }

          &:hover {
            .icon {
              color: $fileupload-hover-color;
            }
          }
        }
      }

      .progress {
        margin: 0 0 7px 33px;
        width: calc(100% - 65px);
      }
    }

    &.completed {
      border-color: $fileupload-completed-border-color;

      .status-icon {
        background-color: $fileupload-completed-color;

        &:hover {
          background-color: $fileupload-completed-color;
        }
      }

      .description {
        color: $fileupload-completed-color;
      }

      .size {
        margin-right: inherit;
      }
    }

    &.error {
      border-color: $fileupload-error-border-color;
      color: $fileupload-error-color;

      .status-icon {
        background-color: $fileupload-error-color;

        &:hover {
          background-color: $fileupload-error-hover-color;

          .icon {
            color: $fileupload-status-color;
          }
        }
      }

      // Area for each file error
      div.msg {
        clear: both;
        font-size: $ids-size-font-base;
        padding: $input-field-padding;
      }

      // Area for general error
      span.msg {
        display: inline-block;
        font-size: $ids-size-font-base;
        padding: 10px 10px 10px 0;
        width: calc(100% - 77px);
      }
    }
  }

  em {
    font-style: normal;
  }
}

// Overides
//================================================== //
.form-layout-compact {
  .field-fileupload {
    .trigger .icon {
      height: 14px;
      top: 3px;
      width: 14px;
    }

    .trigger-close {
      height: 20px;
      margin-left: -45px;
      top: 0;
      width: 20px;

      .icon {
        height: 14px;
        top: 3px;
      }
    }

    .trigger {
      height: 20px;
      margin-left: -27px;
      width: 20px;
    }
  }
}

// Firefox needs some hand-holding
.is-firefox {
  &.is-mac {
    .fileupload-wrapper {
      .container {
        .file-row,
        .progress-row {
          .status-icon {
            button {
              .icon {
                margin-top: 0;
              }
            }

            .icon {
              top: 3px;
            }
          }
        }
      }
    }
  }
}

// RTL Styles
html[dir='rtl'] {
  .field-fileupload {
    input[type='text'] {
      padding-left: 56px;
      padding-right: 8px;
    }

    .trigger {
      margin-right: -30px;
    }

    .trigger-close {
      margin-left: inherit;
      margin-right: -13px;
    }

    // Make this flow offscreen
    label.fileupload input[type='file'],
    input.fileupload[type='file'] {
      left: auto;
      right: -10000px;
    }
  }

  .fileupload-wrapper {
    .container {
      &.drop-area {
        .fileupload-adv-browse-lbl {
          text-align: center;
        }
      }

      &.completed {
        .file-row,
        .progress-row {
          .size {
            margin-left: 1px;
            margin-right: inherit;
          }
        }
      }

      .file-row,
      .progress-row {
        .progress {
          margin: 0 33px 7px 0;
        }

        .size {
          margin-left: 42px;
          margin-right: inherit;
        }

        .status-icon {
          float: right;

          .btn-icon {
            left: inherit;
            right: -1px;
          }

          .icon {
            left: inherit;
            right: 3px;
          }
        }

        &.file-row .l-pull-right .action {
          float: left;
        }
      }
    }
  }

  &.is-firefox {
    .form-layout-compact {
      .field-fileupload {
        .trigger,
        .trigger-close {
          top: -1px;
        }
      }
    }
  }
}
