

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

:root {
  --primary: #0088CC;
  --primary-dark: #0070aa;
  --accent: #179CDE;
  --bg: #111118;
  --bg2: #181825;
  --surface: #1e1e2e;
  --text1: #cdd6f4;
  --text2: #6c7086;
  --text-muted: #585b70;
  --border: #313244;
  --hover: rgba(0,136,204,0.08);
  --active: rgba(0,136,204,0.16);
  --msg-self: #0088CC;
  --msg-other: #262637;
  --danger: #f38ba8;
  --success: #a6e3a1;
  --shadow: 0 1px 4px rgba(0,0,0,0.3);
  --radius: 10px;
  --radius-sm: 6px;
  --glass: rgba(24,24,36,0.88);
  --glass-border: rgba(0,136,204,0.12);
}

html, body {
  height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text1); font-size: 15px; line-height: 1.4;
  overflow: hidden; -webkit-font-smoothing: antialiased;
}

input, button, select, textarea { font-family: inherit; font-size: inherit; outline: none; }

.screen { display: none; height: 100%; width: 100%; }
.screen.active { display: flex; }

/* Spinner */
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
#login-screen {
  align-items: center; justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--glass); padding: 36px 28px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  width: 340px; max-width: 88vw;
  border-radius: var(--radius);
}
.login-title { text-align: center; font-size: 26px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.login-subtitle { text-align: center; color: var(--text2); margin-bottom: 24px; font-size: 13px; }
.form-group { margin-bottom: 12px; }
.form-group input, .modal-content input {
  width: 100%; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text1); transition: border 0.2s;
  border-radius: var(--radius-sm);
}
.form-group input:focus { border-color: var(--primary); }
.btn-group { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  flex: 1; padding: 12px; border: none;
  cursor: pointer; font-weight: 600; transition: opacity 0.2s; font-size: 14px;
  border-radius: var(--radius-sm);
}
.btn:active { opacity: 0.75; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text1); }
.error-msg { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 6px; }
.status-msg { color: var(--text2); font-size: 13px; text-align: center; margin-top: 10px; }

/* Main screen */
#main-screen { display: flex; flex-direction: row; }

/* Sidebar */
#sidebar {
  width: 300px; min-width: 260px;
  display: flex; flex-direction: column; border-right: 1px solid var(--border);
}

/* Chat area */
#chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
#chat-placeholder { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; color: var(--text2); font-size: 15px; }
#chat-active { flex: 1; display: none; flex-direction: column; min-height: 0; }

/* Mobile */
@media (max-width: 640px) {
  #sidebar { width: 100%; min-width: 0; }
  #main-screen #chat-area { display: none; }
  #main-screen.chat-open #sidebar { display: none; }
  #main-screen.chat-open #chat-area { display: flex; }
}

#user-info {
  padding: 14px 16px; display: flex; align-items: center; gap: 10px;
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.user-jid { font-size: 13px; font-weight: 600; color: var(--primary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#user-info select {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text2); padding: 4px 8px; font-size: 11px; cursor: pointer;
  border-radius: var(--radius-sm);
}
#logout-btn { font-size: 16px; color: var(--text2); }

#search-box { padding: 8px 16px 12px; }
#search-input {
  width: 100%; padding: 9px 14px; background: var(--bg);
  border: 1px solid var(--border); color: var(--text1);
  transition: border 0.2s;
  border-radius: var(--radius-sm);
}
#search-input:focus { border-color: var(--primary); }
#search-input::placeholder { color: var(--text2); }

.unread-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 0 5px;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  margin-left: 6px;
  vertical-align: middle;
}

