.message {
  display: flex;
  align-items: center;
  gap: var(--quaver);
  width: 100%;
  position: relative;

  /* top most message has margin to push messages down when not overflowing */
  &:first-child {
    margin-top: auto;
  }

  &.user {
    justify-content: end;
    & .message__text {
      background-color: var(--ib-lighter);
      color: var(--shw);
    }
  }

  &.user:not(:has(+ .user)) {
    margin-bottom: var(--crotchet);
  }

  &.user:not(:has(+ .user)) .message__text {
    border-bottom-right-radius: 0;
    &::after {
      content: "";
      position: absolute;
      bottom: 0;
      right: 0px;
      width: 0;
      height: 0;
      border: 8px solid transparent;
      border-top-color: var(--ib-lighter);
      border-bottom: 0;
      border-right: 0;
      margin-bottom: -8px;
    }
  }

  &.recipient {
    flex-direction: row-reverse;
    justify-content: start;
    & .message__text {
      background-color: var(--grey-200);
    }
  }

  &.recipient:not(:has(+ .recipient)) {
    margin-bottom: var(--crotchet);
  }

  &.recipient:not(:has(+ .recipient)) .message__text {
    border-bottom-left-radius: 0;
    &::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 0px;
      width: 0;
      height: 0;
      border: 8px solid transparent;
      border-top-color: var(--grey-200);
      border-bottom: 0;
      border-left: 0;
      margin-bottom: -8px;
    }
  }

  &:hover .message__button {
    opacity: 1;
  }
}

.message__content {
  display: inline-flex;
  max-width: min(80%, 600px);
  position: relative;
  flex-direction: column;
  gap: var(--quaver);
}

.message__content.user {
  align-items: end;
  margin-left: auto;
}

.message__content.recipient {
  align-items: start;
  margin-right: auto;
}

.message__text {
  display: inline-flex;
  position: relative;
  border-radius: var(--quaver);
  padding: var(--crotchet);
  margin: 0;

  &.user {
    background-color: var(--ib-lighter);
    color: var(--shw);
    border-bottom-right-radius: 0;
    margin-bottom: var(--minim);
  }

  &.user::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: 0px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-top-color: var(--ib-lighter);
    border-bottom: 0;
    border-right: 0;
    margin-bottom: -8px;
  }

  &.recipient {
    background-color: var(--grey-200);
    border-bottom-left-radius: 0;
    margin-bottom: var(--minim);
  }

  &.recipient::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-top-color: var(--grey-200);
    border-bottom: 0;
    border-left: 0;
    margin-bottom: -8px;
  }
}

.message__image {
  margin-top: var(--crotchet);
  object-fit: contain;
  max-width: 100%;
  max-height: 240px;

  &.fw {
    margin: 0 auto;
  }
}

.message__button {
  display: block;
  height: 24px;
  width: 24px;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 150ms ease-in-out;
  position: relative;
  background: transparent;
  border: none;
  cursor: pointer;

  &:hover {
    background-color: var(--grey-200);
  }
  &:active {
    background-color: var(--grey-300);
  }
}
/* vertical ellipsis button */
.vert-ellipsis {
  display: block;
  height: 4px;
  width: 4px;
  border-radius: 50%;
  background-color: var(--grey-600);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  &::before {
    transform: translate(0, -6px);
  }

  &::after {
    transform: translate(0, 6px);
  }

  &::before,
  &::after {
    content: "";
    display: block;
    height: 4px;
    width: 4px;
    border-radius: 50%;
    background-color: var(--grey-600);
    position: absolute;
  }
}

@media only screen and (max-width: 639px) {
  .message__button {
    position: absolute;
    height: auto;
    width: auto;
    border-radius: 0;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: transparent;
    z-index: 10;

    & > .vert-ellipsis {
      visibility: hidden;
    }

    &:hover,
    &:active {
      background: transparent;
    }
  }
}

.message__meta {
  font-style: italic;
}
