// stylelint-disable
:global {
  .react-datepicker-wrapper {
    display: inline-block;
    padding: 0;
    border: 0;
  }

  .react-datepicker {
    color: var(--color-text-body-primary);
    font-size: var(--size-font-sm);
    background-color: var(--color-background-primary);
    border-radius: var(--size-border-radius-sm);
    display: inline-block;
    position: relative;
  }

  .react-datepicker--time-only {
    .react-datepicker__triangle {
      left: 35px;
    }

    .react-datepicker__time-container {
      border-left: 0;
    }

    .react-datepicker__time,
    .react-datepicker__time-box {
      border-bottom-left-radius: 0.3rem;
      border-bottom-right-radius: 0.3rem;
    }
  }

  .react-datepicker__header {
    text-align: center;
    padding-top: 8px;
    position: relative;

    &--time {
      padding-bottom: 8px;
      padding-left: 5px;
      padding-right: 5px;

      &:not(&--only) {
        border-top-left-radius: 0;
      }
    }
  }

  .react-datepicker__year-dropdown-container--select,
  .react-datepicker__month-dropdown-container--select,
  .react-datepicker__month-year-dropdown-container--select,
  .react-datepicker__year-dropdown-container--scroll,
  .react-datepicker__month-dropdown-container--scroll,
  .react-datepicker__month-year-dropdown-container--scroll {
    display: inline-block;
    margin: 0 2px;
  }

  .react-datepicker__current-month,
  .react-datepicker-time__header,
  .react-datepicker-year-header {
    margin-top: 0;
    font-weight: bold;
  }

  .react-datepicker-time__header {
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
  }

  .react-datepicker__navigation {
    background: none;
    text-align: center;
    cursor: pointer;
    position: absolute;
    top: 12px;
    transition-duration: 0.2s;
    transition-property: border-color;
    width: 0;
    padding: 0;
    border-width: 2px 2px 0 0;
    border-style: solid;
    border-color: var(--color-text-body-tertiary);
    z-index: 1;
    height: 10px;
    width: 10px;
    text-indent: -999em;
    overflow: hidden;
    vertical-align: top;

    &--previous {
      left: 20px;
      transform: rotate(-135deg);
    }

    &--next {
      right: 20px;
      transform: rotate(45deg);

      &--with-time:not(&--with-today-button) {
        right: 105px;
      }
    }

    &--previous,
    &--next {
      &:hover {
        border-color: var(--color-text-body-primary);
      }

      &--disabled,
      &--disabled:hover {
        border-color: var(
          --date-picker-navigation-icon-color-disabled-hover,
          var(--color-brand-grey-50)
        );
        cursor: default;
      }
    }

    &--years {
      position: relative;
      top: 0;
      display: block;
      margin-left: auto;
      margin-right: auto;

      &-previous {
        top: 4px;
        border-top-color: var(--color-brand-grey-100);

        &:hover {
          border-top-color: var(--color-brand-grey-300);
        }
      }

      &-upcoming {
        top: -4px;
        border-bottom-color: var(--color-brand-grey-100);

        &:hover {
          border-bottom-color: var(--color-brand-grey-100);
        }
      }
    }
  }

  .react-datepicker__month-container {
    float: left;
  }

  .react-datepicker__year {
    margin: 0.4rem;
    text-align: center;
    &-wrapper {
      display: flex;
      flex-wrap: wrap;
      max-width: 180px;
    }
    .react-datepicker__year-text {
      display: inline-block;
      width: 4rem;
      margin: 2px;
    }
  }

  .react-datepicker__month {
    margin: 0.4rem;
    text-align: center;

    .react-datepicker__month-text,
    .react-datepicker__quarter-text {
      display: inline-block;
      padding: var(--size-spacing-xs);
      margin: 2px;
    }
  }

  .react-datepicker__time-container {
    float: right;
    border-left: 1px solid var(--color-border-separator);
    width: 85px;

    &--with-today-button {
      display: inline;
      border: 1px solid #aeaeae;
      border-radius: 0.3rem;
      position: absolute;
      right: -72px;
      top: 0;
    }

    .react-datepicker__time {
      position: relative;
      border-bottom-right-radius: 0.3rem;
      margin-top: var(--size-spacing-xs);

      .react-datepicker__time-box {
        width: 85px;
        overflow-x: hidden;
        margin: 0 auto;
        text-align: center;
        border-bottom-right-radius: 0.3rem;
        ul.react-datepicker__time-list {
          list-style: none;
          margin: 0;
          height: calc(195px + (1.7rem / 2));
          overflow-y: scroll;
          padding-right: 0px;
          padding-left: 0px;
          width: 100%;
          box-sizing: content-box;

          li.react-datepicker__time-list-item {
            height: 30px;
            padding: 5px 10px;
            white-space: nowrap;
            transition-duration: 0.2s;
            transition-property: background-color;

            &:hover {
              cursor: pointer;
              background-color: var(--color-background-secondary);
            }

            &--selected {
              background-color: var(--color-background-button-primary);
              color: var(--color-text-button-primary);
              font-weight: bold;

              &:hover {
                background-color: var(--color-background-button-primary-hover);
              }
            }

            &--disabled {
              color: var(--color-brand-grey-50);

              &:hover {
                cursor: default;
                background-color: transparent;
              }
            }
          }
        }
      }
    }
  }

  .react-datepicker__week-number {
    color: var(--color-brand-grey-100);
    display: inline-block;
    width: 1.7rem;
    line-height: 1.7rem;
    text-align: center;
    margin: 0.166rem;

    &.react-datepicker__week-number--clickable {
      cursor: pointer;

      &:hover {
        background-color: var(--color-brand-grey-100);
      }
    }
  }

  .react-datepicker__day-names,
  .react-datepicker__week {
    white-space: nowrap;
  }

  .react-datepicker__day-names {
    margin-top: var(--size-spacing-md);
  }

  .react-datepicker__day-name,
  .react-datepicker__day,
  .react-datepicker__time-name {
    display: inline-block;
    width: 2rem;
    line-height: 2rem;
    text-align: center;
    margin: 0 var(--size-spacing-2xs);

    &--outside-month {
      color: var(--color-text-body-tertiary);
    }
  }

  .react-datepicker__month,
  .react-datepicker__quarter {
    &--selected,
    &--in-selecting-range,
    &--in-range {
      background-color: var(--color-background-button-primary);
      color: var(--color-text-button-primary);

      &:hover {
        background-color: var(--color-background-button-primary-hover);
      }
    }

    &--disabled {
      color: var(--color-text-disabled);
      pointer-events: none;

      &:hover {
        cursor: default;
        background-color: transparent;
      }
    }
  }

  .react-datepicker__day,
  .react-datepicker__month-text,
  .react-datepicker__quarter-text,
  .react-datepicker__year-text {
    transition-duration: 0.2s;
    transition-property: background-color, color, border-radius;
    cursor: pointer;
    margin: var(--size-spacing-2xs);
    border-radius: var(--size-border-radius-lg);

    &:hover {
      border-radius: var(--size-border-radius-lg);
      background-color: var(--color-background-secondary);
    }

    &--today {
      font-weight: bold;
      border-radius: var(--size-border-radius-lg);
      background-color: var(--color-background-secondary);
    }

    &--outside-month {
      color: var(--color-text-body-tertiary);
    }

    &--highlighted,
    &--selected,
    &--in-selecting-range,
    &--in-range,
    &--keyboard-selected {
      border-radius: var(--size-border-radius-lg);
      background-color: var(--color-background-button-primary);
      color: var(--color-text-button-primary);

      &:hover {
        background-color: var(--color-background-button-primary-hover);
      }
    }

    &--in-selecting-range:not([class*='--in-range']) {
      background-color: var(--color-background-button-primary);
    }

    &--disabled {
      cursor: default;
      color: var(--color-text-disabled);

      &:hover {
        background-color: transparent;
      }
    }
  }

  .react-datepicker__month-text,
  .react-datepicker__quarter-text {
    &.react-datepicker__month--selected,
    &.react-datepicker__month--in-range,
    &.react-datepicker__quarter--selected,
    &.react-datepicker__quarter--in-range {
      &:hover {
        background-color: var(--color-background-button-primary-hover);
      }
    }
  }

  .react-datepicker__input-container {
    position: relative;
    display: inline-block;
    width: 100%;
  }

  .react-datepicker__year-read-view,
  .react-datepicker__month-read-view,
  .react-datepicker__month-year-read-view {
    border: 1px solid transparent;
    border-radius: var(--size-border-radius-lg);

    &:hover {
      cursor: pointer;

      .react-datepicker__year-read-view--down-arrow,
      .react-datepicker__month-read-view--down-arrow {
        border-top-color: var(--color-brand-grey-300);
      }
    }

    &--down-arrow {
      border-top-color: var(--color-brand-grey-100);
      float: right;
      margin-left: 20px;
      top: 8px;
      position: relative;
      border-width: 8px;
    }
  }

  .react-datepicker__year-dropdown,
  .react-datepicker__month-dropdown,
  .react-datepicker__month-year-dropdown {
    position: absolute;
    width: 50%;
    left: 25%;
    top: 30px;
    z-index: 1;
    text-align: center;
    border-radius: var(--size-border-radius-lg);
    border: 1px solid var(--color-brand-grey-100);

    &:hover {
      cursor: pointer;
    }

    &--scrollable {
      height: 150px;
      overflow-y: scroll;
    }
  }

  .react-datepicker__year-option,
  .react-datepicker__month-option,
  .react-datepicker__month-year-option {
    line-height: 20px;
    width: 100%;
    display: block;
    margin-left: auto;
    margin-right: auto;

    &:first-of-type {
      border-top-left-radius: var(--size-border-radius-lg);
      border-top-right-radius: var(--size-border-radius-lg);
    }

    &:last-of-type {
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
      border-bottom-left-radius: var(--size-border-radius-lg);
      border-bottom-right-radius: var(--size-border-radius-lg);
    }

    &:hover {
      background-color: var(--color-brand-grey-100);

      .react-datepicker__navigation--years-upcoming {
        border-bottom-color: var(--color-brand-grey-100);
      }

      .react-datepicker__navigation--years-previous {
        border-top-color: var(--color-brand-grey-100);
      }
    }

    &--selected {
      position: absolute;
      left: 15px;
    }
  }

  .react-datepicker__close-icon {
    cursor: pointer;
    background-color: transparent;
    border: 0;
    outline: 0;
    padding: 0px 6px 0px 0px;
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    display: table-cell;
    vertical-align: middle;

    &::after {
      cursor: pointer;
      background-color: var(--color-background-button-primary);
      color: #fff;
      border-radius: 50%;
      height: 16px;
      width: 16px;
      padding: 2px;
      font-size: 12px;
      line-height: 1;
      text-align: center;
      display: table-cell;
      vertical-align: middle;
      content: '\00d7';
    }
  }

  .react-datepicker__today-button {
    cursor: pointer;
    text-align: center;
    font-weight: bold;
    padding: 5px 0;
    clear: left;
  }

  .react-datepicker__portal {
    position: fixed;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.8);
    left: 0;
    top: 0;
    justify-content: center;
    align-items: center;
    display: flex;
    z-index: 2147483647;

    .react-datepicker__day-name,
    .react-datepicker__day,
    .react-datepicker__time-name {
      width: 3rem;
      line-height: 3rem;
    }

    // Resize for small screens
    @media (max-width: 400px), (max-height: 550px) {
      .react-datepicker__day-name,
      .react-datepicker__day,
      .react-datepicker__time-name {
        width: 2rem;
        line-height: 2rem;
      }
    }

    .react-datepicker__current-month,
    .react-datepicker-time__header {
      font-size: 1rem * 1.8;
    }

    .react-datepicker__navigation {
      border: 1.8 * 8px solid transparent;
    }

    .react-datepicker__navigation--previous {
      border-right-color: var(--color-brand-grey-100);

      &:hover {
        border-right-color: var(--color-brand-grey-300);
      }

      &--disabled,
      &--disabled:hover {
        border-right-color: var(--color-text-disabled);
        cursor: default;
      }
    }

    .react-datepicker__navigation--next {
      border-left-color: var(--color-brand-grey-100);

      &:hover {
        border-left-color: var(--color-brand-grey-300);
      }

      &--disabled,
      &--disabled:hover {
        border-left-color: var(--color-text-disabled);
        cursor: default;
      }
    }
  }
}
