/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--text-primary);
  background: var(--bg-page);
}
ul { list-style: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, textarea { font: inherit; color: inherit; border: none; outline: none; background: none; }

/* === AUTH PAGE === */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
}

.auth-box {
  width: 100%;
  max-width: 360px;
  padding: 32px;
  background: var(--bg-sidebar);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.tab-btn {
  flex: 1;
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.tab-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

.auth-form { display: none; flex-direction: column; gap: 14px; }
.auth-form.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field input {
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}

.field input:focus { border-color: var(--accent); }

.error-msg {
  font-size: 12px;
  color: #e05555;
  min-height: 16px;
}

/* === BUTTONS === */
.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-icon-sm {
  width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}
.btn-icon-sm:hover { background: var(--bg-hover); color: var(--text-primary); }

/* === CHAT LAYOUT === */
.chat-page {
  display: flex;
  height: 100vh;
  height: 100dvh; /* корректная высота на мобиле (учитывает клавиатуру и адресную строку) */
  overflow: hidden;
}

/* --- Sidebar backdrop --- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
}
.sidebar-open .sidebar-backdrop { display: block; }

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: var(--sidebar-width);
  height: 100%;
  z-index: 40;
  background: var(--bg-sidebar);
  border-radius: 0 var(--sidebar-radius) var(--sidebar-radius) 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 4px 0 24px rgba(0,0,0,0.4);
}

.sidebar-open .sidebar { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.5px;
}
.sidebar-path { color: var(--accent); }
.app-name::after {
  content: '_';
  animation: blink-cursor 1s step-end infinite;
  color: var(--accent);
}
@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.sidebar-section {
  padding: 12px 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.rooms-list, .users-list {
  overflow-y: auto;
  flex: 1;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  margin: 1px 6px;
  cursor: pointer;
  color: var(--text-white, #f0f0f0);
  transition: background 0.1s, color 0.1s;
}

.room-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.room-item.active { background: var(--accent); color: var(--accent-text); }

.room-unread {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.room-item.active .room-unread { background: rgba(255,255,255,0.3); }

.room-hash { opacity: 0.6; font-size: 13px; }

.user-item {
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  margin: 1px 6px;
  color: var(--text-secondary);
  font-size: 14px;
  border-radius: var(--radius-sm);
}
.user-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.user-item.active { background: var(--accent); color: var(--accent-text); }
.user-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  transition: background 0.2s, opacity 0.2s;
}
.user-dot.offline {
  background: var(--text-muted);
  opacity: 0.5;
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.footer-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.btn-admin {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  text-decoration: none;
  transition: background 0.15s;
}
.btn-admin:hover { background: var(--accent-hover); }

.btn-logout {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: #c0392b;
  transition: background 0.15s;
}
.btn-logout:hover { background: #e74c3c; }

/* --- Reply preview --- */
.reply-preview {
  border-top: 1px solid var(--border);
  background: var(--bg-main);
  padding: 6px 16px;
  flex-shrink: 0;
}
.reply-preview-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
}
.reply-preview-text { flex: 1; min-width: 0; }
.reply-preview-author { font-size: 12px; font-weight: 700; color: var(--accent); display: block; }
.reply-preview-content { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.reply-cancel { color: var(--text-muted); font-size: 16px; line-height: 1; flex-shrink: 0; }
.reply-cancel:hover { color: var(--text-primary); }

/* --- Message highlight (reply scroll) --- */
@keyframes msg-highlight-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(74, 122, 220, 0.7); }
  40%  { box-shadow: 0 0 0 8px rgba(74, 122, 220, 0.2); }
  100% { box-shadow: 0 0 0 8px rgba(74, 122, 220, 0); }
}
.msg-highlight .msg-bubble { animation: msg-highlight-pulse 1.2s ease; }

/* --- Reply quote inside message --- */
.msg-reply-quote {
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: rgba(0,0,0,0.15);
  cursor: pointer;
}
.msg-reply-quote-author { font-size: 11px; font-weight: 700; color: var(--accent); }
.msg-reply-quote-text { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Panel resize handles (thin line between panel and chat) --- */
.sidebar-resizer {
  position: fixed;
  left: var(--sidebar-width);
  top: 0;
  width: 12px;
  margin-left: -8px;
  height: 100%;
  cursor: col-resize;
  z-index: 41;
  background: transparent;
}
.sidebar-resizer::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  width: 2px;
  height: 100%;
  background: transparent;
  transition: background 0.15s;
}

.sidebar-resizer:hover::after,
.panel-resizing .sidebar-resizer.active-resizer::after { background: var(--accent); }

body.panel-resizing { cursor: col-resize !important; user-select: none !important; }

