/* KorpChat · Telegram-inspired design system. Tokens only, no raw colors below. */
:root,
[data-theme="dark"] {
  --bg-app: #0e1621;
  --bg-panel: #17212b;
  --bg-panel-2: #1c2733;
  --bg-hover: #202b36;
  --bg-active: #2b5278;
  --bg-input: #242f3d;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --text: #f5f5f5;
  --text-secondary: #708499;
  --text-on-accent: #ffffff;
  --accent: #3390ec;
  --accent-strong: #5288c1;
  --accent-soft: rgba(51, 144, 236, 0.16);
  --border: #0f1c26;
  --divider: #101a24;
  --danger: #e0533d;
  --online: #4dcd5e;
  --overlay: rgba(5, 9, 14, 0.72);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --bubble-shadow: none;
  --radius-bubble: 16px;
  --radius-bubble-join: 6px;
  --radius-control: 10px;
  --header-height: 56px;
  --composer-height: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --call-gradient-1: #3f6fb5;
  --call-gradient-2: #6d55a8;
}

:root {
  --sidebar-width: 420px;
  --panel-width: 340px;
}

[data-theme="light"] {
  --call-gradient-1: #6ea8e6;
  --call-gradient-2: #a98bd8;
  --bg-app: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-panel-2: #f4f4f6;
  --bg-hover: #f1f1f1;
  --bg-active: #419fd9;
  --bg-input: #f1f1f1;
  --bubble-in: #ffffff;
  --bubble-out: #effdde;
  --text: #101114;
  --text-secondary: #707579;
  --text-on-accent: #ffffff;
  --accent: #3390ec;
  --accent-strong: #419fd9;
  --accent-soft: rgba(51, 144, 236, 0.12);
  --border: #e3e4e7;
  --divider: #e3e4e7;
  --danger: #ff3b30;
  --online: #34c759;
  --overlay: rgba(16, 17, 20, 0.45);
  --shadow: 0 18px 50px rgba(16, 17, 20, 0.18);
  --bubble-shadow: 0 1px 2px rgba(16, 17, 20, 0.09);
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  margin: 0;
  background: var(--bg-app);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--text-secondary); }
.small { font-size: 12.5px; }
.error { color: var(--danger); min-height: 18px; margin: 8px 0 0; font-size: 13px; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- generic controls ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-secondary);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.btn-primary, .btn-danger, .btn-ghost {
  border: 0; border-radius: var(--radius-control); padding: 10px 16px;
  font-weight: 500; font-size: 14px;
}
.btn-primary { background: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary.small { padding: 7px 12px; font-size: 13px; }
.btn-danger { background: var(--danger); color: var(--text-on-accent); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.wide { width: 100%; margin-top: 10px; }
label { display: block; margin: 14px 0 0; font-size: 13px; color: var(--text-secondary); }
input, textarea, select {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--bg-input); color: var(--text); font-size: 14px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: none; }

/* ---------- login ---------- */
.login-screen { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--bg-app); }
.login-card {
  width: min(420px, 100%); background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 50%; background: var(--accent);
  color: var(--text-on-accent); font-size: 22px; font-weight: 600;
  display: grid; place-items: center;
}
.logo { font-size: 24px; font-weight: 600; letter-spacing: -0.2px; }
.form { margin-top: 6px; }

