/* ─── Chats: the list, the open chat, its details, the picker and dialogs ───── */

.chats-link { position: relative; }

/* The page fills the window under the top bar: no footer, no bottom padding. */
body:has(.chats) .site-footer { display: none; }
.main:has(> .chats) { padding-bottom: 0; }

.chats {
  --chats-top: 3.5rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: calc(100dvh - var(--chats-top) - 1px);
  height: calc(100svh - var(--chats-top) - 1px);
  max-width: 82rem;
  margin: 0 auto;
  overflow: hidden;
}
.chats-noscript { margin: 1rem; }

.chats-side { display: flex; min-width: 0; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--page); }
.chats-side-head { display: flex; align-items: center; justify-content: space-between; padding: 0.875rem 1rem 0.25rem; }
.chats-title { font-family: var(--font-serif); font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; }
.chats-new { display: flex; gap: 0.25rem; }
.chats-tabs { display: flex; gap: 0.25rem; padding: 0.25rem 0.75rem; }
.chats-tab { display: inline-flex; align-items: center; gap: 0.375rem; border-radius: 9999px; padding: 0.375rem 0.875rem; font-size: 0.875rem; font-weight: 600; color: var(--muted); }
.chats-tab:hover { background: var(--surface-2); color: var(--ink); }
.chats-tab.is-active { background: var(--ink); color: var(--surface); }
.chats-tab-count { border-radius: 9999px; background: var(--danger-fill); color: #fff; padding: 0 0.375rem; font-size: 0.6875rem; line-height: 1.1rem; }
.chats-filter { margin: 0.5rem 0.75rem; width: calc(100% - 1.5rem); }

.chat-rows { flex: 1; min-height: 0; overflow-y: auto; padding: 0 0.375rem 1rem; overscroll-behavior: contain; }
.chat-requests { flex: 1; min-height: 0; overflow-y: auto; padding: 0.25rem 0.375rem 1rem; }
.chat-requests .chat-rows { overflow: visible; padding: 0; }
.chat-requests-title { margin: 1rem 0.625rem 0.25rem; font-size: 0.8125rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.chat-requests-note { margin: 0 0.625rem 0.5rem; font-size: 0.8125rem; color: var(--muted); }

.chat-row { border-radius: 0.875rem; }
.chat-row-link { display: flex; align-items: center; gap: 0.75rem; padding: 0.625rem; border-radius: 0.875rem; color: inherit; text-decoration: none; }
.chat-row-link:hover { background: var(--surface-2); }
.chat-row.is-active .chat-row-link { background: var(--surface-3); }
.chat-row-text { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 0.125rem; }
.chat-row-top, .chat-row-bottom { display: flex; align-items: center; gap: 0.375rem; min-width: 0; }
.chat-row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chat-row-time { margin-left: auto; flex-shrink: 0; font-size: 0.75rem; color: var(--muted); }
.chat-row-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; color: var(--muted); }
.chat-row-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8125rem; color: var(--muted); }
.chat-row-muted { display: inline-flex; color: var(--muted); }
.chat-row.is-unread .chat-row-name, .chat-row.is-unread .chat-row-last { color: var(--ink); font-weight: 600; }
.chat-row-badge { margin-left: auto; flex-shrink: 0; min-width: 1.25rem; border-radius: 9999px; background: var(--ink); color: var(--surface); padding: 0 0.375rem; text-align: center; font-size: 0.75rem; font-weight: 700; line-height: 1.25rem; }
.chat-row.is-muted .chat-row-badge { background: var(--surface-3); color: var(--muted); }
.chat-row-actions { display: flex; flex-wrap: wrap; gap: 0.375rem; padding: 0 0.625rem 0.75rem 3.875rem; }
.chat-invite .chat-row-link { padding-bottom: 0.375rem; }
.chat-empty { padding: 2rem 1rem; text-align: center; }
.chat-empty p + p { margin-top: 0.375rem; font-size: 0.875rem; }
.chat-more { padding: 0.5rem; text-align: center; }

