* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --bg3: #0f3460;
  --accent: #e94560;
  --accent2: #533483;
  --text: #eee;
  --text2: #aaa;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

.screen {
  display: none;
  height: 100dvh;
  width: 100%;
}
.screen.active {
  display: flex;
}

/* ===== LOGIN ===== */
.login-box {
  margin: auto;
  text-align: center;
  padding: 40px;
  background: var(--bg2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 400px;
}
.login-box h1 {
  font-size: 2em;
  margin-bottom: 10px;
}
.login-box p {
  color: var(--text2);
  margin-bottom: 20px;
}
.login-box input {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
}
.login-box button {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: 0.2s;
}
.login-box button:hover {
  opacity: 0.85;
}

/* ===== LOBBY ===== */
#lobbyScreen {
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 20px;
}
.lobby-wrap {
  width: 100%;
  max-width: 500px;
}
.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.lobby-nick {
  color: var(--accent);
  font-weight: bold;
}
.room-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}
.room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: var(--bg2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: 0.2s;
}
.room-item:hover {
  background: var(--bg3);
}
.room-item .room-name {
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 8px;
}
.room-item .room-meta {
  color: var(--text2);
  font-size: 0.85em;
}
.create-room {
  background: var(--bg2);
  padding: 20px;
  border-radius: var(--radius);
}
.create-room h3 {
  margin-bottom: 12px;
}
.create-room input {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 10px;
  outline: none;
}
.create-room button {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent2);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

/* ===== MODAL ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 999;
  align-items: center;
  justify-content: center;
}
.modal.active {
  display: flex;
}
.modal-content {
  background: var(--bg2);
  padding: 30px;
  border-radius: var(--radius);
  width: 90%;
  max-width: 360px;
  text-align: center;
}
.modal-content h3 {
  margin-bottom: 16px;
}
.modal-content input {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 16px;
  outline: none;
}
.modal-btns {
  display: flex;
  gap: 10px;
}
.modal-btns button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  color: #fff;
}
.modal-btns button:first-child {
  background: var(--accent);
}
.btn-secondary {
  background: #555 !important;
}

/* ===== CHAT LAYOUT ===== */
.chat-layout {
  display: flex;
  height: 100dvh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #333;
  transition: 0.3s;
}
.sidebar-header {
  display: flex;
  align-items: center;
  padding: 14px;
  gap: 10px;
  border-bottom: 1px solid #333;
}
.sidebar-header span {
  flex: 1;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-close {
  display: none;
}
.user-list-wrap {
  padding: 14px;
  flex: 1;
  overflow-y: auto;
}
.user-list-wrap h4,
.voice-section h4 {
  color: var(--text2);
  font-size: 0.8em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.user-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.user-item {
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.9em;
}
.voice-section {
  padding: 14px;
  border-top: 1px solid #333;
}
.voice-btn {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--bg3);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 8px;
  transition: 0.2s;
}
.voice-btn.active {
  background: var(--accent);
}
.voice-users {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.voice-user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.85em;
}
.voice-user-item input[type=range] {
  width: 80px;
  accent-color: var(--accent);
}

/* Chat main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-topbar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  border-bottom: 1px solid #333;
  background: var(--bg2);
}
#openSidebar {
  display: none;
}
.chat-topbar span {
  font-weight: bold;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bg2);
  word-break: break-word;
}
.msg.own {
  align-self: flex-end;
  background: var(--bg3);
}
.msg .msg-nick {
  font-size: 0.8em;
  color: var(--accent);
  margin-bottom: 4px;
  font-weight: bold;
}
.msg .msg-time {
  font-size: 0.7em;
  color: var(--text2);
  margin-top: 4px;
  text-align: right;
}
.msg .msg-text {
  line-height: 1.4;
}
.msg img.msg-img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  margin-top: 6px;
  cursor: pointer;
}
.msg video.msg-video {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  margin-top: 6px;
}
.msg .embed-wrap {
  margin-top: 8px;
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  border-radius: 8px;
  overflow: hidden;
}
.msg .embed-wrap iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  border: none;
}
.system-msg {
  text-align: center;
  color: var(--text2);
  font-size: 0.85em;
  padding: 4px;
}

/* Attach preview */
.attach-preview {
  padding: 10px 16px;
  background: var(--bg2);
  border-top: 1px solid #333;
  display: flex;
  align-items: center;
  gap: 10px;
}
.attach-preview.hidden {
  display: none;
}
.attach-preview img,
.attach-preview video {
  max-height: 60px;
  border-radius: 6px;
}
.attach-preview .remove-attach {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
}

/* Input area */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  padding: 10px 12px;
  gap: 8px;
  border-top: 1px solid #333;
  background: var(--bg2);
}
.chat-input-area textarea {
  flex: 1;
  resize: none;
  border: none;
  background: var(--bg);
  color: var(--text);
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  max-height: 120px;
  outline: none;
  font-family: inherit;
}
.btn-icon {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
}
.btn-send {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Fullscreen image */
.img-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.img-overlay img {
  max-width: 95%;
  max-height: 95%;
  border-radius: 8px;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -300px;
    top: 0;
    height: 100dvh;
    z-index: 100;
    box-shadow: var(--shadow);
  }
  .sidebar.open {
    left: 0;
  }
  .sidebar-close {
    display: block !important;
  }
  #openSidebar {
    display: block;
  }
  .msg {
    max-width: 90%;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 3px;
}
/* ===== EMOJI PICKER ===== */
.emoji-picker {
  position: absolute;
  bottom: 60px;
  left: 50px;
  width: 320px;
  max-height: 380px;
  background: var(--bg2);
  border: 1px solid #333;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.emoji-picker.hidden {
  display: none;
}
.emoji-search-wrap {
  padding: 8px;
  border-bottom: 1px solid #333;
}
.emoji-search-wrap input {
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.emoji-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid #333;
  padding: 4px;
  gap: 2px;
  flex-shrink: 0;
}
.emoji-tabs::-webkit-scrollbar {
  height: 0;
}
.emoji-tab {
  padding: 6px 8px;
  font-size: 18px;
  cursor: pointer;
  border-radius: 6px;
  flex-shrink: 0;
  transition: 0.15s;
}
.emoji-tab:hover,
.emoji-tab.active {
  background: var(--bg3);
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}
.emoji-item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  transition: 0.1s;
  user-select: none;
}
.emoji-item:hover {
  background: var(--bg3);
  transform: scale(1.2);
}

@media (max-width: 768px) {
  .emoji-picker {
    left: 5px;
    right: 5px;
    width: auto;
    bottom: 55px;
    max-height: 300px;
  }
  .emoji-grid {
    grid-template-columns: repeat(7, 1fr);
  }
  
  /* ===== Бейджи ролей ===== */
.badge {
  font-size: 12px;
  margin-right: 2px;
}

.badge-admin {
  color: #ffd700;
}

.badge-moder {
  color: #4fc3f7;
}

/* ===== Кнопка управления ролями ===== */
.user-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.role-btn {
  background: none;
  border: 1px solid #555;
  color: #aaa;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  margin-left: auto;
}

.role-btn:hover {
  border-color: #e94560;
  color: #e94560;
}

/* ===== Меню ролей ===== */
.role-menu {
  position: absolute;
  right: 0;
  top: 100%;
  background: #16213e;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 4px 0;
  z-index: 100;
  min-width: 160px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.role-menu-item {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  color: #ccc;
}

.role-menu-item:hover {
  background: #1a1a2e;
  color: #fff;
}

.role-menu-item.active {
  color: #e94560;
  font-weight: bold;
}
}