* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a202c;
  --panel: #2d3748;
  --panel-2: #4a5568;
  --accent: #667eea;
  --text: #e2e8f0;
  --muted: #a0aec0;
  --danger: #fc8181;
  --success: #48bb78;
  --warning: #ecc94b;

  --msg-font-size: 16px;
  --img-max-size: 320px;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
  position: relative;
}

/* ---------- Авторизация ---------- */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #667eea, #764ba2);
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
}
.auth-card {
  background: #fff; color: #2d3748;
  padding: 32px; border-radius: 16px;
  width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.auth-card h1 { text-align: center; margin-bottom: 24px; }
.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
  flex: 1; padding: 10px; border: none;
  background: #edf2f7; color: #4a5568;
  border-radius: 8px; cursor: pointer; font-weight: 600;
}
.tab.active { background: #667eea; color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input[type=text],
.auth-form input[type=password] {
  padding: 12px; border: 1px solid #cbd5e0; border-radius: 8px;
  font-size: 16px; outline: none;
  width: 100%;
}
.auth-form input:focus { border-color: #667eea; }
.auth-form button {
  padding: 12px; background: #667eea; color: #fff; border: none;
  border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.auth-form button:hover { background: #5568d3; }
.color-label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.color-label input[type=color] {
  width: 40px; height: 30px; border: none; background: none; cursor: pointer;
}
.error { color: #e53e3e; margin-top: 12px; font-size: 14px; text-align: center; min-height: 20px; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--panel);
  display: flex; 
  flex-direction: column;
  padding: 16px; 
  gap: 8px;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  z-index: 2;
}

.sidebar__me {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; background: var(--panel-2);
  border-radius: 12px;
  flex-shrink: 0;
}

.sidebar__me-info {
  display: flex; flex-direction: column; gap: 2px;
  flex: 1; min-width: 0;
}
.sidebar__me-name {
  font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar__me-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--muted);
}
.sidebar__me input[type=color] {
  width: 30px; height: 30px;
  border: none; background: none; cursor: pointer; flex-shrink: 0;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.avatar.sm {
  width: 30px;
  height: 30px;
  font-size: 13px;
}

.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  transition: background .3s;
}
.conn-dot.online   { background: var(--success); box-shadow: 0 0 6px var(--success); }
.conn-dot.connecting { background: var(--warning); animation: pulse 1s infinite; }
.conn-dot.offline  { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* ★ Зона прокрутки для списков пользователей */
.sidebar-scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: #4a5568 transparent;
}
.sidebar-scroll-area::-webkit-scrollbar { width: 6px; }
.sidebar-scroll-area::-webkit-scrollbar-thumb { background: #4a5568; border-radius: 4px; }

.sidebar__title {
  font-size: 12px; text-transform: uppercase;
  color: var(--muted); margin-top: 12px; margin-bottom: 4px; 
  letter-spacing: .5px;
  padding: 0 4px;
  flex-shrink: 0;
}

.logout-btn {
  margin-top: auto;
  padding: 10px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--panel-2); border-radius: 8px; cursor: pointer;
  font-size: 14px;
  touch-action: manipulation;
  flex-shrink: 0;
}
.logout-btn:hover { color: var(--danger); border-color: var(--danger); }

.admin-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #d69e2e, #b7791f);
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  border-radius: 10px;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 2px 8px rgba(214, 158, 46, .3);
  flex-shrink: 0;
}
.admin-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(214, 158, 46, .5);
}
.admin-link.hidden { display: none; }

.room-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  background: transparent; color: var(--text);
  border: none; border-radius: 10px; cursor: pointer;
  text-align: left; font-size: 15px;
  transition: background .15s;
  width: 100%;
  touch-action: manipulation;
  flex-shrink: 0;
}
.room-btn:hover, .room-btn.active { background: var(--panel-2); }
.room-btn__label { flex: 1; }
.room-btn__badge {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.users { list-style: none; }
.users li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; cursor: pointer;
  font-size: 14px; transition: background .15s;
  position: relative;
  touch-action: manipulation;
}
.users li:hover { background: var(--panel-2); }
.users li.active { background: var(--panel-2); }

.users li.unread {
  animation: blink 1.2s ease infinite alternate;
}
@keyframes blink {
  from { background: rgba(252, 129, 129, .10); }
  to   { background: rgba(252, 129, 129, .35); }
}