#roster-container { flex: 1; overflow-y: auto; }
#roster-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; font-size: 12px; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.6px;
}
#roster-list { list-style: none; }
.roster-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  cursor: pointer; transition: background 0.15s;
}
.roster-item:hover { background: var(--hover); }
.roster-item.active { background: var(--active); }
.roster-item .avatar {
  width: 36px; height: 36px;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff; flex-shrink: 0;
  border-radius: var(--radius-sm);
}
.roster-item .info { flex: 1; min-width: 0; }
.roster-item .name { font-weight: 600; font-size: 14px; color: var(--text1); }
.roster-item .status-text { font-size: 12px; color: var(--text2); }
.roster-item .presence {
  width: 8px; height: 8px; flex-shrink: 0;
}
.presence.chat { background: var(--success); }
.presence.away { background: #f9e2af; }
.presence.xa, .presence.dnd { background: var(--danger); }
.presence.unavailable { background: var(--border); }

/* Mini-player */
.mini-player {
  display: flex; flex-direction: column; padding: 6px 10px;
  border-top: 1px solid var(--border); background: var(--bg2); cursor: default; flex-shrink: 0;
}
.mini-player-track { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.mini-player-cover {
  width: 36px; height: 36px; border-radius: 6px; background: var(--accent); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px;
  overflow: hidden;
}
.mini-player-cover img { width: 100%; height: 100%; object-fit: cover; }
.mini-player-info { flex: 1; min-width: 0; }
.mini-player-title { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-player-artist { font-size: 10px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-player-controls { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 4px; }
.mini-cmd { background: none; border: none; color: var(--text); font-size: 16px; cursor: pointer; padding: 2px 6px; }
.mini-cmd:hover { color: var(--accent); }
.mini-player-progress-bar { height: 3px; background: var(--border); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.mini-player-progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 2px; transition: width .3s; }

/* Media tab */
#tab-media { display: flex; flex-direction: column; height: 100%; }
#media-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 4px; font-weight: 600; font-size: 14px; }
.media-header-actions { display: flex; align-items: center; gap: 6px; }
.media-cache-info { font-size: 10px; color: var(--text2); font-weight: 400; }
.media-filters { display: flex; gap: 6px; padding: 6px 12px; flex-wrap: wrap; }
.media-filter {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 3px 12px;
  font-size: 11px; color: var(--text2); cursor: pointer; white-space: nowrap;
}
.media-filter.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#media-content { flex: 1; overflow-y: auto; padding: 4px 0; }

/* Media tracks (VK-style flat list) */
.media-track {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border); min-height: 44px;
}
.media-track:hover { background: var(--bg2); }
.media-track.playing { background: var(--bg2); }
.media-track-play { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; font-size: 14px; }
.media-track-info { flex: 1; min-width: 0; }
.media-track-name { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-track-meta { font-size: 10px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-track-media { display: flex; align-items: center; gap: 4px; }
.media-track-dur { font-size: 11px; color: var(--text2); flex-shrink: 0; min-width: 36px; text-align: right; }
.media-track-more { background: none; border: none; color: var(--text2); font-size: 16px; cursor: pointer; padding: 2px 6px; }
.media-track-more:hover { color: var(--text); }
.media-track-waveform { height: 28px; margin-top: 2px; }
.media-track-waveform img.audio-waveform { height: 100%; }

/* Video grid */
.media-video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; padding: 8px 12px; }
.media-video-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg2); cursor: pointer; }
.media-video-item img { width: 100%; height: 100%; object-fit: cover; }
.media-video-item .vid-dur { position: absolute; bottom: 4px; right: 4px; background: rgba(0,0,0,.7); color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 4px; }
.media-video-item .vid-play-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); color: #fff; font-size: 28px; opacity: .8; }
.media-video-item:hover .vid-play-icon { opacity: 1; }

/* Playlist modals */
.playlist-modal-header { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; flex-shrink: 0; }
.playlist-modal-header h3 { margin: 0; font-size: 16px; flex: 1; }
.playlist-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px; cursor: pointer; border-radius: 6px;
}
.playlist-item:hover { background: var(--bg2); }
.playlist-item-icon { width: 36px; height: 36px; border-radius: 8px; background: var(--bg3); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.playlist-item-info { flex: 1; min-width: 0; }
.playlist-item-name { font-size: 13px; font-weight: 500; color: var(--text); }
.playlist-item-count { font-size: 10px; color: var(--text2); }
.playlist-item-actions { display: flex; gap: 4px; }
.playlist-item-actions button { background: none; border: none; color: var(--text2); font-size: 14px; cursor: pointer; padding: 2px 4px; }
.playlist-item-actions button:hover { color: var(--text); }

/* Playlist view track list */
.pv-track {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.pv-track:hover { background: var(--bg2); }
.pv-track.playing { background: var(--bg2); }
.pv-track-num { width: 20px; text-align: right; font-size: 11px; color: var(--text2); flex-shrink: 0; }
.pv-track-info { flex: 1; min-width: 0; }
.pv-track-name { font-size: 12px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-track-dur { font-size: 11px; color: var(--text2); flex-shrink: 0; min-width: 36px; text-align: right; }
.pv-track-more { background: none; border: none; color: var(--text2); font-size: 14px; cursor: pointer; padding: 2px 4px; }

/* Context menu */
.context-menu {
  position: fixed; z-index: 1000; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.3); padding: 4px 0; min-width: 180px;
}
.context-menu-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; font-size: 13px; color: var(--text); cursor: pointer; white-space: nowrap;
}
.context-menu-item:hover { background: var(--bg2); }

.media-section-label { padding: 8px 12px 4px; font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; }
.audio-context-btn {
  font-size: 16px;
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  transition: color 0.2s;
  display: flex;
  align-items: center;
}
.audio-context-btn:hover { color: var(--accent); }

/* Add to playlist modal radio list */
.add-to-pl-radio { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.add-to-pl-radio input[type="radio"] { accent-color: var(--accent); }
.add-to-pl-radio label { flex: 1; cursor: pointer; font-size: 13px; }

#connection-status {
  padding: 6px 16px; font-size: 11px; text-align: center;
  border-top: 1px solid var(--border); flex-shrink: 0; color: var(--text2);
}
#connection-status i { margin-right: 4px; }
#connection-status.offline { color: var(--danger); }
#connection-status.connecting { color: #f9e2af; }
#connection-status.online { color: var(--success); }

/* Chat area */
#chat-area {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--bg);
}

