$duration: 230ms;
$easing: cubic-bezier(0.32, 0.72, 0, 1);

.base-drawer {
  // Local portal target for `position="absolute"`. Fills the nearest
  // positioned ancestor without intercepting pointer events while closed.
  &__anchor {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
  }

  &__overlay {
    inset: 0;
    background-color: rgba(0, 0, 0, 0.4);
    opacity: calc(1 - var(--drawer-swipe-progress, 0));
    transition: opacity $duration $easing;

    &.base-drawer--fixed {
      position: fixed;
      z-index: 9999;
    }

    &.base-drawer--absolute {
      position: absolute;
      z-index: 10;
    }

    &[data-starting-style],
    &[data-ending-style] {
      opacity: 0;
    }

    &[data-swiping] {
      transition-duration: 0ms;
    }

    &[data-ending-style] {
      transition-duration: calc(var(--drawer-swipe-strength, 1) * 230ms);
    }
  }

  &__viewport {
    inset: 0;
    display: flex;
    pointer-events: none;

    &.base-drawer--fixed {
      position: fixed;
      z-index: 10000;
    }

    &.base-drawer--absolute {
      position: absolute;
      z-index: 11;
    }

    &.base-drawer--swipe-down {
      align-items: flex-end;
      justify-content: stretch;
    }

    &.base-drawer--swipe-up {
      align-items: flex-start;
      justify-content: stretch;
    }

    &.base-drawer--swipe-left {
      align-items: stretch;
      justify-content: flex-start;
    }

    &.base-drawer--swipe-right {
      align-items: stretch;
      justify-content: flex-end;
    }
  }

  &__content {
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    max-height: 100%;
    background-color: var(--uikit-bg-color-operate);
    overflow: hidden;
    outline: none;
    transition: transform $duration $easing;

    &.base-drawer--swipe-down,
    &.base-drawer--swipe-up {
      width: 100%;
      height: 80vh;
      height: 80dvh;
    }

    &.base-drawer--swipe-down {
      border-top-left-radius: 12px;
      border-top-right-radius: 12px;
      transform: translateY(var(--drawer-swipe-movement-y, 0px));

      &[data-starting-style],
      &[data-ending-style] {
        transform: translateY(100%);
      }
    }

    &.base-drawer--swipe-up {
      border-bottom-left-radius: 12px;
      border-bottom-right-radius: 12px;
      transform: translateY(var(--drawer-swipe-movement-y, 0px));

      &[data-starting-style],
      &[data-ending-style] {
        transform: translateY(-100%);
      }
    }

    &.base-drawer--swipe-left,
    &.base-drawer--swipe-right {
      height: 100%;
      width: min(80%, 320px);
    }

    &.base-drawer--swipe-left {
      border-top-right-radius: 12px;
      border-bottom-right-radius: 12px;
      transform: translateX(var(--drawer-swipe-movement-x, 0px));

      &[data-starting-style],
      &[data-ending-style] {
        transform: translateX(-100%);
      }
    }

    &.base-drawer--swipe-right {
      border-top-left-radius: 12px;
      border-bottom-left-radius: 12px;
      transform: translateX(var(--drawer-swipe-movement-x, 0px));

      &[data-starting-style],
      &[data-ending-style] {
        transform: translateX(100%);
      }
    }

    &[data-swiping] {
      transition-duration: 0ms;
    }

    &[data-ending-style] {
      transition-duration: calc(var(--drawer-swipe-strength, 1) * 230ms);
    }
  }

  &__header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    height: 48px;
    padding: 0 48px;
    border-bottom: 1px solid var(--uikit-stroke-color-primary);
  }

  &__title {
    max-width: 100%;
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    color: var(--uikit-text-color-primary);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  &__close {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--uikit-text-color-primary);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  &__body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  &__footer {
    flex-shrink: 0;
    border-top: 1px solid var(--uikit-stroke-color-primary);
  }
}
