/* ============================================================================
   Conversation: header, message list, bubbles, media, reactions, menus,
   and the composer.
   ========================================================================== */

.chat-window {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.chat-enter {
  animation: chatEnter var(--dur-3) var(--ease-out);
}
@keyframes chatEnter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}
.chat-window.drop-target::after {
  content: "Drop to attach";
  position: absolute;
  inset: 10px;
  z-index: 40;
  display: grid;
  place-items: center;
  border-radius: var(--r-xl);
  border: 2px dashed var(--primary);
  background: color-mix(in oklab, var(--surface) 80%, transparent);
  color: var(--primary-text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  pointer-events: none;
}

/* ---------------------------------------------------------------------------
   Header
   ------------------------------------------------------------------------- */
.chat-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 68px;
  padding: 10px 12px 10px 14px;
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  border-bottom: 1px solid var(--divider);
}
.chat-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 4px 8px 4px 4px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background-color var(--dur-1) var(--ease);
}
.chat-header-main:hover {
  background: var(--surface-hover);
}
.chat-header-avatar.avatar {
  width: 42px;
  height: 42px;
  font-size: 1rem;
}
.chat-header-info {
  min-width: 0;
  display: grid;
}
.chat-header-info h2 {
  font-size: 1.08rem;
  letter-spacing: -0.015em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-subtitle {
  min-height: 1.2em;
  font-size: 0.8rem;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-subtitle.online {
  color: var(--success);
  font-weight: 600;
}
.chat-subtitle.typing {
  color: var(--primary-text);
  font-weight: 600;
}
.chat-timer-tag {
  color: var(--text-3);
  font-weight: 500;
}
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Menus: chat options, message actions, conversation quick actions,
   snooze. One visual language for every popover. */
.chat-menu,
.msg-actions,
.compose-menu {
  position: absolute;
  z-index: var(--z-popover);
  min-width: 220px;
  padding: 6px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-3);
  animation: popIn var(--dur-2) var(--ease-out);
  transform-origin: top right;
}
.chat-menu {
  top: calc(100% - 6px);
  right: 12px;
}
.msg-actions {
  position: fixed;
}
@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-4px);
  }
}
.chat-menu-item,
.compose-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 0.93rem;
  font-weight: 500;
  text-align: left;
  transition: background-color var(--dur-1) var(--ease);
}
.chat-menu-item:hover,
.compose-menu-item:hover,
.chat-menu-item:focus-visible,
.compose-menu-item:focus-visible {
  background: var(--surface-hover);
  box-shadow: none;
}
.chat-menu-item .icon,
.chat-menu-item [data-icon] {
  color: var(--text-2);
}
.menu-sep {
  height: 1px;
  margin: 5px 8px;
  background: var(--divider);
}

.pinned-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 14px 0;
  padding: 8px 14px;
  border-radius: var(--r-full);
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  align-self: center;
  box-shadow: var(--shadow-1);
}
.pinned-bar:hover {
  color: var(--text);
}
.pinned-bar [data-icon] {
  color: var(--primary-text);
}

/* ---------------------------------------------------------------------------
   Messages
   ------------------------------------------------------------------------- */
#messages-container {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px clamp(10px, 3vw, 28px) 10px;
  overscroll-behavior: contain;
  scroll-padding-bottom: 24px;
}
#messages-list {
  display: flex;
  flex-direction: column;
  max-width: 880px;
  margin: 0 auto;
}

.day-separator {
  position: relative;
  z-index: 2;
  align-self: center;
  margin: 14px 0 10px;
  padding: 4px 12px;
  border-radius: var(--r-full);
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 0.74rem;
  font-weight: 700;
  box-shadow: var(--shadow-1);
}
.unread-divider {
  position: static;
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  color: var(--primary-text);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.unread-divider::before,
.unread-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--primary-line);
}