/* Collapsed panels */
.sidebar.collapsed { display: none; }
.sidebar.collapsed ~ .sidebar-resizer-wrap { display: none; }
body:has(.sidebar.collapsed) .chat-main { margin-left: 0 !important; }
body:has(.sidebar.collapsed) .sidebar-resizer { display: none; }

/* Expand buttons (full height, visible on hover at screen edge) */
.expand-sidebar-btn {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 16px;
  height: 100%;
  z-index: 42;
  background: none;
  border: none;
  color: transparent;
  font-size: 14px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}
.expand-sidebar-btn:hover { color: var(--accent); }
body:has(.sidebar.collapsed) .expand-sidebar-btn { display: flex; }

/* --- Sidebar toggle button --- */
.sidebar-toggle {
  margin-right: 10px;
  font-size: 18px;
  flex-shrink: 0;
}

/* --- Main chat area --- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
}

/* --- Desktop: sidebar + users panel always visible --- */
@media (min-width: 768px) {
  .sidebar {
    transform: none !important;
    box-shadow: none;
  }
  .sidebar-backdrop { display: none !important; }
  .sidebar-toggle { display: none; }
  .chat-main { margin-left: var(--sidebar-width); }
  .sidebar-resizer { display: block; }
}

/* Скрыть resizer на мобилке */
@media (max-width: 767px) {
  .sidebar-resizer { display: none !important; }
  .expand-sidebar-btn { display: none !important; }
}

.chat-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px 0 8px;
  font-weight: 600;
  flex-shrink: 0;
  background: var(--bg-main);
}

.btn-header-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  letter-spacing: 0.5px;
  transition: color 0.15s;
}
.btn-header-text:hover { color: var(--accent); }


.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-main);
}

/* --- Messages --- */
.msg {
  display: flex;
  flex-direction: column;
  width: 100%;          /* полная ширина строки → дабл-клик работает везде */
  animation: msg-in 0.12s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg.own   { align-items: flex-end; }
.msg.other { align-items: flex-start; }

.msg-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
  padding: 0 4px;
  max-width: 72%;
  display: flex;
  align-items: center;
  gap: 4px;
}

.msg-ticks { font-size: 12px; color: var(--text-muted); letter-spacing: -3px; }
.msg-ticks.read { color: var(--accent); }

.msg-bubble {
  padding: 8px 12px;
  border-radius: var(--radius);
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.45;
  max-width: 72%;      /* перенесено с .msg */
}

.msg.own  .msg-bubble { background: var(--bg-message-own); color: var(--text-own); border-radius: var(--radius) var(--radius) var(--radius-sm) var(--radius); }
.msg.other .msg-bubble { background: var(--bg-message); color: var(--text-primary); border-radius: var(--radius) var(--radius) var(--radius) var(--radius-sm); }

/* Continuation: same sender, no meta */
.msg.continued .msg-meta { display: none; }
.msg.continued.own  .msg-bubble { border-top-right-radius: var(--radius-sm); }
.msg.continued.other .msg-bubble { border-top-left-radius: var(--radius-sm); }

/* Image message */
.msg-image {
  max-width: 300px;
  max-height: 300px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: block;
  object-fit: cover;
  transition: opacity 0.15s;
}
.msg-image:hover { opacity: 0.88; }

/* File message */
.msg-file {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}
.msg-file-icon { font-size: 20px; }
.msg-file-info { display: flex; flex-direction: column; gap: 1px; }
.msg-file-name { font-weight: 500; font-size: 13px; }
.msg-file-size { font-size: 11px; color: var(--text-muted); }

/* --- Typing indicator --- */
.typing-indicator {
  min-height: 20px;
  padding: 2px 16px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* --- Input area --- */
.input-area {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  border-top: 1px solid var(--border);
  background: var(--bg-main);
  flex-shrink: 0;
}

.file-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 18px;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.file-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.message-input {
  flex: 1;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  transition: border-color 0.15s;
  line-height: 1.4;
}
.message-input:focus { border-color: var(--accent); }

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  font-size: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Lightbox --- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.8);
  cursor: zoom-out;
}

.lightbox-img {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
}

.modal-box {
  background: var(--bg-sidebar);
  border-radius: var(--radius);
  padding: 24px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}

.modal-box h3 { font-size: 16px; font-weight: 700; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

/* --- Drag & Drop overlay --- */
.drag-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(74, 122, 220, 0.15);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  pointer-events: none;
}
.drag-overlay-inner {
  background: var(--bg-sidebar);
  border-radius: var(--radius);
  padding: 20px 40px;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  box-shadow: var(--shadow);
}
.chat-main { position: relative; }

