.chat-item {
  position: relative;
  display: flex;
  width: 100%;
  margin-bottom: 20px;

  &:first-of-type {
    margin-top: 20px;
  }

  &-box {
    flex: 1;
    padding: 0 12px;
    padding-right: 52px;
  }

  &-user-info {
    display: flex;
    column-gap: 4px;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--font-light);
    white-space: nowrap;

    .user-name:hover {
      color: var(--color-primary);
      cursor: pointer;
    }

    .user-badge {
      width: 18px;
      height: 18px;
      cursor: pointer;
      user-select: none;
    }

    .user-ip {
      user-select: none;
    }

    .send-time {
      display: inline-block;
      user-select: none;
      opacity: 0;
      transition: opacity 0.3s 1s;
    }
  }

  &-content {
    position: relative;
    width: fit-content;

    .text {
      min-height: 1em;
      padding: 8px 12px;
      font-size: 15px;
      line-height: 22px;
      color: var(--font-main);
      word-break: break-word;
      background-color: var(--background-2);
      border-radius: 2px 18px 18px;

      &-card {
        display: inline-flex;
        column-gap: 8px;
        width: 100%;
        padding: 10px 12px;
        margin: 4px 0;
        cursor: pointer;
        user-select: none;
        background-color: var(--background-1);
        border-radius: 4px;
        box-shadow: var(--el-box-shadow-light);

        &-link {
          margin-bottom: 6px;
          font-size: 12px;
          color: var(--color-light-1);

          &-content {
            display: inline-flex;
            flex-direction: column;
          }
        }

        &-image {
          min-width: 60px;
          max-width: 100%;
          min-height: 60px;
          max-height: 100%;

          &-wrapper {
            width: 60px;
            min-width: 60px;
            height: 60px;
            overflow: hidden;
            border-radius: 8px;
          }
        }

        &-title {
          font-size: 14px;
          color: var(--font-main);
        }

        &-desc {
          margin-top: auto;
          font-size: 12px;
          line-height: 1.5;
          color: var(--font-light);
        }

        &:hover {
          box-shadow: var(--el-box-shadow-lighter);
          opacity: 0.85;
        }
      }

      &-mention {
        font-weight: 500;
        color: var(--color-primary);
        cursor: pointer;
        border-radius: 4px;

        &:empty::before {
          content: '';
        }

        &:hover {
          opacity: 0.9;
        }
      }
    }

    .image {
      position: relative;
      width: auto;
      border-radius: 4px;

      img {
        width: 100%;
        height: 100%;
        border-radius: 4px;
      }

      &-slot {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-width: 70px;
        height: 100%;
        font-size: 12px;
        color: var(--color-light-1);
        vertical-align: middle;
        background: var(--background-2);
      }
    }

    .emoji {
      width: 128px;
      height: 128px;
      user-select: none;
    }

    .file {
      display: flex;
      align-items: center;
      padding: 8px;
      line-height: 1;
      color: var(--font-main);
      cursor: pointer;
      background-color: var(--background-2);
      border-radius: 12px;

      .file-desc {
        display: flex;
        flex-direction: column;
        margin: 0 12px 0 6px;

        .file-name {
          display: -webkit-box;
          max-width: 300px;
          margin-bottom: 2px;
          overflow: hidden;
          font-size: 13px;
          line-height: normal; // 修复文件名截断问题
          text-overflow: ellipsis;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }

        .file-size {
          font-size: 12px;
          color: var(--el-text-color-placeholder);
          user-select: none;
        }
      }

      &:hover {
        box-shadow: var(--el-box-shadow-light);
      }

      .icon-xiazai:hover {
        color: var(--color-primary) !important;
      }
    }

    .voice {
      display: flex;
      align-items: center;
      min-width: fit-content;
      max-width: 310px;
      padding: 8px 2px 8px 8px;
      line-height: 1;
      color: var(--font-main);
      cursor: pointer;
      user-select: none;
      background-color: var(--background-2);
      border-radius: 12px;

      .num {
        min-width: 2em;
      }

      .saying {
        position: relative;
        margin-right: 6px;
      }

      .shelter {
        position: absolute;
        top: 0;
        right: 0;
        z-index: 20;
        width: 0;
        height: 100%;
        background: var(--background-2);
      }

      .play {
        animation: scalein 1s ease-out infinite;
      }

      audio {
        display: none;
      }

      @keyframes scalein {
        0% {
          width: 100%;
        }

        10% {
          width: 65%;
        }

        39% {
          width: 65%;
        }

        40% {
          width: 45%;
        }

        69% {
          width: 45%;
        }

        70% {
          width: 0;
        }

        100% {
          width: 0;
        }
      }
    }

    .video {
      position: relative;
      width: auto;
      background-color: var(--background-2);
      border-radius: 4px;

      img {
        width: 100%;
        height: 100%;
        border-radius: 4px;
      }

      .icon-bofang {
        position: absolute;
        top: 50%;
        left: 50%;
        z-index: 10;
        color: var(--font-main);
        transform: translate(-50%, -50%);
      }

      &:hover {
        box-shadow: var(--el-box-shadow-light);

        .icon-bofang {
          color: var(--color-primary);
        }
      }
    }

    a {
      color: var(--color-primary);
    }
  }

  .uploading {
    .file {
      .icon-xiazai {
        display: none !important;
      }
    }
  }

  &-option {
    position: absolute;

    // display: none;
    top: -20px;
    right: 0;
    z-index: 999;
  }

  &-reply {
    display: flex;
    align-items: flex-start;
    width: fit-content;
    padding: 4px 12px;
    margin-top: 4px;
    margin-right: auto;
    overflow: hidden;
    font-size: 12px;
    color: var(--font-light);
    word-break: break-all;
    background-color: var(--background-3);
    border-radius: 8px;

    .icon-totop {
      color: var(--font-main);
    }

    &.pointer {
      cursor: pointer;
    }

    .ellipsis {
      display: -webkit-inline-box;
      text-overflow: ellipsis;
      -webkit-line-clamp: 4;
      -webkit-box-orient: vertical;
    }
  }

  &-read-count {
    position: absolute;
    bottom: 0;
    left: -50px;
    width: 40px;
    color: var(--color-primary);
    text-align: right;

    &.is-gray {
      color: var(--font-gray);
    }

    &-text {
      display: inline-block;
      padding: 1px 4px;
      font-size: 10px;
      line-height: 1;
      cursor: pointer;
      border: 1px solid currentcolor;
      border-radius: 8px;
      transform: scale(0.8);
    }
  }

  .extra {
    width: fit-content;
    margin-top: 4px;
    user-select: none !important;

    &-item {
      display: inline-flex;
      align-items: center;
      padding: 0 6px;
      cursor: pointer;
      background-color: var(--border-1);
      border: 1px solid var(--border-base);
      border-radius: 8px;

      .mallchat {
        line-height: 1;
        transition: transform 0.2s;
      }

      .count {
        margin: 0 4px 0 2px;
        font-size: 12px;
      }

      &:hover {
        .mallchat {
          transform: scale(1.1);
        }

        &.dlike .mallchat {
          transform: scale(0.9);
        }
      }
    }

    .active {
      &.like {
        color: var(--font-pink);
        border-color: var(--border-pink);
      }

      &.dlike {
        color: var(--font-light);
        border-color: var(--el-color-info);
      }
    }
  }
}

