:root {
  --van-popover-arrow-size: 6px;
  --van-popover-radius: var(--van-radius-lg);
  --van-popover-action-width: 128px;
  --van-popover-action-height: 44px;
  --van-popover-action-font-size: var(--van-font-size-md);
  --van-popover-action-line-height: var(--van-line-height-md);
  --van-popover-action-icon-size: 20px;
  --van-popover-horizontal-action-height: 34px;
  --van-popover-horizontal-action-icon-size: 16px;
  --van-popover-light-text-color: var(--van-text-color);
  --van-popover-light-background: var(--van-background-2);
  --van-popover-light-action-disabled-text-color: var(--van-text-color-3);
  --van-popover-dark-text-color: var(--van-white);
  --van-popover-dark-background: #4a4a4a;
  --van-popover-dark-action-disabled-text-color: var(--van-text-color-2);
}

.van-popover {
  position: absolute;
  overflow: visible;
  background-color: transparent;
  transition:
    opacity 0.15s,
    transform 0.15s;

  &__wrapper {
    display: inline-block;
  }

  &__arrow {
    position: absolute;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    border-width: var(--van-popover-arrow-size);
  }

  &__content {
    overflow: hidden;
    border-radius: var(--van-popover-radius);

    &--horizontal {
      display: flex;
      width: max-content;

      .van-popover__action {
        flex: none;
        width: auto;
        height: var(--van-popover-horizontal-action-height);
        padding: 0 var(--van-padding-sm);

        &:last-child::after {
          display: none;
        }

        &-icon {
          margin-right: var(--van-padding-base);
          font-size: var(--van-popover-horizontal-action-icon-size);
        }
      }
    }
  }

  &__action {
    position: relative;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    width: var(--van-popover-action-width);
    height: var(--van-popover-action-height);
    padding: 0 var(--van-padding-md);
    font-size: var(--van-popover-action-font-size);
    line-height: var(--van-line-height-md);
    cursor: pointer;

    &:last-child {
      .van-popover__action-text::after {
        display: none;
      }
    }

    &-text {
      display: flex;
      flex: 1;
      align-items: center;
      justify-content: center;
      height: 100%;
    }

    &-icon {
      margin-right: var(--van-padding-xs);
      font-size: var(--van-popover-action-icon-size);
    }

    &--with-icon {
      .van-popover__action-text {
        justify-content: flex-start;
      }
    }
  }

  &[data-popper-placement^='top'] {
    .van-popover__arrow {
      bottom: 0;
      border-top-color: currentColor;
      border-bottom-width: 0;
      margin-bottom: calc(var(--van-popover-arrow-size) * -1);
    }
  }

  &[data-popper-placement='top'] {
    transform-origin: 50% 100%;

    .van-popover__arrow {
      left: 50%;
      transform: translateX(-50%);
    }
  }

  &[data-popper-placement='top-start'] {
    transform-origin: 0 100%;

    .van-popover__arrow {
      left: var(--van-padding-md);
    }
  }

  &[data-popper-placement='top-end'] {
    transform-origin: 100% 100%;

    .van-popover__arrow {
      right: var(--van-padding-md);
    }
  }

  &[data-popper-placement^='left'] {
    .van-popover__arrow {
      right: 0;
      border-right-width: 0;
      border-left-color: currentColor;
      margin-right: calc(var(--van-popover-arrow-size) * -1);
    }
  }

  &[data-popper-placement='left'] {
    transform-origin: 100% 50%;

    .van-popover__arrow {
      top: 50%;
      transform: translateY(-50%);
    }
  }

  &[data-popper-placement='left-start'] {
    transform-origin: 100% 0;

    .van-popover__arrow {
      top: var(--van-padding-md);
    }
  }

  &[data-popper-placement='left-end'] {
    transform-origin: 100% 100%;

    .van-popover__arrow {
      bottom: var(--van-padding-md);
    }
  }

  &[data-popper-placement^='right'] {
    .van-popover__arrow {
      left: 0;
      border-right-color: currentColor;
      border-left-width: 0;
      margin-left: calc(var(--van-popover-arrow-size) * -1);
    }
  }

  &[data-popper-placement='right'] {
    transform-origin: 0 50%;

    .van-popover__arrow {
      top: 50%;
      transform: translateY(-50%);
    }
  }

  &[data-popper-placement='right-start'] {
    transform-origin: 0 0;

    .van-popover__arrow {
      top: var(--van-padding-md);
    }
  }

  &[data-popper-placement='right-end'] {
    transform-origin: 0 100%;

    .van-popover__arrow {
      bottom: var(--van-padding-md);
    }
  }

  &[data-popper-placement^='bottom'] {
    .van-popover__arrow {
      top: 0;
      border-top-width: 0;
      border-bottom-color: currentColor;
      margin-top: calc(var(--van-popover-arrow-size) * -1);
    }
  }

  &[data-popper-placement='bottom'] {
    transform-origin: 50% 0;

    .van-popover__arrow {
      left: 50%;
      transform: translateX(-50%);
    }
  }

  &[data-popper-placement='bottom-start'] {
    transform-origin: 0 0;

    .van-popover__arrow {
      left: var(--van-padding-md);
    }
  }

  &[data-popper-placement='bottom-end'] {
    transform-origin: 100% 0;

    .van-popover__arrow {
      right: var(--van-padding-md);
    }
  }

  &--light {
    color: var(--van-popover-light-text-color);

    .van-popover__content {
      background: var(--van-popover-light-background);
      box-shadow: 0 2px 12px rgba(50, 50, 51, 0.12);
    }

    .van-popover__arrow {
      color: var(--van-popover-light-background);
    }

    .van-popover__action {
      &:active {
        background-color: var(--van-active-color);
      }

      &--disabled {
        color: var(--van-popover-light-action-disabled-text-color);
        cursor: not-allowed;

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

  &--dark {
    color: var(--van-popover-dark-text-color);

    .van-popover__content {
      background: var(--van-popover-dark-background);
    }

    .van-popover__arrow {
      color: var(--van-popover-dark-background);
    }

    .van-popover__action {
      &:active {
        background-color: rgba(0, 0, 0, 0.2);
      }

      &--disabled {
        color: var(--van-popover-dark-action-disabled-text-color);

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

    .van-popover__action-text {
      &::after {
        border-color: var(--van-gray-7);
      }
    }
  }

  &-zoom-enter-from,
  &-zoom-leave-active {
    transform: scale(0.8);
    opacity: 0;
  }

  &-zoom-enter-active {
    transition-timing-function: var(--van-ease-out);
  }

  &-zoom-leave-active {
    transition-timing-function: var(--van-ease-in);
  }
}
