/* Telegram-style family chat. Colors follow Telegram Web/iOS day and night themes. */
:root {
  color-scheme: light dark;
  --accent: #3390ec;
  --accent-strong: #2481cc;
  --text: #000;
  --text-secondary: #707579;
  --surface: #fff;
  --surface-muted: #f4f4f5;
  --border: #dadce0;
  --header: rgb(255 255 255 / 0.92);
  --incoming: #fff;
  --outgoing: #eeffde;
  --meta: #686c72;
  --meta-own: #4fae4e;
  --link: #3390ec;
  --link-own: #3a8e26;
  --quote-own: #4fae4e;
  --danger: #e53935;
  --pill: rgb(74 90 72 / 0.42);
  --shadow: 0 1px 2px rgb(16 35 47 / 0.15);
  --wallpaper: linear-gradient(145deg, #d9f2ff 0%, #e4ecff 48%, #efe1ff 100%);
  --code-bg: rgb(0 0 0 / 0.06);
  --peer-0: #cc5049;
  --peer-1: #d67722;
  --peer-2: #955cdb;
  --peer-3: #40a920;
  --peer-4: #309eba;
  --peer-5: #368ad1;
  --peer-6: #c7508b;
  --avatar-0: linear-gradient(#ff885e, #ff516a);
  --avatar-1: linear-gradient(#ffcd6a, #ffa85c);
  --avatar-2: linear-gradient(#82b1ff, #665fff);
  --avatar-3: linear-gradient(#a0de7e, #54cb68);
  --avatar-4: linear-gradient(#53edd6, #28c9b7);
  --avatar-5: linear-gradient(#72d5fd, #2a9ef1);
  --avatar-6: linear-gradient(#e0a2f3, #d669ed);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #8774e1;
    --accent-strong: #7360cf;
    --text: #fff;
    --text-secondary: #aaa;
    --surface: #212121;
    --surface-muted: #2c2c2e;
    --border: #303030;
    --header: rgb(33 33 33 / 0.94);
    --incoming: #212121;
    --outgoing: #766ac8;
    --meta: #a2acb4;
    --meta-own: #fff;
    --link: #8774e1;
    --link-own: #fff;
    --quote-own: #fff;
    --pill: rgb(0 0 0 / 0.45);
    --wallpaper: linear-gradient(145deg, #142738 0%, #222b47 52%, #35284d 100%);
    --code-bg: rgb(255 255 255 / 0.08);
    --peer-0: #ff7b74;
    --peer-1: #ffad5c;
    --peer-2: #b99aff;
    --peer-3: #7fd85f;
    --peer-4: #5ccce8;
    --peer-5: #6ab7ff;
    --peer-6: #ff7fc0;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--text);
  overscroll-behavior: none;
}

button,
textarea,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  max-width: 820px;
  margin: 0 auto;
  background: var(--wallpaper);
  overflow: hidden;
}

@supports (height: 100dvh) {
  .shell {
    height: 100dvh;
  }
}

/* ---------- Header ---------- */
.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: max(6px, env(safe-area-inset-top)) 10px 6px 14px;
  background: var(--header);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.group-avatar {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-muted);
}

.group-info {
  min-width: 0;
  flex: 1;
}

.group-info h1 {
  margin: 0;
  overflow: hidden;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.connection {
  display: block;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.25;
}

.connection.online {
  color: var(--accent);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

/* ---------- Enrollment ---------- */
.welcome {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 32px 28px;
  text-align: center;
  background: var(--surface);
}

.welcome-mark {
  width: 88px;
  height: 88px;
  margin-bottom: 20px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.welcome h2 {
  margin: 8px 0 12px;
  font-size: 1.6rem;
  line-height: 1.15;
}

.welcome > p:not(.eyebrow):not(.error) {
  max-width: 420px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.welcome .handoff {
  padding: 14px 16px;
  /* iOS 15 has no color-mix(); the plain border is its fallback. */
  border: 1px solid var(--accent);
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.primary {
  min-height: 52px;
  margin-top: 16px;
  padding: 0 26px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.primary:disabled {
  opacity: 0.5;
}

.secondary {
  min-height: 44px;
  margin-top: 16px;
  padding: 0 20px;
  border: 1px solid var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 12px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}

.secondary:disabled {
  opacity: 0.5;
}

.welcome .home-screen {
  max-width: 420px;
  text-align: left;
}

.welcome .home-screen p {
  margin: 0 0 6px;
}

.welcome .home-screen ol {
  margin: 0 0 8px;
  padding-left: 22px;
  line-height: 1.45;
}

.error {
  min-height: 1.1em;
  margin: 4px 10px 0;
  color: var(--danger);
  font-size: 0.82rem;
}

.error:empty {
  display: none;
}

/* ---------- Timeline ---------- */
main {
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.chat {
  min-height: 100%;
  padding: 8px 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.older-sentinel {
  height: 1px;
}

.older {
  display: block;
  margin: 4px auto 10px;
  padding: 6px 12px;
  border: 0;
  border-radius: 14px;
  background: var(--pill);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
}

.timeline {
  display: flex;
  flex-direction: column;
}

.day {
  display: flex;
  flex-direction: column;
}

.date-pill,
.service {
  position: relative;
  z-index: 1;
  align-self: center;
  max-width: 86%;
  margin: 8px auto;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--pill);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
}

.date-pill {
  position: sticky;
  top: 6px;
  z-index: 3;
}

.unread-divider {
  align-self: stretch;
  margin: 8px -8px;
  padding: 4px 0;
  background: rgb(255 255 255 / 0.55);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  .unread-divider {
    background: rgb(0 0 0 / 0.35);
  }
}

.row {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin-top: 2px;
  transition: transform 0.18s ease;
}

.row.first {
  margin-top: 8px;
}

.row.outbound {
  justify-content: flex-end;
}

.row.highlight .bubble {
  animation: highlight 1.4s ease-out;
}

@keyframes highlight {
  0%,
  40% {
    box-shadow: 0 0 0 3px var(--accent);
  }
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  visibility: hidden;
}

.row.last .avatar {
  visibility: visible;
}

.row.outbound .avatar {
  display: none;
}

.bubble {
  position: relative;
  max-width: min(85%, 480px);
  min-width: 64px;
  padding: 6px 9px 6px;
  border-radius: 15px;
  background: var(--incoming);
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}

.row.outbound .bubble {
  background: var(--outgoing);
}

.row.inbound.last .bubble {
  border-bottom-left-radius: 4px;
}

.row.outbound.last .bubble {
  border-bottom-right-radius: 4px;
}

.row.last .bubble:not(.bare)::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 9px;
  height: 17px;
  background: inherit;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 17'%3E%3Cpath d='M9 0v17H1.5C.7 17 0 16.4 0 15.6c0-.4.2-.8.5-1.1C6.3 9.6 8.6 5.3 9 0z'/%3E%3C/svg%3E")
    no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 17'%3E%3Cpath d='M9 0v17H1.5C.7 17 0 16.4 0 15.6c0-.4.2-.8.5-1.1C6.3 9.6 8.6 5.3 9 0z'/%3E%3C/svg%3E")
    no-repeat;
}

.row.inbound.last .bubble:not(.bare)::after {
  left: -8px;
}

.row.outbound.last .bubble:not(.bare)::after {
  right: -8px;
  transform: scaleX(-1);
}

.bubble.media-bubble {
  padding: 0;
  overflow: hidden;
}

.bubble.media-bubble::after {
  display: none;
}

.bubble.bare {
  padding: 0;
  background: transparent !important;
  box-shadow: none;
}

.sender {
  display: block;
  margin-bottom: 1px;
  overflow: hidden;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.row:not(.first) .sender,
.row.outbound .sender {
  display: none;
}

.media-bubble > .sender,
.media-bubble > .forwarded,
.media-bubble > .reply-quote {
  width: auto;
  margin: 6px 9px 4px;
}

.forwarded {
  display: block;
  margin-bottom: 3px;
  color: var(--accent);
  font-size: 0.85rem;
  line-height: 1.25;
}

.row.outbound .forwarded {
  color: var(--link-own);
}

.forwarded strong {
  display: block;
  font-weight: 600;
}

.peer-0 {
  color: var(--peer-0);
  --peer: var(--peer-0);
}
.peer-1 {
  color: var(--peer-1);
  --peer: var(--peer-1);
}
.peer-2 {
  color: var(--peer-2);
  --peer: var(--peer-2);
}
.peer-3 {
  color: var(--peer-3);
  --peer: var(--peer-3);
}
.peer-4 {
  color: var(--peer-4);
  --peer: var(--peer-4);
}
.peer-5 {
  color: var(--peer-5);
  --peer: var(--peer-5);
}
.peer-6 {
  color: var(--peer-6);
  --peer: var(--peer-6);
}
.avatar.peer-0 {
  background: var(--avatar-0);
  color: #fff;
}
.avatar.peer-1 {
  background: var(--avatar-1);
  color: #fff;
}
.avatar.peer-2 {
  background: var(--avatar-2);
  color: #fff;
}
.avatar.peer-3 {
  background: var(--avatar-3);
  color: #fff;
}
.avatar.peer-4 {
  background: var(--avatar-4);
  color: #fff;
}
.avatar.peer-5 {
  background: var(--avatar-5);
  color: #fff;
}
.avatar.peer-6 {
  background: var(--avatar-6);
  color: #fff;
}

.reply-quote {
  display: block;
  width: 100%;
  min-width: 140px;
  margin: 2px 0 4px;
  padding: 3px 8px 3px 9px;
  border: 0;
  border-left: 3px solid var(--peer, var(--accent));
  border-radius: 5px;
  background: color-mix(in srgb, var(--peer, var(--accent)) 12%, transparent);
  text-align: left;
  line-height: 1.25;
}

.row.outbound .reply-quote {
  --peer: var(--quote-own);
}

.reply-quote strong {
  display: block;
  overflow: hidden;
  color: var(--peer, var(--accent));
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.reply-quote span {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 0.88rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.reply-quote .reply-kind {
  color: var(--text-secondary);
}

.text {
  margin: 0;
  line-height: 1.32;
  white-space: pre-wrap;
}

.bubble .caption {
  padding: 4px 0 0;
}

.media-bubble .caption {
  padding: 5px 9px 7px;
}

.big-emoji .text {
  font-size: 3rem;
  line-height: 1.15;
}

.big-emoji .meta {
  float: none;
  display: flex;
  width: max-content;
  margin: 2px 0 0 auto;
  padding: 3px 6px;
  border-radius: 10px;
  background: rgb(0 0 0 / 0.42);
  color: #fff !important;
  font-size: 0.72rem;
  line-height: 1;
}

.text a {
  color: var(--link);
  text-decoration: none;
}

.row.outbound .text a,
.row.outbound .mention,
.row.outbound .hashtag {
  color: var(--link-own);
}

.mention,
.hashtag {
  color: var(--link);
}

.text code {
  padding: 0 3px;
  border-radius: 4px;
  background: var(--code-bg);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
}

.text pre {
  margin: 4px 0;
  padding: 6px 8px;
  overflow-x: auto;
  border-radius: 6px;
  background: var(--code-bg);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85em;
  white-space: pre;
}

.text blockquote {
  margin: 4px 0;
  padding: 2px 8px;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.row.outbound .text blockquote {
  border-left-color: var(--quote-own);
  background: color-mix(in srgb, var(--quote-own) 12%, transparent);
}

.text blockquote.collapsed {
  max-height: 4.1em;
  overflow: hidden;
  cursor: pointer;
}

.spoiler {
  border-radius: 4px;
  background: currentColor;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.2s;
}

.spoiler * {
  visibility: hidden;
}

.spoiler.revealed {
  background: transparent;
  color: inherit;
}

.spoiler.revealed * {
  visibility: visible;
}

/* ---------- Meta (time, ticks) ---------- */
.meta {
  position: relative;
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 6px 0 -4px 10px;
  color: var(--meta);
  font-size: 0.72rem;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
}

.row.outbound .meta {
  color: var(--meta-own);
}

.meta svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.2;
}

.meta.overlay {
  position: absolute;
  right: 6px;
  bottom: 6px;
  float: none;
  margin: 0;
  padding: 3px 6px;
  border-radius: 10px;
  background: rgb(0 0 0 / 0.42);
  color: #fff !important;
}

.meta .failed {
  color: var(--danger);
  font-weight: 700;
}

.bubble::before {
  content: "";
  display: table;
}

.bubble > .clear {
  clear: both;
}

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 5px 0 0;
}

.reaction {
  display: inline-flex;
  min-width: 38px;
  height: 28px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 2px 9px;
  border: 1px solid rgba(112, 126, 146, 0.22);
  border-radius: 14px;
  background: rgba(235, 240, 248, 0.82);
  color: #536174;
  font: inherit;
  cursor: pointer;
}

.reaction.chosen {
  border-color: #76b8ea;
  background: #dff1ff;
  color: #2186c4;
}

.reaction.pending {
  opacity: 0.7;
}

.reaction-emoji {
  font-size: 16px;
  line-height: 1;
}
.reaction-count {
  font-size: 12px;
  font-weight: 600;
}

/* ---------- Photos, videos, albums ---------- */
.media {
  position: relative;
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: rgb(0 0 0 / 0.08);
  overflow: hidden;
}

.bubble:not(.media-bubble) .media {
  margin: 4px 0 2px;
  border-radius: 10px;
}

.media img,
.media video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media.single {
  max-width: 100%;
}

.media.spoiler-media img,
.media.spoiler-media video {
  filter: blur(24px) brightness(0.8);
  transform: scale(1.1);
}

.media .badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 6px;
  border-radius: 9px;
  background: rgb(0 0 0 / 0.45);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
}

.media .play {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.45);
  color: #fff;
}

.media .play svg {
  fill: currentColor;
  stroke: none;
  margin-left: 3px;
}

.media .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.album {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  width: min(100vw - 80px, 420px);
}

.album .media {
  aspect-ratio: 1;
  grid-column: span 3;
}

.album.count-3 .media:first-child,
.album.count-5 .media:first-child,
.album.count-7 .media:first-child,
.album.count-9 .media:first-child {
  grid-column: span 6;
  aspect-ratio: 16 / 9;
}

.album.count-5 .media:nth-child(n + 4),
.album.count-6 .media:nth-child(n + 4),
.album.count-8 .media:nth-child(n + 6),
.album.count-9 .media:nth-child(n + 7),
.album.count-10 .media:nth-child(n + 7) {
  grid-column: span 2;
}

/* ---------- Round video notes ---------- */
.video-note {
  position: relative;
  width: min(240px, 62vw);
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.15);
  overflow: hidden;
  isolation: isolate;
}

.video-note video {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.video-note .ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
}

.video-note .ring circle {
  fill: none;
  stroke: rgb(255 255 255 / 0.9);
  stroke-width: 2.5;
  stroke-dasharray: 301.6;
  stroke-dashoffset: 301.6;
}

.video-note .note-badge {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgb(0 0 0 / 0.45);
  color: #fff;
  font-size: 0.75rem;
}

.video-note .note-badge svg {
  width: 13px;
  height: 13px;
}

.video-note-row .meta.overlay {
  right: 4px;
  bottom: 4px;
}

/* ---------- Voice and music players ---------- */
.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 2px 0;
}

.audio-play {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}

.row.outbound .audio-play {
  background: var(--meta-own);
}

.audio-play svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  stroke: none;
}

.audio-body {
  flex: 1;
  min-width: 0;
}

.waveform {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: none;
}

.waveform i {
  flex: 0 0 3px;
  min-height: 3px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}

.row.outbound .waveform i {
  background: color-mix(in srgb, var(--meta-own) 40%, transparent);
}

.waveform i.played {
  background: var(--accent);
}

.row.outbound .waveform i.played {
  background: var(--meta-own);
}

.audio-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--meta);
  font-size: 0.78rem;
}

.row.outbound .audio-info {
  color: var(--meta-own);
}

.audio-info .unplayed {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.audio-speed {
  margin-left: auto;
  padding: 1px 6px;
  border: 0;
  border-radius: 8px;
  background: color-mix(in srgb, currentColor 15%, transparent);
  color: inherit;
  font-size: 0.72rem;
  font-weight: 700;
}

.music-title {
  display: block;
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.music-progress {
  display: block;
  height: 3px;
  margin: 6px 0 2px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  overflow: hidden;
}

.music-progress i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}

/* ---------- Documents and cards ---------- */
.document {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 2px 0;
  color: inherit;
  text-decoration: none;
}

.document-icon {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.row.outbound .document-icon {
  background: var(--meta-own);
}

.document-body {
  min-width: 0;
}

.document-name {
  display: block;
  overflow: hidden;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.document-size {
  display: block;
  color: var(--meta);
  font-size: 0.8rem;
}

.card-title {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
}

.card-subtitle {
  display: block;
  color: var(--meta);
  font-size: 0.8rem;
}

.poll-option {
  position: relative;
  margin: 8px 0;
}

.poll-option .label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.92rem;
}

.poll-option .percent {
  font-weight: 700;
}

.poll-option .bar {
  display: block;
  height: 4px;
  margin-top: 4px;
  border-radius: 2px;
  background: var(--accent);
}

.location-card,
.contact-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.location-pin {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
}

.card-link {
  display: inline-block;
  margin-top: 4px;
  color: var(--link);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
}

.row.outbound .card-link {
  color: var(--link-own);
}

.unsupported {
  color: var(--text-secondary);
  font-style: italic;
}

.sticker {
  display: block;
  width: 160px;
  height: 160px;
  object-fit: contain;
  border: 0;
  padding: 0;
  background: transparent;
}

.sticker-emoji {
  display: block;
  font-size: 4.5rem;
  line-height: 1.1;
  text-align: center;
}

.sticker-row .meta.overlay {
  right: 0;
  bottom: 0;
}

/* ---------- Jump button ---------- */
.jump {
  position: absolute;
  right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-secondary);
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.2);
}

.jump-count {
  position: absolute;
  top: -6px;
  left: 50%;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  transform: translateX(-50%);
}

.empty {
  display: grid;
  place-items: center;
  align-self: center;
  margin: auto;
  padding: 20px 26px;
  border-radius: 18px;
  background: var(--pill);
  color: #fff;
  text-align: center;
}

.empty img {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
}

/* ---------- Composer ---------- */
.composer {
  position: relative;
  z-index: 6;
  padding: 6px 8px max(6px, env(safe-area-inset-bottom));
  background: var(--header);
  border-top: 1px solid var(--border);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.composer form {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 14px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 21px;
  background: var(--surface);
  outline: none;
  line-height: 1.25;
}

.composer textarea:focus {
  border-color: var(--accent);
}

.round-button {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
}

.send {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}

.send svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: none;
}

.send:disabled {
  opacity: 0.5;
}

.context-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 4px 6px;
  color: var(--accent);
}

.context-banner > svg {
  flex: 0 0 22px;
}

.context-text {
  flex: 1;
  min-width: 0;
  padding-left: 9px;
  border-left: 2px solid var(--accent);
  line-height: 1.25;
}

.context-text strong,
.context-text span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.context-text strong {
  font-size: 0.85rem;
}

.context-text span {
  color: var(--text);
  font-size: 0.88rem;
}

.context-banner button,
.install-hint button {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.5rem;
  line-height: 1;
}

.install-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 4px 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-size: 0.85rem;
  line-height: 1.3;
}

.mentions {
  max-height: 200px;
  margin: 0 0 6px;
  overflow-y: auto;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.15);
}

.mentions button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  text-align: left;
}

.mentions button[aria-selected="true"] {
  background: var(--surface-muted);
}

.mentions .avatar {
  visibility: visible;
}

.recorder {
  min-width: 0;
  padding: 0;
  border: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 4px;
}

.recorder-cancel {
  border: 0;
  background: transparent;
  color: var(--danger);
  font-weight: 600;
}

.recorder-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  to {
    opacity: 0.3;
  }
}

.recorder-time {
  font-variant-numeric: tabular-nums;
}

.recorder-level {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    var(--accent) var(--level, 0%),
    var(--border) var(--level, 0%)
  );
}

.recorder:not(.hidden) ~ form {
  display: none;
}

/* ---------- Sheets, lightbox, toast ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgb(0 0 0 / 0.35);
}

.sheet-panel {
  width: min(560px, 100%);
  margin: 8px;
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
  border-radius: 14px;
  background: var(--surface);
  animation: sheet-in 0.18s ease-out;
}

@keyframes sheet-in {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
}

.sheet-panel button {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  font-size: 1rem;
  text-align: left;
}

.sheet-panel button:last-child {
  border-bottom: 0;
}

.sheet-panel button.danger {
  color: var(--danger);
}

.sheet-panel button.cancel {
  justify-content: center;
  font-weight: 600;
  color: var(--accent);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #000;
  color: #fff;
}

.lightbox-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: rgb(0 0 0 / 0.5);
}

.lightbox-bar button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: #fff;
}

.lightbox-meta {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.lightbox-meta strong,
.lightbox-meta span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.lightbox-meta span {
  color: rgb(255 255 255 / 0.65);
  font-size: 0.82rem;
}

.lightbox-stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: auto;
  touch-action: pan-x pan-y pinch-zoom;
}

.lightbox-stage img,
.lightbox-stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.2s ease;
}

.lightbox-stage.zoomed img {
  max-width: none;
  max-height: none;
  width: 200%;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 64px;
  margin-top: -32px;
  border: 0;
  background: transparent;
  color: rgb(255 255 255 / 0.8);
}

.lightbox-nav.prev {
  left: 4px;
}

.lightbox-nav.next {
  right: 4px;
}

.lightbox-caption {
  max-height: 30dvh;
  margin: 0;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background: rgb(0 0 0 / 0.5);
  line-height: 1.35;
  white-space: pre-wrap;
}

.lightbox-caption:empty {
  display: none;
}

.video-recorder {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgb(0 0 0 / 0.85);
  color: #fff;
}

.video-recorder-circle {
  position: relative;
  width: min(300px, 78vw);
  aspect-ratio: 1;
}

.video-recorder-circle video {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #111;
}

.video-recorder-ring {
  position: absolute;
  inset: -6px;
  width: calc(100% + 12px);
  height: calc(100% + 12px);
  transform: rotate(-90deg);
}

.video-recorder-ring circle {
  fill: none;
  stroke: var(--danger);
  stroke-width: 2;
  stroke-dasharray: 301.6;
  stroke-dashoffset: 301.6;
}

.video-recorder-time {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.video-recorder-actions {
  display: flex;
  align-items: center;
  gap: 32px;
}

.video-recorder-actions > button:first-child {
  border: 0;
  background: transparent;
  color: #fff;
  font-weight: 600;
}

.record-toggle {
  width: 64px;
  height: 64px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: var(--danger);
}

.record-toggle.recording {
  border-radius: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  z-index: 40;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgb(0 0 0 / 0.78);
  color: #fff;
  font-size: 0.9rem;
  transform: translateX(-50%);
}

@media (prefers-reduced-motion: no-preference) {
  .row.arrived {
    animation: arrive 0.18s ease-out;
  }

  @keyframes arrive {
    from {
      opacity: 0.3;
      transform: translateY(6px);
    }
  }
}

@media (min-width: 821px) {
  body {
    padding: 0;
  }

  .shell {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* Failed local message: large, explicit retry controls instead of a silent resend. */
.send-retry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.875rem;
}

.send-retry-label {
  color: var(--danger);
  font-weight: 600;
}

.send-retry button {
  min-height: 36px;
  padding: 6px 14px;
  border: 0;
  border-radius: 18px;
  font: inherit;
  cursor: pointer;
}

.send-retry-button {
  background: var(--accent);
  color: #fff;
}

.send-retry-discard {
  background: transparent;
  color: var(--text-secondary);
}
