#chat-messages {
  --chat-photo-max-width: min(21rem, 72vw);
  --chat-photo-max-height: min(20rem, 48dvh);
}

@media (min-width: 800px) {
  #chat-messages {
    --chat-photo-max-width: min(28rem, 54vw);
    --chat-photo-max-height: min(24rem, 42dvh);
  }
}

#chat-conversation .chat-message-row > .chat-message:has(> :is(.chat-media, .chat-mobile-album, .chat-video-tile)) {
  min-inline-size: min(100%, 8rem);
  padding: 0 0 6px;
}

#chat-messages .chat-message > :is(.chat-media, .chat-mobile-album, .chat-video-tile) {
  min-inline-size: 100%;
  margin-block: 0;
}

#chat-messages .chat-message > .chat-media {
  display: grid;
  align-items: start;
  gap: 4px;
}

#chat-messages .chat-message > .chat-media > .chat-media-photo {
  inline-size: min(var(--chat-photo-max-width), calc(var(--chat-photo-ratio, 1.33333) * var(--chat-photo-max-height)));
  min-inline-size: 0;
  max-inline-size: 100%;
  min-block-size: 0;
  max-block-size: var(--chat-photo-max-height);
  aspect-ratio: var(--chat-photo-ratio, 4 / 3);
}

#chat-messages .chat-message > .chat-media > .chat-media-photo:only-child {
  min-inline-size: 100%;
}

#chat-messages .chat-message > .chat-media:not(:has(> .chat-media-photo:not(.chat-preview-compact))) {
  inline-size: min(8rem, 100%);
}

#chat-messages .chat-message > .chat-media:has(> :nth-child(2)):not(:has(> .chat-media-photo:not(.chat-preview-compact))) {
  inline-size: min(16rem, 100%);
}

#chat-messages .chat-message > .chat-media > .chat-media-photo.chat-preview-compact {
  inline-size: min(8rem, 100%);
  block-size: 52px;
  aspect-ratio: auto;
}

#chat-messages .chat-message > .chat-video-tile.chat-preview-compact {
  inline-size: min(9rem, 100%);
  block-size: 64px;
  aspect-ratio: auto;
}

#chat-messages .chat-preview-compact .chat-video-icon {
  inline-size: 32px;
  block-size: 32px;
}

#chat-messages .chat-message > .chat-video-tile.chat-preview-compact .chat-video-action {
  justify-items: start;
  padding: 0 0 0 8px;
}

#chat-messages .chat-message > .chat-video-tile.chat-preview-compact :is(.chat-video-summary, .chat-video-progress, .chat-video-status) {
  inset-inline-start: 46px;
}

#chat-messages .chat-message > .chat-video-tile.chat-preview-compact .chat-video-progress {
  inline-size: calc(100% - 54px);
}

#chat-messages .chat-media-photo {
  position: relative;
}

#chat-messages .chat-media-photo img {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  object-fit: contain;
}

#chat-messages .chat-mobile-album-row > .chat-media-photo img {
  object-fit: cover;
}

#chat-messages .chat-message:has(> :is(.chat-media, .chat-mobile-album, .chat-video-tile)) > :not(:is(.chat-media, .chat-mobile-album, .chat-video-tile)) {
  margin-inline: 9px;
}

#chat-messages .chat-message:has(> :is(.chat-media, .chat-mobile-album, .chat-video-tile)) > :first-child:not(:is(.chat-media, .chat-mobile-album, .chat-video-tile)),
#chat-messages .chat-message > :is(.chat-media, .chat-mobile-album, .chat-video-tile) + :not(:is(.chat-media, .chat-mobile-album, .chat-video-tile)) {
  margin-block-start: 6px;
}

#chat-messages .chat-message:has(> :is(.chat-media, .chat-mobile-album, .chat-video-tile)) > :is(.chat-bubble-line, .chat-bubble-text) {
  contain: inline-size;
}

#chat-messages .chat-message:has(> :is(.chat-media, .chat-mobile-album, .chat-video-tile)) > .chat-bubble-line > .chat-bubble-text {
  flex-basis: 100%;
}

#chat-messages .chat-message:has(> :is(.chat-media, .chat-mobile-album, .chat-video-tile)) > :is(.chat-reply-quote, .chat-document-card) {
  max-inline-size: calc(100% - 18px);
}

@media (max-width: 799px) {
  #chat-messages .chat-mobile-album:not(:has(:is(.chat-media-photo, .chat-video-tile):not(.chat-preview-compact))) {
    inline-size: min(14rem, 76vw);
  }

  #chat-messages .chat-mobile-album-row:not(:has(> :not(.chat-preview-compact))) {
    block-size: 58px;
  }

  #chat-messages .chat-photo-placeholder {
    position: absolute;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
    filter: blur(7px);
    transform: scale(1.15);
    pointer-events: none;
  }
}