/* ─── The open chat ───────────────────────────────────────────────────────── */

.chat-pane { position: relative; display: none; flex-direction: column; min-height: 0; min-width: 0; background: var(--surface); }
.chats[data-view='chat'] .chat-pane { display: flex; }
.chats[data-view='chat'] .chats-side { display: none; }
.chat-loading { margin: auto; color: var(--muted); }
.chat-pane-empty { margin: auto; display: flex; max-width: 22rem; flex-direction: column; align-items: center; gap: 0.5rem; padding: 2rem; text-align: center; color: var(--muted); }
.chat-pane-empty h2 { font-family: var(--font-serif); font-size: 1.375rem; font-weight: 600; color: var(--ink); }
.chat-pane-empty-actions { margin-top: 0.75rem; display: flex; gap: 0.5rem; }

.chat-head { display: flex; align-items: center; gap: 0.25rem; border-bottom: 1px solid var(--line); padding: 0.5rem 0.75rem; }
.chat-head-who { display: flex; min-width: 0; flex: 1; align-items: center; gap: 0.75rem; border-radius: 0.75rem; padding: 0.25rem 0.375rem; text-align: left; }
.chat-head-who:hover { background: var(--surface-2); }
.chat-head-text { display: flex; min-width: 0; flex-direction: column; }
.chat-head-name { display: flex; align-items: center; gap: 0.375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chat-head-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8125rem; color: var(--muted); }
.chat-typing { color: var(--ink-2); }
.chat-typing-dots { display: inline-flex; gap: 2px; margin-left: 0.25rem; vertical-align: middle; }
.chat-typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: chat-dot 1.2s infinite ease-in-out; }
.chat-typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* A group's channels: a strip that scrolls sideways, and the list of them all. */
.channel-bar { position: relative; z-index: 7; display: flex; align-items: center; gap: 0.25rem; border-bottom: 1px solid var(--line); padding: 0.375rem 0.5rem 0.375rem 0.75rem; }
.channel-bar[hidden] { display: none; }
.channel-strip {
  display: flex; min-width: 0; flex: 1; gap: 0.25rem; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain;
  scroll-snap-type: x proximity; -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 1.5rem), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 1.5rem), transparent); padding-right: 1.5rem;
}
.channel-strip::-webkit-scrollbar { display: none; }
.channel-pill {
  display: inline-flex; flex-shrink: 0; align-items: center; gap: 0.375rem; scroll-snap-align: start;
  border-radius: 9999px; padding: 0.3125rem 0.75rem; font-size: 0.875rem; font-weight: 600; white-space: nowrap; color: var(--muted);
  transition: background-color 0.15s, color 0.15s;
}
.channel-pill:hover { background: var(--surface-2); color: var(--ink); }
.channel-pill.is-unread { color: var(--ink); }
.channel-pill.is-active { background: var(--ink); color: var(--surface); }
.channel-pill:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.channel-pill-name { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; }
.channel-pill-count { min-width: 1.125rem; border-radius: 9999px; background: var(--ink); color: var(--surface); padding: 0 0.3125rem; text-align: center; font-size: 0.6875rem; font-weight: 700; line-height: 1.125rem; }
.channel-pill.is-active .channel-pill-count { background: var(--surface); color: var(--ink); }
.channel-lock { flex-shrink: 0; opacity: 0.75; }
.channel-menu { flex-shrink: 0; }
.channel-menu-popup { width: min(20rem, calc(100vw - 1.5rem)); max-height: min(26rem, 60dvh); overflow-y: auto; overscroll-behavior: contain; }
.channel-menu-title { padding: 0.375rem 0.625rem 0.25rem; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.channel-rows { display: flex; flex-direction: column; gap: 0.0625rem; }
.channel-row { display: flex; align-items: center; gap: 0.25rem; border-radius: 0.625rem; }
.channel-row-pick { display: flex; min-width: 0; flex: 1; align-items: center; gap: 0.5rem; border-radius: 0.625rem; padding: 0.4375rem 0.625rem; text-align: left; color: inherit; }
.channel-row-pick:hover { background: var(--surface-2); }
.channel-row.is-active .channel-row-pick { background: var(--surface-3); }
.channel-row-text { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.channel-row-name { display: flex; align-items: center; gap: 0.3125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; font-weight: 600; color: var(--ink-2); }
.channel-row.is-unread .channel-row-name, .channel-row.is-active .channel-row-name { color: var(--ink); }
.channel-row-note { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.75rem; color: var(--muted); }
.channel-row .chat-row-badge { margin-left: 0.25rem; }

/* The newest pinned message, above the messages. */
.pin-bar { display: flex; align-items: center; gap: 0.25rem; border-bottom: 1px solid var(--line); background: var(--surface); padding: 0.25rem 0.5rem 0.25rem 0.75rem; }
.pin-bar[hidden] { display: none; }
.pin-bar-main { display: flex; min-width: 0; flex: 1; align-items: center; gap: 0.5rem; border-radius: 0.5rem; padding: 0.25rem 0.375rem; text-align: left; }
.pin-bar-main:hover { background: var(--surface-2); }
.pin-bar-icon { flex-shrink: 0; color: var(--muted); }
.pin-bar-text { display: flex; min-width: 0; flex-direction: column; border-left: 2px solid var(--ink); padding-left: 0.5rem; }
.pin-bar-label { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.pin-bar-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8125rem; color: var(--ink-2); }
.pin-rows { display: flex; max-height: min(28rem, 60dvh); flex-direction: column; gap: 0.125rem; overflow-y: auto; margin: 0 -0.5rem; }
.pin-row { display: flex; align-items: center; gap: 0.375rem; }
.pin-row-main { display: flex; min-width: 0; flex: 1; flex-direction: column; border-radius: 0.625rem; padding: 0.5rem; text-align: left; }
.pin-row-main:hover { background: var(--surface-2); }
.pin-row-who { font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.pin-row-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 0.875rem; }
.msg-system-link { color: inherit; text-decoration: underline; text-decoration-color: color-mix(in oklab, currentColor 40%, transparent); text-underline-offset: 2px; }
.msg-system-link:hover { color: var(--ink); }

.chat-request-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface-2); padding: 0.75rem 1rem; font-size: 0.875rem; }
.chat-request-bar p { flex: 1 1 18rem; }
.chat-request-actions { display: flex; gap: 0.375rem; }

