.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.chat-shell {
  --chat-surface: color-mix(in srgb, var(--c-nav) 72%, var(--c-primary-soft));
  --chat-received: var(--c-surface);
  --chat-sent: var(--c-primary-soft);
  gap: 5px;
  background: var(--chat-surface);
  border: 1px solid var(--c-line);
  border-radius: 16px;
  padding: 4px;
}
.chat-shell .message-list {
  padding: 8px clamp(8px, 2vw, 24px) 4px;
  scroll-behavior: auto;
}
.chat-day {
  width: fit-content;
  max-width: 100%;
  margin: 10px auto;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--c-sunken);
  color: var(--c-ink-2);
  font-size: .76rem;
  font-weight: 600;
}
.chat-message {
  align-items: flex-start;
  max-width: 980px;
  margin-inline: auto;
  padding: 6px 0;
  gap: 8px;
}
.chat-message.is-own { justify-content: end; }
.chat-message:hover { background: transparent; }
.chat-message.chat-grouped { padding-block-start: 0; }
.chat-message .avatar {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: var(--c-primary-soft);
}
.chat-message.chat-grouped .avatar { visibility: hidden; }
.chat-message .message-body {
  position: relative;
  display: grid;
  gap: 3px;
  min-width: 0;
  max-width: min(85%, 690px);
  padding: 0;
  background: transparent;
  color: var(--c-ink);
  white-space: normal;
  border-radius: 0;
}
.chat-message.is-own .message-body { max-width: min(93%, 690px); background: transparent; border-radius: 0; }
.chat-sender { font-size: .79rem; font-weight: 650; padding-inline: 2px; }
.chat-message-content { display: flex; align-items: flex-end; gap: 6px; min-width: 0; }
.chat-message.is-own .chat-message-content { flex-direction: row-reverse; }
.chat-bubble {
  min-width: 0;
  padding: 7px 11px;
  border-radius: 4px 13px 13px 13px;
  background: var(--chat-received);
  box-shadow: 0 1px 1px rgb(18 14 37 / .10);
  overflow-wrap: anywhere;
}
.chat-message.is-own .chat-bubble { background: var(--chat-sent); border-radius: 13px 4px 13px 13px; }
.chat-message-meta {
  display: grid;
  flex: none;
  justify-items: end;
  padding-bottom: 1px;
  white-space: nowrap;
  font-size: .65rem;
}
.chat-quote {
  display: grid;
  min-width: 0;
  gap: 2px;
  padding-inline-start: 8px;
  border-inline-start: 2px solid var(--c-primary-line);
  color: var(--c-ink-2);
  font-size: .8rem;
}
.chat-quote > :is(strong, span) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-bubble > .chat-quote { margin-bottom: 6px; }
.chat-reply-bar:not([hidden]) {
  display: flex;
  grid-column: 1 / -1;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 0 4px 3px;
  border-bottom: 1px solid var(--c-line);
}
.chat-reply-bar > button { flex: none; min-width: 44px; min-height: 44px; }
.chat-selection-dialog textarea { user-select: text; resize: vertical; }
.chat-link { color: var(--c-accent-text); text-underline-offset: 2px; }
.chat-url-card {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 2px 0;
  text-decoration: none;
}
.chat-url-card .work-icon { flex: none; }
.chat-url-detail { min-width: 0; display: grid; }
.chat-url-detail strong { color: var(--c-ink); font-weight: 700; }
.chat-url-detail > span { text-decoration: underline; font-size: .82rem; }

.chat-shell .composer {
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 5px;
  margin: 0;
}
.composer > .attach-button { grid-column: 1; grid-row: 2; }
.composer > .input { grid-column: 2; grid-row: 2; }
.composer > .button { grid-column: 3; grid-row: 2; }
.composer > .form-error { grid-row: 3; }
.comment-form { grid-template-columns: auto minmax(0, 1fr) auto; }
.composer > .queued-files, .comment-form > .queued-files { grid-column: 1 / -1; }
.modal-form > .attach-button { justify-self: start; }

