/* ═══════════════════════════════════════════════════════════════════════════
   BananZa — Telegram-like dark theme
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --bg-dark: #0e1621;
  --bg-sidebar: #17212b;
  --bg-input: #242f3d;
  --bg-hover: #202b36;
  --bg-own-msg: #2b5278;
  --bg-other-msg: #182533;
  --bg-modal: #1e2c3a;
  --text-primary: #f5f5f5;
  --text-secondary: #7e8b99;
  --text-time: rgba(255,255,255,.45);
  --accent: #5eb5f7;
  --accent-hover: #4aa3e5;
  --link: #6ab2f2;
  --danger: #e17076;
  --success: #7bc862;
  --border: #0e1621;
  --border-light: #2a3a4a;
  --radius: 10px;
  --radius-msg: 12px;
}

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

html, body {
  height: 100%; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 15px; color: var(--text-primary); background: var(--bg-dark);
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ── App layout ──────────────────────────────────────────────────────────── */
#app {
  display: flex; height: 100vh; height: 100dvh; width: 100vw;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: 320px; min-width: 200px; background: var(--bg-sidebar);
  display: flex; flex-direction: column; border-right: none;
  z-index: 10;
}

.resize-handle {
  width: 5px; cursor: col-resize; background: var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; position: relative; z-index: 11;
  transition: background .15s;
}
.resize-handle:hover, .resize-handle.active {
  background: var(--accent);
}
.resize-handle-line {
  width: 3px; height: 32px; border-radius: 2px;
  background: rgba(255,255,255,.15);
  opacity: 0; transition: opacity .15s;
}
.resize-handle:hover .resize-handle-line,
.resize-handle.active .resize-handle-line {
  opacity: 1; background: rgba(255,255,255,.4);
}

.sidebar-header {
  display: flex; align-items: center; padding: 10px 12px; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { flex: 1; font-size: 18px; font-weight: 600; white-space: nowrap; }

.sidebar-search { padding: 8px 12px; position: relative; }
.sidebar-search input {
  width: 100%; padding: 8px 30px 8px 12px; background: var(--bg-input); border: none;
  border-radius: 20px; color: var(--text-primary); outline: none; font-size: 14px;
}
.sidebar-search input::placeholder { color: var(--text-secondary); }
.search-clear {
  position: absolute; right: 18px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-secondary); cursor: pointer;
  font-size: 14px; padding: 4px; line-height: 1;
}
.search-clear:hover { color: var(--text); }

.chat-list { flex: 1; overflow-y: auto; }

.chat-item {
  display: flex; align-items: center; padding: 10px 12px; gap: 12px;
  cursor: pointer; transition: background .15s;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--accent); }
.chat-item.active .chat-item-time,
.chat-item.active .chat-item-last { color: rgba(255,255,255,.8); }

.chat-item-avatar {
  width: 48px; height: 48px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 20px;
  font-weight: 600; color: #fff; flex-shrink: 0; position: relative;
  overflow: hidden;
}

.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: center; }
.chat-item-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 12px; color: var(--text-secondary); white-space: nowrap; margin-left: 8px; }
.chat-item-last {
  font-size: 14px; color: var(--text-secondary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.chat-item-last > span { overflow: hidden; text-overflow: ellipsis; }

.chat-list-separator {
  padding: 8px 16px 4px; font-size: 12px; font-weight: 600;
  color: var(--accent); text-transform: uppercase; letter-spacing: .5px;
}

.online-dot {
  width: 10px; height: 10px; background: var(--success); border-radius: 50%;
  border: 2px solid var(--bg-sidebar); position: absolute; bottom: 0; right: 0;
}

.sidebar-footer {
  display: flex; align-items: center; padding: 10px 12px; gap: 8px;
  border-top: 1px solid var(--border);
}
.current-user {
  flex: 1; display: flex; align-items: center; gap: 8px;
  min-width: 0;
}
.current-user .avatar {
  width: 28px; height: 28px; font-size: 11px; flex-shrink: 0;
  border-radius: 50%; overflow: hidden;
}
.current-user-name {
  font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Icon buttons ────────────────────────────────────────────────────────── */
.icon-btn {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; font-size: 18px; transition: background .15s; flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); }

/* ── Chat area ───────────────────────────────────────────────────────────── */
#chatArea { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--text-secondary);
}
.empty-icon { font-size: 80px; margin-bottom: 16px; }
.empty-state h3 { font-size: 22px; margin-bottom: 8px; color: var(--text-primary); }
.empty-state p { font-size: 15px; }

.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

/* ── Chat header ─────────────────────────────────────────────────────────── */
.chat-header {
  display: flex; align-items: center; padding: 10px 16px; gap: 10px;
  background: var(--bg-sidebar); border-bottom: 1px solid var(--border);
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { font-size: 13px; color: var(--text-secondary); }

/* ── Messages ────────────────────────────────────────────────────────────── */
.messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-dark);
}