#chat-placeholder {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text2); font-size: 15px;
}

#chat-active {
  flex: 1; display: none; flex-direction: column; min-height: 0;
}

#chat-header {
  padding: 12px 16px; display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; background: var(--glass);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.chat-contact { font-weight: 600; font-size: 15px; color: var(--text1); flex: 1; }
.chat-contact-status { font-size: 12px; color: var(--text2); }
#chat-contact-controls { display: flex; gap: 6px; }
.btn-icon {
  width: 34px; height: 34px; border: none;
  background: transparent; color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s; font-size: 17px; flex-shrink: 0;
}
.btn-icon:hover { background: var(--hover); }
.btn-icon:active { background: var(--active); }

/* Messages */
#chat-messages {
  flex: 1; overflow-y: auto; padding: 8px 16px;
  display: flex; flex-direction: column; gap: 6px;
}
.load-more-bar {
  text-align: center; padding: 8px 0; flex-shrink: 0;
}
.load-more-btn {
  background: var(--surface); color: var(--text2); border: 1px solid var(--border);
  padding: 8px 20px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; transition: all 0.2s;
}
.load-more-btn:hover { background: var(--hover); color: var(--text1); border-color: var(--primary); }
.load-more-btn:disabled { opacity: 0.6; cursor: default; }
.load-more-end { color: var(--text-muted); font-size: 12px; padding: 4px 0; }
.msg-system {
  align-self: center; text-align: center; font-size: 12px;
  color: var(--text2); padding: 4px 12px;
  line-height: 1.4; max-width: 90%;
}
.msg-system-body {
  background: var(--surface); padding: 4px 10px; display: inline-block;
  border-radius: var(--radius-sm);
}
.msg {
  max-width: 80%; padding: 10px 14px;
  word-wrap: break-word; position: relative; line-height: 1.45;
  border-radius: var(--radius);
}
.msg.has-files { max-width: 92%; }
.msg.self { border-bottom-right-radius: 4px; }
.msg.other { border-bottom-left-radius: 4px; }
.msg.self::before {
  content: ''; position: absolute; bottom: 0; right: -7px;
  border: 0 solid transparent; border-top-width: 8px; border-bottom-width: 0;
  border-left: 8px solid var(--msg-self);
}
.msg.other::before {
  content: ''; position: absolute; bottom: 0; left: -7px;
  border: 0 solid transparent; border-top-width: 8px; border-bottom-width: 0;
  border-right: 8px solid var(--msg-other);
}
.msg.self {
  background: var(--msg-self); color: #fff;
}
.msg.other {
  background: var(--msg-other); color: var(--text1);
}
.msg .time {
  font-size: 10px; color: var(--text2);
  margin-top: 4px; text-align: right;
}
.msg.self .time { color: rgba(255,255,255,0.5); }