.queued-file-list, .shared-files { list-style: none; padding: 0; margin: 0; }
.queued-files { min-width: 0; }
.queued-file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 3px;
  max-height: 7.5rem;
  overflow-y: auto;
  scrollbar-width: thin;
}
.queued-file {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: min(100%, 240px);
  padding-inline-start: 7px;
  border: 1px solid var(--c-line);
  border-radius: 8px;
  background: var(--c-sunken);
  font-size: .78rem;
}
.queued-file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.queued-file .work-icon { width: 15px; height: 15px; flex: none; color: var(--c-accent-text); }
.queued-file button { min-height: 36px; min-width: 36px; flex: none; }
.file-feedback { margin: 3px; color: var(--c-danger); font-size: .8rem; }
.file-feedback:empty { display: none; }

.shared-files { display: grid; gap: 4px; }
:is(.chat-text, .chat-url-card) + .shared-files, .post-card > .shared-files { margin-top: 7px; }
.shared-file {
  display: flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  max-width: 100%;
  min-height: 42px;
  padding: 4px 8px;
  border: 1px solid var(--c-line);
  border-radius: 8px;
  background: var(--c-surface);
  color: var(--c-ink);
  text-decoration: none;
}
.shared-file:hover, .shared-file:active { border-color: var(--c-primary-line); background: var(--c-sunken); }
.shared-file .work-icon { flex: none; width: 16px; height: 16px; color: var(--c-accent-text); }
.shared-file-label { min-width: 0; display: grid; line-height: 1.35; }
.shared-file-label strong { overflow-wrap: anywhere; font-weight: 650; font-size: .82rem; }
.shared-file-label small { color: var(--c-ink-3); font-size: .72rem; }

.channel-screen .screen-title {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 4px;
}
.channel-screen .screen-title > p { grid-column: 2; }
.chat-room-switch .work-icon { width: 18px; height: 18px; }
.channel-screen .chat-mobile-posts { display: none; }