.load-more { text-align: center; padding: 12px; }
.load-more button {
  background: var(--bg-input); color: var(--accent); border: none;
  padding: 8px 20px; border-radius: 20px; cursor: pointer; font-size: 13px;
}
.load-more button:hover { background: var(--bg-hover); }

.msg-row { display: flex; flex-direction: row; align-items: center; max-width: 80%; gap: 4px; }
.msg-row.own { align-self: flex-end; flex-direction: row-reverse; max-width: 80%; }
.msg-row.other { align-self: flex-start; }
.msg-row.other .msg-content { display: flex; flex-direction: column; min-width: 0; }

.msg-group {
  display: flex; align-self: flex-start; gap: 8px; align-items: flex-end; max-width: 80%;
}
.msg-group-avatar {
  flex-shrink: 0; position: sticky; bottom: 6px; align-self: flex-end; margin-bottom: 2px;
}
.msg-group-avatar .avatar { width: 32px; height: 32px; font-size: 13px; overflow: hidden; border-radius: 50%; }
.msg-group-body {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}

.msg-sender {
  font-size: 13px; font-weight: 600; margin-bottom: 2px; padding-left: 12px;
}

.msg-bubble {
  padding: 7px 12px 6px; border-radius: var(--radius-msg); position: relative;
  word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; min-width: 80px;
  max-width: 100%;
  line-height: 1.4;
}
.msg-row.own .msg-bubble {
  background: var(--bg-own-msg);
  border-bottom-right-radius: 4px;
}
.msg-row.other .msg-bubble {
  background: var(--bg-other-msg);
  border-bottom-left-radius: 4px;
}

.msg-text { white-space: pre-wrap; }
.msg-text a { color: var(--link); }

.msg-time {
  font-size: 11px; color: var(--text-time); text-align: right;
  margin-top: 2px; float: right; margin-left: 10px; line-height: 20px;
  display: inline-flex; align-items: center; gap: 3px;
}
.msg-status { font-size: 13px; color: var(--text-time); letter-spacing: -3px; margin-right: 1px; }
.msg-status.read { color: var(--accent); }

.msg-deleted {
  color: var(--text-secondary); font-style: italic; font-size: 14px;
}

/* Compact view: all messages left-aligned with avatars */
.compact-view .msg-row.own { align-self: flex-start; flex-direction: row; }
.compact-view .msg-row.own .msg-bubble { border-bottom-right-radius: var(--radius-msg); border-bottom-left-radius: 4px; }

.msg-delete-btn {
  display: none; position: absolute; top: 4px; right: 4px;
  font-size: 14px; color: var(--text-secondary); width: 22px; height: 22px;
  border-radius: 4px; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; padding: 0;
}
.msg-bubble:hover .msg-delete-btn { display: flex; }
.msg-delete-btn:hover { color: var(--danger); background: rgba(0,0,0,.2); }

.msg-reply-btn {
  opacity: 0; transition: opacity .15s; flex-shrink: 0;
  font-size: 18px; padding: 2px 4px; cursor: pointer;
  background: none; border: none; color: var(--text-secondary);
}
.msg-row:hover .msg-reply-btn { opacity: 1; }
.msg-reply-btn:hover { color: var(--accent); }

.date-separator {
  text-align: center; padding: 12px 0; color: var(--text-secondary); font-size: 13px;
}
.date-separator span {
  background: var(--bg-input); padding: 4px 14px; border-radius: 12px;
}

/* ── File attachments ────────────────────────────────────────────────────── */
.msg-image {
  max-width: 340px; max-height: 300px; border-radius: 8px; cursor: pointer;
  display: block; margin: 4px 0; object-fit: contain;
}

