* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1e1f26;
  color: #e8e8ec;
}

/* Auth pages */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
.auth-box {
  background: #2a2b35;
  padding: 2.5rem;
  border-radius: 12px;
  width: 320px;
}
.auth-box h1 { margin-top: 0; font-size: 1.4rem; }
.auth-box input {
  display: block;
  width: 100%;
  padding: 0.6rem;
  margin-bottom: 0.8rem;
  border-radius: 6px;
  border: 1px solid #444;
  background: #1e1f26;
  color: #fff;
}
.auth-box button {
  width: 100%;
  padding: 0.6rem;
  border: none;
  border-radius: 6px;
  background: #5865f2;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.auth-box a { color: #8ea1ff; }
.error { color: #ff6b6b; }

/* App layout */
.app {
  display: flex;
  height: 100vh;
}
.sidebar {
  width: 260px;
  background: #24252e;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
}
.user-info {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid #3a3b46;
  padding-bottom: 0.8rem;
}
.user-info strong { flex: 1; }
.avatar-sm { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.avatar-lg { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; display: block; margin: 0 auto 0.8rem; }
#profile-btn {
  background: none; border: none; color: #9a9ba8; cursor: pointer; font-size: 1rem;
}
.logout { color: #ff9b9b; font-size: 0.85rem; text-decoration: none; }

.rooms { display: flex; flex-direction: column; gap: 0.3rem; }
.room-btn, .friend-item, .group-item {
  background: none;
  border: none;
  color: #e8e8ec;
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  width: 100%;
}
.room-btn:hover, .friend-item:hover, .group-item:hover { background: #33343f; }
.room-btn.active, .friend-item.active, .group-item.active { background: #5865f2; }

#create-group-form { display: flex; gap: 0.4rem; }
#create-group-input {
  flex: 1;
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid #444;
  background: #1e1f26;
  color: #fff;
}
#create-group-form button {
  padding: 0.4rem 0.6rem;
  border: none;
  border-radius: 6px;
  background: #5865f2;
  color: #fff;
  cursor: pointer;
}

.sidebar h3 { margin: 0.2rem 0 0.3rem; font-size: 0.8rem; text-transform: uppercase; color: #9a9ba8; }

.friend-item { display: flex; justify-content: space-between; width: 100%; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.status-dot.online { background: #3ba55d; }
.status-dot.offline { background: #6a6b76; }

#add-friend-form { display: flex; gap: 0.4rem; }
#add-friend-input {
  flex: 1;
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid #444;
  background: #1e1f26;
  color: #fff;
}
#add-friend-form button {
  padding: 0.4rem 0.6rem;
  border: none;
  border-radius: 6px;
  background: #5865f2;
  color: #fff;
  cursor: pointer;
}

.request-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; padding: 0.3rem 0; }
.request-row button {
  border: none;
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  margin-left: 0.2rem;
  font-size: 0.75rem;
}
.btn-accept { background: #3ba55d; color: #fff; }
.btn-decline { background: #a5423b; color: #fff; }

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #33343f;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-header h2 { margin: 0; font-size: 1.1rem; }
#chat-actions { display: flex; gap: 0.5rem; }
#chat-actions button {
  padding: 0.35rem 0.7rem;
  border: none;
  border-radius: 6px;
  background: #3a3b46;
  color: #e8e8ec;
  cursor: pointer;
  font-size: 0.85rem;
}
.danger-btn { background: #a5423b !important; color: #fff !important; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.msg { max-width: 70%; }
.msg .meta { font-size: 0.75rem; color: #9a9ba8; margin-bottom: 2px; }
.msg .bubble {
  background: #2f303b;
  padding: 0.5rem 0.8rem;
  border-radius: 10px;
  display: inline-block;
  word-wrap: break-word;
  position: relative;
}
.msg.own { align-self: flex-end; }
.msg.own .bubble { background: #5865f2; }
.msg .bubble.deleted { font-style: italic; color: #9a9ba8; background: #26272f; }
.msg-text { white-space: pre-wrap; }
.attachment-img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin-top: 0.3rem; }
.attachment-file { color: #dfe3ff; display: inline-block; margin-top: 0.3rem; }
.edit-input {
  width: 100%;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #8ea1ff;
  background: #1e1f26;
  color: #fff;
}
.msg-actions {
  display: inline-flex;
  gap: 0.3rem;
  margin-left: 0.5rem;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg .bubble:hover .msg-actions { opacity: 1; }
.msg-actions button {
  background: none;
  border: none;
  color: #d8d8e0;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0 2px;
}

.attach-btn {
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  padding: 0 0.3rem;
}
#attachment-preview {
  padding: 0 1.5rem 0.5rem;
  font-size: 0.8rem;
  color: #9a9ba8;
}
#attachment-preview button {
  background: none;
  border: none;
  color: #ff9b9b;
  cursor: pointer;
}

/* Profile modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: #2a2b35;
  padding: 1.5rem;
  border-radius: 12px;
  width: 320px;
}
.modal-box h3 { margin-top: 0; }
.modal-box input[type="file"] { color: #e8e8ec; margin-bottom: 0.8rem; width: 100%; }
.modal-box textarea {
  width: 100%;
  min-height: 70px;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid #444;
  background: #1e1f26;
  color: #fff;
  resize: vertical;
  margin-bottom: 0.8rem;
}
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.modal-actions button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
#profile-save-btn { background: #5865f2; color: #fff; }
#profile-cancel-btn { background: #3a3b46; color: #e8e8ec; }

.message-form {
  display: flex;
  padding: 1rem 1.5rem;
  gap: 0.6rem;
  border-top: 1px solid #33343f;
}
#message-input {
  flex: 1;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  border: 1px solid #444;
  background: #1e1f26;
  color: #fff;
}
.message-form button {
  padding: 0.7rem 1.2rem;
  border: none;
  border-radius: 8px;
  background: #5865f2;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