.users li .name {
  flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.users li .badge {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #718096; flex-shrink: 0;
}
.dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot.offline { background: #4a5568; box-shadow: none; }

.users--recent li {
  opacity: .75;
  transition: opacity .15s, background .15s;
}
.users--recent li:hover {
  opacity: 1;
}

.users--recent .last-seen {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.users--recent .name-block {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}
.users--recent .name {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Chat ---------- */
.chat {
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: rgba(26, 32, 44, 0.4);
}

body.has-bg .chat {
  background: transparent;
}

.chat__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: var(--panel);
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
  min-height: 60px;
  gap: 10px;
  position: relative;
  z-index: 10;
}
.chat__header-left {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
  flex: 1;
}
.chat__header h2 {
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat__subtitle {
  font-size: 12px;
  color: var(--muted);
  min-height: 14px;
  font-style: italic;
  transition: color .2s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat__subtitle.typing { color: var(--accent); }

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 22px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
.mobile-menu-btn:hover { background: var(--panel-2); }

.clear-btn {
  background: transparent; border: 1px solid var(--panel-2);
  color: var(--muted); padding: 6px 12px;
  border-radius: 8px; cursor: pointer; font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  touch-action: manipulation;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.clear-btn:hover { color: var(--danger); border-color: var(--danger); }

#fxCanvas {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  display: none;
}

/* ---------- Бегущая строка ---------- */
.ticker-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(0,0,0,.15);
  transition: background .2s, color .2s;
}
.ticker-bar.hidden { display: none; }

.ticker-bar__icon {
  font-size: 16px;
  flex-shrink: 0;
  animation: pulse 2s infinite;
}

.ticker-bar__viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  height: 20px;
}

.ticker-bar__text {
  position: absolute;
  white-space: nowrap;
  top: 0;
  left: 0;
  will-change: transform;
  transform: translateX(0);
}

/* ---------- Плашка закреплённого сообщения ---------- */
.pinned-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(90deg, rgba(214, 158, 46, .2), rgba(214, 158, 46, .08));
  border-bottom: 1px solid rgba(214, 158, 46, .3);
  flex-shrink: 0;
  animation: slideDown .2s ease;
  cursor: pointer;
  user-select: none;
  transition: background .15s;
}
.pinned-bar:hover {
  background: linear-gradient(90deg, rgba(214, 158, 46, .3), rgba(214, 158, 46, .12));
}
.pinned-bar__icon { font-size: 18px; flex-shrink: 0; }
.pinned-bar__body { flex: 1; min-width: 0; }
.pinned-bar__author {
  font-size: 11px; font-weight: 700; color: #d69e2e; margin-bottom: 2px;
}
.pinned-bar__text {
  font-size: 13px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.pinned-bar__image {
  width: 40px; height: 40px; object-fit: cover;
  border-radius: 6px; flex-shrink: 0;
  border: 1px solid rgba(214, 158, 46, .4);
  transition: transform .15s, border-color .15s;
}
.pinned-bar:hover .pinned-bar__image {
  transform: scale(1.05);
  border-color: rgba(214, 158, 46, .8);
}
.pinned-bar__image.hidden { display: none; }

.pinned-bar__close {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 16px;
  width: 30px; height: 30px; border-radius: 6px; flex-shrink: 0;
  transition: background .15s, color .15s;
}
.pinned-bar__close:hover { background: rgba(0,0,0,.2); color: var(--danger); }
.pinned-bar.hidden { display: none; }

/* ---------- Сообщения ---------- */
.messages-wrapper {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.pm-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.scroll-down-btn {
  position: absolute;
  bottom: 20px;
  right: 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, opacity .2s, visibility .2s;
  z-index: 5;
  touch-action: manipulation;
}
.scroll-down-btn:hover { transform: translateY(-2px) scale(1.05); }
.scroll-down-btn.hidden { 
  opacity: 0; 
  visibility: hidden; 
  transform: translateY(10px); 
}

.date-divider {
  align-self: center;
  background: rgba(160, 174, 192, .15);
  color: var(--muted);
  font-size: 12px;
  padding: 4px 14px;
  border-radius: 12px;
  margin: 8px 0;
  font-weight: 500;
}

.msg {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  width: fit-content;
  max-width: 75%;
  position: relative;
  gap: 8px;
  animation: appear .2s ease;
}
@keyframes appear {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg__body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  width: max-content;
  max-width: 100%;
  cursor: pointer;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
  position: relative;
}

.msg--me {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg--other {
  align-self: flex-start;
}

.msg--me .msg__body {
  background: var(--accent);
  color: #fff;
}

.pm-messages .msg { max-width: 85%; }

.msg__author {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
  width: 100%;
}

.msg__text {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  width: 100%;
  font-size: var(--msg-font-size, 16px);
  line-height: 1.45;
}

.msg__time {
  font-size: 11px;
  opacity: .6;
  margin-top: 4px;
  align-self: flex-end;
  text-align: right;
  width: 100%;
}

.msg__img {
  max-width: var(--img-max-size, 320px);
  max-height: var(--img-max-size, 320px);
  width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  margin-top: 6px;
  cursor: pointer;
  display: block;
  background: rgba(0,0,0,.15);
  transition: transform .15s;
}
.msg__img:hover { transform: scale(1.02); }

/* ---------- Файлы в сообщениях ---------- */
.msg__file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, .22);
  border-radius: 10px;
  margin-top: 6px;
  text-decoration: none;
  color: inherit;
  max-width: 340px;
  transition: background .15s, transform .1s;
  touch-action: manipulation;
}
.msg--me .msg__file { background: rgba(0, 0, 0, .28); }
.msg__file:hover { background: rgba(0, 0, 0, .35); }
.msg__file:active { transform: scale(.98); }

.msg__file-icon {
  font-size: 32px;
  line-height: 1;
  flex-shrink: 0;
}

.msg__file-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.msg__file-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg__file-size {
  font-size: 11px;
  opacity: .7;
}

.view-msg__file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, .2);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  margin-top: 4px;
  font-size: 13px;
  max-width: 100%;
  word-break: break-all;
}
.view-msg__file:hover { background: rgba(0, 0, 0, .3); }
.view-msg__file-icon { font-size: 22px; flex-shrink: 0; }

@media (max-width: 480px) {
  .msg__file { max-width: 100%; padding: 8px 10px; }
  .msg__file-icon { font-size: 28px; }
  .msg__file-name { font-size: 13px; }
}

/* ---------- Форма ---------- */
.msg-form, .pm-form {
  display: flex; gap: 8px; padding: 12px 16px;
  background: var(--panel); border-top: 1px solid #2d3748;
  flex-shrink: 0;
  align-items: flex-end;
  z-index: 2;
}
.msg-form textarea,
.pm-form textarea {
  flex: 1;
  padding: 11px 14px;
  background: var(--panel-2); border: none;
  border-radius: 10px; color: var(--text);
  font-size: 16px;
  outline: none;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
  min-width: 0;
}
.msg-form textarea::placeholder,
.pm-form textarea::placeholder { color: var(--muted); }

.icon-btn {
  background: transparent; border: none; cursor: pointer;
  font-size: 22px; padding: 6px 8px; color: var(--text);
  display: flex; align-items: center;
  border-radius: 8px;
  transition: background .15s;
  touch-action: manipulation;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--panel-2); }