.file-grid { margin-top: 6px; width: 100%; display: flex; flex-wrap: wrap; gap: 4px; }
.file-grid.count-3, .file-grid.count-4, .file-grid.count-multi { display: grid; gap: 4px; }
.file-item { position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; box-shadow: var(--shadow); border-radius: var(--radius-sm); background: var(--surface); }
.file-item .file-preview { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.file-item .file-preview.video { cursor: pointer; }
.file-item .file-preview.audio { height: 44px; min-height: 44px; object-fit: none; background: var(--surface); padding-left: 38px; line-height: 44px; font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 1 image: full width */
.file-grid.count-1 { display: flex; }
.file-grid.count-1 > .file-item { width: 100%; height: 200px; }

/* 2 images: 50/50 */
.file-grid.count-2 > .file-item { width: calc(50% - 2px); height: 160px; flex: 0 0 auto; }

/* 3+ images: VK style – first tall left, rest grid right */
.file-grid.count-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; height: 220px; }
.file-grid.count-3 > .file-item:first-child { grid-row: span 2; }
.file-grid.count-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; height: 220px; }
.file-grid.count-multi { grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; height: 220px; overflow: hidden; }
.file-grid.count-multi > .file-item:first-child { grid-row: span 2; }
.file-item::before {
  content: ''; position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(90deg, rgba(0,136,204,0.03) 0%, rgba(0,136,204,0.08) 50%, rgba(0,136,204,0.03) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  border-radius: inherit;
}
.file-item.loaded::before { display: none; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
/* .file-badge удалён — все файлы в S3, различие локальный/облачный неактуально */

/* ──── Message wrapper + avatar (Telegram-style) ──── */
.msg-wrapper {
  display: flex; gap: 8px; align-items: flex-end;
  max-width: 100%; margin: 2px 0;
}
.msg-wrapper.self { flex-direction: row-reverse; align-self: flex-end; }
.msg-wrapper:not(.self) { align-self: flex-start; }
.msg-wrapper.hide-avatar .msg-avatar { visibility: hidden; }
.msg-avatar {
  width: 40px; height: 40px; min-width: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
  background: var(--primary); flex-shrink: 0;
}
.msg-wrapper.self .msg-avatar { display: none; }

/* ──── Document cards (Telegram-style) ──── */
.doc-list { margin-top: 4px; display: flex; flex-direction: column; gap: 4px; }
.doc-item { background: var(--surface); border-radius: var(--radius-sm); overflow: hidden; }
.doc-card {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  cursor: pointer; transition: background 0.15s;
}
.doc-card:hover { background: var(--hover); }
.doc-icon { font-size: 22px; color: var(--primary); flex-shrink: 0; width: 28px; text-align: center; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-size: 13px; font-weight: 500; color: var(--text1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 11px; color: var(--text2); margin-top: 1px; }
.doc-dl-btn {
  background: none; border: none; color: var(--text2); cursor: pointer;
  font-size: 16px; padding: 4px; flex-shrink: 0; transition: color 0.15s;
}
.doc-dl-btn:hover { color: var(--primary); }

/* ──── Audio compact (Telegram-style) ──── */
.audio-item {
  margin-top: 4px; min-height: 56px;
}
.audio-card {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: var(--radius-sm);
  padding: 6px 8px; min-height: 52px;
}
.audio-play-btn {
  width: 36px; height: 36px; min-width: 36px;
  border-radius: 50%; border: none;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 18px; flex-shrink: 0;
  transition: opacity 0.15s;
}
.audio-play-btn:hover { opacity: 0.85; }
.audio-play-btn i { line-height: 1; }
.audio-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.audio-title {
  font-size: 13px; font-weight: 500; color: var(--text1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.audio-meta-line {
  font-size: 11px; color: var(--text2);
  display: flex; align-items: center; gap: 6px;
}
.audio-waveform-wrap {
  position: relative; height: 32px; border-radius: 3px; overflow: hidden;
  cursor: pointer; margin-top: 2px;
}
.audio-waveform {
  width: 100%; height: 100%; object-fit: cover; display: block;
  background: var(--bg2);
}
.audio-waveform-progress {
  position: absolute; left: 0; top: 0; height: 100%;
  background: rgba(0,136,204,0.25); pointer-events: none;
  transition: width 0.3s linear;
}
.audio-item.playing .audio-waveform-progress {
  background: rgba(0,136,204,0.4);
}
.audio-ctrl-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px 6px; background: var(--surface);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.audio-ctrl-bar .audio-progress {
  flex: 1; height: 4px; background: rgba(255,255,255,0.15);
  border-radius: 2px; cursor: pointer; position: relative;
}
.audio-ctrl-bar .audio-progress-fill {
  height: 100%; background: var(--primary); width: 0%;
  border-radius: 2px;
}
.audio-ctrl-bar .audio-time-display {
  font-size: 11px; color: var(--text2); white-space: nowrap;
  font-variant-numeric: tabular-nums; min-width: 60px;
}
.audio-ctrl-bar .audio-cmd {
  background: none; border: none; color: var(--text2); cursor: pointer;
  font-size: 14px; padding: 2px 4px; display: flex; align-items: center;
  line-height: 1; transition: color 0.2s;
}
.audio-ctrl-bar .audio-cmd:hover { color: var(--text1); }
.audio-ctrl-bar .audio-cmd-speed {
  font-size: 11px; font-weight: 600; min-width: 24px; justify-content: center;
}
.audio-ctrl-bar .audio-vol-slider {
  width: 40px; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,0.2); border-radius: 2px; outline: none;
  cursor: pointer; margin: 0;
}
.audio-ctrl-bar .audio-vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 10px; height: 10px;
  border-radius: 50%; background: #fff; border: none; cursor: pointer;
}
.audio-ctrl-bar .audio-vol-slider::-moz-range-thumb {
  width: 10px; height: 10px; border-radius: 50%; background: #fff; border: none;
}

.play-overlay {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 48px; height: 48px; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; pointer-events: none;
}
.play-overlay i { color: #fff; font-size: 28px; }
.file-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--primary); text-decoration: none; font-size: 13px;
  padding: 6px 10px; background: var(--surface); margin-top: 4px;
}
.msg .msg-status {
  font-size: 11px; margin-left: 6px; vertical-align: middle;
  display: inline-flex; align-items: center;
}
.msg .msg-status i { font-size: 14px; }
.msg.self .msg-status.status-delivered { color: rgba(255,255,255,0.5); }
.msg.self .msg-status.status-read { color: rgba(255,255,255,0.8); }
.msg .msg-status-time {
  font-size: 9px; color: var(--text2);
  margin-left: 4px; vertical-align: middle;
}
.msg .msg-edited {
  font-size: 10px; color: var(--text2);
  margin-left: 6px; font-style: italic;
}
.msg-reply {
  padding: 6px 8px; margin-bottom: 6px;
  border-left: 3px solid var(--primary);
  background: rgba(0,0,0,0.08);
  cursor: pointer; font-size: 12px;
  border-radius: 4px;
}
.msg.self .msg-reply { background: rgba(255,255,255,0.08); }
.msg-reply-author { color: var(--primary); font-weight: 600; margin-bottom: 2px; }
.msg-reply-body { color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg.self .msg-reply-body { color: rgba(255,255,255,0.6); }
.msg-forwarded {
  font-size: 11px; margin-bottom: 4px; padding: 4px 0;
  color: var(--primary); font-weight: 500;
}
.msg.self .msg-forwarded { color: rgba(255,255,255,0.7); }
.fw-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; cursor: pointer; border-radius: 4px;
  font-size: 14px; color: var(--text1);
}
.fw-item:hover { background: var(--hover); }
.fw-item.selected { background: var(--active); color: var(--primary); }
.msg .msg-actions {
  display: none; position: absolute; top: 4px; right: 4px; gap: 2px;
}
.msg.self:hover .msg-actions, .msg.other:hover .msg-actions { display: flex; }
.msg .msg-action {
  background: rgba(0,0,0,0.4); border: none;
  cursor: pointer; font-size: 12px; padding: 2px 4px; line-height: 1; color: #fff;
}

.typing-indicator {
  padding: 2px 16px 4px; font-size: 12px; color: var(--text2);
  font-style: italic; min-height: 20px; flex-shrink: 0;
}

/* Input area */
#chat-input-area {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 12px; flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#message-input {
  flex: 1; padding: 10px 16px; background: var(--surface);
  border: 1px solid var(--border); color: var(--text1);
  transition: border 0.2s; min-width: 0;
  border-radius: var(--radius-sm);
}
#message-input:focus { border-color: var(--primary); }
#message-input::placeholder { color: var(--text2); }
.send-btn {
  background: var(--primary) !important; color: #fff !important;
  width: 38px; height: 38px; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
}
.send-btn:hover { background: var(--primary-dark) !important; }
#attach-btn { font-size: 18px; display: inline-flex; align-items: center; justify-content: center; color: var(--text2); }

/* Call overlay */
#call-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: #000; z-index: 100;
}
#call-videos {
  width: 100%; height: 100%; position: relative;
  background: #000; overflow: hidden;
}
#call-info {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  text-align: center; padding: 20px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}
#call-status { font-size: 16px; color: #fff; margin-bottom: 2px; }
#call-timer { font-size: 13px; color: #999; }
#call-quality { font-size: 12px; margin-top: 4px; }
#remote-video { width: 100%; height: 100%; object-fit: contain; }
#local-video {
  position: absolute; bottom: 80px; right: 16px;
  width: 140px; border: 2px solid #333; background: #111;
}
@media (max-width: 640px) {
  #local-video { width: 70px; bottom: 70px; right: 8px; }
}
#call-controls {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center; gap: 20px; padding: 20px 20px 24px;
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
}
.call-btn {
  width: 52px; height: 52px; border: none;
  background: #333; color: white; font-size: 20px; cursor: pointer;
  transition: transform 0.15s;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.call-btn:active { transform: scale(0.9); }
.call-end { background: var(--danger); width: 60px; height: 60px; font-size: 24px; border-radius: 50%; }
.call-btn.muted { background: var(--danger); }
.call-btn.video-off { background: var(--danger); }

/* Incoming call */
.incoming-call {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--glass); padding: 14px 20px; display: flex;
  align-items: center; gap: 12px; z-index: 99;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.incoming-call .btn { flex: none; padding: 8px 16px; font-size: 13px; }

/* Active call banner */
.active-call-banner {
  padding: 6px 12px; background: #1e3a2e; color: #a6e3a1;
  font-size: 12px; display: flex; align-items: center; gap: 8px;
  justify-content: center; flex-shrink: 0; border-bottom: 1px solid #2a4a3a;
}

/* Group call screen */
#group-call-screen {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: #000; z-index: 100; flex-direction: column;
}
#group-call-header {
  text-align: center; padding: 12px; flex-shrink: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
  z-index: 10;
}
#group-call-status-text { font-size: 14px; color: #fff; }
#group-call-timer { font-size: 12px; color: #999; margin-left: 8px; }
#group-video-grid {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
  padding: 4px; overflow: hidden;
}
.gv-participant {
  position: relative; background: #111;
  overflow: hidden; min-height: 120px;
  display: flex; align-items: center; justify-content: center;
}
.gv-participant video {
  width: 100%; height: 100%; object-fit: contain;
  position: absolute; top: 0; left: 0;
}
.gv-name {
  position: absolute; bottom: 4px; left: 6px;
  font-size: 11px; color: rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.5); padding: 2px 6px;
  z-index: 2;
}
#group-video-remotes {
  flex: 1; display: grid; gap: 4px;
  grid-template-columns: 1fr;
}
#group-video-remotes:has(> :nth-child(2)) { grid-template-columns: 1fr 1fr; }
#group-video-remotes:has(> :nth-child(3)) { grid-template-columns: 1fr 1fr; }
#group-video-remotes:has(> :nth-child(3)) > :last-child { grid-column: span 2; }
#group-video-remotes:has(> :nth-child(4)) { grid-template-columns: 1fr 1fr; }
#gv-local {
  width: 100%; max-height: 30%; flex-shrink: 0;
}
#group-call-controls {
  display: flex; justify-content: center; gap: 20px;
  padding: 12px 20px 20px; flex-shrink: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
}
#group-participants-count {
  text-align: center; font-size: 11px; color: #999;
  padding-bottom: 4px; flex-shrink: 0;
}

