/* СИР Мессенджер — интерфейс уровня Telegram/WhatsApp.
   Без внешних шрифтов и фреймворков: только системные ресурсы. */

:root {
  /* Telegram Light — docs/design/telegram-ui-spec.md §1 */
  --bg: #e4e8ee;
  --panel: #ffffff;
  --panel-2: #f1f3f5;
  --panel-3: #e7e8ec;
  --text: #000000;
  --muted: #707579;
  --line: #e7e8ec;
  --accent: #3390ec;
  --accent-soft: #dbe9fb;
  --mine: #eeffde;
  --bubble: #ffffff;
  --shadow: 0 12px 40px rgba(0, 0, 0, .10);
  --radius: 16px;
  --ok: #4dcd5e;
  --danger: #d1453b;
  --danger-soft: rgba(209, 69, 59, .10);
  --accent-tint: rgba(51, 144, 236, .09);
  --sidebar: 340px;
}

[data-theme="dark"] {
  /* Telegram Dark — bg_chat / bg_primary / bubble_mine / accent */
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #182533;
  --panel-3: #242f3d;
  --text: #f5f5f5;
  --muted: #7f91a4;
  --line: #101921;
  --accent: #5288c1;
  --accent-soft: #24405f;
  --mine: #2b5278;
  --bubble: #182533;
  --shadow: 0 14px 44px rgba(0, 0, 0, .45);
  --ok: #4dcd5e;
  --danger: #e05b5b;
  --danger-soft: rgba(224, 91, 91, .14);
  --accent-tint: rgba(82, 136, 193, .16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
b { font-weight: 600; }
small { color: var(--muted); }
[hidden] { display: none !important; }

/* --- Вход ---------------------------------------------------------------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 12% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 30px 26px;
  box-shadow: var(--shadow);
}
.login-logo {
  width: 54px; height: 54px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: .5px;
  margin-bottom: 16px;
}
.login-card h1 { margin: 0 0 6px; font-size: 24px; }
.login-sub { margin: 0 0 20px; color: var(--muted); }
.login-form { display: grid; gap: 14px; }
.login-form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-form input[type="text"],
.login-form input[type="password"],
.login-form input:not([type]) {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  outline: none;
}
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check-row { display: flex; align-items: center; gap: 8px; color: var(--text) !important; }
.check-row input { width: 16px; height: 16px; accent-color: var(--accent); }
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.btn-primary:hover { filter: brightness(1.05); text-decoration: none; }
.login-hint { margin: 18px 0 0; font-size: 12px; color: var(--muted); }
.alert {
  margin: 0 0 16px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-soft);
  font-size: 13px;
}

/* --- Каркас --------------------------------------------------------------- */

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
  width: var(--sidebar);
  min-width: var(--sidebar);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.brand-mark {
  display: grid; place-items: center;
  min-width: 34px; height: 34px; padding: 0 7px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .4px;
}
.icon {
  display: inline-grid; place-items: center;
  min-width: 36px; height: 36px;
  padding: 0 8px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1;
}
.icon:hover { background: var(--panel-3); }
.icon.only-mobile { display: none; }

.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -4px;
  flex: 0 0 auto;
  pointer-events: none;
}
.send .ic { width: 18px; height: 18px; stroke-width: 2; }
.drop-icon .ic { width: 36px; height: 36px; }

.side-search { padding: 4px 12px 10px; }
.side-search input {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  outline: none;
}
.side-search input:focus { border-color: var(--accent); }

.chat-list { flex: 1; overflow-y: auto; padding: 2px 8px 8px; }
.list-empty { margin: auto; padding: 30px 10px; text-align: center; font-size: 13px; color: var(--muted); }
.chat-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%;
  padding: 10px 10px;
  border: 0; border-radius: 12px;
  background: transparent;
  text-align: left;
  color: var(--text);
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--accent-soft); }
.ci-avatar, .msg-avatar, .avatar {
  position: relative;
  display: grid; place-items: center;
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--panel-3);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}
.msg-avatar { width: 32px; height: 32px; font-size: 11px; }
.avatar { width: 38px; height: 38px; font-size: 13px; }
.presence-dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 11px; height: 11px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--muted);
}
.presence-dot.online { background: var(--ok); }
.ci-main { flex: 1; min-width: 0; }
.ci-top { display: flex; align-items: baseline; gap: 8px; }
.ci-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { flex: 0 0 auto; font-size: 11px; color: var(--muted); }
.ci-bottom { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.ci-preview { flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  flex: 0 0 auto;
  min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-grid; place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}
.pin-mark { font-size: 11px; opacity: .75; }
.pin-mark .ic { width: 13px; height: 13px; }

.side-foot {
  background: var(--panel);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
}
.me {
  display: flex; align-items: center; gap: 10px; min-width: 0; width: 100%;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.me:hover { background: var(--panel-2); }
.me-text { display: grid; min-width: 0; }
.me-text b, .me-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { font-size: 11px; }
.me-gear { margin-left: auto; width: 18px; height: 18px; opacity: .8; flex: none; color: var(--muted); }
/* нижние кнопки перенесены в экран «Настройки» */

.pane { flex: 1; display: flex; min-width: 0; background: var(--bg); }

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.empty-mark {
  width: 64px; height: 64px; margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: 20px;
  background: var(--accent);
  color: #fff; font-weight: 700;
}
.empty h2 { margin: 0 0 6px; color: var(--text); font-size: 20px; }
.empty p { margin: 0; font-size: 13px; }

.chat { position: relative; flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(9px + env(safe-area-inset-top, 0px)) 14px 9px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.chat-title-wrap {
  flex: 1; min-width: 0;
  display: grid; gap: 1px;
  border: 0; background: transparent;
  padding: 2px 4px; border-radius: 8px;
  text-align: left;
}
.chat-title-wrap:hover { background: var(--panel-2); }
.chat-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub .online { color: var(--ok); }
.chat-actions { display: flex; align-items: center; gap: 6px; }
.topic-select {
  max-width: 190px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  outline: none;
}
.pin-count { font-size: 10px; margin-left: 1px; color: var(--muted); }

/* --- Закрепы -------------------------------------------------------------- */

.pins-bar {
  display: flex; gap: 8px;
  padding: 8px 14px;
  overflow-x: auto;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.pin-chip {
  flex: 0 0 auto;
  max-width: 300px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  text-align: left;
  color: var(--text);
  font-size: 12px;
}
.pin-chip:hover { border-color: var(--accent); }
.pin-chip b { display: block; font-size: 11px; color: var(--accent); }
.pin-chip span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Сообщения ------------------------------------------------------------ */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 10px;
  scroll-behavior: smooth;
}
.msg {
  display: flex; align-items: flex-end; gap: 8px;
  margin: 0 0 10px;
  max-width: 100%;
}
.msg .msg-stack { max-width: min(680px, 78%); }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-stack { align-items: flex-end; }
.msg-stack { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.msg-author { font-size: 12px; font-weight: 600; color: var(--accent); padding-left: 4px; }
.msg-bubble {
  position: relative;
  padding: 8px 11px 7px;
  border-radius: 13px;
  background: var(--bubble);
  border: 1px solid var(--line);
  box-shadow: 0 1px 1px rgba(22, 32, 44, .04);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  min-width: 90px;
}
.msg.mine .msg-bubble { background: var(--mine); border-color: transparent; }
.msg-text { white-space: pre-wrap; }
.msg-text .mention { color: var(--accent); font-weight: 600; }
.msg.deleted .msg-text { color: var(--muted); font-style: italic; }
.msg-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}
.msg.edited::after { content: "изм."; font-size: 10px; color: var(--muted); margin-right: 2px; }
.ticks { letter-spacing: -1px; font-size: 12px; color: var(--muted); }
.ticks.read { color: var(--accent); }
.msg-actions {
  align-self: center;
  opacity: .55;
  width: 30px; height: 30px;
  min-width: 30px;
  padding: 0;
  border: 0; border-radius: 50%;
  background: var(--panel);
  color: var(--muted);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .12);
  font-size: 16px;
  line-height: 1;
}
.msg:hover .msg-actions, .msg-actions:focus { opacity: 1; }
.msg-actions:active { opacity: 1; transform: scale(.94); }
.reply-quote {
  display: block; width: 100%;
  margin: 0 0 6px;
  padding: 5px 8px;
  border: 0;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-tint);
  text-align: left;
  font-size: 12px;
}
.reply-quote b { display: block; color: var(--accent); font-size: 11px; }
.reply-quote span { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.forward-label { font-size: 11px; color: var(--accent); margin-bottom: 4px; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction-chip {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 12px;
  line-height: 18px;
}
.reaction-chip.me { border-color: var(--accent); background: var(--accent-soft); }
.system-note { margin: 8px 0; text-align: center; font-size: 12px; color: var(--muted); }

.jump {
  position: absolute; right: 26px; bottom: 92px;
  padding: 8px 13px;
  border: 0; border-radius: 20px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  box-shadow: var(--shadow);
}

.reply-bar {
  display: flex; align-items: center; gap: 10px;
  margin: 0 14px;
  padding: 7px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 8px 8px 0 0;
  background: var(--panel);
}
.reply-info { flex: 1; min-width: 0; }
.reply-info small { display: block; color: var(--accent); font-weight: 600; }
.reply-info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }

.composer {
  display: flex; align-items: flex-end; gap: 9px;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom, 0px));
}
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  resize: none;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.send {
  width: 46px; height: 44px;
  border: 0; border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
}
.send:disabled { opacity: .5; cursor: default; }

