.t-theme-message {
  display: block;
  margin-top: 0.35em;
}

.t-theme-message:last-child {
  margin-top: 1.35em;
}

.t-theme-message[t-sender="currentUser"]:not(:last-child) {
  margin-right: 3em;
}

.t-theme-message[t-sender="other"]:not(:last-child) {
  margin-left: 3em;
}

.t-theme-message:not(:last-child) .t-theme-avatar {
  display: none;
}

.t-theme-message:last-child .t-theme-avatar {
  display: block;
}

.t-theme-message[t-sender="system"] {
  margin-top: 1.35em;
}

.t-theme-message[t-sender="system"] + .t-theme-message[t-sender="system"] {
  /* If there are multiple system messages then make the spacing between them a bit tighter */
  margin-top: 0.5em;
}

.t-theme-message:has(.t-reactions):has(+ .t-theme-message) {
  margin-bottom: 0.75em;
}

.t-theme-message .t-message-row {
  display: flex;
  align-items: center;
}

.t-theme-message[t-sender="currentUser"] .t-message-row {
  flex-direction: row-reverse;
}

.t-theme-message .t-message-body {
  white-space: normal;
  overflow: hidden;
  border-radius: 0.75em;
  border-width: 1px;
  border-style: solid;
  word-wrap: break-word;
  position: relative;
  display: inline-block;
  max-width: calc(100% - 6em - 0.25em - 0.25em);
  border-color: #ececec;
  background-color: #f7f7f7;
  color: #111;
  padding: 0.75em 1em;
}

.t-theme-message .t-message-body .t-theme-referenced-message {
  border-left: solid 2px;
  margin-bottom: 0.4em;
  font-size: 93%;
  padding: 0 0.55em;
}

/* change some styles if the message is by currentUser */
.t-theme-message[t-sender="currentUser"] .t-message-body {
  border-color: #007df9;
  background-color: #007df9;
  color: #fff;
  /* Space between avatar and the message */
  margin-right: 0.5em;
}

.t-theme-message[t-sender="other"] .t-message-body {
  /* Space between avatar and the message */
  margin-left: 0.5em;
}

.t-theme-message .t-message-body .t-message-content {
  display: contents;
  margin-top: 0.75em;
}

.t-theme-message
  .t-message-body:has(
    .t-theme-audio-block,
    .t-theme-voice-block,
    .t-theme-image-block,
    .t-theme-video-block,
    .t-theme-location-block
  ) {
  width: 100%;
}

/* If there's no sender, no referenced message, and the first content block type is neither text nor file, remove the top padding */
.t-theme-message
  .t-message-body:not(
    :has(
        .t-message-sender-name,
        .t-theme-referenced-message,
        .t-theme-text-block:first-child,
        .t-theme-file-block:first-child
      )
  ) {
  padding-top: 0;
}

/* If the first content block type is neither text nor file, add bottom margin to the message sender's name */
.t-theme-message
  .t-message-body:not(:has(.t-theme-text-block:first-child, .t-theme-file-block:first-child))
  .t-message-sender-name {
  margin-bottom: 0.75em;
}

.t-theme-message button[data-action] {
  border-radius: 0.375em;
  font-size: inherit;
  margin: 1px 0;
  padding: 0.25em 0.325em;
  cursor: pointer;
  transition:
    color 200ms ease-in-out,
    background-color 200ms ease-in-out,
    border 200ms ease-in-out;
}

.t-theme-message[t-sender="currentUser"] button[data-action] {
  color: #0761d1;
  background-color: white;
  border: 1px solid white;
}

.t-theme-message[t-sender="currentUser"]:enabled button[data-action]:hover,
.t-theme-message[t-sender="currentUser"]:enabled button[data-action]:active {
  color: inherit;
  background-color: transparent;
}

.t-theme-message[t-sender="currentUser"] button[data-action]:focus-visible {
  outline: white solid 2px;
  outline-offset: 2px;
}

.t-theme-message[t-sender="other"] button[data-action] {
  color: #111;
  background-color: transparent;
  border: 1px solid #525252;
}

.t-theme-message[t-sender="other"]:enabled button[data-action]:hover {
  color: white;
  background-color: #111;
  border: 1px solid #111;
}

.t-theme-message[t-sender="other"]:enabled button[data-action]:active {
  color: white;
  background-color: #404040;
  border: 1px solid #404040;
}

.t-theme-message[t-sender="other"] button[data-action]:focus-visible {
  outline: #525252 solid 2px;
  outline-offset: 2px;
}

.t-theme-message[t-sender="system"] button[data-action] {
  color: white;
  background-color: #007df9;
  border: 1px solid #007df9;
}

.t-theme-message[t-sender="system"]:enabled button[data-action]:hover {
  color: white;
  background-color: #0761d1;
  border: 1px solid #0761d1;
}

.t-theme-message[t-sender="system"]:enabled button[data-action]:active {
  color: white;
  background-color: #3291ff;
  border: 1px solid #3291ff;
}

.t-theme-message[t-sender="system"] button[data-action]:focus-visible {
  outline: #007df9 solid 2px;
  outline-offset: 2px;
}

.t-theme-message button[data-action]:disabled {
  background-color: gray;
  border-color: gray;
}

.t-theme-message .t-message-sender-name {
  font-size: 75%;
  font-weight: bold;
}

.t-theme-message .t-reactions {
  margin-top: 0.25em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25em;
}

.t-theme-message[t-sender="currentUser"] .t-reactions {
  justify-content: flex-end;
  margin-right: 0.75em;
}

.t-theme-message[t-sender="other"] .t-reactions {
  margin-left: 3.75em;
}

.t-theme-message[t-sender="system"] .t-message-body {
  background: transparent;
  width: 100%;
  max-width: none;
  border: none;
}

.t-theme-message[t-sender="system"] .t-message-row {
  white-space: normal;
  border-radius: 0.75em;
  overflow: hidden;
  white-space: pre-wrap;
  background-color: transparent;
  color: #111;
  border: 1px solid #d4d4d4;
}

.t-theme-message .t-message-action-menu-trigger {
  border: none;
  color: inherit;
  cursor: pointer;
  position: absolute;
  top: 0.58em;
  right: 0.58em;
  margin: -0.08em;
  z-index: 1;
  font-size: 120%;
  background: inherit;
  visibility: hidden;
}

.t-theme-message .t-message-row:hover .t-message-action-menu-trigger {
  visibility: visible;
}

.t-theme-message .t-action-menu-icon {
  width: 1.143em;
  height: 1.143em;
}

.t-theme-message .t-message-content a {
  color: currentColor;
}

.t-theme-message .t-message-status {
  display: inline-flex;

  font-size: 75%;

  float: right;
  margin-left: 2em;
  margin-top: 0.6em;
  opacity: 75%;

  min-width: 3.5ch;
  text-align: right;
}

.t-theme-message .t-message-loading-spinner {
  animation: spin 1.2s cubic-bezier(0.42, 0, 0.58, 1) infinite;
  width: 1em;
  height: 1em;
}

.t-theme-message .t-status-icon {
  margin-left: 0.25em;
  letter-spacing: -0.3rem;

  min-width: 1em;
}