.send-btn {
  padding: 10px 20px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 10px;
  font-size: 18px; cursor: pointer;
  transition: background .15s, transform .1s;
  align-self: flex-end;
  touch-action: manipulation;
  flex-shrink: 0;
}
.send-btn:hover { background: #5568d3; }
.send-btn:active { transform: scale(.96); }

/* ---------- Эмодзи ---------- */
.emoji-picker {
  position: absolute; bottom: 70px; left: 16px;
  background: var(--panel); border-radius: 12px;
  padding: 10px; width: 340px;
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 4px; max-height: 220px; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); z-index: 20;
  border: 1px solid var(--panel-2);
}
.emoji-picker span {
  font-size: 26px; cursor: pointer; text-align: center;
  padding: 4px; border-radius: 6px;
  transition: background .1s;
  touch-action: manipulation;
}
.emoji-picker span:hover { background: var(--panel-2); }

/* ---------- Модальное окно PM ---------- */
.pm-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn .15s ease;
  padding: 12px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.pm-window {
  width: 520px;
  max-width: 100%;
  height: 640px;
  max-height: 100%;
  background: var(--bg);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 80px rgba(0,0,0,.6);
  border: 1px solid var(--panel-2);
  animation: slideUp .2s ease;
  position: relative;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.pm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 60px 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
  min-height: 60px;
}

.pm-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.pm-header-titles {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  overflow: hidden;
}