/* --- Модальные окна и меню ------------------------------------------------ */

.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(10, 16, 24, .48);
}
.modal-card {
  width: 100%; max-width: 440px;
  max-height: 82dvh;
  overflow: auto;
  padding: 20px;
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { display: grid; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.field { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
.field input[type="text"], .field textarea, .field select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  outline: none;
  color: var(--text);
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.modal-list { display: grid; gap: 2px; max-height: 320px; overflow-y: auto; margin: 4px 0; }
.modal-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 9px;
  border: 0; border-radius: 10px;
  background: transparent;
  text-align: left;
  color: var(--text);
}
.modal-item:hover { background: var(--panel-2); }
.modal-item .mi-main { flex: 1; min-width: 0; }
.modal-item .mi-main b { display: block; font-size: 13.5px; }
.modal-item .mi-main small { display: block; font-size: 11.5px; }
.modal-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.btn {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { border: 0; background: var(--accent); color: #fff; font-weight: 600; }
.btn-danger { border: 0; background: var(--danger); color: #fff; font-weight: 600; }
.btn-ghost { background: transparent; }
.muted { color: var(--muted); }
.section-title { margin: 10px 0 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.role-tag { font-size: 10px; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }

.ctx-menu {
  position: fixed; z-index: 95;
  min-width: 200px;
  max-height: calc(100vh - 16px);
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.ctx-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: 0; border-radius: 8px;
  background: transparent;
  text-align: left;
  color: var(--text);
  font-size: 13px;
}
.ctx-item:hover { background: var(--panel-2); }
.ctx-item.danger { color: var(--danger); }
.ctx-emoji-row { display: flex; gap: 2px; padding: 4px 6px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.ctx-emoji {
  width: 32px; height: 32px;
  border: 0; border-radius: 8px;
  background: transparent;
  font-size: 17px;
}
.ctx-emoji:hover { background: var(--panel-2); }

.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 80;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--panel);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  max-width: 90vw;
}

/* --- Мобильная раскладка --------------------------------------------------- */

@media (max-width: 820px) {
  .sidebar { width: 100%; min-width: 100%; border-right: 0; }
  .pane { display: none; }
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .pane { display: flex; }
  .icon.only-mobile { display: inline-grid; }
  .pane { position: relative; }
  .jump { right: 16px; bottom: 88px; }
  .topic-select { max-width: 130px; }
  .msg .msg-stack { max-width: 82%; }
  .msg-actions { opacity: 1; }
  .messages { padding: 12px 10px 8px; }
  .chat-head { padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px; }
  .composer { padding: 8px 10px calc(12px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* ===== Этап 2: медиа, галерея, поиск, lightbox, офлайн-очередь ============= */

.composer-tool {
  min-width: 40px;
  height: 40px;
  font-size: 18px;
  color: var(--muted);
}
.composer-tool:hover { color: var(--text); }

.attach-strip,
.queue-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  overflow-x: auto;
}
.queue-bar { font-size: 12px; color: var(--muted); }
.queue-bar b { color: var(--text); }
.queue-bar .btn { padding: 5px 10px; font-size: 12px; }

.attach-chip {
  position: relative;
  flex: 0 0 auto;
  width: 88px;
}
.attach-thumb {
  width: 88px; height: 88px;
  display: grid; place-items: center;
  overflow: hidden;
  border-radius: 10px;
  background: var(--panel-3);
  font-size: 26px;
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-name {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-x {
  position: absolute;
  top: -6px; right: -6px;
  width: 22px; height: 22px;
  border: 2px solid var(--panel-2);
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 1;
}

.msg-media {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin: 0 0 5px;
}
.msg-media.single { grid-template-columns: minmax(0, 1fr); }
.msg-media .media-thumb {
  border: 0; padding: 0; background: none;
  border-radius: 10px; overflow: hidden; cursor: zoom-in;
}
.msg-media img {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: cover;
}
.msg-media.single img { max-height: 360px; }
.msg-video {
  width: 100%;
  max-height: 360px;
  border-radius: 10px;
  background: #000;
}
.video-note {
  width: 200px; height: 200px;
  border-radius: 50%;
  object-fit: cover;
  background: #000;
  border: 2px solid var(--line);
}
.msg-audio { width: min(320px, 100%); height: 36px; }
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
}
.file-card:hover { text-decoration: none; background: var(--panel-3); }
.file-icon { font-size: 22px; }
.file-meta { min-width: 0; }
.file-meta b {
  display: block;
  max-width: 240px;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-meta small { display: block; font-size: 11px; }
.ticks.pending { color: var(--muted); }
.ticks.failed { color: var(--danger); font-weight: 700; }
.msg.pending .msg-bubble { opacity: .86; border-style: dashed; }
.msg.pending .msg-actions { display: none; }
.msg.flash .msg-bubble {
  box-shadow: 0 0 0 3px var(--accent);
  transition: box-shadow .2s ease;
}

/* Панель «Медиа / Файлы / Ссылки» */
.panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 40;
  width: 390px;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-tabs {
  display: flex; gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.ptab {
  flex: 1;
  padding: 8px 3px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
}
.ptab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; padding: 10px; }
.panel-empty { padding: 34px 10px; text-align: center; color: var(--muted); font-size: 13px; }
.media-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.media-grid button { border: 0; padding: 0; background: none; border-radius: 7px; overflow: hidden; }
.media-grid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.media-grid .media-icon {
  display: grid; place-items: center;
  aspect-ratio: 1;
  border-radius: 7px;
  background: var(--panel-3);
  font-size: 22px;
}
.file-row, .link-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 9px;
  border-radius: 9px;
}
.file-row:hover, .link-row:hover { background: var(--panel-2); }
.fr-main, .lr-main { flex: 1; min-width: 0; }
.fr-main b, .lr-main b {
  display: block; font-size: 12.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fr-main small, .lr-main small { display: block; font-size: 11px; }
.lr-main b { color: var(--accent); font-weight: 500; }
.link-row .icon, .file-row .icon { font-size: 14px; color: var(--muted); }

/* Полноэкранный просмотрщик */
.lightbox {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 10, 15, .94);
}
.lb-stage {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 56px 40px 78px;
  box-sizing: border-box;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
.lb-stage.dragging { cursor: grabbing; }
.lb-stage img, .lb-stage video {
  max-width: min(92vw, calc(100vw - 80px));
  max-height: min(84vh, calc(100vh - 134px));
  max-height: min(84dvh, calc(100dvh - 134px));
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
}
.lb-stage img {
  user-select: none;
  -webkit-user-drag: none;
}
.lb-nav {
  position: absolute; top: 50%;
  width: 48px; height: 72px;
  transform: translateY(-50%);
  border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, .1);
  color: #fff; font-size: 34px; line-height: 1;
}
.lb-prev { left: 14px; }
.lb-next { right: 14px; }
.lb-top {
  position: absolute; top: 0; left: 0; right: 0;
  z-index: 3;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(rgba(0, 0, 0, .58), transparent);
}
.lb-close {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff; font-size: 18px;
}
.lb-nav, .lb-bar { z-index: 3; }
.lb-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: center; justify-content: center;
  padding: 14px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
}
.lb-bar .btn {
  background: rgba(255, 255, 255, .12);
  border-color: rgba(255, 255, 255, .28);
  color: #fff;
}
.lb-counter { color: #fff; font-size: 12px; }

/* Результаты поиска */
.search-result {
  display: block; width: 100%;
  padding: 9px 10px;
  border: 0; border-radius: 10px;
  background: transparent;
  text-align: left;
  color: var(--text);
}
.search-result:hover { background: var(--panel-2); }
.sr-top { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--muted); }
.sr-chat { font-weight: 600; color: var(--accent); }
.sr-text { margin-top: 2px; font-size: 12.5px; }
.sr-user { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.sr-user .ci-avatar { width: 28px; height: 28px; font-size: 10px; }
.sr-user .mi-main { min-width: 0; }
.sr-user .mi-main b { display: block; font-size: 13px; }
.sr-user .mi-main small { display: block; font-size: 11px; color: var(--muted); }
.search-result mark { background: var(--accent-soft); color: var(--text); border-radius: 3px; padding: 0 2px; }
.search-note { padding: 8px 10px; font-size: 11px; color: var(--muted); }

/* Запись голосового / кружка */
.rec-wrap {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 10px 0;
}
.rec-preview {
  width: 180px; height: 180px;
  border-radius: 50%;
  object-fit: cover;
  background: #000;
  transform: scaleX(-1);
}
.rec-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--danger);
  animation: rec-pulse 1.2s infinite ease-in-out;
}
.rec-time { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

@media (max-width: 820px) {
  .panel { width: 100vw; }
  .composer-tool { min-width: 34px; }
  .lb-stage { max-width: calc(100vw - 96px); }
  .lb-nav { width: 40px; height: 60px; font-size: 28px; }
  .lb-bar .btn { padding: 7px 9px; font-size: 11.5px; }
  .msg-media img, .msg-video { max-height: 260px; }
  .video-note { width: 170px; height: 170px; }
}

/* ===== Этап 2, исправления после живого теста ============================== */

/* Голосовое сообщение */
.voice-player {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 250px;
  max-width: 330px;
  padding: 2px 0;
}
.voice-player audio { display: none; }
.vp-play {
  width: 40px; height: 40px; min-width: 40px;
  border: 0; border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  line-height: 1;
}
.vp-body { flex: 1; min-width: 0; }
.vp-bar {
  position: relative;
  height: 22px;
  display: flex;
  align-items: center;
  cursor: pointer;
}
.vp-bar::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}
.vp-fill {
  position: absolute;
  left: 0;
  height: 4px;
  width: 0;
  border-radius: 2px;
  background: var(--accent);
}
.vp-knob {
  position: absolute;
  left: 0;
  width: 10px; height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bubble);
}
.vp-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: -3px;
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.vp-speed {
  border: 0;
  border-radius: 7px;
  padding: 5px 7px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
}

/* Запись голосового в панели ввода */
.rec-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px 12px;
  background: var(--panel);
}
.rec-dot {
  width: 9px; height: 9px; min-width: 9px;
  border-radius: 50%;
  background: var(--danger);
  animation: rec-pulse 1s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.8); }
}
.rec-wave { flex: 1; min-width: 60px; height: 32px; }
.rec-time {
  min-width: 42px;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Зона Drag & Drop */
.drop-zone {
  position: fixed;
  inset: 0;
  z-index: 92;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 16, 24, .55);
  pointer-events: none;
}
.drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 460px;
  padding: 34px 40px;
  border: 2px dashed var(--accent);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}
.drop-card b { font-size: 16px; }
.drop-card small { font-size: 12px; color: var(--muted); }
.drop-icon { font-size: 40px; line-height: 1; }

@media (max-width: 820px) {
  .voice-player { min-width: 240px; }
  .rec-wave { height: 28px; }
  .drop-card { margin: 0 18px; padding: 26px 22px; }
}


/* ===== Информация о чате, профиль MAX, закрепы ============================= */

.panel-summary {
  padding: 8px 10px 2px;
  font-size: 12.5px;
  color: var(--muted);
}
.panel-settings {
  display: grid;
  gap: 8px;
  padding: 10px;
  margin-bottom: 6px;
  border-radius: 10px;
  background: var(--panel-2);
}
.panel-settings .field input { background: var(--panel); }
.panel-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 9px;
}
.panel-item:hover { background: var(--panel-2); }
.panel-item .ci-avatar { width: 32px; height: 32px; font-size: 11px; }
.panel-item .mi-main { flex: 1; min-width: 0; }
.panel-item .mi-main b { display: block; font-size: 12.5px; }
.panel-item .mi-main small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panel-item .icon { min-width: 28px; height: 28px; padding: 0; }
.panel-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 4px 10px;
}
.panel-actions .btn { padding: 7px 10px; font-size: 12px; }