.msg-audio { width: 100%; max-width: 320px; margin: 6px 0; }
.msg-audio audio { width: 100%; height: 36px; }

.msg-video { max-width: 360px; margin: 6px 0; }
.msg-video video { width: 100%; border-radius: 8px; max-height: 280px; }

.msg-file {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: rgba(0,0,0,.15); border-radius: 8px; margin: 4px 0;
  text-decoration: none; color: inherit;
}
.msg-file-icon { font-size: 28px; flex-shrink: 0; }
.msg-file-info { flex: 1; min-width: 0; }
.msg-file-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--link); }
.msg-file-size { font-size: 12px; color: var(--text-secondary); }

/* ── Link preview ────────────────────────────────────────────────────────── */
.link-preview {
  border-left: 3px solid var(--accent); padding: 8px 12px; margin: 6px 0;
  background: rgba(0,0,0,.15); border-radius: 0 8px 8px 0; display: block;
  text-decoration: none; color: inherit; max-width: 360px;
}
.link-preview:hover { background: rgba(0,0,0,.25); text-decoration: none; }
.lp-host { font-size: 12px; color: var(--accent); margin-bottom: 2px; }
.lp-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lp-desc { font-size: 13px; color: var(--text-secondary); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.lp-image { width: 100%; max-height: 160px; object-fit: cover; border-radius: 6px; margin-top: 6px; }

/* ── Typing indicator ────────────────────────────────────────────────────── */
.typing-bar {
  padding: 4px 16px; font-size: 13px; color: var(--accent);
  background: var(--bg-dark);
}

/* ── Input area ──────────────────────────────────────────────────────────── */
.input-area {
  background: var(--bg-sidebar); border-top: 1px solid var(--border); padding: 8px 12px;
}

.pending-file {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--bg-input); border-radius: 8px; margin-bottom: 8px; font-size: 14px;
}
.pending-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-file-remove {
  color: var(--text-secondary); cursor: pointer; font-size: 18px; width: 24px;
  height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 4px;
}
.pending-file-remove:hover { color: var(--danger); }

.input-row { display: flex; align-items: flex-end; gap: 4px; }

#msgInput {
  flex: 1; padding: 10px 14px; background: var(--bg-input); border: none;
  border-radius: 20px; color: var(--text-primary); outline: none; resize: none;
  max-height: 150px; line-height: 1.35; font-size: 15px; overflow-y: auto;
}
#msgInput::-webkit-scrollbar { display: none; }
#msgInput { scrollbar-width: none; }
#msgInput::placeholder { color: var(--text-secondary); }

.send-btn { color: var(--accent); font-size: 22px; }
.send-btn:hover { color: var(--accent-hover); }

/* ── Emoji picker ────────────────────────────────────────────────────────── */
.emoji-picker {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%);
  width: 340px; max-height: 320px; background: var(--bg-modal);
  border: 1px solid var(--border-light); border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.4); overflow: hidden; z-index: 100;
  display: flex; flex-direction: column;
}
.emoji-tabs {
  display: flex; border-bottom: 1px solid var(--border-light); padding: 4px;
  overflow-x: auto; flex-shrink: 0;
}
.emoji-tab {
  padding: 6px 8px; font-size: 18px; border-radius: 6px; cursor: pointer; flex-shrink: 0;
}
.emoji-tab.active { background: var(--bg-input); }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); padding: 8px;
  overflow-y: auto; gap: 2px; flex: 1;
}
.emoji-item {
  font-size: 22px; width: 38px; height: 38px; display: flex; align-items: center;
  justify-content: center; border-radius: 6px; cursor: pointer;
}
.emoji-item:hover { background: var(--bg-input); }