.pm-header-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pm-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.pm-header h3 {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.pm-typing {
  font-size: 12px;
  color: var(--accent);
  font-style: italic;
  animation: pulse 1.5s infinite;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pm-header .clear-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.pm-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
  z-index: 5;
  touch-action: manipulation;
}
.pm-close:hover { background: var(--panel-2); color: var(--danger); }

/* ---------- Плашка цитаты над формой ---------- */
.reply-preview {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-top: 1px solid #2d3748;
  animation: slideDown .15s ease;
}
@keyframes slideDown {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
.reply-preview__bar {
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}
.reply-preview__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.reply-preview__author {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-preview__text {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-preview__close {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  width: 32px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: background .15s, color .15s;
  touch-action: manipulation;
}
.reply-preview__close:hover { background: var(--panel-2); color: var(--danger); }

/* ★ Превью вставленного изображения */
.paste-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-top: 1px solid #2d3748;
  animation: slideDown .15s ease;
  flex-shrink: 0;
}
.paste-preview.hidden { display: none; }

.paste-preview img {
  max-height: 60px;
  max-width: 150px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--panel-2);
}

.paste-preview__close {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 18px;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  margin-left: auto;
}
.paste-preview__close:hover { background: rgba(252, 129, 129, .15); }

@media (max-width: 768px) {
  .paste-preview img { max-height: 50px; max-width: 100px; }
}

/* ---------- Цитата внутри сообщения ---------- */
.msg__reply {
  display: flex;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: 8px;
  background: rgba(0,0,0,.18);
  cursor: pointer;
  transition: background .15s;
  max-width: 100%;
}
.msg__reply:hover { background: rgba(0,0,0,.28); }
.msg--me .msg__reply { background: rgba(0,0,0,.20); }
.msg--me .msg__reply:hover { background: rgba(0,0,0,.30); }

.msg__reply-bar {
  width: 3px;
  background: #fff;
  border-radius: 2px;
  opacity: .7;
  flex-shrink: 0;
}
.msg--other .msg__reply-bar { background: var(--accent); }

.msg__reply-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.msg__reply-author {
  font-size: 11px;
  font-weight: 700;
  opacity: .9;
}
.msg__reply-text {
  font-size: 13px;
  opacity: .8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes highlight {
  0%   { background-color: rgba(102, 126, 234, .6); }
  70%  { background-color: rgba(102, 126, 234, .3); }
  100% { background-color: transparent; }
}
.msg--highlight .msg__body { animation: highlight 2s ease; }

.msg--selected .msg__body {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Просмотр от имени админа ---------- */
.admin-view-back {
  background: transparent;
  border: 1px solid var(--panel-2);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
  touch-action: manipulation;
}
.admin-view-back:hover { background: var(--panel-2); }
.admin-view-back.hidden { display: none; }

.admin-view-badge {
  font-size: 11px;
  color: var(--warning);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(236, 201, 75, .15);
  white-space: nowrap;
  flex-shrink: 0;
}

.peer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  overflow-y: auto;
  height: 100%;
}
.peer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panel-2);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  touch-action: manipulation;
}
.peer-item:hover {
  background: #5a6478;
  transform: translateX(2px);
}
.peer-item__info { flex: 1; min-width: 0; }
.peer-item__name {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.peer-item__count {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.peer-item__arrow {
  color: var(--muted);
  font-size: 20px;
  flex-shrink: 0;
}

.view-msg {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}
.view-msg--left {
  align-self: flex-start;
  background: var(--panel-2);
  color: var(--text);
}
.view-msg--right {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}
.view-msg__author {
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 3px;
  opacity: .85;
}
.view-msg__time {
  font-size: 10px;
  opacity: .6;
  margin-top: 3px;
  display: block;
  text-align: right;
}
.view-msg__image {
  max-width: 220px;
  max-height: 220px;
  border-radius: 6px;
  margin-top: 4px;
  display: block;
  cursor: pointer;
}

/* ---------- Все пользователи ---------- */
.all-users-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-2);
  flex-shrink: 0;
}
.all-users-search input {
  width: 100%;
  padding: 10px 14px;
  background: var(--panel-2);
  border: none;
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  font-family: inherit;
}
.all-users-search input:focus {
  box-shadow: 0 0 0 2px var(--accent);
}

.all-users-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}