.max-link-form {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 4px;
}
.max-link-form input,
.max-link-form select {
  flex: 1;
  min-width: 110px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  font-size: 12.5px;
}
.max-code {
  margin: 14px 0 6px;
  padding: 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 30px/1.1 ui-monospace, Consolas, monospace;
  letter-spacing: 8px;
  text-align: center;
}
.pin-row {
  display: grid;
  gap: 2px;
  width: 100%;
  margin-bottom: 5px;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
}
.pin-row:hover { background: var(--panel-3); }
.pin-row-author { font-size: 11px; font-weight: 600; color: var(--accent); }
.pin-row > span:nth-child(2) {
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pin-row small { font-size: 10.5px; color: var(--muted); }

.ctx-item .ic { width: 17px; height: 17px; margin-right: 7px; }
.modal-item .ic { width: 18px; height: 18px; }
.attach-thumb .ic { width: 26px; height: 26px; }
.media-icon .ic { width: 24px; height: 24px; }


.topic-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.topic-bar .topic-select { max-width: 340px; }
@media (max-width: 820px) {
  .topic-bar { padding: 6px 10px; }
  .topic-bar .topic-select { max-width: none; width: 100%; }
}


/* Страница загрузки Android APK / PWA */
.download-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 14px;
  background: var(--bg);
}
.download-card {
  width: min(640px, 100%);
  padding: 26px 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.download-card h1 { margin: 8px 0 4px; font-size: 24px; }
.download-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.download-section h2 { margin: 0 0 8px; font-size: 16px; }
.download-section p { margin: 7px 0; font-size: 13.5px; line-height: 1.5; }
.download-sha {
  display: block;
  padding: 10px;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--muted);
  font: 11px/1.5 ui-monospace, Consolas, monospace;
  overflow-wrap: anywhere;
}
.download-steps { margin: 8px 0 0; padding-left: 20px; font-size: 13px; line-height: 1.55; }
.download-back { margin: 22px 0 0; font-size: 13px; }