.message {
  --bubble-bg: var(--bubble-in);
  --bubble-fg: var(--bubble-in-text);
  position: relative;
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  max-width: min(76%, 560px);
  margin-top: 10px;
  padding: 8px 12px 6px;
  border-radius: var(--bubble-r);
  border-bottom-left-radius: var(--bubble-r-tight);
  background: var(--bubble-bg);
  color: var(--bubble-fg);
  border: 1px solid var(--bubble-in-border);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.03);
  animation: msgIn var(--dur-3) var(--ease-out);
  word-break: break-word;
  overflow-wrap: anywhere;
}
@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.985);
  }
}
:root[data-theme="dark"] .message.my-message {
  --bubble-bg: linear-gradient(135deg, var(--primary), var(--primary-strong));
  box-shadow: 0 8px 22px -10px color-mix(in oklab, var(--primary) 90%, transparent), 0 0 0 1px color-mix(in oklab, var(--primary) 40%, transparent) inset;
}
.message.my-message {
  --bubble-bg: var(--bubble-out);
  --bubble-fg: var(--bubble-out-text);
  align-self: flex-end;
  border-color: transparent;
  border-radius: var(--bubble-r);
  border-bottom-right-radius: var(--bubble-r-tight);
  box-shadow: 0 2px 8px -4px color-mix(in oklab, var(--primary) 60%, transparent);
}
/* Runs from one sender: tight spacing, and only the last bubble keeps the
   tucked corner that points at who said it. */
.message.grouped-mid {
  margin-top: 3px;
}
.message:not(.my-message).grouped-mid:not(.grouped-end) {
  border-bottom-left-radius: var(--bubble-r-tight);
}
.message.grouped-mid:not(.my-message) {
  border-top-left-radius: var(--bubble-r-tight);
}
.message.my-message.grouped-mid {
  border-top-right-radius: var(--bubble-r-tight);
}
:root[data-density="compact"] .message {
  margin-top: 6px;
  padding: 6px 10px 5px;
}
:root[data-density="compact"] .message.grouped-mid {
  margin-top: 2px;
}

/* Names only where they carry information: in groups, on the first bubble
   of someone else's run. */
.message-author {
  font-size: 0.76rem;
  font-weight: 700;
  margin-bottom: 1px;
  color: hsl(var(--author-hue, 18) 58% 42%);
}
:root[data-theme="dark"] .message-author {
  color: hsl(var(--author-hue, 18) 70% 72%);
}
.message.my-message .message-author,
.message.grouped-mid .message-author,
.chat-window:not(.is-group) .message-author {
  display: none;
}

.message-text {
  font-family: var(--chat-font);
  font-size: var(--chat-text);
  line-height: 1.42;
  white-space: pre-wrap;
}
.message-text a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, currentColor 50%, transparent);
  text-underline-offset: 2px;
  word-break: break-all;
}
.message-text a:hover {
  text-decoration-color: currentColor;
}
.mention {
  font-weight: 700;
  color: var(--primary-text);
  background: var(--primary-soft);
  padding: 0 3px;
  border-radius: 5px;
}
.my-message .mention {
  color: inherit;
  background: rgba(255, 255, 255, 0.2);
}
.mention.mention-me {
  background: color-mix(in oklab, var(--brand-sun) 40%, transparent);
  color: var(--text);
}

/* Emoji-only: big, no bubble. */
.message.emoji-only .message-text {
  font-size: 1.6rem;
  line-height: 1.25;
}
/* Stickers have no bubble behind them, so the time gets its own frosted
   pill -- readable on any wallpaper, photo or scene. */
.message.sticker-message .message-footer {
  align-self: flex-start;
  margin-top: 4px;
  padding: 1px 7px;
  border-radius: var(--r-full);
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--text-2);
}
.message.my-message.sticker-message .message-footer {
  align-self: flex-end;
}

.message-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
  font-size: 0.68rem;
  line-height: 1.3;
  color: color-mix(in oklab, var(--bubble-fg) 58%, transparent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.msg-flags {
  display: inline-flex;
  gap: 3px;
}
.msg-flags:empty {
  display: none;
}
.edited-tag {
  font-style: italic;
}
.msg-status {
  font-weight: 700;
}
.retry-btn {
  padding: 2px 10px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  font-weight: 700;
  font-size: 0.72rem;
}

/* Delivery state lives in the bubble itself. */
.message.pending {
  opacity: 0.72;
}
.message[data-state="sending"] .message-time::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 5px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
  vertical-align: -1px;
}
.message.failed {
  --bubble-bg: var(--danger-soft);
  --bubble-fg: var(--text);
  border: 1px solid color-mix(in oklab, var(--danger) 40%, transparent);
  box-shadow: none;
}
.message.failed .message-footer {
  color: var(--danger);
  font-weight: 600;
}