.all-user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  touch-action: manipulation;
}
.all-user-item:hover {
  background: var(--panel-2);
  transform: translateX(2px);
}
.all-user-item__info { flex: 1; min-width: 0; }
.all-user-item__name {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.all-user-item__status {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.all-user-item__status--online {
  color: var(--success);
  font-weight: 600;
}
.all-user-item__arrow {
  color: var(--muted);
  font-size: 20px;
  flex-shrink: 0;
}
.all-users-empty {
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Лайтбокс ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  cursor: zoom-out;
  padding: 16px;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.lightbox.hidden { display: none; }

/* ---------- Скроллбар ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #4a5568; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #718096; }

/* =====================================================
   Кнопки админа/модератора внутри сообщений
   ===================================================== */
.msg__admin-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
  background: rgba(0,0,0,.5);
  border-radius: 6px;
  padding: 2px;
  z-index: 2;
}
.msg:hover .msg__admin-actions,
.msg--selected .msg__admin-actions {
  opacity: 1;
}

.msg--me .msg__admin-actions {
  right: auto;
  left: 4px;
}

.msg__admin-btn {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  padding: 0;
  line-height: 1;
  font-family: inherit;
  touch-action: manipulation;
}
.msg__admin-btn:hover {
  background: rgba(255,255,255,.2);
}
.msg__admin-btn[data-del-msg]:hover {
  background: rgba(252, 129, 129, .4);
}

@media (hover: none) {
  .msg__admin-actions { opacity: .75; }
  .msg__admin-btn { width: 30px; height: 30px; font-size: 16px; }
}

/* =====================================================
   АДАПТИВ
   ===================================================== */

@media (max-width: 1024px) {
  .app { grid-template-columns: 240px 1fr; }
  .msg { max-width: 80%; }
  .view-msg { max-width: 85%; }
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    position: relative;
    z-index: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,.5);
  }
  body.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.mobile-sidebar-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 55;
    animation: fadeIn .2s ease;
    pointer-events: none;
  }

  .mobile-menu-btn { display: inline-flex; }

  .chat__header { padding: 10px 12px; }
  .chat__header h2 { font-size: 16px; }

  .msg { max-width: 85%; }
  .pm-messages .msg { max-width: 90%; }

  .messages { padding: 14px 12px; gap: 10px; }
  .pm-messages { padding: 12px 10px; }

  .msg-form, .pm-form { padding: 10px 12px; gap: 6px; }
  .msg-form textarea, .pm-form textarea { padding: 10px 12px; }

  .icon-btn { font-size: 20px; padding: 5px 6px; }
  .send-btn { padding: 9px 16px; font-size: 17px; }

  .emoji-picker {
    left: 12px;
    right: 12px;
    bottom: 62px;
    width: auto;
    grid-template-columns: repeat(7, 1fr);
    max-height: 180px;
  }
  .emoji-picker span { font-size: 24px; }

  .pm-modal { padding: 0; }
  .pm-window {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }

  .pm-header { padding: 10px 56px 10px 14px; }
  .pm-header h3 { font-size: 15px; max-width: 160px; }
  .pm-close { top: 10px; right: 10px; }

  .all-users-search { padding: 10px 12px; }
  .all-users-list { padding: 8px; }

  .peer-list { padding: 12px; }

  .ticker-bar { font-size: 13px; padding: 6px 12px; }
  .pinned-bar { padding: 8px 12px; }
  .pinned-bar__text { font-size: 12px; }
  .pinned-bar__image { width: 34px; height: 34px; }

  .scroll-down-btn { bottom: 14px; right: 14px; padding: 7px 14px; font-size: 12px; }

  .view-msg { max-width: 85%; font-size: 13px; }
  .view-msg__image { max-width: 180px; max-height: 180px; }

  .chat__header .clear-btn {
    height: 34px;
    width: 34px;
    padding: 0;
    font-size: 14px;
    margin-right: 4px;
  }
}