/* ---------- app shell ---------- */
.sidebar-resizer {
  position: absolute; top: 0; bottom: 0;
  left: var(--sidebar-resized, var(--sidebar-width));
  width: 8px; transform: translateX(-4px);
  z-index: 25; cursor: col-resize; touch-action: none;
}
.sidebar-resizer::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 3px;
  width: 2px; background: transparent; transition: background 0.12s ease;
}
.sidebar-resizer:hover::after,
.sidebar-resizer:focus-visible::after,
.sidebar-resizer.dragging::after { background: var(--accent); }
.sidebar-resizer:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
body.resizing { user-select: none; cursor: col-resize; }
body.resizing .sidebar-resizer::after { background: var(--accent); }
@media (max-width: 899px) {
  .sidebar-resizer { display: none; }
}
.app {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-resized, var(--sidebar-width)) minmax(0, 1fr);
  height: 100%;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  overflow: hidden;
  background: var(--bg-panel); border-right: 1px solid var(--border);
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: var(--header-height); padding: 0 8px 0 6px; border-bottom: 1px solid var(--border);
}
.sidebar-header .brand { font-size: 17px; font-weight: 600; }
.sidebar-search { position: relative; padding: 8px 10px 4px; }
.sidebar-search .search-icon {
  position: absolute; left: 22px; top: 50%; transform: translateY(-42%);
  width: 18px; height: 18px; color: var(--text-secondary); pointer-events: none;
}
.sidebar-search input { margin: 0; padding-left: 38px; background: var(--bg-input); border-color: transparent; border-radius: 18px; }
.chat-tabs { display: flex; gap: 6px; padding: 4px 12px 8px; overflow-x: auto; scrollbar-width: none; }
.chat-tabs::-webkit-scrollbar { display: none; }
.chat-tab {
  border: 0; background: transparent; color: var(--text-secondary);
  padding: 6px 10px; border-radius: 14px; font-size: 13px;
}
.chat-tab:hover { background: var(--bg-hover); color: var(--text); }
.chat-tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.rooms { flex: 1; overflow-y: auto; padding: 4px 6px 10px; }
.room {
  display: grid; grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 10px; align-items: center; padding: 8px 10px; margin: 1px 0;
  border-radius: 12px; cursor: pointer; min-width: 0;
}
.room:hover { background: var(--bg-hover); }
.room.active { background: var(--bg-active); }
.room.active .room-name, .room.active .room-preview, .room.active .room-time, .room.active .room-meta { color: var(--text-on-accent); }
.room.active .room-preview, .room.active .room-time { opacity: 0.8; }
.room-avatar { width: 54px; height: 54px; }
.room-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.room-top { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.room-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.room-time { font-size: 12px; color: var(--text-secondary); flex: 0 0 auto; }
.room-bottom { display: flex; align-items: center; gap: 6px; min-width: 0; }
.room-preview {
  font-size: 13px; color: var(--text-secondary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
.room-meta { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; color: var(--text-secondary); }
.room-meta .icon { width: 14px; height: 14px; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: var(--text-on-accent);
  font-size: 12px; font-weight: 600; display: grid; place-items: center;
}
.room.active .badge { background: var(--text-on-accent); color: var(--bg-active); }
.badge.highlight { background: var(--danger); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
  background: var(--accent-strong); color: var(--text-on-accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex: 0 0 auto;
}
.avatar.small { width: 26px; height: 26px; font-size: 10px; }
.room .avatar { width: 54px; height: 54px; font-size: 16px; }
.room.invite { outline: 1px dashed var(--accent); }

.sidebar-footer {
  border-top: 1px solid var(--border); padding: 0 8px;
  height: var(--composer-height); box-sizing: border-box;
  display: flex; align-items: center; gap: 6px;
}
.me-row {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; border-radius: 10px; padding: 6px; text-align: left;
}
.me-row:hover { background: var(--bg-hover); }
.me-avatar { flex: 0 0 auto; display: inline-flex; }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-username { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer-actions { display: flex; gap: 2px; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }

/* ---------- chat ---------- */
.chat { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg-app); }
.chat-header {
  height: var(--header-height); display: flex; align-items: center; gap: 10px;
  padding: 0 12px; border-bottom: 1px solid var(--border); background: var(--bg-panel);
}
.chat-avatar { display: inline-flex; flex: 0 0 auto; }
.chat-avatar .avatar { width: 40px; height: 40px; }
.chat-heading {
  min-width: 0; flex: 1; display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; padding: 0; text-align: left;
  color: inherit; border-radius: 10px;
}

.chat-title-block { min-width: 0; display: flex; flex-direction: column; flex: 1; }
.chat-heading h1 { margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { display: flex; gap: 8px; min-width: 0; align-items: baseline; }
.typing { font-size: 13px; color: var(--accent); min-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.typing:empty { display: none; }
.chat-actions { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.chat-more { position: relative; }
.chat-more-menu {
  right: 0; top: calc(100% + 6px); width: 232px;
  max-width: calc(100vw - 16px); padding: 6px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
}
.chat-more-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: transparent; color: var(--text);
  text-align: left; padding: 9px 10px; border-radius: 8px;
  font-size: 14px; font-weight: 400;
}
.chat-more-menu button:hover { background: var(--bg-hover); }
.chat-more-menu button:focus-visible {
  outline: none; box-shadow: inset 0 0 0 2px var(--accent);
}
.chat-more-menu button .icon { width: 18px; height: 18px; color: var(--text-secondary); flex: 0 0 auto; }
.chat-more-menu button span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-more-menu button.danger { color: var(--danger); }
.chat-more-menu button.danger .icon { color: var(--danger); }
.chat-more-menu button.menu-separator {
  margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
}
.panel-header-actions { display: flex; align-items: center; gap: 2px; }
.chat-actions .muted { margin-left: 6px; }
.mobile-only { display: none; }
.selection-bar {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  background: var(--accent-soft); border-bottom: 1px solid var(--border);
}
.selection-bar #selection-count { font-weight: 600; font-size: 14px; flex: 1; }
.selection-actions { display: flex; gap: 2px; }
.msg.selectable { cursor: pointer; }
.msg.selectable .reaction-add { display: none !important; }
.msg.selected .msg-content { outline: 2px solid var(--accent); outline-offset: 2px; }
.pinned-bar {
  display: flex; align-items: center; gap: 10px; padding: 5px 10px 5px 16px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  cursor: pointer; min-height: 38px;
}
.pinned-bar:hover { background: var(--bg-hover); }
.pinned-bar .icon { width: 17px; height: 17px; color: var(--accent); flex: 0 0 auto; }
.pinned-bar #pinned-text {
  flex: 1; min-width: 0;
  font-size: 13px; color: var(--text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.pinned-bar #pinned-text::before { content: "Закреплённое: "; color: var(--text-secondary); }
.pinned-count {
  flex: 0 0 auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 600; display: grid; place-items: center;
}
.pinned-unpin {
  flex: 0 0 auto; width: 30px; height: 30px; padding: 0;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--text-secondary);
}
.pinned-unpin:hover { background: var(--bg-hover); color: var(--text); }
.pinned-unpin .icon { width: 16px; height: 16px; color: currentColor; }
.pinned-bar.multiple #pinned-text::before { content: "Закреплённые: "; }
@media (max-width: 760px) {
  .pinned-unpin { width: 40px; height: 40px; }
}
.readers-list { display: grid; gap: 4px; margin-top: 10px; max-height: 60vh; overflow-y: auto; }
.reader-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.reader-row .name { flex: 1; min-width: 0; font-size: 14px; }
.reader-row .status { font-size: 12px; color: var(--text-secondary); }
.reader-row.read .status { color: var(--online); }
.media-more { width: auto; margin: 8px 0 0; padding: 5px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--text-secondary); }
.media-more:hover { background: var(--bg-hover); color: var(--text); }
.pinned-list { display: grid; gap: 4px; margin-top: 10px; max-height: 60vh; overflow-y: auto; }
.pinned-item {
  display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px;
  border-radius: 10px; cursor: pointer;
}
.pinned-item:hover { background: var(--bg-hover); }
.pinned-item .text { flex: 1; min-width: 0; }
.pinned-item .who { font-size: 12px; color: var(--accent-strong); font-weight: 500; }
.pinned-item .body { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-item .icon-btn { width: 28px; height: 28px; }
.room-meta-icon { width: 14px; height: 14px; color: var(--text-secondary); }
.chat-search-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--bg-panel); border-bottom: 1px solid var(--border);
}
.chat-search-bar input { margin: 0; border-radius: 16px; }
.chat-search-bar .icon-btn { width: 32px; height: 32px; }
.context-menu {
  position: fixed; z-index: 60; min-width: 190px; padding: 6px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px;
}
.context-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0;
  background: transparent; color: var(--text); text-align: left;
  padding: 8px 10px; border-radius: 8px; font-size: 14px;
}
.context-menu button:hover { background: var(--bg-hover); }
.context-menu .icon { width: 18px; height: 18px; color: var(--text-secondary); }
.context-menu .danger { color: var(--danger); }
.chat-body { flex: 1; display: flex; min-height: 0; position: relative; }

.timeline {
  flex: 1; min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  padding: 18px max(20px, calc((100% - 760px) / 2));
  display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: none;
}
.timeline::-webkit-scrollbar { display: none; }
.scroll-rail {
  position: absolute; right: 2px; width: 10px; z-index: 12;
  opacity: 0; transition: opacity 0.15s ease; pointer-events: none;
}
.scroll-rail.visible { opacity: 1; pointer-events: auto; }
.chat:hover .scroll-rail.visible, .scroll-rail.scrolling { opacity: 1; }
.scroll-thumb {
  position: absolute; right: 1px; width: 8px;
  background: var(--text-secondary); opacity: 0.55;
  border-radius: 4px; cursor: grab; touch-action: none;
}
.scroll-thumb:hover, .scroll-thumb.dragging { opacity: 1; }
.scroll-thumb.dragging { cursor: grabbing; }
.date-separator { align-self: center; margin: 12px 0 8px; }
.date-separator span {
  background: var(--bg-panel-2); color: var(--text-secondary);
  font-size: 12px; padding: 3px 10px; border-radius: 12px;
}
.unread-divider {
  align-self: stretch; display: flex; align-items: center; gap: 10px;
  color: var(--accent); font-size: 12px; margin: 12px 0 6px;
}
.unread-divider::before, .unread-divider::after {
  content: ""; height: 1px; background: var(--accent); flex: 1; opacity: 0.5;
}
.load-more {
  align-self: center; width: auto; margin: 4px 0 10px; padding: 6px 14px;
  border: 0; border-radius: 14px; background: var(--bg-panel-2);
  color: var(--text-secondary); font-size: 12.5px;
}
.load-more:hover { background: var(--bg-hover); color: var(--text); }

.msg {
  position: relative; display: flex; gap: 8px; max-width: 100%;
  margin-top: 8px; align-items: flex-end;
}
.msg.grouped { margin-top: 2px; }
.msg.grouped .msg-avatar { visibility: hidden; }
.msg-avatar { flex: 0 0 auto; width: 32px; display: flex; align-items: flex-end; }
.msg-avatar .avatar { width: 32px; height: 32px; font-size: 11px; }
.msg-content {
  position: relative; max-width: min(480px, 72%);
  background: var(--bubble-in); border-radius: var(--radius-bubble);
  box-shadow: var(--bubble-shadow);
  padding: 7px 11px 8px; min-width: 120px;
}
.msg.own { justify-content: flex-end; }
.msg.own .msg-avatar { order: 2; }
.msg.own .msg-content { background: var(--bubble-out); }
.msg:not(.grouped) .msg-content { border-bottom-left-radius: var(--radius-bubble); }
.msg.grouped:not(.own) .msg-content { border-top-left-radius: var(--radius-bubble-join); }
.msg.grouped.own .msg-content { border-top-right-radius: var(--radius-bubble-join); }
.msg.msg-highlight .msg-content {
  outline: 2px solid var(--accent); outline-offset: 2px;
  animation: message-highlight 2.4s ease-out;
}
@keyframes message-highlight {
  0% { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 20px var(--accent-soft); }
  60% { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 20px var(--accent-soft); }
  100% { box-shadow: var(--bubble-shadow); }
}
@media (prefers-reduced-motion: reduce) {
  .msg.msg-highlight .msg-content { animation: none; }
}
.msg .who { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--accent-strong); margin-bottom: 2px; }
.msg.own .who { display: none; }
.msg.grouped .who { display: none; }
.timeline.dm .msg-avatar { display: none; }
.timeline.dm .msg .who { display: none; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; padding-right: 52px; }
.msg.own .time, .msg .time { color: var(--text-secondary); }
[data-theme="light"] .msg.own .time { color: #6a8f5a; }
.msg .time {
  position: absolute; right: 9px; bottom: 5px;
  font-size: 11px; display: inline-flex; align-items: center; gap: 3px;
}
.msg .time .ticks { width: 15px; height: 15px; color: var(--text-secondary); }
.msg .time .ticks.read { color: var(--accent); }
[data-theme="light"] .msg.own .time .ticks { color: #6a8f5a; }
.msg .edited { font-size: 11px; color: var(--text-secondary); margin-left: 4px; }
.msg .redacted { color: var(--text-secondary); font-style: italic; }
.msg .quote {
  border-left: 3px solid var(--accent); padding: 2px 8px; margin: 2px 0 6px;
  color: var(--text-secondary); font-size: 12.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.reactions { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.reactions:empty { display: none; margin-top: 0; }
.reaction {
  border: 1px solid var(--border); background: var(--bg-panel-2); color: var(--text);
  border-radius: 12px; padding: 1px 8px; font-size: 12px; cursor: pointer;
}
.reaction.mine { border-color: var(--accent); background: var(--accent-soft); }
.reaction-add { opacity: 0; transition: opacity 0.12s ease; }
.msg:hover .reaction-add, .msg:focus-within .reaction-add { opacity: 1; }
.thread-summary {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 5px;
  padding: 2px 0; border: 0; background: transparent; color: var(--accent);
  font-size: 12.5px; font-weight: 500;
}
.thread-summary:hover { text-decoration: underline; }
.thread-summary .icon { width: 15px; height: 15px; }
button.reaction { width: auto; margin: 0; font-weight: 400; }
button.reaction:hover { background: var(--bg-hover); }
.msg .attachment { margin-top: 6px; max-width: 320px; max-height: 260px; border-radius: 12px; display: block; }
.msg a.file-link { color: var(--accent); text-decoration: none; }
.msg a.file-link:hover { text-decoration: underline; }
.msg audio.attachment-audio { max-width: 300px; height: 40px; display: block; margin-top: 4px; }
.msg.own .body a { color: #cfe0ff; }

.reply-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 16px;
  border-top: 1px solid var(--border); background: var(--bg-panel); color: var(--text-secondary); font-size: 13px;
}
.reply-bar .icon { width: 18px; height: 18px; color: var(--accent); }
.reply-bar #reply-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.composer {
  display: flex; align-items: flex-end; gap: 6px; position: relative;
  padding: 8px 12px; min-height: var(--composer-height);
  background: var(--bg-panel); border-top: 1px solid var(--border);
}
.composer-tools { display: flex; align-items: center; gap: 0; }
.composer textarea {
  flex: 1; margin: 0; min-height: 40px; max-height: 160px; padding: 9px 12px;
  border: 0; border-radius: 18px; background: var(--bg-input); line-height: 1.4;
}
.composer textarea:focus { outline: none; box-shadow: inset 0 0 0 1px var(--accent); }
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--text-on-accent);
}
.send-btn:hover { background: var(--accent-strong); color: var(--text-on-accent); }
.send-btn .icon { width: 20px; height: 20px; }
#record-audio.recording { color: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.popover {
  position: absolute; z-index: 30; background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: grid; gap: 2px;
}
.attach-menu { left: 12px; bottom: 58px; width: 210px; }
.attach-menu button {
  border: 0; background: transparent; color: var(--text); text-align: left;
  padding: 9px 10px; border-radius: 8px; font-size: 14px;
}
.attach-menu button:hover { background: var(--bg-hover); }
.emoji-picker { left: 56px; bottom: 58px; width: 260px; grid-template-columns: repeat(8, 1fr); }
.emoji-picker button { border: 0; background: transparent; font-size: 19px; padding: 4px; border-radius: 8px; }
.emoji-picker button:hover { background: var(--bg-hover); }

/* ---------- side panels ---------- */
.right-panel, .thread-panel {
  width: var(--panel-width); flex: 0 0 auto; display: flex; flex-direction: column;
  background: var(--bg-panel); border-left: 1px solid var(--border); min-height: 0;
}
.panel-header {
  height: 48px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px 0 14px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.right-tabs {
  display: flex; gap: 1px; padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  overflow: visible;
}
.right-tab {
  flex: 1 0 auto; border: 0; background: transparent; color: var(--text-secondary);
  padding: 5px 6px; border-radius: 8px; font-size: 12px; white-space: nowrap;
}
.right-tab:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent);
}
.right-tab:hover { background: var(--bg-hover); color: var(--text); }
.right-tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.panel-body { overflow-y: auto; padding: 12px; }
.settings-panel { padding-bottom: 12px; }
.settings-panel .modal-actions { margin-top: 14px; }
.right-profile { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 0 16px; }
.right-profile .avatar { width: 84px; height: 84px; font-size: 26px; }
.right-profile .name { font-size: 18px; font-weight: 600; }
.members-panel { margin-top: 10px; }
.member { display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 13.5px; }
.member .avatar { width: 28px; height: 28px; font-size: 10px; }
.member-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-secondary); display: inline-block; flex: 0 0 auto; }
.dot.online { background: var(--online); }
button.member-action {
  margin-left: 0; padding: 2px 8px; font-size: 11px; border: 1px solid var(--border);
  border-radius: 6px; background: transparent; color: var(--text-secondary); width: auto;
}
button.member-action:hover { color: var(--text); background: var(--bg-hover); }
.thread-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.thread-msg { background: var(--bubble-in); border-radius: 12px; padding: 8px 10px; }
.thread-msg.root { background: var(--bg-panel-2); border: 1px solid var(--border); }
.thread-msg .who { font-size: 12px; color: var(--accent-strong); }
.thread-msg .body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13.5px; }
.thread-composer { min-height: 48px; padding: 6px 8px; border-top: 1px solid var(--border); }
.thread-composer input { margin: 0; }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center;
  z-index: 50; padding: 16px;
}
.modal-card {
  width: min(420px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 20px; box-shadow: var(--shadow);
}
.wide-card { width: min(640px, 100%); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-header h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-actions button { width: auto; margin: 0; }
.directory { max-height: 340px; overflow-y: auto; margin-top: 10px; display: grid; gap: 2px; }
.directory-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer;
}
.directory-row:hover { background: var(--bg-hover); }
.directory-row .name { font-size: 14px; font-weight: 500; }
.directory-row .uid { color: var(--text-secondary); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-section { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.settings-section h3 { font-size: 13px; color: var(--text-secondary); margin: 0 0 8px; font-weight: 500; }
.roles { display: grid; gap: 6px; max-height: 180px; overflow-y: auto; }
.role-row { display: flex; align-items: center; gap: 8px; }
.role-row select { width: auto; margin: 0; padding: 4px 8px; font-size: 12px; }
.banned { display: grid; gap: 6px; }
.banned-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.banned-row .reason { color: var(--text-secondary); font-size: 12px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.checkbox-row input { width: auto; margin: 0; }

/* ---------- search ---------- */
.search-results { max-height: 42%; overflow-y: auto; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.search-results.expanded { max-height: none; flex: 1; border-bottom: 0; }
.search-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-secondary); padding: 10px 10px 4px;
}
.search-user-result, .search-chat-result, .search-public-result, .search-link-result {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 10px; cursor: pointer;
}
.search-user-result:hover, .search-chat-result:hover, .search-public-result:hover, .search-link-result:hover { background: var(--bg-hover); }
.search-user-result .info, .search-chat-result .info, .search-public-result .info, .search-link-result .info { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.search-user-result .name, .search-chat-result .name, .search-public-result .name, .search-link-result .name {
  font-size: 14px; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.search-user-result .uid, .search-chat-result .uid, .search-public-result .uid, .search-link-result .uid {
  font-size: 12px; color: var(--text-secondary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.search-public-result button, .search-link-result button {
  width: auto; margin: 0; padding: 5px 10px; font-size: 12px; border: 1px solid var(--border);
  border-radius: 8px; background: transparent; color: var(--accent);
}
.search-link-result { border: 1px dashed var(--border); }
.search-user-result .badge-self {
  font-size: 11px; color: var(--text-secondary); border: 1px solid var(--border);
  border-radius: 6px; padding: 1px 5px;
}
.search-loading, .search-empty { padding: 14px 10px; color: var(--text-secondary); font-size: 13px; }
.search-result { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.search-result:hover { background: var(--bg-hover); }
.search-result .room { padding: 0; font-size: 12px; color: var(--text-secondary); display: block; }
.search-result .text { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- call ---------- */
.call-overlay {
  position: fixed; inset: 0; z-index: 70;
  display: flex; color: #fff;
  background: linear-gradient(135deg, var(--call-gradient-1), var(--call-gradient-2));
}
.call-screen {
  width: 100%; height: 100%; min-height: 0;
  display: flex; flex-direction: column; position: relative; overflow: hidden;
  padding: 18px 26px 22px;
  background: radial-gradient(circle at 50% 18%, rgba(255, 255, 255, .10), transparent 46%);
}
.call-top { height: 40px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex: 0 0 auto; }
.call-room {
  margin-right: auto; max-width: calc(100% - 60px); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 12px; opacity: .68;
}
.call-settings-toggle {
  width: 38px; height: 38px; padding: 0; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .22); background: rgba(255, 255, 255, .12);
  color: #fff; display: grid; place-items: center;
}
.call-settings-toggle:hover { background: rgba(255, 255, 255, .22); }
.call-settings-toggle .icon { width: 19px; height: 19px; }
.call-stage {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 18px; padding: 8px 0;
}
.call-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; }
.call-avatar {
  width: 150px; height: 150px; margin-bottom: 18px; display: grid; place-items: center;
  border-radius: 50%;
  box-shadow: 0 0 0 18px rgba(255, 255, 255, .08), 0 0 0 36px rgba(255, 255, 255, .05);
}
.call-avatar .avatar { width: 150px; height: 150px; font-size: 52px; border: 0; background: #55bff0; color: #fff; }
.call-name { margin: 0; font-size: 32px; line-height: 1.15; font-weight: 600; max-width: min(680px, 88vw); overflow-wrap: anywhere; }
.call-status { margin: 0; font-size: 16px; opacity: .78; }
.call-participants { margin: 6px 0 0; font-size: 12px; opacity: .65; max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-videos {
  width: min(100%, 940px); flex: 1; min-height: 0; max-height: 100%;
  display: flex; gap: 12px; align-items: stretch; justify-content: center;
}
.call-videos video {
  width: 100%; height: 100%; min-height: 0; object-fit: cover;
  border-radius: 16px; background: #0e1621;
}
#remote-videos { display: flex; gap: 12px; flex: 1; min-width: 0; }
#remote-videos audio { display: none; }
#remote-videos:empty { display: none; }
#remote-videos video { flex: 1; min-width: 0; }
.call-videos #local-video { flex: 1; }
.call-videos #screen-video { flex: 1; }
.call-stage.video-mode .call-hero { display: none; }
.call-stage.video-mode .call-videos { display: flex; }
.call-stage.video-mode .call-videos.hidden { display: none; }
.call-settings {
  position: absolute; top: 64px; right: 26px; z-index: 2;
  width: min(340px, calc(100vw - 32px)); padding: 14px;
  display: flex; flex-direction: column; gap: 12px; color: #fff;
  background: rgba(20, 28, 38, .96); border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 14px; box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}
.call-settings label { display: flex; flex-direction: column; gap: 5px; font-size: 11px; opacity: .85; }
.call-settings select {
  width: 100%; height: 36px; margin: 0; padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, .18); border-radius: 8px;
  background: rgba(255, 255, 255, .1); color: #fff; font-size: 12px;
}
.call-settings select option { background: #17212b; color: #fff; }
.call-incoming-actions {
  flex: 0 0 auto; display: flex; align-items: flex-start; justify-content: center;
  gap: 72px; padding: 10px 0 8px;
}
.call-overlay.incoming .call-dock,
.call-overlay.incoming .call-settings-toggle { display: none; }
.call-overlay.incoming .call-participants { display: none; }
.call-incoming-btn {
  width: 88px; padding: 0; border: 0; background: transparent; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font-size: 12px;
}
.call-incoming-btn .icon {
  width: 64px; height: 64px; padding: 18px; border-radius: 50%;
  background: rgba(255, 255, 255, .18);
}
.call-incoming-btn.accept .icon { background: #38c46b; }
.call-incoming-btn.decline .icon { background: #e94b3c; }
.call-incoming-btn:hover .icon { filter: brightness(1.08); }

.call-dock { flex: 0 0 auto; display: flex; justify-content: center; align-items: flex-start; gap: 34px; padding-top: 10px; }
.call-dock-btn {
  width: 76px; padding: 0; border: 0; background: transparent; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  font-size: 11px; line-height: 1.2;
}
.call-dock-btn > svg {
  width: 58px; height: 58px; padding: 16px; border-radius: 50%;
  background: rgba(255, 255, 255, .18); color: #fff;
  transition: background-color .15s ease, color .15s ease;
}
.call-dock-btn:hover > svg { background: rgba(255, 255, 255, .26); }
.call-dock-btn.active > svg { background: #fff; color: var(--accent); }
.call-dock-btn.off > svg { background: rgba(255, 255, 255, .92); color: var(--danger); }
.call-dock-btn.call-end > svg { background: #e94b3c; color: #fff; }
.call-dock-btn.call-end:hover > svg { background: #f05a4a; }
#call-participants { margin-left: 0; }
@media (max-width: 760px) {
  .call-screen { padding: 12px 14px 18px; }
  .call-avatar { width: 118px; height: 118px; margin-bottom: 14px; box-shadow: 0 0 0 12px rgba(255, 255, 255, .08), 0 0 0 24px rgba(255, 255, 255, .05); }
  .call-avatar .avatar { width: 118px; height: 118px; font-size: 42px; }
  .call-name { font-size: 25px; }
  .call-status { font-size: 14px; }
  .call-dock { gap: 10px; padding-top: 8px; }
  .call-dock-btn { width: 64px; font-size: 10px; }
  .call-dock-btn > svg { width: 50px; height: 50px; padding: 14px; }
  .call-videos { max-height: 100%; }
  .call-settings { top: 58px; right: 14px; left: 14px; width: auto; }
  .call-incoming-actions { gap: 42px; }
  .call-incoming-btn { width: 78px; font-size: 11px; }
  .call-incoming-btn .icon { width: 58px; height: 58px; padding: 16px; }
}

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  :root { --sidebar-width: 360px; --panel-width: 320px; }
}
@media (max-width: 900px) {
  :root { --sidebar-width: 320px; --panel-width: 300px; }
  .msg-content { max-width: 82%; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; position: relative; overflow: hidden; }
  .sidebar { position: absolute; inset: 0; z-index: 5; border-right: 0; }
  .chat { position: absolute; inset: 0; z-index: 10; transform: translateX(100%); transition: transform 0.18s ease; background: var(--bg-app); }
  .app.chat-open .chat { transform: none; }
  .app.chat-open .sidebar { display: none; }
  .mobile-only { display: inline-flex; }
  .chat-actions #room-meta { display: none; }
  .chat-status #room-topic { display: none; }
  .chat-actions #chat-search-toggle, .chat-actions #invite { display: none; }
  .selection-bar {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  background: var(--accent-soft); border-bottom: 1px solid var(--border);
}
.selection-bar #selection-count { font-weight: 600; font-size: 14px; flex: 1; }
.selection-actions { display: flex; gap: 2px; }
.msg.selectable { cursor: pointer; }
.msg.selectable .reaction-add { display: none !important; }
.msg.selected .msg-content { outline: 2px solid var(--accent); outline-offset: 2px; }
.pinned-bar {
  display: flex; align-items: center; gap: 10px; padding: 5px 10px 5px 16px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  cursor: pointer; min-height: 38px;
}
.pinned-bar:hover { background: var(--bg-hover); }
.pinned-bar .icon { width: 17px; height: 17px; color: var(--accent); flex: 0 0 auto; }
.pinned-bar #pinned-text {
  flex: 1; min-width: 0;
  font-size: 13px; color: var(--text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.pinned-bar #pinned-text::before { content: "Закреплённое: "; color: var(--text-secondary); }
.pinned-count {
  flex: 0 0 auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 600; display: grid; place-items: center;
}
.pinned-unpin {
  flex: 0 0 auto; width: 30px; height: 30px; padding: 0;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--text-secondary);
}
.pinned-unpin:hover { background: var(--bg-hover); color: var(--text); }
.pinned-unpin .icon { width: 16px; height: 16px; color: currentColor; }
.pinned-bar.multiple #pinned-text::before { content: "Закреплённые: "; }
@media (max-width: 760px) {
  .pinned-unpin { width: 40px; height: 40px; }
}
.readers-list { display: grid; gap: 4px; margin-top: 10px; max-height: 60vh; overflow-y: auto; }
.reader-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.reader-row .name { flex: 1; min-width: 0; font-size: 14px; }
.reader-row .status { font-size: 12px; color: var(--text-secondary); }
.reader-row.read .status { color: var(--online); }
.media-more { width: auto; margin: 8px 0 0; padding: 5px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--text-secondary); }
.media-more:hover { background: var(--bg-hover); color: var(--text); }
.pinned-list { display: grid; gap: 4px; margin-top: 10px; max-height: 60vh; overflow-y: auto; }
.pinned-item {
  display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px;
  border-radius: 10px; cursor: pointer;
}
.pinned-item:hover { background: var(--bg-hover); }
.pinned-item .text { flex: 1; min-width: 0; }
.pinned-item .who { font-size: 12px; color: var(--accent-strong); font-weight: 500; }
.pinned-item .body { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-item .icon-btn { width: 28px; height: 28px; }
.room-meta-icon { width: 14px; height: 14px; color: var(--text-secondary); }
.chat-search-bar { padding: 6px 8px; }
  .right-panel, .thread-panel {
    position: fixed; inset: 0; width: 100%; height: 100dvh;
    z-index: 40; border-left: 0;
  }
  .timeline { padding: 12px 10px; }
  .msg-content { max-width: 86%; }
  .composer { padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .composer-tools #emoji-btn { display: none; }
  .modal-card { max-height: 92vh; }
}

.msg .forwarded { font-size: 12px; color: var(--text-secondary); margin-bottom: 2px; }
.msg .forwarded strong { color: var(--accent-strong); font-weight: 500; }

.forwarded { font-size: 12px; color: var(--text-secondary); margin-bottom: 2px; }
.forwarded strong { color: var(--accent-strong); font-weight: 500; }

.right-media { margin: 8px 0 4px; }
.right-media h3 { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin: 12px 0 6px; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.media-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: pointer; }
.media-grid img:hover { opacity: 0.85; }
.media-files { display: grid; gap: 4px; }
.media-file { font-size: 12.5px; color: var(--accent); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-file:hover { text-decoration: underline; }

.info-panel { width: 360px; max-width: var(--panel-width); min-width: 0; }
.info-hero { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 0 16px; text-align: center; }
.info-hero .info-avatar { width: 88px; height: 88px; font-size: 28px; }
.info-name { font-size: 19px; font-weight: 600; }
.info-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 14px; align-items: stretch; }
.info-more { position: relative; min-width: 0; display: flex; }
.info-more > .info-action { width: 100%; }
.info-more-menu { width: 210px; max-width: calc(100vw - 16px); }
.info-action.active { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.info-action {
  display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg-panel-2);
  padding: 8px 4px; color: var(--text-secondary); font-size: 11px;
}
.info-action:hover { background: var(--bg-hover); color: var(--text); }
.info-action .icon { width: 20px; height: 20px; }
.info-action span { overflow-wrap: anywhere; text-align: center; }
.info-action.danger { color: var(--danger); }
.info-about { border-top: 1px solid var(--border); padding-top: 10px; }
.info-about h3 { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin: 0 0 6px; }
.info-topic { margin: 0 0 8px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.info-meta-row { font-size: 12px; color: var(--text-secondary); overflow-wrap: anywhere; margin-top: 2px; }
.info-meta-row.accent { color: var(--accent); }
.info-previews { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 6px; }
.info-preview-row {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  border: 0; background: transparent; color: var(--text); padding: 8px 4px;
  border-radius: 8px; font-size: 14px;
}
.info-preview-row:hover { background: var(--bg-hover); }
.info-preview-grid { margin: 6px 0 8px; }
.info-tab-panel { min-height: 120px; }
@media (max-width: 1000px) {
  .info-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 761px) and (max-width: 860px) {
  .info-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(320px, 100vw); max-width: 100vw;
    z-index: 40; box-shadow: var(--shadow);
  }
}
.info-list { display: grid; gap: 2px; }
.info-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 6px;
  border-radius: 8px; color: var(--text); text-decoration: none;
}
.info-row:hover { background: var(--bg-hover); }
.info-row-icon { flex: 0 0 auto; display: inline-flex; color: var(--text-secondary); }
.info-row-text { min-width: 0; display: flex; flex-direction: column; }
.info-row-title { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info-row-meta { font-size: 11.5px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info-empty { color: var(--text-secondary); font-size: 13px; padding: 20px 6px; }
.members-list { display: grid; gap: 2px; margin-top: 8px; }
.info-tab-panel #members-search { margin: 0 0 4px; border-radius: 16px; }
@media (max-width: 760px) {
  .info-panel { width: 100%; max-width: 100%; }
  .info-actions { grid-template-columns: repeat(3, 1fr); }
}


.reaction-picker {
  position: fixed; z-index: 70; width: 344px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 8px;
}
.reaction-quick { display: flex; align-items: center; gap: 2px; }
.reaction-quick button {
  width: 38px; height: 38px; padding: 0; border: 0; border-radius: 9px;
  background: transparent; font-size: 22px; line-height: 1;
  display: grid; place-items: center;
}
.reaction-quick button:hover, .reaction-quick button:focus-visible {
  background: var(--bg-hover);
}
.reaction-quick .reaction-expand {
  margin-left: auto; width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg-panel-2); color: var(--text-secondary);
}
.reaction-quick .reaction-expand:hover { background: var(--bg-hover); color: var(--text); }
.reaction-quick .reaction-expand .icon { width: 16px; height: 16px; }
.reaction-quick button.selected, .reaction-grid button.selected,
.reaction-frequent button.selected {
  background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent);
}
.reaction-full { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.reaction-search { position: relative; }
.reaction-search .icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-secondary); pointer-events: none;
}
.reaction-search input {
  margin: 0; padding: 8px 10px 8px 32px; border-radius: 16px;
  background: var(--bg-input); border-color: transparent; font-size: 13px;
}
.reaction-filters { display: flex; gap: 4px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.reaction-filters::-webkit-scrollbar { display: none; }
.reaction-filters button {
  flex: 0 0 auto; width: 30px; height: 30px; border: 0; border-radius: 8px;
  background: transparent; font-size: 17px; padding: 0;
}
.reaction-filters button:hover { background: var(--bg-hover); }
.reaction-filters button.active { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.reaction-frequent { display: flex; gap: 2px; margin-top: 6px; }
.reaction-frequent button {
  width: 34px; height: 34px; border: 0; border-radius: 8px;
  background: transparent; font-size: 20px; padding: 0;
}
.reaction-frequent button:hover { background: var(--bg-hover); }
.reaction-heading {
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-secondary); margin: 10px 0 6px;
}
.reaction-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 260px; overflow-y: auto; }
.reaction-grid button {
  width: 100%; aspect-ratio: 1; border: 0; border-radius: 8px;
  background: transparent; font-size: 22px; line-height: 1; padding: 0;
  display: grid; place-items: center;
}
.reaction-grid button:hover { background: var(--bg-hover); }
@media (max-width: 760px) {
  .reaction-picker {
    left: 8px !important; right: 8px; top: auto !important; bottom: 8px;
    width: auto; max-height: 72dvh; display: flex; flex-direction: column;
  }
  .reaction-full { overflow-y: auto; }
  .reaction-grid { max-height: none; }
}

.toast {
  position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%);
  z-index: 90; max-width: min(440px, calc(100vw - 24px));
  padding: 10px 16px; border-radius: 12px;
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 13.5px; line-height: 1.4; text-align: center;
  pointer-events: none;
}
@media (max-width: 760px) {
  .toast { bottom: 88px; }
}

.recording-panel {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  padding: 0 4px; color: var(--text);
}
.recording-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto;
  background: var(--danger); animation: pulse 1.2s ease-in-out infinite;
}
.recording-time { font-size: 13px; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.recording-wave { display: flex; align-items: center; gap: 2px; height: 22px; flex: 0 0 auto; }
.recording-wave span {
  width: 3px; height: 5px; border-radius: 2px; background: var(--accent);
  transition: height 0.08s linear;
}
.recording-hint {
  font-size: 12px; color: var(--text-secondary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.recording-cancel {
  flex: 0 0 auto; width: auto; margin-left: auto; padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: transparent;
  color: var(--danger); font-size: 12px;
}
.recording-cancel:hover { background: var(--bg-hover); }
.composer.recording #message, .composer.recording .send-btn { display: none; }
.composer.recording #record-audio.recording { color: var(--danger); }
.composer.cancelling .recording-panel { color: var(--danger); }
.composer.cancelling .recording-dot { background: var(--danger); }
.composer.cancelling .recording-hint { color: var(--danger); }
@media (max-width: 760px) {
  .recording-hint { white-space: normal; line-height: 1.2; }
}

.icon-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- profile modal ---------- */
.profile-card { width: min(365px, 100%); padding: 20px; }
.profile-identity { display: flex; align-items: center; gap: 14px; margin-top: 22px; }
.profile-avatar-preview { width: 58px; height: 58px; flex: 0 0 auto; display: inline-flex; }
.profile-avatar-preview .avatar { width: 58px; height: 58px; font-size: 19px; }
.profile-identity-text { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.profile-preview-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.profile-preview-id { color: var(--text-secondary); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.profile-photo-btn {
  border: 0; background: transparent; color: var(--accent); padding: 0;
  margin-top: 7px; font-size: 12px; font-weight: 500;
}
.profile-photo-btn:hover { text-decoration: underline; }
.profile-file { display: none; }
.profile-field { display: block; margin-top: 20px; }
.profile-label { display: block; color: var(--text-secondary); font-size: 12px; margin-bottom: 7px; }
.profile-field input { margin: 0; height: 42px; border-radius: 10px; background: var(--bg-panel-2); }
.profile-section { margin-top: 22px; }
.profile-theme-row {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-panel-2); padding: 11px 12px;
}
.profile-theme-icon {
  width: 26px; height: 26px; border-radius: 8px; background: var(--bg-input);
  display: grid; place-items: center; color: var(--text-secondary); flex: 0 0 auto;
}
.profile-theme-icon .icon { width: 17px; height: 17px; }
.profile-theme-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.profile-theme-title { font-size: 14px; }
.profile-theme-state { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.theme-switch {
  width: 46px; height: 26px; flex: 0 0 auto; padding: 0; position: relative;
  border: 1px solid var(--border); border-radius: 13px; background: var(--bg-input);
  transition: background-color .16s ease, border-color .16s ease;
}
.theme-switch span {
  position: absolute; left: 2px; top: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--text-secondary);
  transition: transform .16s ease, background-color .16s ease;
}
.theme-switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.theme-switch[aria-checked="true"] span { transform: translateX(20px); background: #fff; }
.theme-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.profile-notify-row {
  display: flex; align-items: flex-start; gap: 11px; margin-top: 2px;
  font-size: 14px; color: var(--text); cursor: pointer;
}
.profile-notify-row input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.profile-notify-row > span { min-width: 0; display: flex; flex-direction: column; }
.profile-notify-title { font-size: 14px; }
.profile-notify-sub { font-size: 11px; color: var(--text-secondary); margin-top: 3px; line-height: 1.35; }
.profile-save { width: 100%; margin-top: 22px; height: 42px; }
.profile-divider { height: 1px; background: var(--border); margin: 20px 0 12px; }
.profile-logout {
  width: 100%; border: 0; background: transparent; color: var(--danger);
  display: flex; align-items: center; gap: 10px; padding: 8px 2px;
  font-size: 14px; text-align: left;
}
.profile-logout:hover { background: var(--bg-hover); border-radius: 8px; }
.profile-logout .icon { width: 18px; height: 18px; color: var(--danger); flex: 0 0 auto; }
.profile-card .error { min-height: 16px; margin: 8px 0 0; }
@media (max-width: 760px) {
  .profile-card { padding: 18px; }
}

/* anchored profile popover */
#profile-modal.profile-anchored {
  display: block;
  background: rgba(4, 10, 16, 0.38);
}
#profile-modal.profile-anchored .profile-card {
  position: fixed;
  left: var(--profile-left, 12px);
  top: var(--profile-top, 12px);
  width: min(365px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  margin: 0;
  z-index: 51;
}
[data-theme="light"] #profile-modal.profile-anchored { background: rgba(20, 30, 40, 0.28); }
@media (max-width: 760px) {
  #profile-modal.profile-anchored { display: grid; place-items: center; }
  #profile-modal.profile-anchored .profile-card {
    position: static;
    width: 100%;
    max-height: 92vh;
    margin: 0;
  }
}

/* avatar editor */
.avatar-editor { z-index: 60; }
.avatar-editor-card { width: min(420px, 100%); padding: 18px; }
.avatar-crop {
  position: relative; width: min(320px, calc(100vw - 72px)); aspect-ratio: 1;
  margin: 16px auto 4px; overflow: hidden; background: #000;
  border-radius: 12px; touch-action: none; cursor: grab;
}
.avatar-crop:active { cursor: grabbing; }
#avatar-crop-image {
  position: absolute; max-width: none; user-select: none;
  pointer-events: none; transform-origin: 0 0;
}
.avatar-crop-mask {
  position: absolute; inset: 0; border-radius: 50%;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.crop-corner { position: absolute; width: 18px; height: 18px; border-color: #fff; border-style: solid; pointer-events: none; }
.crop-corner.tl { left: 10px; top: 10px; border-width: 2px 0 0 2px; }
.crop-corner.tr { right: 10px; top: 10px; border-width: 2px 2px 0 0; }
.crop-corner.bl { left: 10px; bottom: 10px; border-width: 0 0 2px 2px; }
.crop-corner.br { right: 10px; bottom: 10px; border-width: 0 2px 2px 0; }
.avatar-zoom-row {
  display: flex; align-items: center; gap: 10px; margin-top: 14px;
  color: var(--text-secondary); font-size: 12px;
}
.avatar-zoom-row input { flex: 1; margin: 0; accent-color: var(--accent); }
#avatar-zoom-value { min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.avatar-editor-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.avatar-editor-actions .btn-primary { margin-left: auto; }
.avatar-editor-actions button { width: auto; margin: 0; }

/* ---------- new group screen ---------- */
.new-group-screen {
  position: absolute; inset: 0; z-index: 25; display: flex; flex-direction: column;
  background: var(--bg-app); color: var(--text);
}
.new-group-header {
  height: 72px; flex: 0 0 auto; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; position: relative;
}
.new-group-header h2 {
  position: absolute; left: 50%; transform: translateX(-50%);
  margin: 0; font-size: 19px; font-weight: 600; white-space: nowrap;
}
.new-group-back {
  width: 46px; height: 46px; padding: 0; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-panel);
  color: var(--text); display: grid; place-items: center;
}
.new-group-back .icon { width: 22px; height: 22px; }
.new-group-back:hover { background: var(--bg-hover); }
.new-group-create {
  margin-left: auto; width: auto; height: 44px; padding: 0 20px;
  border: 1px solid var(--border); border-radius: 22px;
  background: var(--bg-panel); color: var(--text); font-size: 15px; font-weight: 600;
}
.new-group-create:disabled { opacity: .45; cursor: default; }
.new-group-create:not(:disabled):hover { background: var(--bg-hover); }
.new-group-body { flex: 1; overflow-y: auto; padding: 30px 36px 40px; }
.new-group-form { width: min(780px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.new-group-name-card {
  display: flex; align-items: center; gap: 16px; min-height: 104px;
  padding: 14px 18px; border: 1px solid var(--border); border-radius: 24px;
  background: var(--bg-panel);
}
.new-group-avatar {
  width: 70px; height: 70px; flex: 0 0 auto; padding: 0; overflow: hidden;
  border: 2px solid var(--text-secondary); border-radius: 50%;
  background: transparent; color: var(--text-secondary);
  display: grid; place-items: center; position: relative;
}
.new-group-avatar .icon { width: 28px; height: 28px; }
.new-group-avatar img { width: 100%; height: 100%; object-fit: cover; display: none; }
.new-group-avatar.has-image img { display: block; }
.new-group-avatar.has-image .new-group-camera { display: none; }
.new-group-file { display: none; }
.new-group-name {
  flex: 1; min-width: 0; height: 42px; margin: 0; padding: 0 0 0 14px;
  border: 0; border-left: 2px solid var(--text); border-radius: 0;
  background: transparent; color: var(--text); font-size: 20px;
  box-shadow: none;
}
.new-group-name:focus { outline: none; box-shadow: none; }
.new-group-name::placeholder { color: var(--text-secondary); }
.new-group-add {
  min-height: 66px; display: flex; align-items: center; gap: 14px;
  padding: 0 22px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--bg-panel); color: var(--accent); font-size: 16px; font-weight: 500;
  text-align: left;
}
.new-group-add .icon { width: 24px; height: 24px; flex: 0 0 auto; }
.new-group-add:hover { background: var(--bg-hover); }
.new-group-selected { display: flex; flex-wrap: wrap; gap: 6px; }
.new-group-selected:empty { display: none; }
.new-group-chip {
  display: inline-flex; align-items: center; gap: 7px; max-width: 100%;
  padding: 5px 9px 5px 6px; border-radius: 16px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px;
}
.new-group-chip .avatar { width: 24px; height: 24px; font-size: 9px; }
.new-group-chip span { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-group-chip button { border: 0; background: transparent; color: inherit; padding: 0 2px; font-size: 16px; }
.new-group-picker {
  border: 1px solid var(--border); border-radius: 16px; background: var(--bg-panel);
  padding: 10px;
}
.new-group-search { position: relative; }
.new-group-search .icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: var(--text-secondary); pointer-events: none;
}
.new-group-search input {
  margin: 0; padding: 9px 10px 9px 34px; border-radius: 12px;
  background: var(--bg-input); border-color: transparent;
}
.new-group-results { max-height: 240px; overflow-y: auto; margin-top: 6px; display: grid; gap: 2px; }
.new-group-result {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 9px;
  cursor: pointer;
}
.new-group-result:hover, .new-group-result.selected { background: var(--bg-hover); }
.new-group-result .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.new-group-result .name { font-size: 13.5px; }
.new-group-result .uid { font-size: 11.5px; color: var(--text-secondary); }
.new-group-result .check { color: var(--accent); }
.new-group-hint { margin: 2px 4px; color: var(--text-secondary); font-size: 12px; }
.new-group-screen .error { margin: 0 4px; }
@media (max-width: 760px) {
  .new-group-header { height: 60px; padding: 0 10px; }
  .new-group-header h2 { font-size: 16px; max-width: 55vw; overflow: hidden; text-overflow: ellipsis; }
  .new-group-back { width: 40px; height: 40px; }
  .new-group-create { height: 38px; padding: 0 14px; font-size: 13px; }
  .new-group-body { padding: 20px 12px 30px; }
  .new-group-name-card { min-height: 84px; padding: 12px; border-radius: 18px; }
  .new-group-avatar { width: 56px; height: 56px; }
  .new-group-name { font-size: 17px; }
  .new-group-add { min-height: 58px; border-radius: 16px; font-size: 14px; }
}

/* ---------- service confirm dialog ---------- */
.confirm-modal { z-index: 80; }
.confirm-card { width: min(380px, calc(100vw - 32px)); padding: 20px; }
.confirm-card h2 { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.3; }
.confirm-card p { margin: 10px 0 0; color: var(--text-secondary); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.confirm-actions button { width: auto; margin: 0; min-width: 92px; }
.confirm-actions .btn-ghost {
  border: 1px solid var(--border); background: transparent; color: var(--text-secondary);
}
.confirm-actions .btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.confirm-actions .btn-danger { background: var(--danger); color: var(--text-on-accent); }

/* ---------- service prompt dialog ---------- */
.prompt-modal { z-index: 80; }
.prompt-card { width: min(420px, calc(100vw - 32px)); padding: 20px; }
.prompt-card h2 { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.3; }
.prompt-card p { margin: 8px 0 0; color: var(--text-secondary); font-size: 13px; line-height: 1.4; }
.prompt-card p:empty { display: none; }
.prompt-card input, .prompt-card textarea {
  margin-top: 14px; width: 100%; border-radius: 10px;
  background: var(--bg-panel-2); color: var(--text);
}
.prompt-card textarea { resize: vertical; min-height: 96px; line-height: 1.4; }
.prompt-card input[readonly], .prompt-card textarea[readonly] { color: var(--text-secondary); }
.prompt-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.prompt-actions button { width: auto; margin: 0; min-width: 92px; }
.prompt-actions .btn-ghost { border: 1px solid var(--border); background: transparent; color: var(--text-secondary); }
.prompt-actions .btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- forced password change ---------- */
.password-modal { z-index: 85; }
.password-card { width: min(380px, calc(100vw - 32px)); padding: 20px; }
.password-card h2 { margin: 0; font-size: 18px; }
.password-card > p { margin: 8px 0 0; color: var(--text-secondary); font-size: 13px; line-height: 1.45; }
.password-card .profile-field { margin-top: 14px; }
.password-card .profile-save { margin-top: 16px; height: 42px; }

/* B2B profile details */
.profile-work {
  margin-top: 14px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg-panel-2);
  display: flex; flex-direction: column; gap: 4px;
}
.profile-work-row { font-size: 12px; color: var(--text-secondary); display: flex; gap: 8px; }
.profile-work-row strong { color: var(--text); font-weight: 500; }
.profile-work-row a { color: var(--accent); text-decoration: none; }
.profile-work-row a:hover { text-decoration: underline; }

/* Mobile chat list: no persistent active highlight (Telegram-style) */
@media (max-width: 760px) {
  .room.active { background: transparent; }
  .room.active .room-name,
  .room.active .room-preview,
  .room.active .room-time,
  .room.active .room-meta { color: inherit; }
  .room.active .room-preview,
  .room.active .room-time { opacity: 1; }
  .room.active .badge { background: var(--accent); color: var(--text-on-accent); }
}