.message.flash {
  animation: flashHighlight 1.2s var(--ease);
}
@keyframes flashHighlight {
  0%,
  40% {
    box-shadow: 0 0 0 4px color-mix(in oklab, var(--brand-sun) 70%, transparent);
  }
}
.message.snoozed::after {
  content: "⏰";
  position: absolute;
  top: -8px;
  right: -6px;
  font-size: 0.8rem;
}
.message.my-message.snoozed::after {
  right: auto;
  left: -6px;
}

/* Hover actions: a small button that appears beside the bubble. */
.msg-menu-btn {
  position: absolute;
  top: 50%;
  right: -38px;
  transform: translateY(-50%) scale(0.9);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  box-shadow: var(--shadow-1);
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.my-message .msg-menu-btn {
  right: auto;
  left: -38px;
}
.message:hover .msg-menu-btn,
.msg-menu-btn:focus-visible {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}
@media (hover: none) {
  /* Touch: long-press (chat.js) opens the menu; keep a subtle affordance. */
  .msg-menu-btn {
    display: none;
  }
}

/* System notes: timer changes, key requests. */
.message.system-note {
  align-self: center;
  max-width: 88%;
  margin: 12px 0;
  padding: 6px 14px;
  border-radius: var(--r-full);
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  color: var(--text-2);
  text-align: center;
  box-shadow: none;
}
.message.system-note .message-text {
  font-size: 0.8rem;
  font-weight: 500;
}
.message.system-note .message-footer,
.message.system-note .message-author,
.message.system-note .msg-menu-btn,
.message.system-note .reaction-bar {
  display: none;
}

/* Reply quote inside a bubble. */
.reply-quote {
  display: grid;
  gap: 1px;
  margin: 2px 0 6px;
  padding: 6px 10px;
  border-radius: 10px;
  border-left: 3px solid var(--primary);
  background: color-mix(in oklab, var(--bubble-fg) 7%, transparent);
  text-align: left;
  color: inherit;
  max-width: 100%;
}
.my-message .reply-quote {
  border-left-color: rgba(255, 255, 255, 0.85);
  background: rgba(0, 0, 0, 0.12);
}
.reply-quote-author {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--primary-text);
}
.my-message .reply-quote-author {
  color: inherit;
}
.reply-quote-text {
  font-size: 0.82rem;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-quote.missing {
  opacity: 0.6;
  font-style: italic;
}

/* ---- Reactions ---- */
.reaction-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.reaction-bar.empty {
  display: none;
}
.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 0 8px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  transition: transform var(--dur-1) var(--ease-spring);
  animation: badgePop var(--dur-3) var(--ease-spring);
}
.reaction-pill:hover {
  transform: scale(1.06);
}
.reaction-pill.mine {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-text);
}
.my-message .reaction-pill {
  background: rgba(255, 255, 255, 0.92);
  border-color: transparent;
  color: #1b1822;
}
.my-message .reaction-pill.mine {
  box-shadow: 0 0 0 1.5px #fff inset;
}
.reaction-emoji {
  font-size: 0.95rem;
}
.reaction-picker {
  position: fixed;
  z-index: var(--z-popover);
  display: flex;
  gap: 2px;
  padding: 6px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-3);
  animation: popIn var(--dur-2) var(--ease-spring);
}
.reaction-choice {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.4rem;
  transition: transform var(--dur-1) var(--ease-spring), background-color var(--dur-1);
}
.reaction-choice:hover {
  transform: scale(1.22) translateY(-2px);
  background: var(--surface-hover);
}