@media (max-width: 480px) {
  .auth-card {
    padding: 24px 20px;
    border-radius: 12px;
  }
  .auth-card h1 { font-size: 22px; margin-bottom: 20px; }

  .sidebar { width: 280px; }
  .sidebar__me { padding: 10px; gap: 8px; }
  .sidebar__me-name { font-size: 14px; }

  .msg { max-width: calc(100% - 8px); }
  .pm-messages .msg { max-width: calc(100% - 8px); }

  .chat__header { min-height: 54px; padding: 8px 10px; }
  .chat__header h2 { font-size: 15px; }

  .chat__header .clear-btn {
    padding: 0;
    font-size: 14px;
    width: 32px;
    height: 32px;
  }

  .mobile-menu-btn { width: 36px; height: 36px; font-size: 20px; }

  .msg-form, .pm-form { padding: 8px 10px; gap: 4px; }
  .msg-form textarea, .pm-form textarea { padding: 9px 11px; font-size: 16px; }
  .icon-btn { font-size: 19px; padding: 4px 5px; }
  .send-btn { padding: 8px 14px; font-size: 16px; }

  .emoji-picker {
    grid-template-columns: repeat(6, 1fr);
    gap: 2px;
    padding: 8px;
  }
  .emoji-picker span { font-size: 22px; padding: 3px; }

  .pm-header h3 { max-width: 120px; font-size: 14px; }
  .pm-typing { font-size: 11px; }

  .ticker-bar { font-size: 12px; padding: 5px 10px; }
  .ticker-bar__icon { font-size: 14px; }

  .view-msg { max-width: 92%; }
  .view-msg__image { max-width: 140px; max-height: 140px; }

  .scroll-down-btn { bottom: 10px; right: 10px; padding: 6px 12px; font-size: 11px; }

  .all-user-item { padding: 9px 10px; }
  .all-user-item__name { font-size: 14px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .chat__header { min-height: 46px; padding: 6px 10px; }
  .chat__header h2 { font-size: 14px; }
  .msg-form, .pm-form { padding: 6px 10px; }
  .emoji-picker { max-height: 120px; }
  .sidebar { padding: 10px; }
}

@media (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
  .app { grid-template-columns: 240px 1fr; }
}

body.admin-body {
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-form--wide { max-width: 100%; }

/* ★ Три колонки: настройки + настройки + предпросмотр */
.appearance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 24px;
  align-items: start;
}
.appearance-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.appearance-preview-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 16px;
}
.appearance-section-title {
  font-size: 13px;
  font-weight: 700;
  color: #cbd5e0;
  padding: 6px 0;
  border-bottom: 1px solid #4a5568;
  margin-top: 4px;
  letter-spacing: 0.3px;
}
.effect-options {
  padding: 0;
}

@media (max-width: 1200px) {
  .appearance-grid { grid-template-columns: 1fr 1fr; }
  .appearance-preview-col {
    grid-column: 1 / -1;
    position: static;
  }
}

@media (max-width: 768px) {
  .appearance-grid { grid-template-columns: 1fr; }
  .appearance-preview-col { grid-column: auto; }
}

/* =====================================================
   ★ ПАГИНАЦИЯ И ПОИСК В ОБЩЕМ ЧАТЕ
   ===================================================== */

.header-search-btn {
  background: transparent;
  border: 1px solid var(--panel-2);
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s, border-color .15s;
  touch-action: manipulation;
}
.header-search-btn:hover {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--accent);
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-2);
  animation: slideDown .15s ease;
  flex-shrink: 0;
}
.search-bar.hidden { display: none; }

.search-bar input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: var(--panel-2);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.search-bar input:focus {
  box-shadow: 0 0 0 2px var(--accent);
}
.search-bar input::placeholder { color: var(--muted); }

.search-counter {
  font-size: 12px;
  color: var(--muted);
  min-width: 60px;
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
}

.search-nav-btn {
  background: transparent;
  border: 1px solid var(--panel-2);
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s;
  touch-action: manipulation;
}
.search-nav-btn:hover:not(:disabled) {
  background: var(--panel-2);
}
.search-nav-btn:disabled {
  opacity: .35;
  cursor: default;
}

.load-older-indicator {
  position: sticky;
  top: 0;
  z-index: 4;
  align-self: center;
  background: rgba(102, 126, 234, .9);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 12px;
  margin: 8px auto 0;
  display: inline-block;
  pointer-events: none;
  animation: pulse 1.2s infinite;
}
.load-older-indicator.hidden { display: none; }

@media (max-width: 768px) {
  .search-bar { padding: 6px 12px; gap: 6px; }
  .search-bar input { padding: 7px 10px; font-size: 13px; }
  .search-counter { font-size: 11px; min-width: 45px; }
  .search-nav-btn { width: 28px; height: 28px; font-size: 12px; }
  .header-search-btn { width: 34px; height: 34px; font-size: 15px; }
}

@media (max-width: 480px) {
  .search-bar { padding: 5px 8px; gap: 4px; }
  .search-bar input { padding: 6px 8px; font-size: 13px; }
  .search-counter { font-size: 10px; min-width: 40px; }
  .search-nav-btn { width: 26px; height: 26px; font-size: 11px; }
  .header-search-btn { width: 32px; height: 32px; font-size: 14px; }
}