.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0.75rem 0.75rem 0.5rem; scroll-padding-bottom: 2rem; }
.chat-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.chat-top { height: 1px; }
.chat-msgs { display: flex; flex-direction: column; }

.chat-jump {
  position: absolute; right: 1rem; bottom: 5.5rem; z-index: 5;
  display: inline-flex; align-items: center; gap: 0.25rem; border-radius: 9999px;
  background: var(--surface); box-shadow: var(--shadow-lg), inset 0 0 0 1px var(--line); padding: 0.5rem 0.75rem; color: var(--ink);
}
.chat-jump[hidden] { display: none; }
.chat-jump-count:empty { display: none; }
.chat-drop {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem;
  border: 2px dashed var(--line-strong); border-radius: 1rem; margin: 0.5rem;
  background: color-mix(in oklab, var(--surface) 88%, transparent); font-weight: 600; pointer-events: none;
}
.chat-drop[hidden] { display: none; }

/* Separators and what happened in the chat. */
.msg-day, .msg-unread { display: flex; align-items: center; gap: 0.75rem; margin: 0.875rem 0 0.5rem; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.msg-day::before, .msg-day::after, .msg-unread::before, .msg-unread::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.msg-unread { color: var(--danger); }
.msg-unread::before, .msg-unread::after { background: color-mix(in oklab, var(--danger) 45%, transparent); }
.msg-system { margin: 0.375rem auto; max-width: 30rem; border-radius: 9999px; background: var(--surface-2); padding: 0.25rem 0.75rem; text-align: center; font-size: 0.8125rem; color: var(--muted); }

/* A message. */
.msg { position: relative; display: flex; align-items: flex-end; gap: 0.5rem; margin-top: 2px; }
.msg.is-first { margin-top: 0.625rem; }
.msg.is-mine { flex-direction: row-reverse; }
.msg-avatar { width: 2rem; flex-shrink: 0; align-self: flex-end; }
.msg-main { display: flex; min-width: 0; max-width: min(36rem, 78%); flex-direction: column; align-items: flex-start; }
.msg.is-mine .msg-main { align-items: flex-end; }
.msg-sender { margin: 0 0 0.125rem 0.75rem; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.msg-row { position: relative; display: flex; max-width: 100%; align-items: center; gap: 0.25rem; }
.msg.is-mine .msg-row { flex-direction: row-reverse; }

.msg-bubble {
  position: relative; min-width: 3.5rem; max-width: 100%; overflow: hidden;
  border-radius: 1.125rem; background: var(--surface-2); padding: 0.4375rem 0.75rem 0.375rem; color: var(--ink);
  overflow-wrap: anywhere; line-height: 1.4;
}
.msg.is-mine .msg-bubble { background: var(--ink); color: var(--surface); }
.msg.is-theirs:not(.is-first) .msg-bubble { border-top-left-radius: 0.375rem; }
.msg.is-theirs:not(.is-last) .msg-bubble { border-bottom-left-radius: 0.375rem; }
.msg.is-mine:not(.is-first) .msg-bubble { border-top-right-radius: 0.375rem; }
.msg.is-mine:not(.is-last) .msg-bubble { border-bottom-right-radius: 0.375rem; }
.msg-bubble.is-emoji { background: none !important; padding: 0; font-size: 2.5rem; line-height: 1.15; color: inherit; }
.msg.is-mine .msg-bubble.is-emoji { color: var(--ink); }
.msg-bubble.is-emoji { overflow: visible; }
.msg-bubble.is-emoji .msg-meta { float: none; display: flex; justify-content: flex-end; margin: 0.125rem 0 0; font-size: 0.6875rem; color: var(--muted); }
.msg-bubble.is-deleted { background: none; box-shadow: inset 0 0 0 1px var(--line); color: var(--muted); font-style: italic; }
.msg.is-mine .msg-bubble.is-deleted { background: none; color: var(--muted); }
.msg-bubble.is-media { padding: 0.25rem; }
.msg-bubble.is-media .msg-meta { position: absolute; right: 0.625rem; bottom: 0.5rem; border-radius: 9999px; background: rgb(0 0 0 / 0.5); padding: 0 0.375rem; color: #fff; }
.msg.is-sending .msg-bubble, .msg.is-pending .msg-bubble { opacity: 0.72; }
.msg.is-error .msg-bubble, .msg.is-failed .msg-bubble { box-shadow: 0 0 0 1.5px var(--danger); }
.msg.is-highlighted .msg-bubble { animation: chat-flash 1.6s ease; }
@keyframes chat-flash { 0%, 60% { box-shadow: 0 0 0 3px var(--focus); } 100% { box-shadow: 0 0 0 0 transparent; } }

.msg-text { white-space: pre-wrap; }
.msg-url, .msg-mention { color: inherit; text-decoration: underline; text-underline-offset: 2px; text-decoration-color: color-mix(in oklab, currentColor 45%, transparent); }
.msg.is-theirs .msg-url, .msg.is-theirs .msg-mention { color: var(--link); text-decoration-color: color-mix(in oklab, var(--link) 40%, transparent); }
.msg-meta { float: right; display: inline-flex; align-items: center; gap: 0.25rem; margin: 0.375rem 0 -0.125rem 0.625rem; font-size: 0.6875rem; line-height: 1; opacity: 0.7; }
.msg-edited { font-style: italic; }
.msg-status { margin: 0.1875rem 0.25rem 0; display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.6875rem; color: var(--muted); }
.msg-status.is-error { color: var(--danger); font-weight: 600; }
.msg-status.is-seen { color: var(--ink-2); }

.msg-quote {
  display: flex; max-width: 100%; flex-direction: column; margin: 0.0625rem -0.25rem 0.375rem; border-left: 3px solid currentColor;
  border-radius: 0.5rem; background: color-mix(in oklab, currentColor 9%, transparent); padding: 0.25rem 0.5rem; text-align: left; font-size: 0.8125rem;
}
.msg-quote-name { font-weight: 700; }
.msg-quote-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.85; }

/* Pictures and videos: the posts' lightbox and player. */
.msg-album { display: grid; gap: 2px; overflow: hidden; border-radius: 0.875rem; width: min(22rem, 62vw); margin: 0 0 0.25rem; }
.msg-album-1 { grid-template-columns: 1fr; }
.msg-album-2, .msg-album-4 { grid-template-columns: 1fr 1fr; }
.msg-album-3 { grid-template-columns: 1fr 1fr 1fr; }
.msg-media-item { position: relative; display: block; aspect-ratio: var(--ratio, 1); max-height: 26rem; overflow: hidden; }
.msg-album:not(.msg-album-1) .msg-media-item { aspect-ratio: 1; }
.msg-media-item img { width: 100%; height: 100%; object-fit: cover; }
.msg-gif { position: absolute; left: 0.375rem; bottom: 0.375rem; border-radius: 0.25rem; background: rgb(0 0 0 / 0.6); padding: 0 0.25rem; font-size: 0.625rem; font-weight: 800; color: #fff; }
.msg-media-wait { display: flex; min-height: 6rem; align-items: center; justify-content: center; gap: 0.5rem; border-radius: 0.75rem; background: var(--surface-3); padding: 1rem; font-size: 0.8125rem; color: var(--muted); }
.msg-video { width: min(22rem, 62vw); border-radius: 0.875rem; overflow: hidden; margin-bottom: 0.25rem; }

/* Files. */
.msg-file {
  display: flex; min-width: 14rem; max-width: 22rem; align-items: center; gap: 0.625rem; margin: 0.125rem 0 0.25rem;
  border-radius: 0.75rem; background: color-mix(in oklab, currentColor 8%, transparent); padding: 0.5rem 0.625rem; color: inherit; text-decoration: none;
}
.msg-file:hover { background: color-mix(in oklab, currentColor 14%, transparent); }
.msg-file-text { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.msg-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 0.875rem; }
.msg-file-meta { font-size: 0.75rem; opacity: 0.75; }
/* Amber, darkened or lightened toward the bubble's own text so it reads on either bubble. */
.msg-file.is-risky > .icon:first-child, .msg-file-warning { color: color-mix(in oklab, #d97706 62%, currentColor); }
.msg-file-warning { font-weight: 700; }
.msg-file-get { flex-shrink: 0; opacity: 0.7; }

/* A link's preview, fetched by the server. */
.msg-link { display: flex; flex-direction: column; overflow: hidden; margin: 0.375rem -0.125rem 0.125rem; border-radius: 0.75rem; background: color-mix(in oklab, currentColor 7%, transparent); color: inherit; text-decoration: none; max-width: 22rem; }
.msg-link:hover { background: color-mix(in oklab, currentColor 12%, transparent); }
.msg-link-image { width: 100%; max-height: 12rem; object-fit: cover; }
.msg-link-text { display: flex; flex-direction: column; gap: 0.125rem; padding: 0.5rem 0.625rem 0.625rem; }
.msg-link-site { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.7; }
.msg-link-title { font-weight: 700; font-size: 0.875rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msg-link-desc { font-size: 0.8125rem; opacity: 0.8; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* A shared post: its own card. */
.msg-post { width: min(30rem, 72vw); margin: 0.25rem -0.375rem 0.25rem; border-radius: 0.875rem; background: var(--surface); color: var(--ink); text-align: left; }
.msg-post .post { margin: 0; border-radius: 0.875rem; box-shadow: inset 0 0 0 1px var(--line); }
.msg-post-wait { padding: 1rem; font-size: 0.8125rem; color: var(--muted); }

/* Reactions under a message. */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.1875rem; }
.msg-reaction { display: inline-flex; align-items: center; gap: 0.25rem; border-radius: 9999px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); padding: 0.0625rem 0.5rem; font-size: 0.8125rem; }
.msg-reaction:hover { background: var(--surface-2); }
.msg-reaction.is-mine { background: color-mix(in oklab, var(--focus) 14%, var(--surface)); box-shadow: inset 0 0 0 1.5px var(--focus); }
.msg-reaction-emoji { font-size: 1rem; line-height: 1.375rem; }
.msg-reaction-count { font-weight: 600; color: var(--ink-2); }
.msg-reaction-who { display: inline-flex; align-items: center; border-radius: 9999px; padding: 0 0.375rem; color: var(--muted); opacity: 0; }
.msg-reactions:hover .msg-reaction-who, .msg-reaction-who:focus-visible { opacity: 1; }

/* The actions beside a message: shown on hover, on focus, or once tapped on a touch screen. */
.msg-actions {
  position: absolute; bottom: calc(100% - 0.375rem); z-index: 6; display: flex; align-items: center; gap: 0.125rem;
  border-radius: 9999px; background: var(--surface); box-shadow: var(--shadow-lg), inset 0 0 0 1px var(--line); padding: 0.125rem;
  opacity: 0; pointer-events: none; transition: opacity 0.12s;
}
.msg.is-mine .msg-actions { right: 0.25rem; }
.msg.is-theirs .msg-actions { left: 0.25rem; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .msg.is-picked .msg-actions { opacity: 1; pointer-events: auto; }
.chat-quick { display: flex; align-items: center; }
.chat-quick-emoji { width: 1.875rem; height: 1.875rem; border-radius: 9999px; font-size: 1.0625rem; transition: transform 0.1s; }
.chat-quick-emoji:hover { transform: scale(1.18); background: var(--surface-2); }
.msg-menu > .menu-popup { min-width: 12rem; }
@media (hover: none) {
  .msg-reaction-who { opacity: 1; }
}

/* ─── Writing ─────────────────────────────────────────────────────────────── */

.chat-composer { border-top: 1px solid var(--line); background: var(--surface); padding: 0.5rem 0.75rem max(0.5rem, env(safe-area-inset-bottom)); }
.chat-composer.is-disabled .chat-input { background: var(--surface-2); }
.chat-compose-row { display: flex; align-items: flex-end; gap: 0.25rem; }
.chat-input-wrap { min-width: 0; flex: 1; }
.chat-input {
  display: block; width: 100%; min-height: 2.5rem; max-height: 12.5rem; resize: none; border: 0; border-radius: 1.25rem;
  background: var(--surface-2); padding: 0.5625rem 0.875rem; font: inherit; line-height: 1.4; color: var(--ink);
}
.chat-input:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.chat-send { width: 2.5rem; height: 2.5rem; border-radius: 9999px; padding: 0; justify-content: center; }
.chat-context { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.375rem; border-left: 3px solid var(--ink); border-radius: 0.5rem; background: var(--surface-2); padding: 0.25rem 0.25rem 0.25rem 0.625rem; font-size: 0.8125rem; }
.chat-context[hidden] { display: none; }
.chat-context-text { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.chat-tray { display: flex; gap: 0.5rem; overflow-x: auto; margin-bottom: 0.5rem; padding-bottom: 0.125rem; }
.chat-tray[hidden] { display: none; }
.chat-chip {
  position: relative; display: grid; flex-shrink: 0; width: 6.5rem; grid-template-rows: 4.5rem auto auto; overflow: hidden;
  border-radius: 0.75rem; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); font-size: 0.6875rem;
}
.chat-chip-thumb { width: 100%; height: 4.5rem; object-fit: cover; }
.chat-chip-icon { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.chat-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.25rem 0.375rem 0; font-weight: 600; }
.chat-chip-size { padding: 0 0.375rem 0.375rem; color: var(--muted); }
.chat-chip-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: calc(var(--p, 0) * 100%); background: var(--focus); transition: width 0.15s; }
.chat-chip.is-done .chat-chip-bar { opacity: 0; }
.chat-chip.is-error { box-shadow: inset 0 0 0 1.5px var(--danger); }
.chat-chip-remove { position: absolute; top: 0.25rem; right: 0.25rem; width: 1.5rem; height: 1.5rem; background: rgb(0 0 0 / 0.55); color: #fff; }
.chat-chip-remove:hover { background: rgb(0 0 0 / 0.75); color: #fff; }
.chat-link-preview { display: flex; align-items: center; gap: 0.625rem; margin-bottom: 0.5rem; border-radius: 0.75rem; background: var(--surface-2); padding: 0.375rem 0.375rem 0.375rem 0.5rem; }
.chat-link-preview[hidden] { display: none; }
.chat-link-thumb { width: 3rem; height: 3rem; flex-shrink: 0; border-radius: 0.5rem; object-fit: cover; }
.chat-link-text { display: flex; min-width: 0; flex: 1; flex-direction: column; font-size: 0.8125rem; }
.chat-link-site { color: var(--muted); font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.04em; }
.chat-link-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* ─── The emoji picker ────────────────────────────────────────────────────── */

.emoji-picker {
  position: fixed; z-index: 70; display: flex; width: 21.5rem; height: 24rem; flex-direction: column; overflow: hidden;
  border-radius: 1rem; background: var(--surface); box-shadow: var(--shadow-xl), inset 0 0 0 1px var(--line);
  animation: bt-fade-up 160ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.emoji-picker.is-sheet { inset: auto 0 0 0; width: auto; height: min(26rem, 70dvh); border-radius: 1rem 1rem 0 0; padding-bottom: env(safe-area-inset-bottom); }
.emoji-head { display: flex; align-items: center; gap: 0.375rem; padding: 0.5rem 0.5rem 0.25rem; }
.emoji-search { flex: 1; height: 2.25rem; }
.emoji-tone { font-size: 1.125rem; }
.emoji-tabs { display: flex; gap: 0.125rem; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); padding: 0 0.375rem 0.25rem; }
.emoji-tabs::-webkit-scrollbar { display: none; }
.emoji-tab { flex-shrink: 0; width: 2rem; height: 2rem; border-radius: 0.5rem; font-size: 1.125rem; }
.emoji-tab:hover { background: var(--surface-2); }
.emoji-grid { flex: 1; overflow-y: auto; padding: 0.25rem 0.375rem 0.5rem; overscroll-behavior: contain; }
.emoji-section { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.25rem, 1fr)); content-visibility: auto; contain-intrinsic-size: auto 12rem; }
.emoji-section-title { grid-column: 1 / -1; padding: 0.5rem 0.25rem 0.25rem; font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.emoji-cell { height: 2.25rem; border-radius: 0.5rem; font-size: 1.375rem; line-height: 1; }
.emoji-cell:hover, .emoji-cell:focus-visible { background: var(--surface-2); outline: none; }
.emoji-cell:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.emoji-empty { padding: 1.5rem; text-align: center; color: var(--muted); }

/* ─── Details ─────────────────────────────────────────────────────────────── */

.chat-info { display: flex; min-height: 0; flex-direction: column; overflow-y: auto; border-left: 1px solid var(--line); background: var(--page); }
.chat-info[hidden] { display: none; }
.chat-info-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: var(--page); padding: 0.75rem 0.75rem 0.75rem 1rem; }
.chat-info-head h2 { font-weight: 700; }
.chat-info-body { display: flex; flex-direction: column; padding-bottom: 2rem; }
.chat-info-hero { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; border-bottom: 1px solid var(--line); padding: 1.25rem 1rem; text-align: center; }
.chat-info-hero .control { width: 100%; }
.chat-info-hero textarea.control, .chat-dialog textarea.control { height: auto; min-height: 4.5rem; padding-top: 0.5rem; padding-bottom: 0.5rem; resize: vertical; }
.chat-info-name { font-family: var(--font-serif); font-size: 1.375rem; font-weight: 600; }
.chat-info-handle { color: var(--muted); }
.chat-info-desc { color: var(--ink-2); white-space: pre-wrap; }
.chat-info-count { font-size: 0.875rem; color: var(--muted); }
.chat-info-section { display: flex; flex-direction: column; gap: 0.5rem; border-bottom: 1px solid var(--line); padding: 1rem; }
.chat-info-title { font-size: 0.8125rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.chat-info-actions { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.chat-info-action { justify-content: flex-start; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover:not(:disabled) { background: color-mix(in oklab, var(--danger) 10%, transparent); }
.chat-link-box { display: flex; flex-direction: column; gap: 0.5rem; }
.chat-setting { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; font-size: 0.875rem; }
.chat-setting .control { width: auto; }
.chat-members { max-height: none; }
.chat-member { display: flex; align-items: center; gap: 0.5rem; }
.chat-member .chat-person { flex: 1; }
.chat-member-actions { display: flex; gap: 0.25rem; }
.chat-role { flex-shrink: 0; }

/* People in lists and pickers. */
.chat-people { display: flex; flex-direction: column; gap: 0.125rem; }
.chat-pick { max-height: min(22rem, 50dvh); overflow-y: auto; margin: 0 -0.5rem; }
.chat-person { display: flex; width: 100%; min-width: 0; align-items: center; gap: 0.625rem; border-radius: 0.75rem; padding: 0.375rem 0.5rem; text-align: left; color: inherit; text-decoration: none; }
.chat-person:hover { background: var(--surface-2); }
.chat-person-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chat-person-handle { font-weight: 400; color: var(--muted); }
.chat-person-note { margin-left: auto; font-size: 0.75rem; color: var(--muted); }
.chat-person-icon { display: inline-flex; width: 2rem; height: 2rem; align-items: center; justify-content: center; border-radius: 9999px; background: var(--surface-2); }
.chat-people-group + .chat-people-group { margin-top: 0.75rem; }
.chat-people-title { margin-bottom: 0.25rem; font-size: 1.25rem; }
.chat-invite-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.chat-invite-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.chip-x { margin-left: 0.25rem; font-weight: 700; color: var(--muted); }
.chat-dialog { width: min(28rem, calc(100vw - 2rem)); }
.chat-avatar-wrap { display: inline-flex; }

/* An invite link's page, and blocked accounts in Settings. */
.chat-join-card { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; margin-top: 1rem; padding: 2rem 1.5rem; text-align: center; }
.chat-join-desc { max-width: 28rem; color: var(--ink-2); white-space: pre-wrap; }
.chat-join-initial { --avatar-hue: 210; }
.blocked-list { display: flex; flex-direction: column; gap: 0.5rem; }
.blocked-list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.profile-message { margin-left: 0.375rem; }

/* ─── Side by side ────────────────────────────────────────────────────────── */

@media (max-width: 639px) {
  /* A phone: the open chat takes the screen (the bottom navigation steps aside). */
  .chats { height: calc(100dvh - var(--chats-top) - 4.25rem - env(safe-area-inset-bottom)); }
  body:has(.chats[data-view='chat']) .bottomnav { display: none; }
  .chats[data-view='chat'] { height: calc(100dvh - var(--chats-top) - 1px); }
  .chat-info:not([hidden]) { position: fixed; inset: var(--chats-top) 0 0 0; z-index: 30; }
  .msg-main { max-width: 84%; }
}

@media (min-width: 800px) {
  .chats { grid-template-columns: 21rem minmax(0, 1fr); }
  .chats[data-info='true'] { grid-template-columns: 21rem minmax(0, 1fr) 20rem; }
  .chats-side, .chats[data-view='chat'] .chats-side { display: flex; }
  .chat-pane { display: flex; }
  .chat-back { display: none; }
}

@media (min-width: 640px) and (max-width: 799px) {
  .chat-info:not([hidden]) { position: fixed; top: var(--chats-top); right: 0; bottom: 0; z-index: 30; width: min(22rem, 90vw); box-shadow: var(--shadow-xl); }
}