/* ---- Media & documents (mediabubble.js) ---- */
.message.has-media {
  padding: 4px;
}
.message.has-media .message-text,
.message.has-media .reply-quote,
.message.has-media .message-author {
  margin-left: 8px;
  margin-right: 8px;
}
.message.has-media .message-text {
  margin-top: 6px;
}
.message.has-media .message-footer {
  padding: 0 8px 4px;
}
.media-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 180px;
  min-height: 120px;
  max-height: 380px;
  border-radius: calc(var(--bubble-r) - 4px);
  overflow: hidden;
  background: var(--surface-3);
}
.media-frame.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, color-mix(in oklab, #fff 35%, transparent) 50%, transparent 80%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
.chat-image,
.chat-video {
  width: 100%;
  max-width: 420px;
  max-height: 380px;
  object-fit: cover;
  cursor: zoom-in;
}
.chat-video {
  cursor: auto;
  background: #000;
}
.doc-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
  max-width: 340px;
  padding: 10px 12px;
  border-radius: calc(var(--bubble-r) - 6px);
  background: color-mix(in oklab, var(--bubble-fg) 7%, transparent);
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.my-message .doc-card {
  background: rgba(0, 0, 0, 0.14);
}
.doc-badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 48px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--primary-text);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-1);
}
.doc-card.kind-pdf .doc-badge { color: #c42b2b; }
.doc-card.kind-audio .doc-badge { color: #7b45e0; }
.doc-card.kind-archive .doc-badge { color: #a3620a; }
.doc-meta {
  flex: 1;
  min-width: 0;
  display: grid;
}
.doc-name {
  font-weight: 650;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-sub {
  font-size: 0.75rem;
  opacity: 0.75;
}
.doc-download {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: color-mix(in oklab, var(--bubble-fg) 12%, transparent);
  color: inherit;
}

/* ---- Stickers ---- */
.message.sticker-message {
  background: none;
  border-color: transparent;
  box-shadow: none;
  padding: 0;
}

.sticker-img {
  width: 132px;
  height: 132px;
  object-fit: contain;
}

/* ---- Location + call log ---- */
.location-card,
.call-log {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px;
  cursor: pointer;
}
.location-pin,
.call-log-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: color-mix(in oklab, var(--bubble-fg) 10%, transparent);
}
.location-meta {
  display: grid;
}
.location-title {
  font-weight: 650;
}
.location-coords {
  font-size: 0.76rem;
  opacity: 0.75;
  font-family: var(--font-mono);
}
.call-log {
  cursor: default;
  font-weight: 600;
}
.call-log.missed .call-log-icon {
  color: var(--danger);
}

/* ---- "On this day" banner ---- */
.memories-banner {
  position: relative;
  align-self: stretch;
  margin: 6px 0 14px;
  padding: 14px 16px;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, color-mix(in oklab, var(--brand-sun) 16%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in oklab, var(--brand-sun) 35%, var(--border));
  box-shadow: var(--shadow-1);
}
.memories-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: color-mix(in oklab, #9a6400 70%, var(--text));
}
.memories-title {
  font-family: var(--font-display);
  font-weight: 700;
}
.memories-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--text-3);
}
.memories-close:hover {
  background: var(--surface-3);
  color: var(--text);
}
.memory-group + .memory-group {
  margin-top: 8px;
}
.memory-when {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.memory-line {
  font-size: 0.88rem;
  line-height: 1.45;
}
.memory-who {
  font-weight: 700;
}
.memory-line.mine .memory-who {
  color: var(--primary-text);
}

/* ---- Encryption banners (keyshare.js) ---- */
.key-banner {
  align-self: stretch;
  display: flex;
  gap: 12px;
  margin: 6px 0 12px;
  padding: 14px 16px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid color-mix(in oklab, var(--warning) 40%, var(--border));
  box-shadow: var(--shadow-1);
}
.key-banner-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--warning-soft);
  color: var(--warning);
}
.key-banner-body {
  flex: 1;
  min-width: 0;
}
.key-banner-text {
  font-size: 0.9rem;
  line-height: 1.5;
}
.key-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.key-banner-btn {
  min-height: 36px;
  padding: 0 14px;
  font-size: var(--fs-sm);
}
.key-request {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.key-request-icon {
  display: inline-grid;
  color: var(--warning);
}
.key-request-share {
  padding: 4px 12px;
  border-radius: var(--r-full);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
  font-size: 0.78rem;
}

/* ---- Loading skeletons ---- */
.msg-skeleton {
  height: 46px;
  width: 42%;
  margin-top: 12px;
  border-radius: var(--bubble-r);
  background: linear-gradient(100deg, var(--skeleton) 30%, var(--skeleton-hi) 50%, var(--skeleton) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
.msg-skeleton.right {
  align-self: flex-end;
  width: 34%;
}
.msg-skeleton:nth-child(3) {
  width: 58%;
  height: 64px;
}
@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* ---- Typing bubble + jump to latest ---- */
.typing-bubble {
  display: flex;
  gap: 4px;
  width: max-content;
  max-width: 880px;
  margin: 10px auto 0 max(0px, calc((100% - 880px) / 2));
  padding: 13px 15px;
  border-radius: var(--bubble-r);
  border-bottom-left-radius: var(--bubble-r-tight);
  background: var(--bubble-in);
  border: 1px solid var(--bubble-in-border);
  color: var(--text-2);
  animation: msgIn var(--dur-3) var(--ease-out);
}
.jump-latest {
  position: absolute;
  right: 20px;
  bottom: 96px;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-2);
  animation: popIn var(--dur-2) var(--ease-spring);
}
.jump-latest:hover {
  background: var(--surface-hover);
}
.jump-count {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 20px;
}

/* ---------------------------------------------------------------------------
   Composer
   ------------------------------------------------------------------------- */
.composer {
  position: relative;
  z-index: 4;
  padding: 6px clamp(8px, 2.4vw, 20px) calc(12px + env(safe-area-inset-bottom));
}
.composer > * {
  max-width: 880px;
  margin-left: auto;
  margin-right: auto;
}

.quick-bar {
  display: flex;
  gap: 6px;
  padding: 2px 2px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.quick-bar::-webkit-scrollbar {
  display: none;
}
.quick-btn {
  flex: none;
  min-height: 36px;
  padding: 0 13px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--chat-font);
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-1) var(--ease-spring), border-color var(--dur-2);
}
.quick-btn:hover {
  transform: translateY(-1px);
  border-color: var(--primary-line);
}

.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  padding: 8px 8px 8px 14px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-1);
  animation: rowIn var(--dur-2) var(--ease-out);
}
.reply-bar-icon {
  color: var(--primary-text);
}
.reply-bar-body {
  flex: 1;
  min-width: 0;
}
.reply-bar-author {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--primary-text);
}
.reply-bar-text {
  font-size: 0.86rem;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-cancel {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-3);
}
.reply-cancel:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* Files waiting to be sent (attachtray.js). */
.file-preview-bar {
  margin-bottom: 6px;
  padding: 10px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}
