:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0b0f14;
  --panel: #111820;
  --panel-2: #151e28;
  --border: #26313d;
  --text: #edf3f8;
  --muted: #8ea0b1;
  --accent: #6fa8ff;
  --accent-2: #3d7cda;
  --danger: #ff7f87;
  --bubble: #192431;
  --bubble-mine: #214a78;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { min-height: 22px; color: var(--danger); font-size: 14px; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(100%, 440px);
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 22px 60px rgba(0,0,0,.35);
}
.brand-row { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand-row h1 { margin: 0; font-size: 22px; }
.brand-row p { margin: 4px 0 0; }
.logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  font-weight: 800;
  color: white;
}
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 18px; background: #0c1218; padding: 4px; border-radius: 10px; }
.tab { border: 0; border-radius: 8px; padding: 9px; background: transparent; color: var(--muted); }
.tab.active { background: var(--panel-2); color: var(--text); }
.auth-form { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: #c9d4de; font-size: 14px; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  background: #0c1218;
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(61,124,218,.16); }
.primary { border: 0; border-radius: 10px; padding: 11px 15px; background: var(--accent-2); color: white; font-weight: 700; }
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .55; cursor: default; }
.ghost { border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: 9px; padding: 7px 10px; }
.note { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 0; }

.app-shell { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 320px 1fr; overflow: hidden; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; min-width: 0; flex-direction: column; }
.sidebar-header { min-height: 68px; padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.search-box { padding: 12px; }
.user-list { min-height: 0; flex: 1; overflow: auto; padding: 0 8px; }
.user-item { width: 100%; border: 0; display: flex; align-items: center; gap: 11px; color: var(--text); background: transparent; padding: 9px; border-radius: 10px; text-align: left; }
.user-item:hover, .user-item.active { background: var(--panel-2); }
.avatar-wrap { position: relative; width: 38px; height: 38px; flex: 0 0 38px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: #26394b; color: #bcd6ef; font-size: 13px; font-weight: 800; }
.user-copy { min-width: 0; flex: 1; display: grid; gap: 3px; }
.user-item-top, .user-item-bottom { min-width: 0; display: flex; align-items: center; gap: 8px; }
.user-item-top { justify-content: space-between; }
.user-item-bottom { justify-content: space-between; }
.user-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.user-time { color: var(--muted); font-size: 10px; flex: 0 0 auto; }
.user-item-subtitle { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.user-presence-text { color: var(--muted); font-size: 11px; }
.unread-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: inline-grid; place-items: center; background: var(--accent-2); color: white; font-size: 10px; font-weight: 800; flex: 0 0 auto; }
.sidebar-empty { padding: 18px 12px; color: var(--muted); font-size: 12px; line-height: 1.45; text-align: center; }
.presence-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #65717d; box-shadow: 0 0 0 3px rgba(101,113,125,.1); flex: 0 0 auto; }
.presence-dot[data-online="true"] { background: #54d38a; box-shadow: 0 0 0 3px rgba(84,211,138,.12); }
.presence-dot[data-online="pending"] { background: #e8b94c; box-shadow: 0 0 0 3px rgba(232,185,76,.1); }
.user-presence-dot { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border: 2px solid var(--panel); box-shadow: none; }
.user-item.active .user-presence-dot, .user-item:hover .user-presence-dot { border-color: var(--panel-2); }
.security-note { border-top: 1px solid var(--border); padding: 13px 14px; display: grid; gap: 4px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.security-note strong { color: #d5e1ec; }
.chat { min-width: 0; min-height: 0; background: radial-gradient(circle at 50% 0%, #111a23 0, var(--bg) 55%); }
.empty-state { height: 100%; display: grid; place-content: center; text-align: center; padding: 30px; color: var(--muted); }
.empty-state h2 { color: var(--text); margin-bottom: 5px; }
.empty-state p { max-width: 460px; }
.chat-layout { height: 100%; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.chat-header { height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: rgba(11,15,20,.82); backdrop-filter: blur(12px); }
.chat-header-status { display: flex; align-items: center; gap: 14px; }
.peer-presence { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #687582; box-shadow: 0 0 0 4px rgba(104,117,130,.1); }
.status-dot[data-state="open"] { background: #54d38a; box-shadow: 0 0 0 4px rgba(84,211,138,.1); }
/* A healthy connection needs no indicator; next to the peer's presence dot it
   read as a second "online" mark. Problems show as a dot plus the banner. */
#socket-state[data-state="open"] { display: none; }
.status-dot[data-state="connecting"] { background: #e8b94c; }
.messages { min-height: 0; flex: 1 1 auto; overflow: auto; padding: 20px clamp(14px, 4vw, 56px); }
.message-row { display: flex; margin: 7px 0; }
.message-row.mine { justify-content: flex-end; }
.message-bubble { max-width: min(680px, 78%); background: var(--bubble); border: 1px solid #273646; border-radius: 14px 14px 14px 4px; padding: 9px 11px 6px; box-shadow: 0 4px 15px rgba(0,0,0,.12); }
.message-row.mine .message-bubble { background: var(--bubble-mine); border-color: #2d5a8c; border-radius: 14px 14px 4px 14px; }
.message-bubble.crypto-error { border-color: #6b3a3e; background: #311d20; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.42; }
.message-text.message-hydrating {
  min-width: 88px;
  min-height: 1.42em;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(255,255,255,.035), rgba(255,255,255,.09), rgba(255,255,255,.035));
  background-size: 220% 100%;
  animation: message-hydrating-shimmer 1.15s ease-in-out infinite;
}
@keyframes message-hydrating-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.conversation-loading {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: 4px;
  pointer-events: none;
}
.conversation-loading-row { display: flex; margin: 7px 0; }
.conversation-loading-row.mine { justify-content: flex-end; }
.conversation-loading-bubble {
  width: clamp(150px, 32vw, 310px);
  padding: 11px;
  border: 1px solid rgba(255,255,255,.045);
  border-radius: 14px 14px 14px 4px;
  background: rgba(255,255,255,.025);
}
.conversation-loading-row.mine .conversation-loading-bubble {
  width: clamp(130px, 28vw, 270px);
  border-radius: 14px 14px 4px 14px;
}
.conversation-loading-line {
  display: block;
  width: 74%;
  height: 13px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255,255,255,.035), rgba(255,255,255,.085), rgba(255,255,255,.035));
  background-size: 220% 100%;
  animation: message-hydrating-shimmer 1.15s ease-in-out infinite;
}
.conversation-load-error {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .message-text.message-hydrating, .conversation-loading-line { animation: none; }
}
.message-meta { margin-top: 5px; display: flex; align-items: center; justify-content: flex-end; gap: 4px; color: #93a8bb; font-size: 10px; max-width: 420px; overflow: hidden; white-space: nowrap; }
.message-time { flex: 0 0 auto; }
.message-receipt { flex: 0 0 20px; width: 20px; display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; letter-spacing: -1px; transition: color .12s ease, opacity .12s ease; }
.message-receipt[data-state="pending"] { opacity: .55; }
.message-receipt[data-state="sent"] { opacity: .72; }
.message-receipt[data-state="delivered"] { opacity: .9; }
.message-receipt[data-state="read"] { color: #8fc9ff; opacity: 1; }
.message-receipt[data-state="failed"] { color: var(--danger); opacity: 1; font-weight: 800; letter-spacing: 0; }
.message-device { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.message-device:not(:empty)::before { content: "·"; margin-right: 4px; }
.composer { flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; padding: 13px clamp(12px, 3vw, 32px) 16px; border-top: 1px solid var(--border); background: rgba(11,15,20,.9); }
.composer textarea { resize: none; height: 52px; min-height: 52px; max-height: 132px; overflow-y: hidden; line-height: 21px; transition: height .08s ease; }
.send-button { align-self: end; min-height: 44px; }

@media (max-width: 720px) {
  .app-shell { grid-template-columns: 130px 1fr; }
  .sidebar-header { align-items: flex-start; flex-direction: column; }
  .sidebar-header .small, .security-note { display: none; }
  .user-copy { display: none; }
  .user-item { justify-content: center; }
  .peer-presence span:last-child { display: none; }
  .search-box { padding: 8px; }
  .search-box input { padding: 8px; font-size: 12px; }
  .message-bubble { max-width: 90%; }
}

/* v0.3 multi-device + verification */
.auth-actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
.sidebar-actions { display: flex; align-items: center; gap: 6px; }
.sidebar-actions .ghost { font-size: 12px; padding: 6px 8px; }

.peer-info-button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  white-space: nowrap;
}
.peer-info-button:hover { color: var(--text); border-color: #3a4a5c; background: rgba(255,255,255,.025); }
.security-alert {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 18px;
  border-bottom: 1px solid #765b28;
  background: rgba(118,91,40,.19);
  color: #ffd98c;
  font-size: 12px;
  line-height: 1.45;
}
.security-alert-button {
  flex: 0 0 auto;
  border: 1px solid #8c6c33;
  border-radius: 8px;
  background: rgba(0,0,0,.14);
  color: #ffe6ad;
  padding: 6px 9px;
  font-size: 11px;
}
.modal {
  width: min(760px, calc(100vw - 28px));
  max-height: min(82vh, 820px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
}
.modal::backdrop { background: rgba(0,0,0,.66); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.modal-head h2 { margin: 0 0 5px; font-size: 19px; }
.modal-head p { margin: 0; max-width: 570px; line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.verification-code {
  margin: 10px 0 14px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0c1218;
  color: #d3e5f6;
  font: 600 11px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}
.device-list { display: grid; gap: 10px; }
.device-card {
  display: grid;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #0d141b;
}
.device-card.revoked { opacity: .58; }
.device-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.device-tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.device-tag { border: 1px solid #324253; border-radius: 999px; padding: 3px 7px; color: var(--muted); font-size: 10px; }
.device-tag.current { border-color: #2c5c43; color: #83dfa9; }
.fingerprint {
  display: block;
  border-radius: 8px;
  padding: 9px 10px;
  background: #080d12;
  color: #bcd6ef;
  white-space: normal;
  overflow-wrap: anywhere;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.tiny { font-size: 11px; }
.danger-button {
  justify-self: start;
  border: 1px solid #6b3a3e;
  background: rgba(107,58,62,.15);
  color: #ff9da4;
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 11px;
}
.danger-button:disabled { opacity: .5; }

@media (max-width: 920px) {
  .chat-header-status { gap: 8px; }
}

@media (max-width: 720px) {
  .sidebar-actions { flex-direction: column; align-items: stretch; }
  .sidebar-actions .ghost { font-size: 10px; padding: 5px 6px; }
  .peer-info-button { font-size: 0; width: 32px; height: 32px; padding: 0; }
  .peer-info-button::after { content: "i"; font-size: 13px; font-weight: 800; }
  .security-alert { align-items: flex-start; padding: 9px 12px; }
  .modal { padding: 14px; }
  .modal-head { flex-direction: column; }
}

/* v0.4 approved devices + history transfer */
.app-shell { position: relative; }
.pending-device-banner {
  position: fixed;
  z-index: 40;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 28px));
  padding: 10px 14px;
  border: 1px solid #765b28;
  border-radius: 11px;
  background: #2a2214;
  color: #ffd98c;
  box-shadow: 0 12px 36px rgba(0,0,0,.35);
  font-size: 12px;
  line-height: 1.45;
}
.pending-device-banner strong { color: #ffe8b3; margin-right: 5px; }
/* Sits above the composer so it never covers the chat header buttons. */
.realtime-banner {
  top: auto;
  bottom: calc(86px + env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}
.realtime-retry {
  flex: none;
  padding: 6px 12px;
  border: 1px solid currentColor;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.device-card.pending { border-color: #765b28; }
.device-tag.pending { border-color: #765b28; color: #ffd27a; background: rgba(118,91,40,.15); }
.device-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 3px; }
.device-waiting-note {
  padding: 9px 10px;
  border: 1px solid #765b28;
  border-radius: 8px;
  background: rgba(118,91,40,.13);
  color: #ffd98c;
  font-size: 11px;
  line-height: 1.45;
}
.composer textarea:disabled { opacity: .65; cursor: not-allowed; }


/* v0.6 Crypto v1 pairwise session UX */
.peer-profile-modal { width: min(780px, calc(100vw - 28px)); }
.profile-section {
  display: grid;
  gap: 9px;
  margin: 4px 0 14px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0d141b;
}
.profile-section h3 { margin: 0 0 2px; font-size: 14px; }
.security-summary {
  border-radius: 9px;
  padding: 9px 10px;
  background: #0a1016;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.security-summary[data-state="ok"] { color: #9eddb9; border: 1px solid #285b40; }
.security-summary[data-state="warning"] { color: #ffd98c; border: 1px solid #765b28; }
.security-summary[data-state="neutral"] { border: 1px solid #253342; }
.security-details {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: #0c1218;
}
.security-details > summary { cursor: pointer; color: #dbe7f1; font-weight: 650; font-size: 13px; }
.security-details[open] > summary { margin-bottom: 10px; }

/* Internal delivery state remains hidden from the ordinary chat flow. */
.composer-status {
  grid-column: 1 / -1;
  min-height: 16px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}
.composer-status[data-state="working"] { color: #9db7d1; }
.composer-status[data-state="error"] { color: #e6a3a3; }

/* v0.6.7: pending -> sent -> delivered -> read mutates only a fixed-width receipt glyph. */
.pending-message .message-bubble { opacity: 1; }
.pending-message .message-meta { font-style: normal; }

/* v0.7 reliability + pagination + developer diagnostics */
.history-loader {
  width: fit-content;
  margin: 2px auto 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(13,20,27,.86);
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  pointer-events: none;
}
.history-loader[data-state="loading"]::before { content: "Загружаем ранние сообщения…"; }
.history-loader[data-state="more"]::before { content: "Прокрути выше для ранних сообщений"; }

.debug-panel {
  position: fixed;
  z-index: 1000;
  right: 12px;
  bottom: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: min(56vh, 560px);
  overflow: auto;
  border: 1px solid #39516a;
  border-radius: 12px;
  background: rgba(7,12,17,.96);
  box-shadow: 0 18px 60px rgba(0,0,0,.5);
  color: #cde2f5;
  padding: 10px;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.debug-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.debug-actions { display: flex; align-items: center; gap: 5px; }
.debug-head .ghost { padding: 4px 7px; font-size: 10px; }
#debug-stats { margin: 0 0 8px; white-space: pre-wrap; color: #9fd3ff; }
.debug-log { display: grid; gap: 3px; color: #9aaebf; }
.debug-log-entry { border-top: 1px solid rgba(255,255,255,.05); padding-top: 3px; overflow-wrap: anywhere; }
.debug-log-entry strong { color: #cde2f5; }
.status-dot[data-state="offline"] { background: #65717d; box-shadow: 0 0 0 4px rgba(101,113,125,.08); }

/* v0.8 encrypted media */
.chat-layout { position: relative; }
.composer {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 8px;
}
.composer-main {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 9px;
}
.composer-main textarea { min-width: 0; }
.attachment-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0c1218;
  color: #c9d7e4;
  font-size: 18px;
  display: grid;
  place-items: center;
}
.attachment-button:hover { border-color: #405264; background: #101922; }
.attachment-button:disabled { opacity: .45; cursor: default; }
.attachment-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 1px;
  scrollbar-width: thin;
}
.attachment-chip {
  min-width: 180px;
  max-width: 270px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #0c1218;
}
.attachment-chip img,
.attachment-chip-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  display: grid;
  place-items: center;
  background: #17212c;
}
.attachment-chip-copy { min-width: 0; display: grid; gap: 2px; }
.attachment-chip-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.attachment-chip-copy small { color: var(--muted); font-size: 10px; }
.attachment-chip-remove {
  width: 27px;
  height: 27px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.attachment-chip-remove:hover { background: rgba(255,255,255,.06); color: var(--text); }
.drop-overlay {
  position: absolute;
  z-index: 20;
  inset: 78px 20px 86px;
  border: 2px dashed #4d79a8;
  border-radius: 18px;
  background: rgba(20,43,66,.88);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  color: #d9ebff;
  font-size: 18px;
  font-weight: 750;
  pointer-events: none;
}
.message-rich { display: grid; gap: 8px; }
.message-caption { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.42; }
.message-attachments { display: grid; gap: 7px; }
.message-attachment {
  width: min(390px, 68vw);
  min-width: 230px;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 11px;
  background: rgba(6,12,18,.28);
}
.message-attachment-preview,
.message-attachment-icon {
  width: 54px;
  height: 54px;
  border-radius: 9px;
  object-fit: cover;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.2);
  font-size: 22px;
}
.message-attachment-info { min-width: 0; display: grid; gap: 4px; }
.message-attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 700; }
.message-attachment-size { color: #9fb3c5; font-size: 10px; }
.message-attachment-download {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 9px;
  background: rgba(255,255,255,.05);
  color: #dcecff;
  padding: 7px 9px;
  font-size: 10px;
}
.message-attachment-download:hover { background: rgba(255,255,255,.09); }
.message-attachment-download:disabled { opacity: .55; cursor: default; }
.media-progress {
  width: 100%;
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.09);
}
.media-progress-bar {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #79b0ff;
  transition: width .12s linear;
}
.media-draft-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding-top: 2px;
}
.media-draft-actions .ghost { padding: 5px 8px; font-size: 10px; }
.media-draft-error { color: #ffadb2; font-size: 10px; margin-right: auto; }
.pending-media-message .message-receipt[data-state="pending"] { opacity: .62; }

@media (max-width: 720px) {
  .composer-main { grid-template-columns: 40px minmax(0, 1fr) auto; gap: 6px; }
  .attachment-button { width: 40px; height: 44px; }
  .message-attachment { min-width: 190px; width: min(320px, 82vw); grid-template-columns: 46px minmax(0,1fr) auto; }
  .message-attachment-preview, .message-attachment-icon { width: 46px; height: 46px; }
  .message-attachment-download { padding: 6px 7px; }
}

/* v0.8.3 inline media + explicit send-as choice */
.attachment-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 1px 0;
  color: var(--muted);
  font-size: 11px;
}
.attachment-mode-switch {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0b1117;
}
.attachment-mode {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 11px;
}
.attachment-mode:hover { color: var(--text); }
.attachment-mode.active {
  background: #1b2c3d;
  color: #eaf5ff;
  box-shadow: inset 0 0 0 1px rgba(126,180,236,.18);
}

.message-media-grid {
  width: min(560px, 70vw);
  display: grid;
  grid-template-columns: 1fr;
  gap: 3px;
  overflow: hidden;
  border-radius: 12px;
}
.message-media-grid[data-count="2"],
.message-media-grid[data-count="3"],
.message-media-grid[data-count="4"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.message-media {
  position: relative;
  min-width: 0;
  min-height: 160px;
  max-height: 440px;
  overflow: hidden;
  border-radius: 10px;
  background: #080d12;
  display: grid;
  place-items: center;
}
.message-media-grid[data-count="2"] .message-media,
.message-media-grid[data-count="3"] .message-media,
.message-media-grid[data-count="4"] .message-media {
  min-height: 190px;
  aspect-ratio: 1 / 1;
}
.message-media-poster,
.message-inline-video {
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
  max-height: 440px;
  object-fit: cover;
  background: #080d12;
}
.message-media-poster.loading { opacity: .72; }
.message-media-no-poster { opacity: 0; }
.message-media-open {
  position: absolute;
  inset: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}
.message-media-play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 50%;
  background: rgba(7,12,17,.78);
  color: white;
  font-size: 20px;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 24px rgba(0,0,0,.36);
  backdrop-filter: blur(5px);
}
.message-media-play:hover { background: rgba(22,45,67,.9); }
.message-media-play:disabled { opacity: .7; }
.message-media-download {
  position: absolute;
  z-index: 3;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 50%;
  background: rgba(7,12,17,.68);
  color: white;
  display: grid;
  place-items: center;
  font-size: 17px;
  opacity: 0;
  transition: opacity .12s ease, background .12s ease;
  backdrop-filter: blur(5px);
}
.message-media:hover .message-media-download,
.message-media-download:focus-visible { opacity: 1; }
.message-media-download:hover { background: rgba(22,45,67,.92); }
.message-media-download:disabled { opacity: .55; }
.media-load-error::after {
  content: "Не удалось открыть медиа";
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(49,29,32,.9);
  color: #ffd3d6;
  font-size: 10px;
}

.media-viewer {
  width: min(1180px, calc(100vw - 30px));
  height: min(92vh, 900px);
  padding: 0;
  border: 1px solid #33485d;
  border-radius: 16px;
  overflow: hidden;
  background: #05090d;
  color: var(--text);
  box-shadow: 0 26px 100px rgba(0,0,0,.72);
}
.media-viewer::backdrop { background: rgba(0,0,0,.86); backdrop-filter: blur(4px); }
.media-viewer-head {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: #0a1016;
}
.media-viewer-head strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-viewer-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #c9d7e4;
  font-size: 24px;
  line-height: 1;
}
.media-viewer-close:hover { background: rgba(255,255,255,.07); }
.media-viewer-stage {
  position: relative;
  height: calc(100% - 50px);
  display: grid;
  place-items: center;
  padding: 12px;
}
.media-viewer-stage img,
.media-viewer-stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.media-viewer-status {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  color: #bfd0df;
  font-size: 12px;
  background: rgba(7,12,17,.7);
  padding: 6px 10px;
  border-radius: 999px;
}
.media-viewer-status:empty { display: none; }

@media (max-width: 720px) {
  .attachment-options { font-size: 10px; }
  .attachment-mode { padding: 5px 7px; font-size: 10px; }
  .message-media-grid { width: min(82vw, 440px); }
  .message-media { min-height: 130px; }
  .message-media-grid[data-count="2"] .message-media,
  .message-media-grid[data-count="3"] .message-media,
  .message-media-grid[data-count="4"] .message-media { min-height: 135px; }
  .message-media-download { opacity: 1; width: 29px; height: 29px; }
  .media-viewer { width: calc(100vw - 12px); height: calc(100vh - 20px); border-radius: 12px; }
}


/* v0.9 voice messages + video notes */
.composer-main {
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
}
.record-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0c1218;
  color: #d7e6f4;
  display: grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
}
.record-button:hover { border-color: #405264; background: #101922; }
.record-button:disabled { opacity: .45; cursor: default; }
.video-note-trigger { color: #8fc9ff; font-size: 20px; }
.voice-recorder {
  min-height: 48px;
  display: grid;
  grid-template-columns: auto auto auto minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border: 1px solid #3b4c5e;
  border-radius: 13px;
  background: #0c131a;
}
.composer.recording-active .composer-main,
.composer.recording-active .attachment-options,
.composer.recording-active .attachment-strip { display: none !important; }
.recording-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff6670;
  box-shadow: 0 0 0 4px rgba(255,102,112,.11);
  animation: recordPulse 1.15s ease-in-out infinite;
}
@keyframes recordPulse { 50% { opacity: .42; transform: scale(.86); } }
.voice-recorder-label { color: #dce9f5; font-size: 12px; }
.recording-time { font-variant-numeric: tabular-nums; font-size: 12px; color: #cfe2f5; }
.recorder-wave,
.voice-waveform {
  min-width: 0;
  height: 30px;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow: hidden;
}
.recorder-wave span,
.voice-waveform span {
  width: 3px;
  min-height: 3px;
  border-radius: 999px;
  background: #6f8da9;
  flex: 1 1 auto;
  max-width: 4px;
  transition: height .08s linear, background .12s ease;
}
.voice-waveform span.played { background: #8fc9ff; }
.recording-cancel, .recording-send { white-space: nowrap; }

.voice-message {
  width: min(390px, 68vw);
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 5px 2px;
}
.voice-play {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: rgba(123,181,255,.2);
  color: #e8f4ff;
  display: grid;
  place-items: center;
  font-size: 15px;
}
.voice-play:hover { background: rgba(123,181,255,.3); }
.voice-body { min-width: 0; display: grid; gap: 2px; }
.voice-waveform { height: 24px; cursor: pointer; }
.voice-footer { display: flex; align-items: center; justify-content: space-between; color: #a6bbcd; font-size: 10px; }
.voice-speed {
  border: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  color: #cfe3f5;
  padding: 2px 6px;
  font-size: 10px;
}

.video-note-message {
  position: relative;
  width: 230px;
  height: 230px;
  border-radius: 50%;
  overflow: hidden;
  background: #05090d;
  box-shadow: 0 8px 32px rgba(0,0,0,.28);
}
.video-note-poster,
.video-note-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 50%;
}
.video-note-play {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 50%;
  background: rgba(6,12,18,.7);
  color: white;
  font-size: 18px;
  display: grid;
  place-items: center;
  backdrop-filter: blur(5px);
}
.video-note-play.is-playing { opacity: .18; }
.video-note-message:hover .video-note-play.is-playing { opacity: .82; }
.video-note-duration {
  position: absolute;
  z-index: 2;
  right: 17px;
  bottom: 15px;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(5,10,15,.68);
  color: #f1f7fc;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.video-note-recorder {
  padding: 0;
  border: 1px solid #33485d;
  border-radius: 20px;
  background: #0b1117;
  color: var(--text);
  box-shadow: 0 28px 100px rgba(0,0,0,.72);
}
.video-note-recorder::backdrop { background: rgba(0,0,0,.78); backdrop-filter: blur(7px); }
.video-note-recorder-card { width: min(390px, calc(100vw - 28px)); padding: 20px; display: grid; gap: 16px; justify-items: center; }
.video-note-live-wrap {
  position: relative;
  width: min(300px, 72vw);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  background: #05090d;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.video-note-live { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.video-note-live-overlay { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 9px; border-radius: 999px; background: rgba(5,10,15,.62); }
.video-note-recorder-copy { display: grid; gap: 3px; text-align: center; }
.video-note-recorder-copy span { color: var(--muted); font-size: 11px; }
.video-note-recorder-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

@media (max-width: 720px) {
  .composer-main { grid-template-columns: 40px minmax(0, 1fr) 40px 40px auto; gap: 5px; }
  .record-button { width: 40px; height: 44px; }
  .voice-recorder { grid-template-columns: auto auto minmax(60px, 1fr) auto auto; gap: 6px; }
  .voice-recorder-label { display: none; }
  .recording-cancel, .recording-send { padding: 7px 8px; font-size: 10px; }
  .voice-message { width: min(320px, 78vw); }
  .video-note-message { width: min(210px, 64vw); height: min(210px, 64vw); }
}

/* v0.9.1 compact encrypted audio-file player */
.message-audio-files { display: grid; gap: 7px; }
.audio-file-message {
  width: min(390px, 68vw);
  min-width: 250px;
  display: grid;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 12px;
  background: rgba(6,12,18,.28);
}
.audio-file-head {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 8px;
}
.audio-file-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: rgba(123,181,255,.16);
  color: #dceeff;
  font-size: 18px;
  font-weight: 800;
}
.audio-file-identity { min-width: 0; display: grid; gap: 2px; }
.audio-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}
.audio-file-meta { color: #9fb3c5; font-size: 10px; }
.audio-file-download,
.audio-file-speed,
.audio-file-play {
  border: 0;
  color: #e8f4ff;
  background: rgba(255,255,255,.06);
}
.audio-file-download {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 15px;
}
.audio-file-download:hover,
.audio-file-speed:hover { background: rgba(255,255,255,.11); }
.audio-file-controls {
  display: grid;
  grid-template-columns: 34px minmax(90px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}
.audio-file-play {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(123,181,255,.2);
  font-size: 13px;
}
.audio-file-play:hover { background: rgba(123,181,255,.3); }
.audio-file-play:disabled,
.audio-file-download:disabled { opacity: .55; cursor: default; }
.audio-file-progress {
  width: 100%;
  min-width: 0;
  accent-color: #8fc9ff;
  cursor: pointer;
}
.audio-file-time {
  color: #aac0d2;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.audio-file-speed {
  min-width: 30px;
  padding: 3px 6px;
  border-radius: 999px;
  font-size: 10px;
}
@media (max-width: 720px) {
  .audio-file-message { width: min(320px, 82vw); min-width: 210px; }
  .audio-file-controls { grid-template-columns: 32px minmax(70px, 1fr) auto; }
  .audio-file-speed { grid-column: 3; }
  .audio-file-time { display: none; }
}

/* v0.10 one-to-one audio calls */
.call-header-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: #cfe4f7;
  display: grid;
  place-items: center;
  font-size: 17px;
}
.call-header-button:hover { background: rgba(255,255,255,.04); border-color: #3a4a5c; }
.call-header-button:disabled { opacity: .45; cursor: default; }
.call-dialog {
  width: min(92vw, 360px);
  border: 1px solid #314255;
  border-radius: 22px;
  padding: 0;
  color: var(--text);
  background: #101820;
  box-shadow: 0 28px 90px rgba(0,0,0,.58);
}
.call-dialog::backdrop { background: rgba(3,8,12,.72); backdrop-filter: blur(8px); }
.call-card {
  min-height: 370px;
  padding: 32px 24px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}
.call-avatar {
  width: 94px;
  height: 94px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #29425d, #1b2d40);
  color: #dceeff;
  font-size: 30px;
  font-weight: 800;
  box-shadow: 0 14px 40px rgba(0,0,0,.32);
}
.call-peer { margin-top: 6px; font-size: 22px; }
.call-status { min-height: 20px; color: var(--muted); font-size: 13px; }
.call-duration { color: #cce2f4; font-size: 18px; font-variant-numeric: tabular-nums; }
.call-actions { margin-top: 20px; display: flex; align-items: center; justify-content: center; gap: 28px; }
.call-actions.incoming { gap: 54px; }
.call-round {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 8px 26px rgba(0,0,0,.25);
}
.call-accept { background: #2d9c63; }
.call-accept:hover { filter: brightness(1.08); }
.call-decline { background: #cf4d58; }
.call-decline:hover { filter: brightness(1.08); }
.call-pill {
  min-width: 126px;
  height: 46px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid #334456;
  background: #17222d;
  color: #dce8f2;
}
.call-pill:hover, .call-pill.active { background: #243342; border-color: #496078; }
#call-remote-audio { display: none; }
@media (max-width: 720px) {
  .chat-header-status { gap: 8px; }
  .call-header-button { width: 32px; height: 32px; }
  .call-card { min-height: 330px; padding: 26px 18px 22px; }
}

/* CP2.2 message editing */
.message-bubble { position: relative; }
.message-actions {
  position: absolute;
  top: -10px;
  right: 8px;
  z-index: 12;
  display: flex;
  gap: 4px;
  opacity: 0;
  transform: translateY(3px);
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
}
.message-row:not(.mine) .message-actions { left: 8px; right: auto; }
.message-bubble:hover .message-actions,
.message-bubble:focus-within .message-actions,
.message-row.message-menu-open .message-actions,
.message-failed .message-actions {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.message-action-button {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #162434;
  color: #c8d8e7;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  font-size: 19px;
  font-weight: 800;
  line-height: 1;
}
.message-action-button:hover,
.message-action-button:focus-visible { background: #20354b; border-color: #49627a; }
.message-more-button[aria-expanded="true"] { background: #25415d; border-color: #5a7894; color: #fff; }
.message-context-menu {
  position: absolute;
  top: 34px;
  right: 0;
  z-index: 20;
  width: max-content;
  min-width: 194px;
  max-width: min(260px, calc(100vw - 24px));
  padding: 6px;
  display: grid;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #142231;
  box-shadow: 0 14px 36px rgba(0,0,0,.4);
}
.message-row:not(.mine) .message-context-menu { left: 0; right: auto; }
.message-context-menu.hidden { display: none; }
.message-context-menu.open-up { top: auto; bottom: 34px; }
.message-context-item {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px 7px 8px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d7e3ed;
  text-align: left;
  font-size: 12px;
  white-space: nowrap;
}
.message-context-item:hover,
.message-context-item:focus-visible { background: rgba(255,255,255,.07); outline: none; }
.message-context-glyph { display: grid; place-items: center; width: 26px; color: #9fc8ec; font-size: 15px; font-weight: 800; }
.message-context-label { overflow: hidden; text-overflow: ellipsis; }
.message-context-item.danger { color: #ffaaa5; }
.message-context-item.danger .message-context-glyph { color: #ff8f89; }
.message-context-item.danger:hover,
.message-context-item.danger:focus-visible { background: rgba(214,77,70,.13); }
.message-failed .message-bubble { border-color: rgba(255,127,135,.55); }
.message-failed .message-retry-button { color: var(--danger); }
.message-failed .message-retry-button .message-context-glyph { color: var(--danger); }
@media (hover: none) {
  .message-actions { opacity: 1; transform: none; pointer-events: auto; top: -8px; }
  .message-action-button { width: 32px; height: 32px; }
  .message-context-menu { top: 36px; }
  .message-context-menu.open-up { top: auto; bottom: 36px; }
}
.message-edited { opacity: .8; }
.message-edited:empty { display: none; }
.composer-edit-bar {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  border: 1px solid rgba(76, 137, 218, .34);
  border-left: 3px solid var(--accent-2);
  border-radius: 11px;
  background: rgba(28, 62, 102, .22);
}
.composer-edit-copy { min-width: 0; display: grid; gap: 2px; }
.composer-edit-copy strong { color: #9ec8ff; font-size: 11px; font-weight: 700; }
.composer-edit-copy span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #b4c2cf; font-size: 11px; }
.composer-edit-cancel {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #aebdca;
  font-size: 21px;
  line-height: 1;
}
.composer-edit-cancel:hover { background: rgba(255,255,255,.06); color: #fff; }
.composer.editing-message .attachment-options,
.composer.editing-message .attachment-strip { display: none !important; }
.composer.editing-message .attachment-button,
.composer.editing-message .record-button { opacity: .42; }
.composer.editing-message[data-edit-busy="true"] .composer-main,
.composer.editing-message[data-edit-busy="true"] .composer-edit-bar { opacity: .72; }

/* CP2.3 deletion actions are rendered inside the CP2.7 unified context menu. */

/* CP2.4 replies */
.message-reply-preview {
  display: grid;
  gap: 2px;
  margin: 0 0 7px;
  padding: 6px 8px 6px 10px;
  border-left: 3px solid #5e9ee6;
  border-radius: 7px;
  background: rgba(36, 91, 145, .18);
  cursor: pointer;
  min-width: 0;
}
.message-reply-preview:hover { background: rgba(44, 106, 166, .25); }
.message-reply-preview strong, .message-reply-preview span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message-reply-preview strong { color: #9ec8ff; font-size: 11px; font-weight: 750; }
.message-reply-preview span { color: #b4c2cf; font-size: 11px; }
.message-reply-preview[data-status="deleted"],
.message-reply-preview[data-status="unavailable"] { cursor: default; opacity: .76; }
.message-row.reply-jump-highlight .message-bubble {
  animation: reply-jump-pulse .9s ease-out;
}
@keyframes reply-jump-pulse {
  0% { box-shadow: 0 0 0 0 rgba(94,158,230,.65), 0 4px 15px rgba(0,0,0,.12); }
  45% { box-shadow: 0 0 0 5px rgba(94,158,230,.22), 0 4px 15px rgba(0,0,0,.12); }
  100% { box-shadow: 0 0 0 0 rgba(94,158,230,0), 0 4px 15px rgba(0,0,0,.12); }
}
.composer-reply-bar {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  border: 1px solid rgba(76, 137, 218, .28);
  border-left: 3px solid #5e9ee6;
  border-radius: 11px;
  background: rgba(28, 62, 102, .18);
}
.composer-reply-copy { min-width: 0; display: grid; gap: 2px; }
.composer-reply-copy strong { color: #9ec8ff; font-size: 11px; font-weight: 700; }
.composer-reply-copy span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #b4c2cf; font-size: 11px; }
.composer-reply-cancel {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #aebdca;
  font-size: 21px;
  line-height: 1;
}
.composer-reply-cancel:hover { background: rgba(255,255,255,.06); color: #fff; }

/* CP2.4.1 configurable forwarding — inline selection UX */
.message-forward-header {
  margin: 0 0 6px;
  color: #8fbcf0;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.25;
}
.message-body-text { white-space: pre-wrap; overflow-wrap: anywhere; }

.message-selection-toggle {
  display: none;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin: 0 2px;
  padding: 0;
  border: 1px solid #49627a;
  border-radius: 50%;
  background: #0d151d;
  color: #fff;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 3px 10px rgba(0,0,0,.18);
}
.message-row.forward-selecting {
  align-items: center;
  gap: 8px;
}
.message-row.forward-selecting .message-selection-toggle { display: grid; }
.message-row.mine.forward-selecting .message-selection-toggle { order: 2; }
.message-row.forward-selecting .message-bubble { cursor: pointer; }
.message-row.forward-selected .message-selection-toggle {
  border-color: #5e9ee6;
  background: #347cc8;
}
.message-row.forward-selected .message-bubble {
  box-shadow: 0 0 0 2px rgba(94,158,230,.42), 0 4px 15px rgba(0,0,0,.12);
}
.messages.forward-selection-mode .message-actions { display: none !important; }

.composer-forward-bar {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  border: 1px solid rgba(87, 159, 224, .32);
  border-left: 3px solid #5e9ee6;
  border-radius: 11px;
  background: rgba(27, 72, 112, .22);
}
.composer-forward-copy { min-width: 0; display: grid; gap: 2px; }
.composer-forward-copy strong { color: #9ec8ff; font-size: 11px; font-weight: 750; }
.composer-forward-copy span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #b4c2cf;
  font-size: 11px;
}
.composer-forward-cancel {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #aebdca;
  font-size: 21px;
  line-height: 1;
}
.composer-forward-cancel:hover { background: rgba(255,255,255,.06); color: #fff; }

.composer-main { grid-template-columns: auto minmax(0, 1fr) auto auto auto auto; }
.forward-settings-button { position: relative; color: #9ccaff; }
.forward-settings-button.active {
  border-color: #4d83b9;
  background: #17304a;
}
.forward-settings-button[data-count]:not([data-count="0"])::after {
  content: attr(data-count);
  position: absolute;
  right: -5px;
  top: -5px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #347cc8;
  color: white;
  font-size: 9px;
  font-weight: 800;
}
.composer.forwarding-selection .attachment-button,
.composer.forwarding-selection .record-button:not(.forward-settings-button),
.composer.forwarding-selection .attachment-options,
.composer.forwarding-selection .attachment-strip { display: none !important; }
.composer.forwarding-selection .composer-main { grid-template-columns: minmax(0, 1fr) auto auto; }
.composer.forwarding-selection[data-forward-busy="true"] .composer-main,
.composer.forwarding-selection[data-forward-busy="true"] .composer-forward-bar,
.composer.forwarding-selection[data-forward-busy="true"] .forward-settings-panel { opacity: .72; }

.forward-settings-panel {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px solid #32475b;
  border-radius: 12px;
  background: #0d151d;
  box-shadow: 0 12px 30px rgba(0,0,0,.22);
}
.forward-settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.forward-settings-head > div { min-width: 0; display: grid; gap: 2px; }
.forward-settings-head strong { font-size: 12px; }
.forward-settings-close {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 19px;
  line-height: 1;
}
.forward-recipient-list {
  display: grid;
  gap: 5px;
  max-height: 190px;
  overflow: auto;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(6, 11, 16, .38);
}
.forward-choice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.forward-choice:hover { background: rgba(255,255,255,.045); }
.forward-choice input { margin: 0; }
.forward-choice-copy { min-width: 0; display: grid; gap: 2px; }
.forward-choice-copy strong,
.forward-choice-copy span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.forward-choice-copy strong { font-size: 12px; }
.forward-choice-copy span { color: var(--muted); font-size: 11px; }
.forward-search { width: 100%; box-sizing: border-box; }
.forward-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,.025);
}
.forward-option-inline { margin: 0; }
.forward-option input { margin-top: 3px; }
.forward-option span { display: grid; gap: 3px; }
.forward-option strong { font-size: 12px; }
.forward-option small { color: var(--muted); line-height: 1.35; }
.forward-status { font-size: 11px; color: var(--muted); }
.forward-status[data-state="error"] { color: #e6a3a3; }
.forward-status[data-state="working"] { color: #9db7d1; }
.forward-empty { padding: 10px; color: var(--muted); font-size: 11px; text-align: center; }

@media (max-width: 720px) {
  .message-row.forward-selecting { gap: 5px; }
  .message-selection-toggle { width: 22px; height: 22px; font-size: 12px; }
  .composer.forwarding-selection .composer-main { grid-template-columns: minmax(0, 1fr) 40px auto; gap: 7px; }
  .forward-settings-button { width: 40px; height: 40px; }
  .forward-recipient-list { max-height: 155px; }
}


/* v0.16 Checkpoint 3.1/3.3 profiles + enriched user search */
.sidebar-actions { flex-wrap: wrap; justify-content: flex-end; }
.peer-heading { min-width: 0; }
.peer-title-line { min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.peer-title-line strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-handle, .peer-profile-handle, .user-handle { color: var(--muted); font-size: 11px; white-space: nowrap; }
.avatar, .profile-avatar { overflow: hidden; position: relative; }
.avatar img, .profile-avatar img { width: 100%; height: 100%; display: block; object-fit: cover; }
.profile-avatar { display: grid; place-items: center; border-radius: 50%; background: #26394b; color: #bcd6ef; font-weight: 800; flex: 0 0 auto; }
.profile-avatar-large { width: 82px; height: 82px; font-size: 24px; }
.profile-edit-modal { width: min(680px, calc(100vw - 28px)); }
.profile-editor-avatar-row { display: flex; align-items: center; gap: 16px; margin: 4px 0 18px; }
.profile-avatar-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.profile-avatar-upload { cursor: pointer; display: inline-flex; align-items: center; }
/* The upload control is a <label>, the delete one a <button>; size both alike. */
.profile-avatar-controls .ghost { font-size: 14px; line-height: 1.2; min-height: 40px; padding: 8px 14px; }
.profile-form { display: grid; gap: 12px; }
.profile-form label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.profile-form input, .profile-form textarea, .profile-form select { width: 100%; box-sizing: border-box; }
.profile-form textarea { resize: vertical; min-height: 92px; max-height: 180px; line-height: 1.45; }
.profile-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.profile-form-status { min-height: 18px; }
.profile-form-status[data-state="error"] { color: var(--danger); }
.profile-form-status[data-state="ok"] { color: #9eddb9; }
.profile-privacy-section { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.profile-section-head h3 { margin: 0 0 4px; }
.profile-section-head p { margin: 0; line-height: 1.45; }
.peer-public-profile { display: flex; align-items: flex-start; gap: 14px; margin: 4px 0 14px; padding: 13px; border: 1px solid var(--border); border-radius: 12px; background: #0d141b; }
.peer-public-profile-copy { min-width: 0; display: grid; gap: 4px; }
.peer-public-profile-copy > strong { font-size: 18px; overflow-wrap: anywhere; }
.peer-profile-bio { margin: 5px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; color: #c6d2dc; line-height: 1.45; }
.peer-profile-bio:empty::before { content: "Описание не заполнено"; color: var(--muted); }
.user-item-top .user-name { display: inline-flex; align-items: baseline; gap: 6px; }

@media (max-width: 720px) {
  .profile-form-grid { grid-template-columns: 1fr; }
  .profile-editor-avatar-row, .peer-public-profile { align-items: flex-start; }
  .profile-editor-avatar-row { flex-direction: column; }
  .peer-title-line { display: grid; gap: 1px; }
  .peer-handle { font-size: 10px; }
}

/* v0.16.1 Checkpoint 3.4 peer profile: ordinary profile first, security details second-level */
.peer-profile-modal { width: min(620px, calc(100vw - 28px)); }
.peer-public-profile-main { margin-bottom: 10px; }
.peer-profile-actions { display: flex; gap: 10px; margin: 0 0 12px; }
.peer-profile-actions > button { min-width: 132px; }
.profile-nav-row {
  width: 100%;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0d141b;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.profile-nav-row:hover, .profile-nav-row:focus-visible { border-color: #3d5a74; background: #101a23; }
.profile-nav-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: #142331; font-size: 17px; }
.profile-nav-copy { min-width: 0; display: grid; gap: 3px; }
.profile-nav-copy strong { font-size: 13px; }
.profile-nav-copy span { color: var(--muted); font-size: 11px; line-height: 1.35; }
.profile-nav-copy span[data-state="warning"] { color: #ffd98c; }
.profile-nav-copy span[data-state="ok"] { color: #9eddb9; }
.profile-nav-chevron { color: var(--muted); font-size: 25px; line-height: 1; }
.peer-encryption-modal { width: min(680px, calc(100vw - 28px)); }
.encryption-status-section { padding: 0; border: 0; background: transparent; }
.encryption-status-section .security-summary { padding: 11px 12px; }
.encryption-actions { justify-content: flex-start; flex-wrap: wrap; }
.peer-encryption-footer { justify-content: flex-start; margin-top: 12px; }

@media (max-width: 720px) {
  .peer-profile-actions > button { flex: 1 1 auto; }
  .profile-nav-row { grid-template-columns: 34px minmax(0, 1fr) auto; padding: 11px; }
  .profile-nav-icon { width: 34px; height: 34px; }
}

/* v0.16.3 Checkpoint 3.2 UX hotfix: drawer + consolidated settings */
:root[data-theme="dark"],
:root[data-theme="system"] {
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef3f8;
  --panel: #ffffff;
  --panel-2: #edf3f8;
  --border: #cfd9e3;
  --text: #17212b;
  --muted: #66798a;
  --accent: #4d8fe8;
  --accent-2: #2f74d0;
  --danger: #c84f58;
  --bubble: #ffffff;
  --bubble-mine: #d9eaff;
}

@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    color-scheme: light;
    --bg: #eef3f8;
    --panel: #ffffff;
    --panel-2: #edf3f8;
    --border: #cfd9e3;
    --text: #17212b;
    --muted: #66798a;
    --accent: #4d8fe8;
    --accent-2: #2f74d0;
    --danger: #c84f58;
    --bubble: #ffffff;
    --bubble-mine: #d9eaff;
  }
}

:root[data-theme="light"] input,
:root[data-theme="light"] textarea,
:root[data-theme="light"] select,
:root[data-theme="light"] .tabs,
:root[data-theme="light"] .auth-card,
:root[data-theme="light"] .modal,
:root[data-theme="light"] .call-dialog,
:root[data-theme="light"] .message-context-menu,
:root[data-theme="light"] .forward-settings-panel,
:root[data-theme="light"] .attachment-options {
  background-color: var(--panel);
  color: var(--text);
}

@media (prefers-color-scheme: light) {
  :root[data-theme="system"] input,
  :root[data-theme="system"] textarea,
  :root[data-theme="system"] select,
  :root[data-theme="system"] .tabs,
  :root[data-theme="system"] .auth-card,
  :root[data-theme="system"] .modal,
  :root[data-theme="system"] .call-dialog,
  :root[data-theme="system"] .message-context-menu,
  :root[data-theme="system"] .forward-settings-panel,
  :root[data-theme="system"] .attachment-options {
    background-color: var(--panel);
    color: var(--text);
  }
}

.sidebar-header {
  justify-content: flex-start;
  gap: 10px;
}
.sidebar-identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
.sidebar-identity-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.sidebar-identity-copy strong,
.sidebar-identity-copy .small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-me-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
}
.main-menu-button,
.drawer-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 20px;
}
.main-menu-button:hover,
.drawer-close:hover { background: var(--panel-2); }

.main-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0,0,0,.46);
  backdrop-filter: blur(2px);
}
.main-drawer {
  position: fixed;
  z-index: 81;
  inset: 0 auto 0 0;
  width: min(338px, calc(100vw - 32px));
  background: var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: 22px 0 60px rgba(0,0,0,.32);
  display: flex;
  flex-direction: column;
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform .18s ease, visibility .18s step-end;
}
.main-drawer.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform .18s ease, visibility 0s;
}
.main-drawer-head {
  display: grid;
  grid-template-columns: 52px minmax(0,1fr) 38px;
  align-items: center;
  gap: 11px;
  min-height: 82px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.main-drawer-avatar { width: 52px; height: 52px; font-size: 17px; }
.main-drawer-identity { min-width: 0; display: grid; gap: 3px; }
.main-drawer-identity strong,
.main-drawer-identity span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main-drawer-nav {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  /* Without this the grid stretched its rows over the whole drawer height. */
  align-content: start;
  gap: 3px;
  padding: 10px;
}
.drawer-nav-item {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 11px;
  padding: 9px 10px;
  display: grid;
  grid-template-columns: 34px minmax(0,1fr) auto;
  align-items: center;
  gap: 10px;
  text-align: left;
  color: var(--text);
  background: transparent;
}
.drawer-nav-item:hover:not(:disabled),
.drawer-nav-item:focus-visible { background: var(--panel-2); }
.drawer-nav-item:disabled { cursor: default; opacity: .5; }
.drawer-nav-icon { display: grid; place-items: center; font-size: 18px; color: var(--muted); }
.drawer-nav-copy { min-width: 0; display: grid; gap: 2px; }
.drawer-nav-copy strong { font-size: 13px; }
.drawer-nav-copy small { color: var(--muted); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-nav-badge {
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 9px;
}
.main-drawer-bottom {
  margin-top: auto;
  display: grid;
  gap: 3px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.drawer-logout { color: var(--danger); }
.drawer-logout .drawer-nav-icon { color: inherit; }

.settings-modal { width: min(820px, calc(100vw - 28px)); }
.settings-layout {
  display: grid;
  grid-template-columns: 180px minmax(0,1fr);
  gap: 18px;
  min-height: 360px;
}
.settings-tabs {
  align-self: start;
  display: grid;
  gap: 4px;
}
.settings-tab {
  width: 100%;
  border: 0;
  border-radius: 9px;
  padding: 10px 11px;
  text-align: left;
  color: var(--muted);
  background: transparent;
}
.settings-tab:hover,
.settings-tab.active { color: var(--text); background: var(--panel-2); }
.settings-content { min-width: 0; }
.settings-panel { display: grid; gap: 16px; }
.settings-section-head { display: grid; gap: 4px; margin-bottom: 2px; }
.settings-section-head h3,
.settings-section-head p { margin: 0; font-size: 12px; line-height: 1.45; }
.settings-form { max-width: 520px; }
.settings-actions { justify-content: flex-start; }
.settings-panel .device-list { margin-top: 2px; }

@media (max-width: 720px) {
  .sidebar-header { flex-direction: row; align-items: center; padding: 10px 8px; }
  .sidebar-identity-copy { display: none; }
  .sidebar-me-avatar { width: 34px; height: 34px; flex-basis: 34px; }
  .main-menu-button { width: 34px; height: 34px; }
  .settings-modal { width: calc(100vw - 12px); }
  .settings-layout { grid-template-columns: 1fr; min-height: 0; gap: 12px; }
  .settings-tabs { display: flex; overflow-x: auto; padding-bottom: 2px; }
  .settings-tab { width: auto; flex: 0 0 auto; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .main-drawer { transition: none; }
}

:root[data-theme="light"] label { color: #394b5a; }
:root[data-theme="light"] .chat { background: radial-gradient(circle at 50% 0%, #ffffff 0, var(--bg) 55%); }
:root[data-theme="light"] .chat-header { background: rgba(255,255,255,.88); }
:root[data-theme="light"] .message-bubble { border-color: #d6e0e8; }
:root[data-theme="light"] .message-row.mine .message-bubble { border-color: #b8d3ef; }
:root[data-theme="light"] .auth-card,
:root[data-theme="light"] .main-drawer { box-shadow: 0 20px 55px rgba(42,60,78,.15); }

@media (prefers-color-scheme: light) {
  :root[data-theme="system"] label { color: #394b5a; }
  :root[data-theme="system"] .chat { background: radial-gradient(circle at 50% 0%, #ffffff 0, var(--bg) 55%); }
  :root[data-theme="system"] .chat-header { background: rgba(255,255,255,.88); }
  :root[data-theme="system"] .message-bubble { border-color: #d6e0e8; }
  :root[data-theme="system"] .message-row.mine .message-bubble { border-color: #b8d3ef; }
}

/* v0.16.4 Checkpoint 3 UX polish: coherent soft-light palette + resolved system theme */
:root[data-resolved-theme="light"] {
  color-scheme: light;
  --bg: #e8edf2;
  --panel: #f7f9fb;
  --panel-2: #e9eff5;
  --border: #c7d1db;
  --text: #1d2935;
  --muted: #677887;
  --accent: #4f8fd8;
  --accent-2: #3479c4;
  --danger: #ba4e58;
  --bubble: #f8fafc;
  --bubble-mine: #d7e7f7;
}

:root[data-resolved-theme="light"] html,
:root[data-resolved-theme="light"] body { background: var(--bg); color: var(--text); }
:root[data-resolved-theme="light"] .sidebar { background: #f3f6f9; }
:root[data-resolved-theme="light"] .chat {
  background: radial-gradient(circle at 50% 0%, #f5f8fb 0, #e8edf2 58%, #e3e9ef 100%);
}
:root[data-resolved-theme="light"] .chat-header,
:root[data-resolved-theme="light"] .composer {
  background: rgba(244,247,250,.94);
  border-color: var(--border);
}
:root[data-resolved-theme="light"] .composer { box-shadow: 0 -8px 24px rgba(45,63,80,.035); }
:root[data-resolved-theme="light"] label { color: #425464; }
:root[data-resolved-theme="light"] input,
:root[data-resolved-theme="light"] textarea,
:root[data-resolved-theme="light"] select,
:root[data-resolved-theme="light"] .tabs,
:root[data-resolved-theme="light"] .verification-code,
:root[data-resolved-theme="light"] .security-details,
:root[data-resolved-theme="light"] .attachment-button,
:root[data-resolved-theme="light"] .record-button,
:root[data-resolved-theme="light"] .attachment-chip,
:root[data-resolved-theme="light"] .forward-settings-panel,
:root[data-resolved-theme="light"] .message-context-menu {
  background: #f1f5f8;
  color: var(--text);
  border-color: var(--border);
}
:root[data-resolved-theme="light"] input:focus,
:root[data-resolved-theme="light"] textarea:focus,
:root[data-resolved-theme="light"] select:focus {
  border-color: #6f9fd1;
  box-shadow: 0 0 0 3px rgba(70,126,184,.13);
}
:root[data-resolved-theme="light"] .auth-card,
:root[data-resolved-theme="light"] .modal,
:root[data-resolved-theme="light"] .main-drawer,
:root[data-resolved-theme="light"] .call-dialog {
  background: #f7f9fb;
  color: var(--text);
  border-color: #c5d0da;
  box-shadow: 0 20px 60px rgba(41,57,72,.16);
}
:root[data-resolved-theme="light"] .modal::backdrop { background: rgba(34,47,59,.36); }
:root[data-resolved-theme="light"] .main-drawer-backdrop { background: rgba(34,47,59,.28); }
:root[data-resolved-theme="light"] .user-item:hover,
:root[data-resolved-theme="light"] .user-item.active,
:root[data-resolved-theme="light"] .drawer-nav-item:hover:not(:disabled),
:root[data-resolved-theme="light"] .drawer-nav-item:focus-visible,
:root[data-resolved-theme="light"] .settings-tab:hover,
:root[data-resolved-theme="light"] .settings-tab.active,
:root[data-resolved-theme="light"] .main-menu-button:hover,
:root[data-resolved-theme="light"] .drawer-close:hover {
  background: #e4ebf2;
}
:root[data-resolved-theme="light"] .avatar,
:root[data-resolved-theme="light"] .profile-avatar,
:root[data-resolved-theme="light"] .profile-nav-icon,
:root[data-resolved-theme="light"] .attachment-chip-icon {
  background: #d9e5ef;
  color: #315d82;
}
:root[data-resolved-theme="light"] .security-note strong,
:root[data-resolved-theme="light"] .security-details > summary { color: #344a5d; }
:root[data-resolved-theme="light"] .message-bubble {
  border-color: #ccd6df;
  box-shadow: 0 4px 14px rgba(50,66,80,.08);
}
:root[data-resolved-theme="light"] .message-row.mine .message-bubble { border-color: #b4cce4; }
:root[data-resolved-theme="light"] .message-meta,
:root[data-resolved-theme="light"] .voice-footer,
:root[data-resolved-theme="light"] .message-attachment-size,
:root[data-resolved-theme="light"] .audio-file-meta { color: #748696; }
:root[data-resolved-theme="light"] .message-bubble.crypto-error {
  background: #f7e8e9;
  border-color: #d4a7aa;
}
:root[data-resolved-theme="light"] .message-text.message-hydrating,
:root[data-resolved-theme="light"] .conversation-loading .message-bubble {
  background-color: #edf2f6;
}
:root[data-resolved-theme="light"] .message-text.message-hydrating {
  background-image: linear-gradient(90deg, rgba(78,101,122,.04), rgba(78,101,122,.10), rgba(78,101,122,.04));
}
:root[data-resolved-theme="light"] .profile-section,
:root[data-resolved-theme="light"] .peer-public-profile,
:root[data-resolved-theme="light"] .profile-nav-row,
:root[data-resolved-theme="light"] .device-card,
:root[data-resolved-theme="light"] .security-summary {
  background: #f0f4f7;
  border-color: var(--border);
}
:root[data-resolved-theme="light"] .profile-nav-row:hover,
:root[data-resolved-theme="light"] .profile-nav-row:focus-visible { background: #e7eef4; border-color: #aebfce; }
:root[data-resolved-theme="light"] .peer-profile-bio { color: #536777; }
:root[data-resolved-theme="light"] .fingerprint {
  background: #e7edf2;
  color: #365a78;
}
:root[data-resolved-theme="light"] .device-tag { border-color: #bdcbd6; }
:root[data-resolved-theme="light"] .security-summary[data-state="ok"] { color: #33734f; border-color: #9fc9ae; background: #edf6f0; }
:root[data-resolved-theme="light"] .security-summary[data-state="warning"] { color: #8a651d; border-color: #d4bc82; background: #faf5e8; }
:root[data-resolved-theme="light"] .security-summary[data-state="neutral"] { border-color: #c5d0da; }
:root[data-resolved-theme="light"] .pending-device-banner,
:root[data-resolved-theme="light"] .device-waiting-note {
  background: #f6f0df;
  color: #71551c;
  border-color: #cfb674;
  box-shadow: 0 12px 32px rgba(67,55,31,.12);
}
:root[data-resolved-theme="light"] .pending-device-banner strong { color: #624712; }
:root[data-resolved-theme="light"] .security-alert { background: rgba(188,145,58,.12); color: #6f531b; border-color: #d1b675; }
:root[data-resolved-theme="light"] .security-alert-button { background: #f6efd9; color: #684d16; border-color: #c9aa65; }
:root[data-resolved-theme="light"] .history-loader { background: rgba(240,244,247,.94); }

:root[data-resolved-theme="light"] .message-attachment,
:root[data-resolved-theme="light"] .audio-file,
:root[data-resolved-theme="light"] .voice-message {
  background: rgba(235,241,246,.82);
  border-color: rgba(102,126,146,.22);
}
:root[data-resolved-theme="light"] .message-attachment-preview,
:root[data-resolved-theme="light"] .message-attachment-icon { background: rgba(116,139,158,.12); }
:root[data-resolved-theme="light"] .message-attachment-download,
:root[data-resolved-theme="light"] .audio-file-speed,
:root[data-resolved-theme="light"] .voice-speed {
  background: rgba(91,126,158,.08);
  border-color: rgba(91,126,158,.20);
  color: #36566f;
}
:root[data-resolved-theme="light"] .message-attachment-download:hover,
:root[data-resolved-theme="light"] .audio-file-speed:hover,
:root[data-resolved-theme="light"] .voice-speed:hover { background: rgba(91,126,158,.14); }
:root[data-resolved-theme="light"] .media-progress { background: rgba(85,110,132,.14); }

:root[data-resolved-theme="light"] .composer-edit-bar,
:root[data-resolved-theme="light"] .composer-reply-bar,
:root[data-resolved-theme="light"] .composer-forward-bar,
:root[data-resolved-theme="light"] .message-reply-preview {
  background: rgba(67,128,188,.09);
  border-color: rgba(67,128,188,.24);
  border-left-color: #568fc8;
}
:root[data-resolved-theme="light"] .composer-edit-copy strong,
:root[data-resolved-theme="light"] .composer-reply-copy strong,
:root[data-resolved-theme="light"] .composer-forward-copy strong,
:root[data-resolved-theme="light"] .message-reply-preview strong,
:root[data-resolved-theme="light"] .message-forward-header,
:root[data-resolved-theme="light"] .forward-settings-button { color: #356fa8; }
:root[data-resolved-theme="light"] .composer-edit-copy span,
:root[data-resolved-theme="light"] .composer-reply-copy span,
:root[data-resolved-theme="light"] .composer-forward-copy span,
:root[data-resolved-theme="light"] .message-reply-preview span,
:root[data-resolved-theme="light"] .composer-edit-cancel,
:root[data-resolved-theme="light"] .composer-reply-cancel,
:root[data-resolved-theme="light"] .composer-forward-cancel { color: #6b7d8d; }
:root[data-resolved-theme="light"] .composer-edit-cancel:hover,
:root[data-resolved-theme="light"] .composer-reply-cancel:hover,
:root[data-resolved-theme="light"] .composer-forward-cancel:hover,
:root[data-resolved-theme="light"] .attachment-chip-remove:hover { background: rgba(62,86,108,.08); color: #263746; }
:root[data-resolved-theme="light"] .forward-recipient-list { background: rgba(221,230,238,.52); }
:root[data-resolved-theme="light"] .forward-choice:hover { background: rgba(69,97,122,.07); }
:root[data-resolved-theme="light"] .forward-option { background: rgba(242,246,249,.86); }
:root[data-resolved-theme="light"] .forward-settings-button.active { background: #dbe9f6; border-color: #7ca5cc; }
:root[data-resolved-theme="light"] .message-selection-toggle { background: #edf2f6; color: #3c566d; border-color: #aabac8; }
:root[data-resolved-theme="light"] .message-row.forward-selected .message-selection-toggle { background: #4585c4; color: white; border-color: #4585c4; }

:root[data-resolved-theme="light"] .message-action-button { background: #e4ebf1; border-color: #c4d0db; color: #52697c; }
:root[data-resolved-theme="light"] .message-action-button:hover,
:root[data-resolved-theme="light"] .message-action-button:focus-visible { background: #d9e4ed; border-color: #9fb2c3; }
:root[data-resolved-theme="light"] .message-more-button[aria-expanded="true"] { background: #cfe0ef; border-color: #86a7c3; color: #25445f; }
:root[data-resolved-theme="light"] .message-context-item { color: #2c3d4c; }
:root[data-resolved-theme="light"] .message-context-item:focus-visible { background: rgba(63,92,117,.08); }
:root[data-resolved-theme="light"] .message-context-glyph { color: #477da9; }
:root[data-resolved-theme="light"] .message-context-item.danger { color: #a7444d; }

:root[data-resolved-theme="light"] .call-header-button { color: #476075; }
:root[data-resolved-theme="light"] .call-header-button:hover { background: rgba(62,86,108,.07); border-color: #afbecb; }
:root[data-resolved-theme="light"] .call-avatar { background: linear-gradient(145deg, #d9e6f0, #c7d7e4); color: #355875; box-shadow: 0 14px 36px rgba(50,66,80,.12); }
:root[data-resolved-theme="light"] .call-duration { color: #526a7c; }
:root[data-resolved-theme="light"] .call-pill { background: #e7edf2; color: #40586b; border-color: #bdcad5; }
:root[data-resolved-theme="light"] .call-pill:hover,
:root[data-resolved-theme="light"] .call-pill.active { background: #dbe5ed; border-color: #9eb1c1; }

/* Media viewers intentionally remain dark so images/video keep predictable contrast. */
:root[data-resolved-theme="light"] .media-viewer,
:root[data-resolved-theme="light"] .video-note-recorder { color-scheme: dark; }

:root[data-resolved-theme="light"] .debug-panel {
  background: rgba(239,244,248,.97);
  border-color: #aabccc;
  color: #31516c;
  box-shadow: 0 18px 55px rgba(48,64,79,.16);
}
:root[data-resolved-theme="light"] #debug-stats { color: #376f9b; }
:root[data-resolved-theme="light"] .debug-log { color: #63798b; }
:root[data-resolved-theme="light"] .debug-log-entry { border-top-color: rgba(69,92,112,.10); }
:root[data-resolved-theme="light"] .debug-log-entry strong { color: #35566f; }

/* v0.18.0 CP3.6A Music Player Foundation */
.audio-file-message {
  width: min(520px, 72vw);
  min-width: 280px;
  border: 1px solid rgba(111,168,255,.28);
  background: linear-gradient(145deg, rgba(28,43,58,.94), rgba(21,32,43,.94));
  border-radius: 14px;
  padding: 10px;
  display: grid;
  gap: 10px;
}
.audio-file-message.is-active { border-color: rgba(111,168,255,.68); box-shadow: 0 0 0 1px rgba(111,168,255,.12); }
.audio-file-head { display: grid; grid-template-columns: 46px minmax(0,1fr) auto; align-items: center; gap: 10px; }
.audio-file-icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(145deg, rgba(111,168,255,.28), rgba(61,124,218,.18));
  color: #9bc6ff; font-size: 22px; font-weight: 800;
}
.audio-file-identity { min-width: 0; display: grid; gap: 3px; }
.audio-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 760; }
.audio-file-meta { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audio-file-actions { display: flex; align-items: center; gap: 5px; }
.audio-file-download,
.audio-file-save,
.audio-file-play {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); display: grid; place-items: center;
}
.audio-file-download,
.audio-file-save { width: 34px; height: 34px; padding: 0; border-radius: 10px; }
.audio-file-save { color: #f3c45c; font-size: 18px; }
.audio-file-play { width: 38px; height: 38px; border-radius: 50%; padding: 0; background: var(--accent-2); border-color: transparent; color: white; }
.audio-file-controls { display: grid; grid-template-columns: 38px minmax(100px,1fr) auto; align-items: center; gap: 10px; }
.audio-file-time { color: var(--muted); font-size: 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.music-seek { min-width: 0; height: 24px; display: flex; align-items: center; cursor: pointer; touch-action: none; outline: none; }
.music-seek-rail { position: relative; width: 100%; height: 4px; border-radius: 999px; background: rgba(142,160,177,.28); }
.music-seek-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit; background: var(--accent); pointer-events: none; }
.music-seek-thumb {
  position: absolute; top: 50%; left: 0; width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%,-50%);
  background: var(--accent); box-shadow: 0 0 0 3px rgba(111,168,255,.15); pointer-events: none;
}
.music-seek:focus-visible .music-seek-rail { box-shadow: 0 0 0 3px rgba(111,168,255,.18); }

.main-drawer-nav { flex: 1 1 auto; }
.drawer-music-player {
  flex: 0 0 auto;
  margin: 0 10px 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-2);
  overflow: hidden;
}
.drawer-music-compact { display: grid; grid-template-columns: 38px minmax(0,1fr) repeat(5, 30px); gap: 6px; align-items: center; padding: 9px; }
.drawer-music-compact .drawer-music-control { width: 30px; height: 30px; }
.drawer-music-control:disabled { opacity: .34; cursor: default; }
.drawer-music-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: rgba(111,168,255,.16); color: var(--accent); font-size: 20px; }
.drawer-music-copy { min-width: 0; display: grid; gap: 2px; }
.drawer-music-copy strong,
.drawer-music-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-music-copy strong { font-size: 12px; }
.drawer-music-copy small { color: var(--muted); font-size: 10px; }
.drawer-music-control { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text); padding: 0; display: grid; place-items: center; }
.drawer-music-control.primary { border-color: transparent; background: var(--accent-2); color: white; }
.drawer-music-expanded { border-top: 1px solid var(--border); padding: 8px 10px 10px; display: grid; gap: 7px; }
.drawer-music-seek { height: 20px; }
.drawer-music-meta-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.drawer-music-meta-row button { border: 1px solid var(--border); background: transparent; color: var(--text); border-radius: 8px; padding: 5px 7px; font-size: 10px; }
.drawer-music-queue-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 2px; }
.drawer-music-queue-head strong { font-size: 11px; }
.drawer-music-queue-list { display: grid; gap: 4px; max-height: 180px; overflow: auto; padding-right: 2px; }
.drawer-music-queue-item { width: 100%; min-width: 0; display: grid; grid-template-columns: 22px minmax(0,1fr); align-items: center; gap: 7px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--text); padding: 6px 7px; text-align: left; }
.drawer-music-queue-item:hover, .drawer-music-queue-item.is-active { background: rgba(111,168,255,.08); border-color: rgba(111,168,255,.22); }
.drawer-music-queue-number { color: var(--muted); font-size: 10px; text-align: center; font-variant-numeric: tabular-nums; }
.drawer-music-queue-copy { min-width: 0; display: grid; gap: 1px; }
.drawer-music-queue-copy strong, .drawer-music-queue-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-music-queue-copy strong { font-size: 10px; }
.drawer-music-queue-copy small { color: var(--muted); font-size: 9px; }

.music-modal { width: min(920px, calc(100vw - 28px)); max-height: min(760px, calc(100dvh - 28px)); }
.music-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.music-tab { border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); padding: 9px 12px; }
.music-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.music-panel { min-height: 280px; max-height: 60dvh; overflow: auto; }
.music-empty { min-height: 220px; display: grid; place-content: center; text-align: center; gap: 6px; color: var(--muted); }
.music-empty strong { color: var(--text); }
.music-library-list,
.music-playlist-list,
.music-playlist-tracks { display: grid; gap: 8px; }
.music-library-track {
  display: grid; grid-template-columns: 40px minmax(0,1fr) auto; gap: 10px; align-items: center;
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 12px; padding: 9px;
}
.music-library-track.is-active { border-color: rgba(111,168,255,.65); }
.music-library-play { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent-2); color: white; padding: 0; }
.music-library-copy { min-width: 0; display: grid; gap: 2px; }
.music-library-copy strong,
.music-library-copy span,
.music-library-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.music-library-copy span { color: var(--muted); font-size: 12px; }
.music-library-copy small { color: var(--muted); font-size: 10px; }
.music-library-actions { display: flex; align-items: center; gap: 6px; }
.music-playlist-select { width: 150px; padding: 7px 8px; border-radius: 8px; font-size: 11px; }
.music-playlist-form { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; margin-bottom: 12px; }
.music-playlist-card { border: 1px solid var(--border); border-radius: 14px; background: rgba(255,255,255,.015); padding: 10px; display: grid; gap: 10px; }
.music-playlist-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.music-playlist-head > div { display: grid; gap: 2px; }
.music-playlist-head small { color: var(--muted); }
.music-playlist-empty { padding: 12px; }

:root[data-resolved-theme="light"] .audio-file-message,
:root[data-resolved-theme="light"] .drawer-music-player,
:root[data-resolved-theme="light"] .music-library-track,
:root[data-resolved-theme="light"] .music-playlist-card {
  background: #edf3f8;
  border-color: #c6d4df;
  color: #243442;
}
:root[data-resolved-theme="light"] .audio-file-icon,
:root[data-resolved-theme="light"] .drawer-music-icon { background: #dcebf7; color: #3979b6; }
:root[data-resolved-theme="light"] .audio-file-download,
:root[data-resolved-theme="light"] .audio-file-save,
:root[data-resolved-theme="light"] .drawer-music-control,
:root[data-resolved-theme="light"] .drawer-music-meta-row button { background: #f7fafc; border-color: #c5d2dc; color: #344d62; }
:root[data-resolved-theme="light"] .audio-file-play,
:root[data-resolved-theme="light"] .drawer-music-control.primary,
:root[data-resolved-theme="light"] .music-library-play { background: #4387ca; color: white; }
:root[data-resolved-theme="light"] .music-seek-rail { background: #c7d5df; }
:root[data-resolved-theme="light"] .music-seek-fill,
:root[data-resolved-theme="light"] .music-seek-thumb { background: #4e91d2; }
:root[data-resolved-theme="light"] .audio-file-meta,
:root[data-resolved-theme="light"] .drawer-music-copy small,
:root[data-resolved-theme="light"] .music-library-copy span,
:root[data-resolved-theme="light"] .music-library-copy small { color: #708493; }

:root[data-resolved-theme="light"] .voice-recorder {
  background: #f7fafc;
  border-color: #b9c9d6;
}
:root[data-resolved-theme="light"] .voice-recorder-label,
:root[data-resolved-theme="light"] .recording-time { color: #38546b; }
:root[data-resolved-theme="light"] .recorder-wave span,
:root[data-resolved-theme="light"] .voice-waveform span { background: #8aa1b5; }
:root[data-resolved-theme="light"] .voice-waveform span.played { background: #3f82bf; }
:root[data-resolved-theme="light"] .voice-play { background: #d7e8f6; color: #2f6fa8; }
:root[data-resolved-theme="light"] .voice-play:hover { background: #c9dff1; }
:root[data-resolved-theme="light"] .voice-speed { background: #e4edf4; color: #355b79; }
:root[data-resolved-theme="light"] .voice-footer { color: #6f8495; }
:root[data-resolved-theme="light"] .drawer-music-queue-item:hover,
:root[data-resolved-theme="light"] .drawer-music-queue-item.is-active { background: #e6f0f8; border-color: #bfd3e4; }

@media (max-width: 720px) {
  .audio-file-message { width: min(340px, 82vw); min-width: 220px; }
  .audio-file-controls { grid-template-columns: 36px minmax(80px,1fr); }
  .audio-file-time { grid-column: 2; justify-self: end; margin-top: -7px; }
  .music-library-track { grid-template-columns: 38px minmax(0,1fr); }
  .music-library-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .music-playlist-select { width: min(180px, 48vw); }
}

/* CP3.6B conversation state / realtime sidebar */
.sidebar-unread-total {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: var(--accent-2);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.sidebar-unread-total.hidden { display: none; }
.user-item-state { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; color: var(--muted); }
.user-state-icon { width: 16px; height: 16px; display: inline-grid; place-items: center; font-size: 11px; opacity: .9; }
.user-state-icon.pinned { color: #8bbcf0; }
.user-state-icon.muted { color: var(--muted); }
.user-item[data-conversation-pinned="1"] .user-name { font-weight: 800; }
.sidebar-archive-switch {
  width: calc(100% - 2px);
  margin: 1px 1px 7px;
  border: 0;
  border-radius: 10px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(78, 139, 214, .09);
  color: var(--text);
  text-align: left;
}
.sidebar-archive-switch:hover { background: rgba(78, 139, 214, .15); }
.sidebar-archive-switch strong { font-size: 12px; }
.sidebar-archive-switch span { color: var(--muted); font-size: 10px; }
.sidebar-view-head { display: flex; align-items: center; gap: 8px; padding: 2px 2px 8px; }
.sidebar-view-back {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--border);
  background: transparent; color: var(--text); font-size: 18px;
}
.sidebar-view-title { min-width: 0; display: grid; gap: 1px; }
.sidebar-view-title strong { font-size: 13px; }
.sidebar-view-title span { color: var(--muted); font-size: 10px; }

.conversation-context-menu {
  position: fixed;
  z-index: 1200;
  width: min(260px, calc(100vw - 20px));
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .38);
}
.conversation-context-menu.hidden { display: none; }
.conversation-context-item {
  width: 100%; border: 0; border-radius: 8px; padding: 9px 10px;
  display: grid; grid-template-columns: 26px 1fr; align-items: center; gap: 8px;
  background: transparent; color: var(--text); text-align: left;
}
.conversation-context-item:hover,
.conversation-context-item:focus-visible { background: rgba(255,255,255,.07); outline: none; }
.conversation-context-glyph { display: grid; place-items: center; color: #9fc8ec; font-size: 15px; }
.conversation-context-separator { height: 1px; margin: 5px 6px; background: var(--border); }
.conversation-context-menu[data-busy="1"] .conversation-context-item { opacity: .55; pointer-events: none; }

.conversation-mute-modal { width: min(420px, calc(100vw - 28px)); }
.conversation-mute-options { display: grid; gap: 8px; }
.conversation-mute-options > button {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
  background: var(--panel-2); color: var(--text); text-align: left;
}
.conversation-mute-options > button:hover { border-color: var(--accent-2); }
.conversation-mute-options > button.hidden { display: none; }

:root[data-resolved-theme="light"] .conversation-context-menu,
:root[data-resolved-theme="light"] .conversation-mute-options > button { background: #f7fafc; }
:root[data-resolved-theme="light"] .conversation-context-item:hover,
:root[data-resolved-theme="light"] .conversation-context-item:focus-visible { background: rgba(63,92,117,.08); }
:root[data-resolved-theme="light"] .sidebar-archive-switch { background: rgba(58, 130, 203, .08); }
:root[data-resolved-theme="light"] .sidebar-archive-switch:hover { background: rgba(58, 130, 203, .14); }

/* CP3.6C: chat details, shared content and per-device chat appearance. */
.chat-details-modal { width: min(760px, calc(100vw - 28px)); max-height: min(860px, calc(100dvh - 24px)); overflow: auto; }
.chat-details-profile { margin-bottom: 10px; }
.chat-details-presence { display: flex; align-items: center; gap: 7px; margin-top: 2px; }
.chat-details-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.chat-details-actions > button { min-width: 0; }
.chat-details-section { border-top: 1px solid var(--border); padding: 14px 0 2px; margin-top: 12px; }
.chat-details-section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.chat-details-section-head > div { min-width: 0; display: grid; gap: 3px; }
.chat-details-section-head .compact { flex: 0 0 auto; padding: 6px 9px; }
.chat-details-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.chat-details-tabs > button { border: 1px solid var(--border); background: var(--panel-2); color: var(--muted); border-radius: 9px; padding: 8px 9px; }
.chat-details-tabs > button.active { border-color: var(--accent-2); color: var(--text); background: rgba(61,124,218,.16); }
.chat-details-tabs > button span { margin-left: 4px; font-size: 10px; opacity: .8; }
.peer-shared-panel { min-height: 76px; }
.peer-shared-empty { min-height: 74px; display: grid; place-items: center; text-align: center; border: 1px dashed var(--border); border-radius: 11px; padding: 14px; }
.peer-shared-media-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.peer-shared-media-item { min-width: 0; border: 1px solid var(--border); background: var(--panel-2); border-radius: 11px; overflow: hidden; }
.peer-shared-media-visual { position: relative; aspect-ratio: 1 / 1; background: #0b1118; overflow: hidden; }
.peer-shared-media-poster, .peer-shared-media-visual > video { width: 100%; height: 100%; display: block; object-fit: cover; }
.peer-shared-media-no-preview { opacity: 0; }
.peer-shared-media-open { position: absolute; inset: 0; width: 100%; border: 0; background: transparent; color: white; font-size: 28px; text-shadow: 0 2px 10px rgba(0,0,0,.8); }
.peer-shared-media-item.is-video .peer-shared-media-open { background: linear-gradient(transparent, rgba(0,0,0,.18)); }
.peer-shared-media-download { position: absolute; right: 7px; top: 7px; z-index: 2; width: 30px; height: 30px; padding: 0; border: 1px solid rgba(255,255,255,.28); border-radius: 9px; background: rgba(8,13,18,.7); color: white; }
.peer-shared-media-meta { min-width: 0; padding: 7px 8px; display: grid; gap: 2px; }
.peer-shared-media-meta strong, .peer-shared-media-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-shared-media-meta strong { font-size: 11px; }
.peer-shared-media-meta span { color: var(--muted); font-size: 9px; }
.peer-shared-files, .peer-shared-music { display: grid; gap: 7px; }
.peer-shared-file-item { width: 100%; max-width: none; }
.peer-shared-file-date { color: var(--muted); font-size: 9px; white-space: nowrap; }
.peer-shared-music-item { display: grid; grid-template-columns: 38px minmax(0,1fr) auto; gap: 10px; align-items: center; border: 1px solid var(--border); background: var(--panel-2); border-radius: 11px; padding: 9px; }
.peer-shared-music-item.is-active { border-color: rgba(111,168,255,.62); }
.peer-shared-music-play { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--accent-2); color: white; padding: 0; }
.peer-shared-music-copy { min-width: 0; display: grid; gap: 2px; }
.peer-shared-music-copy strong, .peer-shared-music-copy span, .peer-shared-music-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-shared-music-copy span, .peer-shared-music-copy small { color: var(--muted); font-size: 10px; }
.peer-shared-music-actions { display: flex; gap: 6px; }
.peer-shared-music-actions > button { width: 34px; height: 34px; padding: 0; border: 1px solid var(--border); border-radius: 9px; background: transparent; color: var(--text); }
.chat-details-load-more { width: 100%; margin-top: 9px; }
.chat-preferences-grid { display: grid; grid-template-columns: minmax(0, 210px) 1fr; gap: 12px; align-items: start; }
.chat-preference-toggle { grid-template-columns: auto 1fr; align-items: start; gap: 9px; border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.chat-preference-toggle input { width: auto; margin-top: 3px; }
.chat-preference-toggle span { display: grid; gap: 3px; }
.chat-preference-toggle small { color: var(--muted); line-height: 1.35; }

#active-chat[data-chat-wallpaper="mesh"] .messages {
  background-image:
    radial-gradient(circle at 18% 22%, rgba(77,126,181,.12) 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 64%, rgba(111,168,255,.09) 0 1px, transparent 1.5px);
  background-size: 28px 28px, 38px 38px;
}
#active-chat[data-chat-wallpaper="midnight"] .messages {
  background: radial-gradient(circle at 50% -10%, #162436 0, #0b1118 48%, #080c11 100%);
}
#active-chat[data-chat-wallpaper="warm"] .messages {
  background: radial-gradient(circle at 20% 0%, rgba(132,91,62,.20), transparent 42%), radial-gradient(circle at 85% 90%, rgba(72,96,126,.16), transparent 42%);
}

:root[data-resolved-theme="light"] .chat-details-tabs > button,
:root[data-resolved-theme="light"] .peer-shared-media-item,
:root[data-resolved-theme="light"] .peer-shared-music-item { background: #f3f7fa; }
:root[data-resolved-theme="light"] .chat-details-tabs > button.active { background: #e3eef9; }
:root[data-resolved-theme="light"] .peer-shared-media-visual { background: #dfe8ef; }
:root[data-resolved-theme="light"] #active-chat[data-chat-wallpaper="mesh"] .messages {
  background-color: #edf2f6;
  background-image:
    radial-gradient(circle at 18% 22%, rgba(65,116,163,.13) 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 64%, rgba(89,139,184,.10) 0 1px, transparent 1.5px);
}
:root[data-resolved-theme="light"] #active-chat[data-chat-wallpaper="midnight"] .messages {
  background: radial-gradient(circle at 50% -10%, #dbe6ef 0, #e9eff4 50%, #eef3f6 100%);
}
:root[data-resolved-theme="light"] #active-chat[data-chat-wallpaper="warm"] .messages {
  background: radial-gradient(circle at 20% 0%, rgba(213,181,153,.28), transparent 42%), radial-gradient(circle at 85% 90%, rgba(152,180,203,.24), transparent 42%), #eef2f5;
}

@media (max-width: 720px) {
  .chat-details-modal { width: calc(100vw - 12px); max-height: calc(100dvh - 12px); }
  .chat-details-actions { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .peer-shared-media-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .chat-preferences-grid { grid-template-columns: 1fr; }
}

/* v0.28.0 Mobile UX foundation + human-readable device labels */
.mobile-chat-back { display: none; }

@media (max-width: 767px) {
  html, body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }
  body { min-height: 100dvh; }

  .auth-shell {
    min-height: 100dvh;
    padding: max(14px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    align-items: center;
  }
  .auth-card {
    width: 100%;
    max-width: 440px;
    padding: 18px;
    border-radius: 16px;
  }
  .auth-form input,
  .auth-form button,
  .tabs .tab { min-height: 46px; }

  .app-shell {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
  }
  .sidebar {
    width: 100%;
    min-width: 0;
    height: 100%;
    border-right: 0;
    display: flex;
  }
  .chat {
    display: none;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
  }
  .app-shell.mobile-chat-open .sidebar { display: none; }
  .app-shell.mobile-chat-open .chat { display: block; }

  .sidebar-header {
    min-height: 64px;
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }
  .main-menu-button,
  .drawer-close,
  .sidebar-view-back {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  .sidebar-identity { min-width: 0; flex: 1; }
  .sidebar-identity-copy { display: grid; min-width: 0; }
  .sidebar-identity-copy strong,
  .sidebar-identity-copy .small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar-me-avatar { width: 40px; height: 40px; flex-basis: 40px; }
  .sidebar-unread-total { margin-left: auto; }

  .search-box { padding: 10px 12px; }
  .search-box input { min-height: 46px; padding: 11px 12px; font-size: 16px; }
  .user-list {
    padding: 0 8px max(12px, env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .user-item {
    min-height: 64px;
    justify-content: flex-start;
    padding: 10px;
    gap: 12px;
    touch-action: pan-y;
  }
  .avatar-wrap { width: 44px; height: 44px; flex-basis: 44px; }
  .user-item .avatar { width: 44px; height: 44px; }
  .user-copy { display: grid; }
  .user-name { font-size: 15px; }
  .user-item-subtitle { font-size: 12px; }
  .user-time { font-size: 11px; }

  .chat-layout { height: 100dvh; min-height: 0; }
  .chat-header {
    height: auto;
    min-height: 60px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left));
    gap: 8px;
  }
  .mobile-chat-back {
    display: inline-grid;
    place-items: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--text);
    font-size: 32px;
    line-height: 1;
    padding: 0 0 4px;
  }
  .mobile-chat-back:active { background: var(--panel-2); }
  .peer-heading { min-width: 0; flex: 1; }
  .peer-title-line { min-width: 0; }
  .peer-title-line strong,
  .peer-handle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-header-status { gap: 4px; flex: 0 0 auto; }
  .call-header-button,
  .peer-info-button {
    min-width: 44px;
    width: 44px;
    min-height: 44px;
    height: 44px;
    padding: 0;
  }
  .peer-info-button { font-size: 0; }
  .peer-info-button::after { content: "i"; font-size: 15px; font-weight: 800; }
  .peer-presence { gap: 0; }
  .peer-presence span:last-child { display: none; }
  .peer-presence .presence-dot { margin: 0 4px; }
  #socket-state { display: none; }

  .security-alert { padding: 8px 10px; font-size: 11px; }
  .messages {
    padding: 12px 10px 16px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: 12px;
  }
  .message-row { margin: 5px 0; }
  .message-bubble { max-width: 90%; font-size: 15px; }
  .message-media-grid { width: min(88vw, 440px); }
  .message-attachment { width: min(84vw, 340px); min-width: 0; }
  .audio-file-message { width: min(84vw, 390px); min-width: 0; }
  .voice-message { width: min(84vw, 340px); }

  .composer {
    width: 100%;
    padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: 7px;
    background: var(--panel);
  }
  .composer-main {
    width: 100%;
    grid-template-columns: 44px minmax(0, 1fr) 44px 44px 46px;
    gap: 5px;
    align-items: end;
  }
  .composer-main textarea {
    height: 44px;
    min-height: 44px;
    max-height: min(132px, 30dvh);
    padding: 10px 11px;
    font-size: 16px;
  }
  .attachment-button,
  .record-button,
  .send-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
  }
  .send-button { width: 46px; min-width: 46px; font-size: 0; border-radius: 12px; }
  .send-button::after { content: "➤"; font-size: 18px; line-height: 1; }
  .composer.forwarding-selection .composer-main { grid-template-columns: minmax(0, 1fr) 44px 46px; }
  .forward-settings-button { width: 44px; height: 44px; }
  .attachment-options { align-items: flex-start; flex-wrap: wrap; }
  .attachment-mode-switch { max-width: 100%; }
  .voice-recorder { min-width: 0; overflow: hidden; }

  .conversation-context-menu,
  .message-context-menu {
    max-width: calc(100vw - 16px);
    touch-action: manipulation;
  }
  .conversation-context-item,
  .message-context-menu button { min-height: 44px; }

  .main-drawer {
    width: min(88vw, 360px);
    padding-left: env(safe-area-inset-left);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .main-drawer-head { padding-top: max(12px, env(safe-area-inset-top)); }
  .drawer-nav-item { min-height: 52px; }

  .modal,
  .settings-modal,
  .chat-details-modal {
    width: calc(100vw - 10px);
    max-width: none;
    max-height: calc(100dvh - 10px);
    margin: auto;
    padding: 14px;
    border-radius: 16px;
  }
  .modal-head {
    position: sticky;
    top: -14px;
    z-index: 4;
    margin: -14px -14px 12px;
    padding: 14px;
    flex-direction: row;
    align-items: flex-start;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
  }
  .modal-head > div { min-width: 0; }
  .modal-head [data-close-dialog] { min-width: 44px; min-height: 44px; }
  .settings-layout { grid-template-columns: 1fr; min-height: 0; gap: 12px; }
  .settings-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 3px;
    scrollbar-width: none;
  }
  .settings-tabs::-webkit-scrollbar { display: none; }
  .settings-tab { flex: 0 0 auto; width: auto; min-height: 44px; white-space: nowrap; }
  .settings-form { max-width: none; }
  .settings-panel input,
  .settings-panel select,
  .settings-panel button { min-height: 44px; }
  .device-card { padding: 12px; }
  .device-card-head { align-items: flex-start; }
  .device-actions .danger-button { min-height: 44px; }

  .chat-details-actions { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .peer-shared-media-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .chat-preferences-grid { grid-template-columns: 1fr; }

  .media-viewer {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
  }
  .media-viewer-head { padding-top: max(10px, env(safe-area-inset-top)); }
}

@media (max-width: 390px) {
  .chat-header-status .peer-presence { display: none; }
  .composer-main { grid-template-columns: 42px minmax(0, 1fr) 42px 42px 44px; gap: 4px; }
  .attachment-button,
  .record-button { width: 42px; min-width: 42px; }
  .send-button { width: 44px; min-width: 44px; }
  .message-bubble { max-width: 94%; }
}

@media (display-mode: standalone) and (max-width: 767px) {
  .app-shell,
  .chat-layout { height: 100dvh; }
}

@media (max-width: 767px) and (hover: none) {
  .message-actions { opacity: 1; transform: none; pointer-events: auto; }
  .message-action-button,
  .message-more-button { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
}

/* v0.28.1 mobile interaction hotfix
   Keep taps app-like on touch devices. `manipulation` preserves ordinary
   panning/pinch zoom but removes the browser's double-tap-to-zoom gesture. */
html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
button,
input,
textarea,
select,
[role="button"],
.tabs,
.tab {
  touch-action: manipulation;
}
button,
[role="button"],
.tab {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.tabs {
  position: relative;
  z-index: 2;
  isolation: isolate;
}
.tab {
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

@media (max-width: 767px), (pointer: coarse) {
  .auth-card { position: relative; z-index: 1; }
  .tabs { min-height: 52px; }
  .tabs .tab {
    min-height: 48px;
    font-size: 16px;
  }
  .auth-form input,
  .auth-form button {
    min-height: 48px;
    font-size: 16px;
  }
  .auth-form label { font-size: 14px; }
  .auth-shell,
  .app-shell {
    touch-action: manipulation;
  }
}


/* v0.28.2: local iOS/LAN secure-context recovery. */
.secure-context-help {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border, #273445);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface, #111923) 92%, #2c67a8 8%);
}
.secure-context-help.hidden { display: none; }
.secure-context-help p,
.secure-context-help small { margin: 0; color: var(--muted, #93a4b8); line-height: 1.4; }
.secure-context-actions { display: grid; gap: 8px; }
.secure-context-link {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  touch-action: manipulation;
}
@media (max-width: 767px) {
  .secure-context-help { padding: 12px; }
}


/* v0.28.3: mobile polish pass.
   Keep the phone UI app-like: actions live behind long-press, dialogs become
   proper sheets, and the composer follows the visual viewport/keyboard. */
/* Inline SVG icons replace emoji and text glyphs, which rendered as colour
   emoji on some platforms and as thin symbols on others. */
.ui-icon { width: 20px; height: 20px; display: block; flex: none; pointer-events: none; }
.drawer-nav-icon .ui-icon { width: 19px; height: 19px; }
.attachment-button .ui-icon,
.record-button .ui-icon { width: 21px; height: 21px; }
.secret-message-toggle { color: var(--muted); }
.secret-message-toggle.active { color: #d5adff; border-color: #8b67b3; background: rgba(139,103,179,.14); }
.attachment-button.active-secret { color: #d5adff; border-color: #8b67b3; }
.message-bubble.secret-message::before { content: 'Секретное'; display: block; color: #c5a7e5; font-size: 11px; font-weight: 600; margin-bottom: 4px; }
.composer-more-menu { display: none; }
@media (max-width: 767px) {
  .composer { position: relative; }
  .composer-main { grid-template-columns: 44px minmax(0, 1fr) 46px; }
  .composer-main .secret-message-toggle,
  .composer-main #voice-record-button,
  .composer-main #video-note-button { display: none; }
  .composer-more-menu:not(.hidden) {
    display: grid;
    position: absolute;
    z-index: 30;
    bottom: calc(100% + 5px);
    left: max(8px, env(safe-area-inset-left));
    width: min(230px, calc(100vw - 16px));
    padding: 6px;
    gap: 2px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 12px 30px rgba(0, 0, 0, .32);
  }
  .composer-more-menu button {
    min-height: 44px;
    padding: 9px 12px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    text-align: left;
    font: inherit;
  }
  .composer-more-menu button:active { background: rgba(120, 150, 190, .15); }
}
@media (max-width: 390px) {
  .composer-main { grid-template-columns: 44px minmax(0, 1fr) 44px; }
}
.call-round .ui-icon { width: 26px; height: 26px; }
.ui-icon-hangup { transform: rotate(135deg); }
#peer-profile-call-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
#peer-profile-call-button .ui-icon { width: 18px; height: 18px; }
.call-header-button .ui-icon {
  width: 20px;
  height: 20px;
  display: block;
  pointer-events: none;
}

@media (max-width: 767px) {
  .app-shell,
  .chat-layout {
    height: var(--mobile-viewport-height, 100dvh);
    max-height: var(--mobile-viewport-height, 100dvh);
  }

  .chat-header {
    min-height: 52px;
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
    gap: 6px;
  }
  .mobile-chat-back,
  .call-header-button,
  .peer-info-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    flex-basis: 44px;
  }
  .mobile-chat-back { font-size: 29px; border-radius: 11px; }
  .call-header-button .ui-icon { width: 19px; height: 19px; }
  .peer-info-button::after { font-size: 14px; }
  .chat-header-status { gap: 3px; }

  .messages {
    padding: 10px 12px 14px;
    scroll-padding-bottom: 72px;
  }
  .message-row { margin: 4px 0; }
  .message-bubble {
    max-width: 82%;
    padding: 8px 10px 6px;
    border-radius: 15px 15px 15px 5px;
    -webkit-touch-callout: none;
  }
  .message-row.mine .message-bubble { border-radius: 15px 15px 5px 15px; }
  .message-bubble.crypto-error { max-width: 82%; }

  /* On touch, the floating ellipsis was larger than some messages. Long-press
     already opens the same menu, so keep the control invisible until needed. */
  .message-actions,
  .message-bubble:hover .message-actions,
  .message-bubble:focus-within .message-actions,
  .message-failed .message-actions {
    top: 0;
    right: 0;
    left: auto;
    opacity: 1;
    transform: none;
    pointer-events: none;
  }
  .message-row:not(.mine) .message-actions { left: 0; right: auto; }
  .message-more-button { display: none !important; }
  .message-row.message-menu-open .message-actions { pointer-events: auto; }
  .message-context-menu,
  .message-context-menu.open-up,
  .message-row:not(.mine) .message-context-menu {
    position: fixed;
    z-index: 1600;
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    top: auto !important;
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
    width: auto;
    max-width: none;
    min-width: 0;
    padding: 8px;
    border-radius: 16px;
    pointer-events: auto;
  }
  .message-context-item {
    min-height: 48px;
    padding: 10px 12px 10px 10px;
    font-size: 14px;
  }
  .message-context-glyph { width: 28px; font-size: 17px; }

  .conversation-context-menu {
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
    top: auto !important;
    width: auto;
    max-width: none;
    padding: 8px;
    border-radius: 16px;
  }
  .conversation-context-item { min-height: 48px; font-size: 14px; }

  .composer {
    padding: 7px max(8px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: 5px;
  }
  .composer-main {
    grid-template-columns: 44px minmax(0, 1fr) 44px 44px 44px;
    gap: 4px;
  }
  .composer-main textarea {
    min-height: 44px;
    height: 42px;
    padding: 9px 10px;
    border-radius: 12px;
  }
  .attachment-button,
  .record-button,
  .send-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }
  .send-button { width: 44px; min-width: 44px; }
  .composer.forwarding-selection .composer-main { grid-template-columns: minmax(0, 1fr) 44px 44px; }
  .forward-settings-button { width: 44px; height: 44px; }

  /* Settings are a real mobile surface instead of a desktop dialog squeezed
     into the viewport. */
  .settings-modal {
    inset: 0;
    width: 100vw;
    height: var(--mobile-viewport-height, 100dvh);
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    overflow: hidden;
  }
  .settings-modal[open] {
    display: flex;
    flex-direction: column;
  }
  .settings-modal .modal-head {
    position: relative;
    top: auto;
    z-index: 5;
    flex: 0 0 auto;
    margin: 0;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    align-items: center;
    flex-direction: row;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
  }
  .settings-modal .modal-head h2 { margin: 0; font-size: 20px; }
  .settings-modal .modal-head p { display: none; }
  /* Every dialog closes with the same square "×" on phones; a "Закрыть" label
     next to a long description got squeezed and clipped at the screen edge. */
  .modal .modal-close {
    margin-left: auto;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 12px;
    font-size: 0;
    flex: 0 0 44px;
  }
  .modal .modal-close::after {
    content: "×";
    font-size: 28px;
    line-height: 1;
  }
  .settings-modal .settings-layout {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
  }
  .settings-modal .settings-tabs {
    flex: 0 0 auto;
    width: 100%;
    gap: 4px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
  }
  .settings-modal .settings-tab {
    min-height: 44px;
    padding: 8px 11px;
    border-radius: 10px;
  }
  .settings-modal .settings-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px max(14px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .settings-modal .settings-panel { gap: 14px; }
  .settings-modal .settings-section-head p { line-height: 1.35; }

  .settings-modal .device-list { gap: 8px; }
  .settings-modal .device-card {
    gap: 8px;
    padding: 11px 12px;
    border-radius: 14px;
  }
  .settings-modal .device-card-head { align-items: center; }
  .settings-modal .device-card-head strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .settings-modal .device-tags { flex: 0 0 auto; gap: 4px; }
  .settings-modal .device-tag { padding: 3px 6px; font-size: 9px; }
  .settings-modal .device-actions {
    margin-top: 0;
    justify-content: flex-end;
  }
  .settings-modal .device-actions .danger-button {
    min-height: 44px;
    width: auto;
    padding: 8px 11px;
  }

  .media-viewer img,
  .media-viewer video {
    max-width: 100%;
    max-height: calc(var(--mobile-viewport-height, 100dvh) - 116px);
    object-fit: contain;
  }
}

@media (max-width: 390px) {
  .message-bubble,
  .message-bubble.crypto-error { max-width: 86%; }
  .composer-main { grid-template-columns: 44px minmax(0, 1fr) 44px 44px 44px; gap: 3px; }
  .settings-modal .settings-tab { padding-inline: 9px; }
}

@media (max-width: 340px) {
  .peer-info-button { display: none; }
  .message-bubble,
  .message-bubble.crypto-error { max-width: 88%; }
  .settings-modal .settings-tabs { padding-inline: 8px; }
}

/* v0.28.6: keep the phone app and its message sheet inside the visible screen. */
@media (max-width: 767px) {
  .app-shell {
    position: fixed;
    top: var(--mobile-viewport-top, 0px);
    left: 0;
    width: 100%;
    height: var(--mobile-viewport-height, 100dvh);
    max-height: var(--mobile-viewport-height, 100dvh);
  }
  .chat-layout { height: 100%; max-height: 100%; }
  .messages {
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .message-row { min-width: 0; max-width: 100%; }
  .message-bubble,
  .message-bubble.crypto-error {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .message-rich,
  .message-attachments,
  .message-reply-preview,
  .message-forward-header,
  .message-media-grid,
  .message-attachment,
  .voice-message,
  .audio-file-message {
    min-width: 0;
    max-width: 100%;
  }
  .message-context-menu.mobile-portal,
  .message-context-menu.mobile-portal.open-up {
    position: fixed;
    top: var(--message-menu-top) !important;
    bottom: auto !important;
    left: var(--message-menu-left) !important;
    right: auto !important;
    width: var(--message-menu-width);
    max-height: var(--message-menu-max-height);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .mobile-keyboard-open .composer {
    padding-bottom: 7px;
  }
  .settings-modal {
    top: var(--mobile-viewport-top, 0px);
  }
}

/* v0.28.7: inline photos fit a message instead of filling the phone height. */
@media (max-width: 767px) {
  .message-media-grid[data-count="1"] {
    width: min(100%, 360px);
  }
  .message-media-grid[data-count="1"] .message-media {
    width: 100%;
    min-height: 0;
    max-height: min(42dvh, 360px);
    aspect-ratio: 1 / 1;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }
  .message-media-grid[data-count="1"] .message-media-poster {
    min-width: 0;
    min-height: 0;
    max-height: 100%;
    object-fit: contain;
  }
  .message-media-grid[data-count="1"] .message-inline-video {
    min-height: 0;
    max-height: 100%;
    object-fit: contain;
  }
}

.history-recovery-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}
.history-recovery-panel .ghost { justify-self: start; min-height: 44px; }

/* AzriX: monochrome graphite / porcelain pair based on the supplied marks. */
:root,
:root[data-resolved-theme="dark"] {
  --bg: #0d1014;
  --panel: #161b21;
  --panel-2: #20262e;
  --border: #303943;
  --text: #f3f5f6;
  --muted: #a1adb8;
  --accent: #ccd7e1;
  --accent-2: #71869a;
  --bubble: #202831;
  --bubble-mine: #354655;
  --azrix-action: #edf1f3;
  --azrix-action-text: #141a20;
  --azrix-focus: rgba(171,190,208,.18);
}
:root[data-theme="light"],
:root[data-resolved-theme="light"] {
  --bg: #f2f4f6;
  --panel: #fff;
  --panel-2: #edf1f3;
  --border: #d6dce1;
  --text: #1b232b;
  --muted: #62717e;
  --accent: #526578;
  --accent-2: #455b6d;
  --bubble: #fff;
  --bubble-mine: #dce5eb;
  --azrix-action: #222c35;
  --azrix-action-text: #fff;
  --azrix-focus: rgba(69,91,109,.16);
}

.azrix-mark {
  display: block;
  flex: none;
  background-image: url('/assets/azrix-mark-dark.svg');
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}
:root[data-theme="light"] .azrix-mark,
:root[data-resolved-theme="light"] .azrix-mark { background-image: url('/assets/azrix-mark-light.svg'); }

.auth-shell { background: radial-gradient(ellipse 60% 42% at 50% 19%, rgba(115,132,150,.12), transparent 82%), var(--bg); }
.auth-card { border-radius: 24px; background: var(--panel); box-shadow: 0 26px 70px rgba(0,0,0,.23); }
.brand-row { gap: 16px; margin-bottom: 26px; }
.logo.azrix-mark { width: 62px; height: 62px; border-radius: 16px; background-color: transparent; box-shadow: 0 10px 25px rgba(0,0,0,.16); }
.brand-row h1 { font-size: 30px; font-weight: 790; letter-spacing: -.045em; line-height: 1.05; }
.brand-row p { font-size: 12px; line-height: 1.4; }
.tabs { background: var(--bg); border: 1px solid var(--border); }
.tab.active { background: var(--panel-2); }
input, textarea, select { background: var(--bg); }
input:focus, textarea:focus, select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--azrix-focus); }
.primary { background: var(--azrix-action); color: var(--azrix-action-text); }
.primary:hover { filter: brightness(.94); }
.sidebar { background: var(--panel); }
.sidebar-header { gap: 9px; }
.sidebar-brand { display: flex; align-items: center; gap: 7px; flex: none; white-space: nowrap; color: var(--text); font-size: 17px; font-weight: 780; letter-spacing: -.045em; }
.sidebar-brand-mark { width: 32px; height: 32px; border-radius: 9px; }
.sidebar-identity { margin-left: auto; justify-content: flex-end; }
.sidebar-me-avatar { width: 34px; height: 34px; flex-basis: 34px; }
.sidebar-identity-copy { max-width: 88px; }
.chat { background: radial-gradient(circle at 52% 0%, #1a242c 0, var(--bg) 64%); }
.chat-header { background: rgba(17,21,26,.88); }
.message-bubble { border-color: var(--border); }
.message-row.mine .message-bubble { border-color: #4b6071; }
.empty-brand-mark { width: 88px; height: 88px; margin: 0 auto 18px; border-radius: 21px; box-shadow: 0 16px 35px rgba(0,0,0,.13); }
.empty-state h2 { margin-top: 0; }

:root[data-resolved-theme="light"] .auth-card { background: var(--panel); border-color: var(--border); }
:root[data-resolved-theme="light"] .sidebar { background: #f8f9fa; }
:root[data-resolved-theme="light"] .chat { background: radial-gradient(circle at 52% 0%, #fff 0, var(--bg) 64%); }
:root[data-resolved-theme="light"] .chat-header { background: rgba(255,255,255,.9); }
:root[data-resolved-theme="light"] .message-bubble { border-color: #d7dee3; }
:root[data-resolved-theme="light"] .message-row.mine .message-bubble { border-color: #c7d2d9; }
:root[data-resolved-theme="light"] .avatar,
:root[data-resolved-theme="light"] .profile-avatar { background: #e0e6ea; color: #344b5e; }
:root[data-resolved-theme="light"] .tabs,
:root[data-resolved-theme="light"] input,
:root[data-resolved-theme="light"] textarea,
:root[data-resolved-theme="light"] select { background: #f8fafb; }
:root[data-resolved-theme="light"] input:focus,
:root[data-resolved-theme="light"] textarea:focus,
:root[data-resolved-theme="light"] select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--azrix-focus); }
:root[data-resolved-theme="light"] .primary { background: var(--azrix-action); color: var(--azrix-action-text); }

@media (max-width: 767px) {
  .sidebar-header { gap: 8px; }
  .sidebar-brand-mark { width: 32px; height: 32px; }
  .sidebar-identity { flex: 1 1 auto; }
  .sidebar-identity-copy { max-width: none; }
  .sidebar-me-avatar { width: 34px; height: 34px; flex-basis: 34px; }
  .logo.azrix-mark { width: 56px; height: 56px; }
  .brand-row h1 { font-size: 27px; }
}
@media (max-width: 380px) {
  .sidebar-identity-copy { display: none; }
  .sidebar-identity { flex: 0 0 auto; }
}

/* Keep the phone composer to three visible controls: actions, text, send. */
@media (max-width: 767px) {
  .composer-main { grid-template-columns: 44px minmax(0, 1fr) 46px; }
  .composer.forwarding-selection .composer-main { grid-template-columns: minmax(0, 1fr) 44px 46px; }
  .composer.editing-message .composer-more-menu,
  .composer.forwarding-selection .composer-more-menu { display: none; }
}
@media (max-width: 390px) {
  .composer-main { grid-template-columns: 44px minmax(0, 1fr) 44px; }
}