/* --- In-page notifications --- */
.notif-toasts {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.notif-toast {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-width: 220px;
  max-width: 300px;
  box-shadow: var(--shadow);
  animation: notif-in 0.2s ease;
  pointer-events: auto;
}
@keyframes notif-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.notif-toast-author { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.notif-toast-text   { font-size: 13px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Upload progress toasts --- */
.upload-toasts {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.upload-toast {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  width: 260px;
  box-shadow: var(--shadow);
}
.upload-toast-name {
  font-size: 12px;
  color: var(--text-primary);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-toast-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.upload-toast-bar-wrap {
  flex: 1;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
}
.upload-toast-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.15s;
  width: 0%;
}
.upload-toast-pct {
  font-size: 11px;
  color: var(--text-muted);
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* --- Context Menu --- */
.context-menu {
  position: fixed;
  z-index: 200;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px 0;
  min-width: 180px;
}
.context-menu-item {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s;
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item.danger { color: #e74c3c; }
.context-menu-item.danger:hover { background: rgba(231, 76, 60, 0.15); }
.context-menu-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* --- Delete confirm button --- */
.btn-danger {
  background: #c0392b !important;
}
.btn-danger:hover {
  background: #e74c3c !important;
}

/* --- Edited message marker --- */
.msg-edited {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* --- Edit preview bar --- */
.edit-preview-inner {
  border-left-color: #f39c12;
}

/* --- Readers modal --- */
.readers-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 300px;
  overflow-y: auto;
}
.reader-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.reader-item:last-child { border-bottom: none; }
.reader-name { font-weight: 600; color: var(--text-primary); }
.reader-time { font-size: 12px; color: var(--text-muted); }
.readers-empty { text-align: center; color: var(--text-muted); font-size: 13px; padding: 16px 0; }

/* --- DM items --- */
.dm-icon { opacity: 0.6; font-size: 13px; font-weight: 700; color: var(--accent); }

/* --- Chat header info --- */
.chat-header-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-header-info #current-room-name { line-height: 1.2; }
.chat-header-status { font-size: 11px; font-weight: 400; color: var(--text-muted); line-height: 1.2; }
.chat-header-status.online { color: var(--accent); }
.chat-header-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* --- Search bar --- */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-main); flex-shrink: 0;
}
.search-input {
  flex: 1; padding: 6px 10px; background: var(--bg-input);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-primary);
}
.search-input:focus { border-color: var(--accent); }
.search-count { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.msg-search-highlight { background: rgba(94,186,125,0.3); border-radius: 2px; padding: 0 1px; }

/* (pinned bar replaced by pinned-banner) */

/* --- Reactions --- */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-badge {
  padding: 2px 8px; border-radius: 12px; font-size: 12px; cursor: pointer;
  background: var(--bg-hover); border: 1px solid var(--border);
  color: var(--text-primary); transition: background 0.1s, border-color 0.1s;
}
.reaction-badge:hover { background: var(--bg-input); }
.reaction-badge.mine { border-color: var(--accent); background: rgba(94,186,125,0.1); }

/* --- Context menu reactions row --- */
.context-menu-reactions {
  display: flex; justify-content: center; gap: 2px; padding: 6px 8px;
}
.ctx-emoji {
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 16px; transition: background 0.1s;
}
.ctx-emoji:hover { background: var(--bg-hover); }

/* --- Mute icon in sidebar --- */
.room-mute-icon {
  margin-left: auto; font-size: 10px; opacity: 0.5; flex-shrink: 0;
}

/* --- Pinned banner (always visible) --- */
.pinned-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar); cursor: pointer; flex-shrink: 0;
  transition: background 0.1s;
}
.pinned-banner:hover { background: var(--bg-hover); }
.pinned-banner-icon { font-size: 14px; flex-shrink: 0; }
.pinned-banner-content { flex: 1; min-width: 0; }
.pinned-banner-author { font-size: 11px; font-weight: 700; color: var(--accent); display: block; }
.pinned-banner-text { font-size: 12px; color: var(--text-secondary); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-banner-counter { font-size: 10px; color: var(--text-muted); flex-shrink: 0; }

/* --- Forward modal --- */
.forward-room-list { list-style: none; padding: 0; margin: 0; max-height: 300px; overflow-y: auto; }
.forward-room-item {
  padding: 8px 12px; cursor: pointer; border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 13px; transition: background 0.1s;
}
.forward-room-item:hover { background: var(--bg-hover); }

/* --- Markdown in messages --- */
.msg-bubble strong { font-weight: 700; }
.msg-bubble em { font-style: italic; }
.msg-inline-code {
  background: rgba(0,0,0,0.3); padding: 1px 5px; border-radius: 3px;
  font-family: var(--font-mono); font-size: 12px;
}
.msg-code-block {
  background: rgba(0,0,0,0.3); padding: 8px 10px; border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: 12px; margin-top: 4px;
  overflow-x: auto; white-space: pre;
}
.msg-code-block code { background: none; padding: 0; }


/* --- Scrollbar --- */
::-webkit-scrollbar { width: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === PWA Install Banner === */
#pwa-install-banner {
  position: fixed;
  bottom: -80px;
  left: 0; right: 0;
  z-index: 10000;
  transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0 12px 12px;
}
#pwa-install-banner.visible { bottom: 0; }
.pwa-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px;
  background: var(--bg-sidebar, #262a35);
  border: 1px solid var(--border, #3a3f4b);
  border-radius: 14px;
  box-shadow: 0 -2px 20px rgba(0,0,0,0.4);
}
.pwa-banner-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  flex-shrink: 0;
}
.pwa-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text-primary, #e0e0e0);
  font-size: 14px;
  line-height: 1.3;
}
.pwa-banner-text span { color: var(--text-muted, #888); font-size: 13px; }
.pwa-banner-install {
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: var(--accent, #5b9bd5);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.pwa-banner-install:hover { filter: brightness(1.1); }
.pwa-banner-close {
  background: none;
  border: none;
  color: var(--text-muted, #888);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.pwa-banner-close:hover { color: var(--text-primary, #e0e0e0); }

/* iOS — стрелка вниз */
.pwa-ios .pwa-banner-content::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: var(--bg-sidebar, #262a35);
}
.pwa-ios .pwa-banner-content { position: relative; }

/* --- Date separators --- */
.msg-date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 8px;
  color: var(--text-muted);
  font-size: 12px;
  user-select: none;
}
.msg-date-separator::before,
.msg-date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* --- Unread divider --- */
.unread-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  user-select: none;
}
.unread-divider::before,
.unread-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--accent);
}

/* --- Mentions --- */
.mention { color: var(--accent); font-weight: 600; }
.mention-me {
  background: rgba(74, 122, 220, 0.2);
  color: var(--accent);
  font-weight: 600;
  padding: 1px 4px;
  border-radius: 3px;
}
.mention-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  margin-bottom: 4px;
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.3);
}
.mention-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
}
.mention-dropdown-item:hover,
.mention-dropdown-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.mention-dropdown-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}
.mention-dropdown-dot.offline {
  background: var(--text-muted); opacity: 0.5;
}

/* --- Global Search --- */
.search-global-label {
  display: flex; align-items: center; gap: 4px;
  color: var(--text-muted); font-size: 12px;
  white-space: nowrap; cursor: pointer;
}
.search-global-check { accent-color: var(--accent); }
.search-results {
  max-height: 300px; overflow-y: auto;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
}
.search-result-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-room { font-size: 11px; color: var(--accent); font-weight: 600; }
.search-result-content {
  font-size: 13px; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-result-meta { font-size: 11px; color: var(--text-muted); }

/* === User Profiles === */
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.msg-avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 700;
}
.user-item-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.user-item-avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  width: 24px;
  height: 24px;
  border-radius: 50%;
}
.user-item-info {
  flex: 1;
  min-width: 0;
}
.user-item-status {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-avatar-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}
.profile-avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  overflow: hidden;
}
.profile-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile-avatar-btn {
  cursor: pointer;
}
.my-profile-link {
  cursor: pointer;
}
.my-profile-link:hover {
  color: var(--accent);
}