.tray-tiles {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.tray-tile {
  position: relative;
  flex: none;
  display: grid;
  justify-items: center;
  gap: 4px;
  width: 84px;
}
.tray-thumb,
.tray-badge {
  width: 84px;
  height: 84px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--surface-3);
}
.tray-badge {
  display: grid;
  place-items: center;
  color: var(--primary-text);
  font-weight: 800;
  font-size: 0.8rem;
}
.tray-name {
  width: 100%;
  font-size: 0.7rem;
  color: var(--text-2);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tray-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--text);
  color: var(--surface);
  font-size: 0.8rem;
  box-shadow: var(--shadow-1);
}
.tray-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-size: var(--fs-sm);
  color: var(--text-2);
}
.tray-clear {
  color: var(--danger);
  font-weight: 600;
  font-size: var(--fs-sm);
}

#message-form {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.compose-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-2) var(--ease-spring), color var(--dur-2), background-color var(--dur-2);
}
.compose-btn:hover {
  color: var(--text);
}
.compose-btn[aria-expanded="true"] {
  transform: rotate(45deg);
  color: var(--primary-text);
}
.compose-field {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
.compose-field:focus-within {
  border-color: var(--primary-line);
  box-shadow: 0 0 0 4px var(--primary-softer), var(--shadow-1);
}
#message-input {
  flex: 1;
  min-height: 46px;
  max-height: 180px;
  padding: 12px 4px 12px 18px;
  border: 0;
  border-radius: 24px;
  background: transparent;
  box-shadow: none;
  resize: none;
  font-family: var(--chat-font);
  font-size: 1rem;
  line-height: 1.4;
  overflow-y: auto;
}
#message-input:focus {
  box-shadow: none;
  background: transparent;
}
.compose-emoji {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 3px 4px 3px 0;
  border-radius: 50%;
  color: var(--text-3);
}
.compose-emoji:hover,
.compose-emoji[aria-expanded="true"] {
  color: var(--primary-text);
  background: var(--surface-hover);
}
#send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-3);
  position: relative;
  overflow: hidden;
  transition: background-color var(--dur-2) var(--ease), color var(--dur-2) var(--ease), transform var(--dur-2) var(--ease-spring);
}
#send-btn .send-label {
  display: none;
}
#send-btn.ready,
#message-form.has-files #send-btn {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 6px 16px -6px color-mix(in oklab, var(--primary) 80%, transparent);
}
#send-btn.ready:hover {
  background: var(--primary-strong);
}
#send-btn:active {
  transform: scale(0.9);
}

