html:has(.chat-image-viewer[open]) {
  overflow: hidden;
}

dialog.chat-image-viewer[open] {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
  color: #f0f6f3;
}

.chat-image-viewer::backdrop {
  background: #071210dc;
}

.chat-image-toolbar {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 96px;
  align-items: center;
  gap: 12px;
}

.chat-image-title {
  grid-column: 2;
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: normal;
  line-height: 1.35;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-image-actions {
  display: flex;
  gap: 8px;
}

.chat-image-actions .chat-image-action {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #a6c5b865;
  border-radius: 12px;
  background: #153c38d9;
  color: #f0f6f3;
  text-decoration: none;
}

.chat-image-actions .chat-image-close {
  border-radius: 50%;
  font-size: 26px;
  line-height: 1;
}

.chat-image-actions .chat-image-action:hover {
  border-color: #b6d7ca;
  background: #2e6155;
}

.chat-image-actions .chat-image-action:focus-visible {
  outline: 2px solid #def697;
  outline-offset: 2px;
}

.chat-image-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.chat-image-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.chat-image-stage p {
  text-align: center;
}

.chat-image-caption {
  justify-self: center;
  width: min(100%, 44rem);
  max-height: min(8rem, 22dvh);
  margin: 0;
  padding: 7px 12px;
  overflow: auto;
  border-radius: 8px;
  background: #0b1b18b3;
  font-size: 14px;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 600px) {
  .chat-image-toolbar {
    grid-template-columns: minmax(0, 1fr) 96px;
  }

  .chat-image-title {
    grid-column: 1;
    text-align: start;
  }
}