/* ===== Мобильные правки и Telegram-панели (2026-12-05) ===================== */

/* Никакой синей заливки при тапе по кнопкам и вкладкам. */
* { -webkit-tap-highlight-color: transparent; }

/* Карточка профиля сотрудника. */
.profile-card { display: grid; justify-items: center; gap: 6px; text-align: center; }
.profile-avatar {
  position: relative;
  width: 84px; height: 84px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 28px; font-weight: 700;
}
.profile-avatar .presence-dot {
  position: absolute; right: 4px; bottom: 6px;
  width: 14px; height: 14px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--muted);
}
.profile-avatar .presence-dot.online { background: var(--ok); }
.profile-card h2 { margin: 6px 0 0; font-size: 19px; }
.profile-sub { font-size: 13px; color: var(--muted); }
.profile-status { font-size: 12px; color: var(--muted); }
.profile-status.online { color: var(--ok); font-weight: 600; }
.profile-rows { display: grid; gap: 8px; width: 100%; margin: 12px 0; text-align: left; }
.profile-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 13px;
}
.profile-row span { color: var(--muted); }
.profile-row a, .profile-row b { font-weight: 600; word-break: break-all; }
.profile-actions { display: flex; gap: 8px; width: 100%; }
.profile-actions .btn { flex: 1; text-align: center; }
.btn-wide { width: 100%; margin-top: 8px; text-align: center; }