/* ── Image viewer ────────────────────────────────────────────────────────── */
.image-viewer {
  position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 200;
  display: none; overflow: hidden;
}
.image-viewer:not(.hidden) { display: block; }
.iv-close {
  position: absolute; top: 16px; right: 16px; color: #fff;
  font-size: 28px; width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.1);
}
.iv-close:hover { background: rgba(255,255,255,.2); }
#ivStrip {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: flex; align-items: center;
  will-change: transform; touch-action: none;
}
.iv-slide {
  flex: 0 0 100vw; width: 100vw; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.iv-slide img { max-width: 95vw; max-height: 95vh; object-fit: contain; user-select: none; -webkit-user-drag: none; pointer-events: none; }

.iv-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  color: #fff; font-size: 56px; line-height: 1;
  width: 60px; height: 80px; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.3); border: none; cursor: pointer;
  opacity: 0; transition: opacity .2s;
  border-radius: 8px; z-index: 201;
  -webkit-user-select: none; user-select: none;
}
.iv-prev { left: 12px; }
.iv-next { right: 12px; }
.image-viewer:hover .iv-arrow { opacity: .6; }
.iv-arrow:hover { opacity: 1 !important; background: rgba(0,0,0,.5); }

@media (max-width: 768px) {
  .iv-arrow { display: none !important; }
  .iv-slide img { max-width: 100vw; max-height: 85vh; }
}

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 150;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-content {
  background: var(--bg-modal); border-radius: 12px; width: 100%;
  max-width: 420px; max-height: 80vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-content.wide { max-width: 600px; }
.modal-content.narrow { max-width: 320px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border-light);
}
.modal-header h3 { font-size: 17px; }
.modal-close {
  font-size: 20px; color: var(--text-secondary); width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-tabs {
  display: flex; border-bottom: 1px solid var(--border-light);
}
.modal-tab {
  flex: 1; text-align: center; padding: 10px; font-size: 14px;
  font-weight: 600; color: var(--text-secondary); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: .2s;
}
.modal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-input {
  width: 100%; padding: 10px 14px; background: var(--bg-input); border: 1px solid var(--border-light);
  border-radius: 8px; color: var(--text-primary); outline: none; margin-bottom: 12px; font-size: 14px;
}
.modal-input:focus { border-color: var(--accent); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── User list ───────────────────────────────────────────────────────────── */
.user-list { display: flex; flex-direction: column; gap: 2px; }
.user-list-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; transition: background .15s;
}
.user-list-item:hover { background: var(--bg-hover); }
.user-list-item .avatar {
  width: 40px; height: 40px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 16px;
  font-weight: 600; color: #fff; flex-shrink: 0; overflow: hidden;
}
.user-list-item .name { font-size: 15px; font-weight: 500; }
.user-list-item .status-text { font-size: 12px; color: var(--text-secondary); }

.checkable .user-list-item { position: relative; padding-left: 40px; }
.checkable .user-list-item::before {
  content: ''; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; border: 2px solid var(--border-light); border-radius: 4px;
}
.checkable .user-list-item.selected::before {
  background: var(--accent); border-color: var(--accent);
}
.checkable .user-list-item.selected::after {
  content: '✓'; position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: #fff; font-size: 14px; font-weight: 700;
}

.btn-primary {
  width: 100%; padding: 10px; background: var(--accent); color: #fff;
  border: none; border-radius: 8px; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-top: 12px; transition: .2s;
}
.btn-primary:hover { background: var(--accent-hover); }

/* ── Admin user list ─────────────────────────────────────────────────────── */
.admin-user-list { display: flex; flex-direction: column; gap: 4px; }
.admin-user-row {
  display: flex; align-items: center; gap: 12px; padding: 10px;
  background: var(--bg-input); border-radius: 8px;
}
.admin-user-row .avatar {
  width: 36px; height: 36px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 15px;
  font-weight: 600; color: #fff; flex-shrink: 0; overflow: hidden;
}
.admin-user-row .info { flex: 1; min-width: 0; }
.admin-user-row .info .name { font-size: 14px; font-weight: 600; }
.admin-user-row .info .meta { font-size: 12px; color: var(--text-secondary); }
.admin-user-actions { display: flex; gap: 6px; flex-shrink: 0; }
.admin-user-row .badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600;
}
.badge-admin { background: var(--accent); color: #fff; }
.badge-blocked { background: var(--danger); color: #fff; }
.admin-user-row .block-btn {
  padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;
}
.block-btn.is-blocked { background: var(--success); color: #fff; }
.block-btn:not(.is-blocked) { background: var(--danger); color: #fff; }
.admin-user-row .reset-btn {
  padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;
  background: var(--accent); color: #fff; margin-right: 4px;
}
.admin-user-row .reset-btn:hover { opacity: .85; }

/* ── Settings modal ──────────────────────────────────────────────────────── */
.settings-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 14px 16px;
  background: var(--bg-input); border: none; border-radius: 8px; color: var(--text-primary);
  font-size: 15px; cursor: pointer; transition: background .15s; margin-bottom: 6px;
}
.settings-item:hover { background: var(--bg-hover); }
.settings-toggle-item { cursor: default; justify-content: space-between; }
.settings-toggle-item:hover { background: var(--bg-input); }
.settings-hint { font-size: 12px; color: var(--text-secondary); padding: 0 16px 12px; }

/* Toggle switch */
.toggle-switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: #3a4a5c; border-radius: 24px;
  cursor: pointer; transition: .2s;
}
.toggle-slider::before {
  content: ''; position: absolute; width: 18px; height: 18px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

.cp-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }
.cp-success { color: var(--success); font-size: 13px; margin-top: 4px; min-height: 18px; }

/* ── Menu body ───────────────────────────────────────────────────────────── */
.menu-user-info {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px;
}
.menu-user-info .avatar {
  width: 64px; height: 64px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 28px;
  font-weight: 600; color: #fff;
}
.menu-user-info .name { font-size: 18px; font-weight: 600; }
.menu-user-info .username { font-size: 14px; color: var(--text-secondary); }

/* ── Avatar upload ───────────────────────────────────────────────────────── */
.avatar-large {
  overflow: hidden;
  width: 80px; height: 80px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 32px;
  font-weight: 600; color: #fff; background-size: cover;
  background-position: center; background-repeat: no-repeat;
}
.avatar-upload-wrap {
  position: relative; display: inline-block; margin-bottom: 8px;
}
.avatar-upload-wrap.center { display: flex; flex-direction: column; align-items: center; }
.avatar-upload-label {
  position: absolute; bottom: 0; right: 0; width: 28px; height: 28px;
  border-radius: 50%; background: var(--accent); display: flex;
  align-items: center; justify-content: center; font-size: 14px;
  cursor: pointer; border: 2px solid var(--bg-modal); transition: .2s;
}
.avatar-upload-label:hover { background: var(--accent-hover); }
.avatar-upload-label input { display: none; }

.avatar-img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
}

.chat-item-avatar .avatar-img {
  width: 48px; height: 48px; border-radius: 50%; object-fit: cover;
}

.btn-text {
  background: none; border: none; color: var(--danger); font-size: 13px;
  cursor: pointer; padding: 4px 8px; margin-bottom: 8px;
}
.btn-text:hover { text-decoration: underline; }

.btn-sm {
  padding: 8px 16px; background: var(--accent); color: #fff; border: none;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
}
.btn-sm:hover { background: var(--accent-hover); }

.profile-form { width: 100%; }
.profile-form .field-group { margin-bottom: 16px; }
.profile-form .field-group label {
  display: block; font-size: 12px; color: var(--text-secondary);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px;
}

.color-picker {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.color-swatch {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; transition: .15s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: #fff; }

.inline-edit { display: flex; gap: 8px; align-items: center; }
.inline-edit .modal-input { flex: 1; }

.divider {
  border: none; border-top: 1px solid var(--border-light);
  margin: 16px 0;
}

.profile-meta {
  text-align: center; margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border-light);
}
.meta-username { font-size: 14px; color: var(--text-secondary); }

.member-remove {
  margin-left: auto; color: var(--text-secondary); font-size: 14px;
  width: 28px; height: 28px; display: flex; align-items: center;
  justify-content: center; border-radius: 50%; flex-shrink: 0;
}
.member-remove:hover { color: var(--danger); background: rgba(225,112,118,.15); }

/* ── Chat header avatar ──────────────────────────────────────────────────── */
.chat-header-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600; color: #fff;
  background-size: cover; background-position: center;
  overflow: hidden;
}

/* ── User avatar in message ──────────────────────────────────────────────── */
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff;
  overflow: hidden;
}