/* === Link Previews === */
.link-preview {
  display: flex;
  gap: 12px;
  padding: 10px;
  margin-top: 6px;
  background: rgba(0,0,0,0.15);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm, 6px) var(--radius-sm, 6px) 0;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  transition: background 0.15s;
}
.link-preview:hover { background: rgba(0,0,0,0.25); }
.link-preview-image {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.link-preview-text { flex: 1; min-width: 0; }
.link-preview-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-preview-desc {
  font-size: 12px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}
.link-preview-domain {
  font-size: 11px;
  color: var(--text-muted);
}

/* === Bookmarks === */
.bookmarks-panel {
  position: absolute;
  top: var(--header-height, 48px);
  right: 0;
  width: 350px;
  max-height: 400px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 0 0 0 var(--radius-sm, 6px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.bookmarks-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}
.bookmarks-list {
  flex: 1;
  overflow-y: auto;
}
.bookmark-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.bookmark-item:hover { background: var(--bg-hover); }
.bookmark-room {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}
.bookmark-content {
  font-size: 13px;
  color: var(--text-primary);
  margin: 4px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bookmark-meta {
  font-size: 11px;
  color: var(--text-muted);
}
.bookmarks-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.btn-header-text {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
}
.btn-header-text:hover {
  color: var(--accent);
}
