.Modal,
.Popup {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  height: 100%;
  z-index: @zindex-modal;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: 0;
}

.Modal {
  &.active {
    .Modal-dialog {
      opacity: @modal-show-opacity;
      transform: @modal-show-transform;
    }
  }
}

.Modal-dialog {
  position: relative;
  z-index: @zindex-modal;
  overflow: hidden;
  width: @modal-width;
  max-width: 90vw;
  border-radius: var(--radius-md);
  background: @modal-bg;
  opacity: @modal-opacity;
  transition: @modal-transition;
  transform: @modal-fade-transform;
  font-size: 15px;

  &[data-has-avatar='true'] {
    padding-top: 37px;
    overflow: visible;
    background-image:
      linear-gradient(to bottom, rgba(255, 255, 255, 75%) 0%, rgba(255, 255, 255, 75%) 120px),
      linear-gradient(to bottom, var(--brand-1) 0%, var(--color-fill-1) 120px);
  }
}

.Modal-avatar {
  background-image: var(--avatar),
    linear-gradient(-51deg, rgba(255, 255, 255, 50%) 0%, rgba(255, 255, 255, 80%) 100%),
    linear-gradient(-51deg, var(--brand-1) 0%, var(--brand-1) 100%);
  background-repeat: no-repeat;
  background-size: cover;
  box-shadow: 0 0 2px 0px var(--color-fill-1), 0 0 2px 0px var(--brand-1);
  box-sizing: border-box;
  border: 2px solid var(--color-fill-1);
  border-radius: 50%;
  width: 58px;
  height: 58px;
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -25%);
}

.Modal-header {
  position: relative;
  padding: 18px 20px 10px;
}

.Modal-body {
  padding: 18px 15px;

  .Modal-header + & {
    padding-top: 0;
  }
}

.Modal-footer {
  display: flex;

  .Btn--outline {
    padding-top: 10px;
    padding-bottom: 10px;
    border-width: 1px 0 0;
    border-color: var(--color-line-1);
    border-radius: 0;

    &:not(.Btn--primary) {
      color: var(--color-text-2);
    }
  }
}

.Modal-footer--h {
  &[data-variant='round'] {
    padding: 0 15px 18px;

    .Btn + .Btn {
      margin-left: @modal-btn-x-spacing;
    }
  }
  &[data-variant='outline'] {
    .Btn + .Btn {
      border-left-width: 1px;
    }
  }
  .Btn {
    flex: 1;
  }
}

.Modal-footer--v {
  flex-direction: column;
}

// Confirm
.Confirm {
  .Modal-body {
    text-align: center;
  }
}

// Popup
.Popup {
  align-items: flex-end;

  &.active {
    .Popup-dialog {
      opacity: 1;
      transform: translate3d(0, 0, 0);
    }
  }
}

.Popup-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.Popup-dialog {
  position: relative;
  z-index: @zindex-popup;
  overflow: hidden;
  width: 100%;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: @popup-bg;
  opacity: 0;
  transform: translate3d(0, 100%, 0);
  transition: 0.3s;

  &[data-bg-color="gray"] {
    background: var(--color-fill-2);
  }
  &[data-height="80"] {
    height: 80vh;
  }
  &[data-height="60"] {
    height: 60vh;
  }
  &[data-height="40"] {
    height: 40vh;
  }
}

.Popup-header {
  position: relative;
  padding: @popup-header-padding;
}

.Modal-title,
.Popup-title {
  margin: @popup-title-margin;
  color: @popup-title-color;
  font-size: @popup-title-font-size;
  font-weight: 500;
  text-align: center;
}

.Popup-subtitle {
  margin: @popup-subtitle-margin;
  color: @popup-subtitle-color;
  font-size: @popup-subtitle-font-size;
  font-weight: 400;
  text-align: center;
  margin-top: 3px;
}

.Popup[data-elder-mode='true'] {
  .Modal-title,
  .Popup-title {
    font-size: 23Px;
  }
  .Popup-close {
    font-size: 32Px;
  }
}

.Modal-close,
.Popup-close {
  position: absolute;
  right: 12px;
  color: @popup-close-color;
}

.Modal-close {
  top: 12px;
}

.Popup-title {
  min-height: 25Px;
}

.Popup-close {
  top: 18px;
}

.Popup-body {
  flex: 1;
  min-height: 0;

  &.overflow {
    max-height: @popup-max-height;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

.Popup-footer {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: @popup-footer-padding;
  padding-bottom: calc(9px + var(--safe-bottom));
  background: var(--color-fill-1);

  .Btn + .Btn {
    margin-top: @popup-btn-y-spacing;
  }
}

.Popup-footer--h {
  flex-direction: row;

  .Btn + .Btn {
    margin-top: 0;
    margin-left: @popup-btn-x-spacing;
  }
}

.S--modalOpen,
.S--modalOpen .MessageContainer > .PullToRefresh {
  overflow: hidden;
}

.S--wide {
  .Popup {
    align-items: center;
  }
  .Popup-dialog {
    width: @popup-wide-width;
    border-radius: @modal-border-radius;
  }
  .Popup-footer--v {
    padding-bottom: 12px;
  }
}
