.bubble:has(.chat-message-attachment) {
  width: min(88%, 350px);
  max-width: 88%;
}

.chat-message-text {
  white-space: pre-wrap;
}

.chat-message-text a,
.chat-shared-items a {
  color: var(--green);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-message-attachment {
  display: grid;
  min-width: 0;
  gap: 4px;
  padding-bottom: 2px;
  white-space: normal;
}

.chat-message-attachment:has(+ .chat-message-text) {
  margin-bottom: 4px;
}

.chat-photo-link,
.chat-message-attachment :is(img, video),
.chat-upload-preview :is(img, video) {
  display: block;
  width: 100%;
  min-width: 0;
  border-radius: 10px;
}

.chat-message-attachment :is(img, video),
.chat-upload-preview :is(img, video) {
  max-height: 340px;
  background: var(--muted-bg, var(--paper, #f3f6f4));
  object-fit: contain;
}

.chat-media-caption {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
}

.chat-media-download {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  color: var(--green);
}

.chat-media-download:hover {
  background: var(--mint);
}

.chat-upload {
  display: grid;
  gap: 13px;
}

.chat-file-picker,
.chat-recorder,
.chat-upload-preview {
  display: grid;
  gap: 10px;
  padding: 22px 14px;
  justify-items: center;
  text-align: center;
  border-radius: 14px;
  background: var(--muted-bg, var(--paper, #f3f6f4));
  border: 1px solid var(--line);
}

.chat-file-picker {
  position: relative;
  border-style: dashed;
  cursor: pointer;
}

.chat-file-picker:hover,
.chat-file-picker:focus-within {
  border-color: var(--green);
  background: var(--mint);
}

.chat-file-picker input {
  inset: 0;
  position: absolute;
  width: 100%;
  cursor: pointer;
  opacity: 0;
}

.chat-recorder-icon,
.chat-shared-link-icon {
  width: 43px;
  height: 43px;
  border-radius: 12px;
  display: inline-grid;
  place-items: center;
  color: var(--green);
  background: var(--mint);
}

.chat-recorder.is-recording .chat-recorder-icon {
  background: var(--rose-bg, #f9e3e4);
  color: var(--rose, #a63943);
}

.chat-file-picker small,
.chat-recorder p:not(.chat-recorder-time),
.chat-upload-preview p {
  display: block;
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.chat-upload-preview {
  min-width: 0;
  padding: 10px;
}

.dialog[data-kind="chat-voice"] {
  width: min(440px, calc(100% - 26px));
}

.chat-voice-upload .chat-recorder {
  justify-items: stretch;
  gap: 14px;
  padding: 14px;
  text-align: left;
}

.chat-recorder-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-recorder-status > div:nth-child(2) {
  flex: 1;
  min-width: 0;
}

.chat-recorder-controls {
  display: flex;
  justify-content: flex-end;
}

.chat-recorder-controls .button {
  min-height: 44px;
}

.chat-voice-upload .chat-upload-preview:not([hidden]) {
  display: block;
  border: 0;
  padding: 0;
  background: transparent;
}

.chat-recorder-time {
  flex: none;
  color: var(--rose, #a63943);
  font-size: 20px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  margin: 0;
}

.chat-upload-actions,
.chat-shared-more {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.chat-media-error {
  padding: 9px 12px;
  margin: 0;
  border-radius: 8px;
  background: var(--rose-bg, #fbecee);
  color: var(--rose, #9f302e);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.chat-shared-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  margin-bottom: 12px;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.chat-shared-tabs button {
  border: 0;
  min-height: 40px;
  color: var(--muted);
  background: transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.chat-shared-tabs button:hover,
.chat-shared-tabs button[aria-selected="true"] {
  color: var(--green);
  background: var(--mint);
}

.chat-shared-status {
  padding: 13px 0;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.chat-shared-status:empty,
.chat-shared-items:empty,
.chat-shared-more:has(button[hidden]) {
  display: none;
}

.chat-shared-items {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  list-style: none;
}

.chat-shared-items[data-shared-tab="media"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chat-shared-items > li {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow-wrap: anywhere;
}

.chat-shared-items[data-shared-tab="media"] > li:has(audio) {
  grid-column: 1 / -1;
}

.chat-shared-items[data-shared-tab="media"] :is(img, video) {
  aspect-ratio: 4 / 3;
}

.chat-shared-items[data-shared-tab="links"] > li {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  gap: 9px;
}

.chat-shared-items[data-shared-tab="links"] > li > div {
  flex: 1 1 150px;
  min-width: 0;
}

.chat-shared-link-icon {
  width: 35px;
  height: 35px;
  flex: none;
}

.chat-shared-items strong,
.chat-shared-items[data-shared-tab="links"] a {
  display: block;
  font-size: 13px;
}

.chat-shared-items time {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
}

.chat-shared-more {
  margin-top: 12px;
}

@media (max-width: 400px) {
  .chat-shared-items[data-shared-tab="media"] {
    grid-template-columns: minmax(0, 1fr);
  }
}