/* Modal */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6); display: flex; align-items: center;
  justify-content: center; z-index: 200;
}
.modal-content {
  background: var(--glass); padding: 24px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  width: 340px; max-width: 88vw;
  border-radius: var(--radius);
}
.modal-content h3 { margin-bottom: 14px; font-size: 17px; color: var(--text1); }
.modal-content input {
  width: 100%; padding: 10px 14px; background: var(--surface);
  border: 1px solid var(--border); color: var(--text1);
}

/* Lightbox */
.lightbox {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.92); z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-close {
  position: absolute; top: 12px; right: 16px;
  font-size: 32px; color: white; cursor: pointer;
  z-index: 301; line-height: 1;
}
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 301; background: rgba(255,255,255,0.08); border: none;
  color: #fff; font-size: 36px; cursor: pointer;
  width: 48px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.lb-nav:hover { background: rgba(255,255,255,0.18); }
#lb-prev { left: 8px; }
#lb-next { right: 8px; }
.lb-counter {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,0.5); font-size: 13px; z-index: 301;
  background: rgba(0,0,0,0.4); padding: 3px 10px;
}
.lb-size {
  position: absolute; bottom: 16px; right: 56px;
  color: rgba(255,255,255,0.4); font-size: 11px; z-index: 301;
  background: rgba(0,0,0,0.4); padding: 3px 8px;
}
#lightbox-img {
  max-width: 94vw; max-height: 94vh;
  object-fit: contain;
  cursor: default;
}
.lb-download {
  position: absolute; bottom: 16px; right: 16px; z-index: 301;
  color: rgba(255,255,255,0.6); font-size: 22px; text-decoration: none;
  padding: 8px; background: rgba(0,0,0,0.3); transition: color 0.2s;
  cursor: pointer;
}
.lb-download:hover { color: #fff; }
.lb-dl-progress {
  position: absolute; bottom: 16px; right: 52px; z-index: 301;
  color: rgba(255,255,255,0.8); font-size: 14px;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: rgba(0,0,0,0.4); border-radius: 6px;
  white-space: nowrap;
}
.lb-delete {
  position: absolute; bottom: 16px; right: 52px; z-index: 301;
  color: rgba(255,100,100,0.6); font-size: 20px; text-decoration: none;
  padding: 8px; background: rgba(0,0,0,0.3); transition: color 0.2s;
  cursor: pointer; border: none; border-radius: 0;
}
.lb-delete:hover { color: #ff4444; }

.msg-details {
  font-size: 11px; color: var(--text2); margin-top: 4px; padding: 4px 6px;
  background: rgba(255,255,255,0.04);
}
.msg-detail-row { display: flex; justify-content: space-between; gap: 8px; line-height: 1.6; }
.msg-detail-label { color: var(--text2); }
.msg-detail-value { color: var(--text1); text-align: right; }
.self .msg-details { background: rgba(255,255,255,0.06); }
.self .msg-detail-label { color: rgba(255,255,255,0.5); }
.self .msg-detail-value { color: rgba(255,255,255,0.8); }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Mobile */
@media (max-width: 640px) {
  #sidebar { width: 100%; min-width: 0; }
  #main-screen #chat-area { display: none; }
  #main-screen.chat-open #sidebar { display: none; }
  #main-screen.chat-open #chat-area { display: flex; }
}

/* When no chat is active, show placeholder */
@media (min-width: 641px) {
  #main-screen:not(.chat-open) #chat-area { display: flex; flex: 1; align-items: center; justify-content: center; }
  #main-screen:not(.chat-open) #chat-active { display: none !important; }
  #main-screen.chat-open #chat-area { display: flex; flex: 1; }
}

/* ──── Tabs ──── */
#tabs { display:flex; background:var(--bg2); border-bottom:1px solid var(--border); }
.tab-btn { flex:1; padding:10px 4px; background:none; border:none; color:var(--text2); cursor:pointer; font-size:12px; text-align:center; transition:0.2s; position:relative; }
.tab-btn.active { color:var(--primary); border-bottom:2px solid var(--primary); }
.tab-btn i { display:block; font-size:18px; margin-bottom:2px; }
.tab-pane { display:none; height:100%; overflow-y:auto; }
.tab-pane.active { display:block; }
.badge { position:absolute; top:2px; right:4px; background:var(--primary); color:#fff; font-size:10px; padding:1px 5px; }

/* ──── Chats list ──── */
#chats-header, #users-header, #events-header { display:flex; align-items:center; justify-content:space-between; padding:8px 12px; border-bottom:1px solid var(--border); font-size:14px; font-weight:600; color:var(--text1); }
.chat-item, .user-item { display:flex; align-items:center; gap:10px; padding:10px 12px; cursor:pointer; border-bottom:1px solid var(--border); transition:0.2s; }
.chat-item:hover, .user-item:hover { background:var(--hover); }
.chat-item.active, .user-item.active { background:var(--active); }
.chat-icon { width:40px; height:40px; display:flex; align-items:center; justify-content:center; color:#fff; font-weight:700; font-size:18px; flex-shrink:0; background:var(--primary); border-radius:var(--radius-sm); }
.chat-info { flex:1; min-width:0; }
.chat-name { font-size:14px; font-weight:500; color:var(--text1); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.chat-meta { font-size:11px; color:var(--text2); margin-top:2px; }
.chat-type-badge { font-size:10px; padding:1px 6px; background:var(--surface); color:var(--text2); }

/* ──── Events list ──── */
.event-item { display:flex; align-items:center; gap:10px; padding:10px 12px; border-bottom:1px solid var(--border); cursor:pointer; transition:0.2s; }
.event-item:hover { background:var(--hover); }
.event-icon { width:36px; height:36px; display:flex; align-items:center; justify-content:center; font-size:16px; background:var(--surface); color:var(--primary); border-radius:var(--radius-sm); }
.event-body { flex:1; min-width:0; }
.event-title { font-size:13px; font-weight:500; color:var(--text1); }
.event-desc { font-size:11px; color:var(--text2); margin-top:2px; }
.event-time { font-size:10px; color:var(--text2); white-space:nowrap; }

/* ──── Chat settings ──── */
#cs-overlay input { width:100%; padding:10px 14px; background:var(--surface); border:1px solid var(--border); color:var(--text1); }

/* ──── Chat Info Panel ──── */
.chat-info-panel {
  position: fixed; top:0; right:0; width:340px; max-width:85vw; height:100%;
  background:var(--bg2); z-index:90; display:flex; flex-direction:column;
  border-left:1px solid var(--border); box-shadow:-4px 0 20px rgba(0,0,0,0.3);
  animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform:translateX(100%); } to { transform:translateX(0); } }
.chat-info-header {
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px; border-bottom:1px solid var(--border); font-weight:600; font-size:15px;
}
.chat-info-tabs { display:flex; border-bottom:1px solid var(--border); }
.ci-tab-btn {
  flex:1; padding:10px; background:none; border:none; color:var(--text2);
  cursor:pointer; font-size:13px; transition:0.2s;
}
.ci-tab-btn.active { color:var(--primary); border-bottom:2px solid var(--primary); }
.ci-tab-content { display:none; flex:1; overflow-y:auto; padding:12px 16px; font-size:13px; }
.ci-tab-content.active { display:block; }
.ci-label { color:var(--text2); font-size:11px; margin-bottom:2px; }
.ci-value { color:var(--text1); margin-bottom:10px; word-break:break-all; }
.ci-file-item {
  display:flex; align-items:center; gap:8px; padding:8px 0; border-bottom:1px solid var(--border); cursor:pointer;
}
.ci-file-item:hover { background:var(--hover); }
.ci-file-icon { font-size:20px; color:var(--primary); flex-shrink:0; }
.ci-file-info { flex:1; min-width:0; }
.ci-file-name { font-size:13px; color:var(--text1); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.ci-file-meta { font-size:11px; color:var(--text2); }

/* Media Player */
.media-player {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: #000; z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
#media-video {
  max-width: 100%; max-height: 100%; width: 100%; height: auto;
  outline: none;
}
.media-controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 16px 16px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  display: flex; align-items: center; gap: 10px;
  opacity: 1; transition: opacity 0.3s;
}
.media-controls.hidden { opacity: 0; pointer-events: none; }
.media-btn {
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 20px; padding: 4px 6px; display: flex; align-items: center;
  opacity: 0.85; transition: opacity 0.2s; line-height: 1;
}
.media-btn:hover { opacity: 1; }
.media-speed-btn { font-size: 12px; min-width: 30px; justify-content: center; font-weight: 600; }
.media-seek-wrap {
  flex: 1; position: relative; height: 4px;
  background: rgba(255,255,255,0.2); border-radius: 2px; cursor: pointer;
}
.media-seek {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  -webkit-appearance: none; appearance: none; background: transparent;
  z-index: 2; cursor: pointer; margin: 0;
}
.media-seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; border: none; cursor: pointer;
}
.media-seek::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: #fff; border: none; cursor: pointer;
}
.media-seek-fill {
  position: absolute; top: 0; left: 0; height: 100%;
  background: var(--primary, #4CAF50); border-radius: 2px;
  pointer-events: none; z-index: 1;
}
.media-buffer-bar {
  position: absolute; top: 0; left: 0; height: 100%;
  background: rgba(255,255,255,0.25); border-radius: 2px;
  pointer-events: none;
}
.media-time {
  font-size: 12px; color: rgba(255,255,255,0.8);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  min-width: 70px; text-align: center;
}
.media-volume {
  width: 60px; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,0.3); border-radius: 2px; outline: none;
  cursor: pointer;
}
.media-volume::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px;
  border-radius: 50%; background: #fff; border: none; cursor: pointer;
}
.media-volume::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; background: #fff; border: none;
}