/* ── Reply bar ────────────────────────────────────────────────────────────── */
.reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg-input); border-left: 3px solid var(--accent);
  border-radius: 4px; margin: 0 8px;
}
.reply-bar-content { flex: 1; min-width: 0; }
.reply-bar-name { font-size: 13px; font-weight: 600; color: var(--accent); }
.reply-bar-text { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-close { font-size: 16px; }

/* ── Reply inside message ────────────────────────────────────────────────── */
.msg-reply {
  padding: 6px 10px; background: rgba(94,181,247,0.15); border-left: 3px solid var(--accent);
  border-radius: 4px; margin-bottom: 4px; cursor: pointer; font-size: 13px;
}
.own .msg-reply { background: rgba(255,255,255,0.1); }
.msg-reply-name { font-weight: 600; color: var(--accent); font-size: 12px; }
.msg-reply-text { color: #b0cfe0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.own .msg-reply-text { color: rgba(255,255,255,0.7); }

/* ── Unread badge ────────────────────────────────────────────────────────── */
.unread-badge {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 10px; display: flex;
  align-items: center; justify-content: center; padding: 0 6px;
  margin-left: auto; flex-shrink: 0;
}

/* ── Search panel ────────────────────────────────────────────────────────── */
.search-panel {
  position: absolute; top: 0; right: 0; width: 320px; max-width: 100%;
  height: 100%; background: var(--bg-sidebar); z-index: 15;
  display: flex; flex-direction: column; border-left: 1px solid var(--border-light);
}
.search-panel-header {
  display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border-light);
}
.search-panel-header .modal-input { flex: 1; margin: 0; }
.search-results { flex: 1; overflow-y: auto; padding: 8px; }
.search-result-item {
  padding: 10px; border-radius: 8px; cursor: pointer; transition: background .15s;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-name { font-size: 12px; font-weight: 600; color: var(--accent); }
.search-result-text { font-size: 14px; margin-top: 2px; }
.search-result-text mark { background: var(--accent); color: #fff; border-radius: 2px; padding: 0 2px; }
.search-result-time { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

/* ── Drag & drop overlay ─────────────────────────────────────────────────── */
.drag-overlay {
  position: absolute; inset: 0; background: rgba(14,22,33,0.85); z-index: 20;
  display: flex; align-items: center; justify-content: center;
  border: 3px dashed var(--accent); border-radius: 12px; margin: 8px;
}
.drag-overlay-content {
  font-size: 20px; font-weight: 600; color: var(--accent);
}

/* ── Media duration ──────────────────────────────────────────────────────── */
.media-duration { font-size: 11px; color: var(--text-secondary); margin-right: 4px; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.25); }

/* ── Mobile only button ──────────────────────────────────────────────────── */
.mobile-only { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE (< 768px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .resize-handle { display: none; }
  #app { height: 100vh; height: 100dvh; }
  #sidebar {
    position: fixed; inset: 0; width: 100%; min-width: 0;
    z-index: 20; transition: transform .25s ease;
  }
  #sidebar.sidebar-hidden { transform: translateX(-100%); }

  .mobile-only { display: flex !important; }

  .chat-header {
    padding: 8px 6px;
    min-height: 52px;
    position: sticky; top: 0; z-index: 15;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-light);
  }
  .chat-header .icon-btn { width: 40px; height: 40px; font-size: 20px; }
  .chat-header-avatar { width: 40px; height: 40px; font-size: 16px; }
  .chat-title { font-size: 16px; }
  .chat-status { font-size: 12px; }

  .messages { padding: 8px; }

  .msg-row { max-width: 90%; }
  .msg-group { max-width: 90%; }
  .msg-image { max-width: 260px; max-height: 240px; }
  .msg-video { max-width: 280px; }

  .emoji-picker { width: 300px; bottom: 60px; }

  .modal-content { max-height: 90vh; max-height: 90dvh; }
  .modal-content.wide { max-width: 95vw; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Animations
   ═══════════════════════════════════════════════════════════════════════════ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.msg-row { animation: fadeIn .2s ease; }

/* ── Mobile attach menu ──────────────────────────────────────────────────── */
.attach-menu-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 300;
}
.attach-menu {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 301;
  background: var(--bg-modal); border-radius: 16px 16px 0 0;
  padding: 12px 16px 32px; display: flex; flex-direction: column; gap: 4px;
}
.attach-menu button {
  padding: 14px 16px; text-align: left; font-size: 16px;
  border-radius: 10px; color: var(--text-primary);
}
.attach-menu button:hover { background: var(--bg-hover); }
#attachMenuCancel { color: var(--danger); margin-top: 4px; }