/* --- Настройки: полноэкранная карточка --- */
.modal-card.settings-card { max-width: 520px; max-height: 88vh; overflow-y: auto; }
.settings { display: grid; gap: 10px; }
.settings-profile { display: flex; align-items: center; gap: 12px; padding: 2px 0 6px; }
.settings-profile .profile-avatar { width: 58px; height: 58px; font-size: 21px; margin: 0; }
.settings-profile b { font-size: 16px; }
.settings-seg { display: flex; gap: 8px; }
.settings-seg button {
  flex: 1; padding: 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer;
}
.settings-seg button.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 2px; border-bottom: 1px solid var(--line);
  color: var(--text); text-decoration: none; font-size: 13.5px;
}
.settings-row small { color: var(--muted); }
.settings-row:last-of-type { border-bottom: 0; }
.settings-danger { margin-top: 14px; }
.settings-card .btn-wide { margin-top: 4px; }
@media (max-width: 768px) {
  .modal-card.settings-card { max-width: 100%; max-height: 92vh; }
}

/* Нижняя шторка (Bottom Sheet) для скрепки. */
.modal.sheet-mode { align-items: flex-end; justify-content: center; padding: 0; }
.modal-card.sheet {
  width: 100%; max-width: 560px;
  max-height: 88dvh;
  border-radius: 20px 20px 0 0;
  padding: 8px 12px calc(16px + env(safe-area-inset-bottom, 0px));
  animation: sheet-up .24s cubic-bezier(.2, .9, .3, 1);
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grabber { width: 42px; height: 4px; margin: 6px auto 10px; border-radius: 2px; background: var(--line); }
.sheet-title { margin: 0 0 8px; font-size: 15px; text-align: center; }
.sheet-list { display: grid; gap: 2px; }
.sheet-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 12px 10px;
  border: 0; border-radius: 14px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.sheet-item:hover, .sheet-item:active { background: var(--panel-2); }
.sheet-ico {
  width: 46px; height: 46px; min-width: 46px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 20px;
}
.sheet-item .mi-main b { display: block; font-size: 14.5px; }
.sheet-item .mi-main small { display: block; font-size: 12px; color: var(--muted); }
.msg-avatar[data-profile], .msg-author[data-profile] { cursor: pointer; }
.composer-tool.note-mode { color: var(--accent); }

@media (max-width: 768px) {
  .modal-card.sheet { max-width: 100%; }
  /* Голосовое сообщение не обрезается справа на телефоне. */
  .voice-player {
    width: 100%;
    max-width: calc(100vw - 110px);
    min-width: 210px;
    box-sizing: border-box;
  }
  /* Фото в просмотрщике строго по центру, стрелки скрыты (листание свайпом). */
  .lb-stage {
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%; margin: 0 auto;
    padding: 52px 8px 72px;
  }
  .lb-stage img, .lb-stage video { margin: 0 auto; max-width: calc(100vw - 16px); }
  .lb-nav { display: none !important; }
}
/* --- Telegram-полировка: вкладки, drawer, аватары, альбомы, выделение ------- */

.chat { position: relative; }

/* Вкладки-папки над списком чатов */
.chat-tabs {
  display: flex; gap: 2px;
  padding: 0 8px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}
.chat-tabs::-webkit-scrollbar { display: none; }
.ctab {
  position: relative;
  flex: 0 0 auto;
  padding: 9px 10px 10px;
  border: 0; border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px; font-weight: 600;
  white-space: nowrap;
}
.ctab:hover { color: var(--text); }
.ctab.active { color: var(--accent); }
.ctab.active::after {
  content: ''; position: absolute; left: 10px; right: 10px; bottom: 0;
  height: 2.5px; border-radius: 2px; background: var(--accent);
}
.ctab-count { margin-left: 5px; font-size: 10.5px; color: var(--muted); }
.ctab-count:empty { display: none; }
.ctab.active .ctab-count { color: var(--accent); }

/* Палитра аватарок по ID (Telegram) */
.ci-avatar.av-0, .msg-avatar.av-0, .avatar.av-0 { background: #e17076; color: #fff; }
.ci-avatar.av-1, .msg-avatar.av-1, .avatar.av-1 { background: #7bc862; color: #fff; }
.ci-avatar.av-2, .msg-avatar.av-2, .avatar.av-2 { background: #e5ca77; color: #3a3120; }
.ci-avatar.av-3, .msg-avatar.av-3, .avatar.av-3 { background: #65aadd; color: #fff; }
.ci-avatar.av-4, .msg-avatar.av-4, .avatar.av-4 { background: #a695e7; color: #fff; }
.ci-avatar.av-5, .msg-avatar.av-5, .avatar.av-5 { background: #ee7aae; color: #fff; }
.ci-avatar.av-6, .msg-avatar.av-6, .avatar.av-6 { background: #6ec9cb; color: #08343a; }
.ci-avatar.av-7, .msg-avatar.av-7, .avatar.av-7 { background: #faa774; color: #4a2410; }
.ci-avatar.av-8, .msg-avatar.av-8, .avatar.av-8 { background: #5fbe84; color: #fff; }
.ci-avatar.av-9, .msg-avatar.av-9, .avatar.av-9 { background: #b58ae0; color: #fff; }
.ci-avatar.av-10, .msg-avatar.av-10, .avatar.av-10 { background: #d9776b; color: #fff; }
.ci-avatar.av-11, .msg-avatar.av-11, .avatar.av-11 { background: #4fa8c7; color: #fff; }

/* «Избранное» — синий круг с закладкой */
.ci-avatar.fav { background: var(--accent) !important; color: #fff; }
.ci-avatar.fav .ic { width: 21px; height: 21px; stroke-width: 2; }

/* Выдвижное меню */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 60; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: min(320px, 84vw);
  display: flex; flex-direction: column;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 61;
  overflow-y: auto;
}
.drawer-head {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 16px; margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.drawer-head .avatar { width: 52px; height: 52px; font-size: 16px; }
.drawer-head b { display: block; font-size: 14px; }
.drawer-head small { color: var(--muted); font-size: 12px; }
.drawer-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 10px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 13.5px; text-align: left;
}
.drawer-item:hover { background: var(--panel-2); }
.drawer-item b { color: var(--muted); font-weight: 600; font-size: 12px; }
.drawer-item .ic { color: var(--muted); }

/* Плашка закрепа в шапке чата */
.pins-bar {
  display: flex; align-items: center; gap: 8px;
  min-height: 46px; max-height: 48px;
  padding: 0 12px;
  overflow: hidden;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.pin-chip {
  flex: 1; min-width: 0;
  padding: 6px 0 6px 12px;
  border: 0; border-left: 3px solid var(--accent);
  background: transparent;
  text-align: left;
  color: var(--text);
}
.pin-chip b {
  display: block; font-size: 10.5px; color: var(--accent);
  text-transform: uppercase; letter-spacing: .3px;
}
.pin-chip span {
  display: block; font-size: 12.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pin-more { flex: 0 0 auto; font-size: 11px; color: var(--muted); }

/* Группировка пузырей */
.msg.same-next { margin-bottom: 2px; }
.msg.same-prev .msg-bubble { border-top-left-radius: 6px; }
.msg.mine.same-prev .msg-bubble { border-top-left-radius: 13px; border-top-right-radius: 6px; }
.msg.same-next .msg-bubble { border-bottom-left-radius: 6px; }
.msg.mine.same-next .msg-bubble { border-bottom-left-radius: 13px; border-bottom-right-radius: 6px; }
.msg.same-next .msg-foot { margin-top: 1px; }
.ticks.read { color: #64b5ef; }

/* Коллаж-альбомы */
.msg-media.collage {
  display: grid; gap: 3px;
  max-width: 420px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border-radius: 10px;
}
.msg-media.collage.count-3 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.msg-media.collage.count-3 .media-thumb:first-child { grid-row: span 2; }
.msg-media.collage .media-thumb {
  position: relative;
  width: 100%; aspect-ratio: 1 / 1;
  padding: 0; border: 0; overflow: hidden;
  border-radius: 6px; background: var(--panel-3);
}
.msg-media.collage .media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.msg-media.collage .media-thumb.more::after {
  content: attr(data-more);
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .48);
  color: #fff; font-size: 18px; font-weight: 700;
}

/* Панель стикеров и GIF */
.sticker-panel {
  position: absolute;
  right: 12px; bottom: 80px;
  width: min(430px, 92%);
  max-height: 330px;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 25;
  overflow: hidden;
}
.sticker-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.stab {
  padding: 6px 12px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 600;
}
.stab.active { background: var(--accent-soft); color: var(--accent); }
.sticker-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px; padding: 10px; overflow-y: auto;
}
.sticker-grid.gifs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.sticker-item {
  padding: 4px; border: 0; border-radius: 10px;
  background: transparent;
}
.sticker-item:hover { background: var(--panel-2); }
.sticker-item img { display: block; width: 100%; height: auto; }

/* Режим выделения сообщений */
.select-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
.select-bar b { font-size: 13px; }
.sel-actions { margin-left: auto; display: flex; gap: 2px; }
.select-check {
  display: none;
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  place-items: center;
  color: transparent;
  font-size: 12px; font-weight: 700;
}
.select-mode .msg .select-check { display: grid; }
.select-mode .msg { cursor: pointer; }
.msg.selected .msg-bubble { outline: 2px solid var(--accent); outline-offset: -2px; }
.msg.selected .select-check { border-color: var(--accent); background: var(--accent); color: #fff; }

@media (max-width: 760px) {
  .chat-tabs { padding: 0 4px; }
  .sticker-panel { right: 8px; left: 8px; width: auto; bottom: 74px; }
  .msg-media.collage { max-width: 100%; }
}

/* Аватарки-картинки и выбор иконки темы */
.ci-avatar img, .msg-avatar img, .avatar img, .profile-avatar img {
  width: 100%; height: 100%;
  -o-object-fit: cover;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.topic-icons {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 4px 0 8px;
}
.topic-icon {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 18px;
  line-height: 1;
}
.topic-icon.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.settings-profile .btn { margin-top: 6px; }