.right {
  flex-direction: row-reverse;

  .chat-item-user-info {
    justify-content: flex-end;

    .send-time {
      order: 0;
    }

    .user-badge {
      order: 1;
    }

    .user-name {
      order: 2;
    }

    .user-ip {
      order: 3;
    }
  }

  .chat-item-content {
    margin-left: auto;

    .text {
      border-radius: 18px 2px 18px 18px;
    }
  }

  .extra,
  .chat-item-reply {
    margin-right: 0;
    margin-left: auto;
  }
}

.chat-item:hover {
  .send-time {
    opacity: 1;
  }

  .chat-item-option {
    display: inline-flex;
  }
}

.send-time-block {
  display: inline-block;
  width: 100%;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--font-light);
  text-align: center;
  user-select: none;
}

.is-me {
  .chat-item-box {
    padding-right: 12px;
    padding-left: 52px;
  }

  .chat-item-content {
    display: flex;
    align-items: center;

    .icon-loading {
      margin: 0 8px;
    }

    .text {
      background-color: var(--color-primary);

      &-mention {
        color: #f1f1f1;
      }
    }

    a {
      color: #fff;
    }
  }
}

.fade-enter-leave,
.fade-enter-active {
  animation: fade 0.5s;
}

@keyframes fade {
  0% {
    transform: translateY(100%);
  }

  100% {
    transform: translateY(0);
  }
}

.count-up-enter-active,
.count-up-leave-active {
  transition: all 0.25s ease-out;
}

.count-up-enter-from {
  opacity: 0;
  transform: translateY(5px);
}

.count-up-leave-to {
  opacity: 0;
  transform: translateY(-5px);
}

.remove-enter-active,
.remove-leave-active {
  transition: opacity 0.12s, transform 0.12s, height 0.12s;
}

.remove-leave-to {
  height: 14px; // 防抖动的核心，与send-time-block真实高度一致
  opacity: 0;
  transform: scale(0);
}