.compose-menu {
  bottom: calc(100% + 10px);
  left: 0;
  transform-origin: bottom left;
}
.cm-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

/* Sticker + emoji panels sit above the composer. */
.sticker-panel,
.emoji-panel {
  margin-bottom: 8px;
  padding: 10px;
  border-radius: var(--r-xl);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-3);
  animation: popIn var(--dur-2) var(--ease-out);
  transform-origin: bottom center;
}
.chat-filters {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-tab {
  flex: none;
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface-2);
}
.filter-tab.active {
  background: var(--text);
  color: var(--surface);
}
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}
.sticker-cell {
  display: grid;
  place-items: center;
  padding: 6px;
  border-radius: var(--r-md);
  transition: transform var(--dur-1) var(--ease-spring), background-color var(--dur-1);
}
.sticker-cell:hover {
  background: var(--surface-hover);
  transform: scale(1.05);
}
.sticker-cell svg,
.sticker-cell img {
  width: 78px;
  height: 78px;
}
.emoji-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--divider);
}
.emoji-tab {
  display: grid;
  place-items: center;
  width: 36px;
  height: 34px;
  border-radius: var(--r-sm);
  font-size: 1.15rem;
  filter: grayscale(0.7);
  opacity: 0.7;
}
.emoji-tab[aria-selected="true"] {
  background: var(--surface-3);
  filter: none;
  opacity: 1;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
}
.emoji-cell {
  display: grid;
  place-items: center;
  height: 40px;
  border-radius: var(--r-sm);
  font-size: 1.5rem;
  transition: transform var(--dur-1) var(--ease-spring), background-color var(--dur-1);
}
.emoji-cell:hover {
  background: var(--surface-hover);
  transform: scale(1.18);
}

/* @mention autocomplete */
.mention-picker {
  position: absolute;
  left: 56px;
  bottom: calc(100% + 8px);
  z-index: var(--z-popover);
  display: grid;
  min-width: 200px;
  padding: 6px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-3);
  animation: popIn var(--dur-2) var(--ease-out);
}
.mention-option {
  min-height: 38px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  text-align: left;
  font-weight: 600;
}
.mention-option::before {
  content: "@";
  color: var(--text-3);
}
.mention-option:hover,
.mention-option.active {
  background: var(--primary-soft);
  color: var(--primary-text);
}

/* ---------------------------------------------------------------------------
   Phone
   ------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .chat-header {
    min-height: 60px;
    padding: calc(6px + env(safe-area-inset-top)) 6px 6px 4px;
    gap: 2px;
  }
  .chat-header-main {
    gap: 10px;
    padding-left: 2px;
  }
  .chat-header-avatar.avatar {
    width: 38px;
    height: 38px;
  }
  .wide-only {
    display: none;
  }
  .message {
    max-width: 84%;
  }
  .compose-btn,
  #send-btn {
    width: 44px;
    height: 44px;
  }
  .compose-emoji {
    display: none; /* the phone keyboard has emoji */
  }
  #message-input {
    min-height: 44px;
    padding: 11px 16px;
  }
  .jump-latest {
    right: 14px;
    bottom: calc(84px + env(safe-area-inset-bottom));
  }
  .chat-menu {
    right: 6px;
  }
}
@media (min-width: 769px) and (max-width: 1100px) {
  .wide-only#theme-btn {
    display: none;
  }
}

/* Incoming message elsewhere: the bell icons give a small wiggle (chat.js). */
.bell-jiggle {
  animation: bellJiggle 0.6s var(--ease);
  transform-origin: 50% 10%;
}
@keyframes bellJiggle {
  20% { transform: rotate(14deg); }
  40% { transform: rotate(-12deg); }
  60% { transform: rotate(8deg); }
  80% { transform: rotate(-4deg); }
}