.chat-bubble-menu { touch-action: manipulation; }
.chat-context-menu > button { min-height: 44px; }
@media (any-pointer: coarse) {
  .chat-bubble-menu { -webkit-touch-callout: none; }
  .chat-bubble-menu .chat-text { user-select: none; }
}
.chat-room-picker .modal-form { padding-block-start: 13px; gap: 9px; }
.view-chats { width: min(100%, 820px); margin-inline: auto; }
.view-chats .screen-heading { margin-bottom: 12px; }
.view-chats .screen-heading .actions:empty { display: none; }
.chat-rooms-page { display: grid; gap: 10px; }
.chat-rooms-page .chat-room-search .input { min-height: 44px; font-size: 16px; }
.chat-room-search { gap: 4px; }
.chat-room-list { display: grid; min-width: 0; }
.chat-room {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  min-height: 68px;
  padding: 8px 7px;
  margin: 0;
  border: 0;
  border-bottom: 1px solid var(--c-line);
  background: transparent;
  color: var(--c-ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
}
.chat-room-picker, .chat-room, .phone-tab { -webkit-tap-highlight-color: transparent; }
.chat-room:last-child { border-bottom-color: transparent; }
.chat-room:is(:hover, :active, [aria-current='page']) { border-radius: 9px; background: var(--c-sunken); }
.chat-room-emblem {
  display: grid;
  width: 44px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 14px;
  color: var(--c-accent-text);
  background: var(--c-primary-soft);
}
.chat-room-emblem[data-tone='1'] { background: color-mix(in srgb, var(--c-surface) 87%, #3995aa); }
.chat-room-emblem[data-tone='2'] { background: color-mix(in srgb, var(--c-surface) 85%, #c47969); }
.chat-room-emblem[data-tone='3'] { background: color-mix(in srgb, var(--c-surface) 83%, #486ac3); }
.chat-room-emblem .work-icon { width: 21px; height: 21px; }
.chat-room-text, .chat-room-activity { min-width: 0; display: grid; gap: 2px; }
.chat-room-title, .chat-room-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-room-title { font-size: .91rem; }
.chat-room-summary { color: var(--c-ink-3); font-size: .8rem; }
.chat-room-activity { justify-items: end; color: var(--c-ink-3); font-size: .73rem; white-space: nowrap; }
.chat-room-unread {
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--c-primary);
  color: var(--c-on-primary);
  font-size: .68rem;
  font-weight: 700;
}

@media (max-width: 760px) {
  .chat-shell .message-list { padding-inline: 8px; }
  .chat-shell .composer { padding: 4px; }
  .composer .attach-button, .comment-form .attach-button, .chat-room-switch { min-width: 44px; min-height: 44px; }
  .queued-file button { min-width: 44px; min-height: 44px; }
  .shared-file { min-height: 44px; }
}
@media (max-width: 540px) {
  .chat-message .avatar { width: 30px; height: 30px; flex-basis: 30px; }
  .chat-message-content { gap: 4px; }
}

@media (max-width: 759px) {
  .work:has(> .channel-conversation) > .topbar { display: none; }
  .work > .content.channel-conversation,
  [data-phone-keyboard] .work > .content.channel-conversation {
    padding: 0 var(--phone-right) var(--phone-bottom) var(--phone-left);
    gap: 0;
  }
  .work:has(.phone-tabs) > .content.channel-conversation {
    padding-bottom: calc(var(--phone-nav-h) + var(--phone-bottom));
  }
  [data-phone-keyboard] .work:has(.phone-tabs) > .content.channel-conversation {
    padding-bottom: var(--phone-bottom);
  }
  .channel-conversation > .screen-heading {
    flex-wrap: nowrap;
    gap: 2px;
    padding: var(--phone-top) 6px 0;
    min-height: calc(var(--phone-top) + var(--topbar-h));
    border-bottom: 1px solid var(--c-line);
  }
  .channel-conversation > .screen-heading > .actions { flex: none; gap: 0; }
  .channel-conversation > .screen-heading .button.compact {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
  }
  .channel-conversation > .screen-heading .button.compact:active { background: var(--c-primary-soft); }
  .channel-conversation .chat-mobile-posts { display: inline-flex; }
  .channel-conversation :is(.channel-action-label, .channel-heading-icon, .screen-title p),
  .channel-conversation > .tabs { display: none; }
  .channel-conversation .screen-title h1 {
    overflow: hidden;
    font-size: clamp(18px, 5vw, 22px);
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .channel-conversation .chat-shell { border: 0; border-radius: 0; padding: 0; }
}

.chat-shell .composer-gallery {
  grid-template-columns: auto auto minmax(0, 1fr) auto;
}
.composer-gallery > .gallery-button { grid-column: 2; grid-row: 2; }
.composer-gallery > .input { grid-column: 3; }
.composer-gallery > .button { grid-column: 4; }
.gallery-button { color: var(--c-accent-text); }
/* Keep a multi-photo message compact enough to read on a phone. */
.shared-files:has(.shared-photo-item ~ .shared-photo-item) {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  inline-size: min(100%, 360px);
  align-items: start;
}
.shared-files:has(.shared-photo-item) > li:not(.shared-photo-item) { grid-column: 1 / -1; }
.shared-photo-item {
  display: grid;
  min-inline-size: 0;
  inline-size: min(100%, 175px);
  gap: 4px;
}
.shared-files:has(.shared-photo-item ~ .shared-photo-item) > .shared-photo-item { inline-size: 100%; }
.shared-photo-preview {
  display: grid;
  place-items: center;
  min-inline-size: 0;
  inline-size: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--c-line);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: var(--c-sunken);
  cursor: zoom-in;
}
.shared-photo-preview:hover, .shared-photo-preview:active { border-color: var(--c-primary-line); }
.shared-photo-preview img {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  object-fit: contain;
}
.shared-photo-modal { width: min(860px, calc(100% - 24px)); }
.shared-photo-modal .modal-head h2 { overflow-wrap: anywhere; }
.shared-photo-body {
  display: grid;
  gap: 12px;
  justify-items: center;
  padding: 12px 14px;
}
.shared-photo-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--c-line);
  background: var(--c-surface);
}
.shared-photo-download { min-height: 44px; }
.shared-photo-full {
  display: block;
  inline-size: 100%;
  block-size: min(64dvh, max(96px, calc(100dvh - 180px)));
  object-fit: contain;
  border-radius: 6px;
}
@media (max-width: 540px) {
  .chat-shell .composer-gallery { gap: 4px; }
  .composer-gallery > .input { padding-inline: 4px; }
  .composer-gallery > .button { padding-inline: 8px; }
  .shared-photo-item { inline-size: min(100%, 140px); }
}
