html, body {
  height: 100%;
  font-family: 'Inter', 'Segoe UI', Arial, Helvetica, sans-serif;
  background: #181c20;
  color: #f5f6fa;
  margin: 0;
  padding: 0;
  letter-spacing: 0.01em;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: linear-gradient(135deg, #232526 0%, #414345 100%);
}

.container {
  display: flex;
  max-width: 1100px;
  width: 100vw;
  background: #23272f;
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.18);
  border-radius: 18px;
  overflow: hidden;
  height: 90vh;
  min-height: 0;
  margin: 32px 0;
}

.users {
  width: 240px;
  background: #20232a;
  padding: 32px 18px 18px 18px;
  border-right: 1px solid #2d3748;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 2px 0 8px #0001;
}

.users h2 {
  color: #00bcd4;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 18px;
  letter-spacing: 0.03em;
}

#userList {
  list-style: none;
  padding: 0;
  width: 100%;
}

#userList li {
  padding: 8px 0 8px 8px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #23272f;
  color: #b2becd;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.2s;
}
#userList li:hover {
  background: #2d3748;
  color: #fff;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #00bcd4;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  box-shadow: 0 2px 8px #00bcd422;
}

.chat {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  padding: 32px 32px 18px 32px;
  height: 100%;
  min-height: 0;
  background: #23272f;
}

h1 {
  color: #00bcd4;
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 18px 0;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  background: #23272f;
  z-index: 10;
  padding: 12px 0 12px 0;
  box-shadow: 0 2px 8px #00bcd411;
}

.chat-main {
  display: flex;
  flex-direction: row;
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  gap: 18px;
}

#messages {
  flex: 1 1 0;
  overflow-y: auto;
  list-style: none;
  padding: 0 0 12px 0;
  margin: 0;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#messages li {
  background: transparent;
  margin-bottom: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  font-size: 18px;
  display: flex;
  justify-content: flex-start;
}

#messages li.self {
  justify-content: flex-end;
}

.msg-container {
  display: flex;
  align-items: flex-end;
  background: #2d3748;
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 2px 8px #0002;
  padding: 10px 16px;
  gap: 10px;
  min-height: 38px;
  max-width: 420px;
  width: fit-content;
  position: relative;
  transition: background 0.2s;
}
#messages li.self .msg-container {
  background: #00bcd4;
  color: #23272f;
  border-radius: 16px 16px 4px 16px;
  justify-content: flex-end;
  box-shadow: 0 2px 8px #00bcd422;
}

.msg-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  word-break: break-word;
}

.msg-time {
  font-size: 13px;
  color: #b2becd;
  margin-left: 10px;
  vertical-align: middle;
}
#messages li.self .msg-time {
  color: #23272f;
}

#messages li.system .msg-container {
  background: #333;
  font-style: italic;
  border-left: 4px solid #00bcd4;
  color: #aaa;
}

#typingIndicator {
  min-height: 22px;
  color: #00bcd4;
  font-size: 15px;
  margin: 0 0 8px 0;
}

.input-area {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

#messageInput {
  flex: 1;
  padding: 16px;
  background: #181c20;
  color: #fff;
  border: 1.5px solid #00bcd433;
  border-radius: 8px;
  font-size: 18px;
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px #00bcd411;
}
#messageInput:focus {
  border: 1.5px solid #00bcd4;
  box-shadow: 0 2px 12px #00bcd422;
}

button {
  background: linear-gradient(90deg, #00bcd4 0%, #0097a7 100%);
  color: #fff;
  border: none;
  padding: 14px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 600;
  box-shadow: 0 2px 8px #00bcd422;
  transition: background 0.2s, box-shadow 0.2s;
}
button:hover {
  background: linear-gradient(90deg, #0097a7 0%, #00bcd4 100%);
  box-shadow: 0 4px 16px #00bcd433;
}

#emojiBar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 6px;
  background: #181c20;
  border-radius: 12px;
  margin-left: 18px;
  max-height: 400px;
  overflow-y: auto;
  min-width: 38px;
  box-shadow: 0 0 8px #00bcd411;
  transition: background 0.2s;
}
#emojiBar .emoji {
  font-size: 24px;
  cursor: pointer;
  padding: 4px 0;
  border-radius: 6px;
  transition: background 0.2s, transform 0.1s;
}
#emojiBar .emoji:hover {
  background: #00bcd433;
  transform: scale(1.15);
}

/* Emoji picker styles */
#emojiPicker {
  min-width: 220px;
  background: #23272f;
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 24px;
  user-select: none;
  border-radius: 12px;
  box-shadow: 0 2px 8px #00bcd411;
  padding: 12px 8px;
}
#emojiPicker .emoji {
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.2s, transform 0.1s;
}
#emojiPicker .emoji:hover {
  background: #00bcd433;
  transform: scale(1.15);
}

/* --- Avatar improvements --- */
.avatar, .avatar-preview {
  width: 44px !important;
  height: 44px !important;
  min-width: 44px;
  min-height: 44px;
  max-width: 44px;
  max-height: 44px;
  border-radius: 50%;
  background: #00bcd4;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  box-shadow: 0 2px 8px #00bcd422;
  border: 2px solid #fff2;
  object-fit: cover;
  transition: box-shadow 0.2s, border 0.2s;
}
.avatar.avatar-fallback {
  background: linear-gradient(135deg, #00bcd4 60%, #0097a7 100%);
  color: #fff;
  font-size: 20px;
  border: 2px solid #00bcd4;
  box-shadow: 0 2px 8px #00bcd422;
}

/* --- User list improvements --- */
.users {
  background: rgba(32,35,42,0.98);
  box-shadow: 2px 0 12px #0002;
  border-right: 1.5px solid #00bcd433;
}
.users h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #00bcd4;
  margin-bottom: 20px;
}
#userList li {
  padding: 10px 0 10px 10px;
  border-radius: 10px;
  margin-bottom: 8px;
  background: #23272f;
  color: #b2becd;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.2s;
}
#userList li:hover {
  background: #2d3748;
  color: #fff;
}

/* --- Chat header improvements --- */
h1 {
  background: rgba(35,39,47,0.98);
  border-bottom: 2px solid #00bcd433;
  font-size: 30px;
  font-weight: 800;
  color: #00bcd4;
  letter-spacing: 0.06em;
  box-shadow: 0 2px 12px #00bcd411;
  padding: 18px 0 18px 0;
  border-radius: 0 0 18px 18px;
}

/* --- Chat area and message bubbles --- */
.chat {
  background: rgba(35,39,47,0.98);
  border-radius: 18px;
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.18);
}
.msg-container {
  background: #2d3748;
  border-radius: 18px 18px 18px 6px;
  box-shadow: 0 2px 12px #0003;
  padding: 14px 20px;
  gap: 14px;
  min-height: 44px;
  max-width: 480px;
  width: fit-content;
  position: relative;
  transition: background 0.2s;
}
#messages li.self .msg-container {
  background: linear-gradient(90deg, #00bcd4 60%, #0097a7 100%);
  color: #23272f;
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 2px 12px #00bcd422;
}

/* --- Light theme improvements --- */
body.light-theme {
  background: #f4f4f4;
  color: #222;
}
body.light-theme .container,
body.light-theme .chat {
  background: #fff;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.08);
}
body.light-theme .users {
  background: #f9f9f9;
  border-right: 1.5px solid #00bcd433;
}
body.light-theme h1 {
  background: #fff;
  color: #00bcd4;
  border-bottom: 2px solid #00bcd433;
}
body.light-theme #userList li {
  background: #f0f0f0;
  color: #222;
}
body.light-theme #userList li:hover {
  background: #e0f7fa;
  color: #00bcd4;
}
body.light-theme .msg-container {
  background: #e0f7fa;
  color: #222;
}
body.light-theme #messages li.self .msg-container {
  background: linear-gradient(90deg, #00bcd4 60%, #4dd0e1 100%);
  color: #23272f;
}
.avatar, .avatar-preview, .avatar.avatar-fallback {
  border: 2px solid #00bcd4;
  background: #fff;
  color: #00bcd4;
}
body.light-theme .avatar.avatar-fallback {
  background: linear-gradient(135deg, #00bcd4 60%, #4dd0e1 100%);
  color: #fff;
}

/* --- Reply-to-message feature styles --- */
.reply-preview {
  background: #23272f;
  color: #00bcd4;
  border-left: 4px solid #00bcd4;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.reply-preview .reply-to-user {
  font-weight: 600;
  margin-right: 6px;
}
.reply-preview .reply-to-snippet {
  color: #b2becd;
  font-style: italic;
  margin-right: 10px;
}
#cancelReplyBtn {
  background: none;
  border: none;
  color: #00bcd4;
  font-size: 20px;
  cursor: pointer;
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}
#cancelReplyBtn:hover {
  background: #00bcd422;
}
.reply-block {
  background: #181c20;
  color: #00bcd4;
  border-left: 3px solid #00bcd4;
  padding: 4px 10px;
  margin-bottom: 4px;
  border-radius: 6px;
  font-size: 15px;
  opacity: 0.95;
  display: flex;
  gap: 6px;
}
.reply-block .reply-user {
  font-weight: 600;
  margin-right: 4px;
}
.reply-block .reply-snippet {
  color: #b2becd;
  font-style: italic;
}
.reply-btn {
  background: none;
  border: none;
  color: #00bcd4;
  font-size: 22px;
  cursor: pointer;
  margin-left: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background 0.2s;
  align-self: flex-start;
}
.reply-btn:hover {
  background: #00bcd422;
}
body.light-theme .reply-preview {
  background: #f0f0f0;
  color: #00bcd4;
  border-left: 4px solid #00bcd4;
}
body.light-theme .reply-block {
  background: #e0f7fa;
  color: #00bcd4;
  border-left: 3px solid #00bcd4;
}

/* Responsive & Mobile Improvements */
@media (max-width: 900px) {
  .container {
    flex-direction: column;
    max-width: 100vw;
    height: 100vh;
    min-height: 0;
    border-radius: 0;
    margin: 0;
  }
  .users {
    width: 100vw;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid #00bcd433;
    padding: 14px 8px;
    border-radius: 0;
    order: 1;
    box-shadow: none;
  }
  .chat {
    padding: 14px 4px 4px 4px;
    height: 100%;
    min-height: 0;
    order: 2;
  }
  .chat-main {
    flex-direction: column;
    min-height: 0;
    height: auto;
    gap: 10px;
  }
  #emojiBar {
    flex-direction: row;
    margin-left: 0;
    margin-top: 8px;
    max-height: none;
    min-width: 0;
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
  }
  #emojiBar .emoji {
    font-size: 20px;
    padding: 0 2px;
  }
  h1 {
    font-size: 22px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .input-area {
    flex-direction: column;
    gap: 6px;
  }
  #messageInput, button {
    font-size: 17px;
    padding: 12px;
  }
  #messages li {
    font-size: 16px;
    padding: 8px 2px;
  }
  .chat > h1 {
    position: sticky;
    top: 0;
    z-index: 10;
    background: inherit;
    padding-top: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid #00bcd433;
  }
}
@media (max-width: 600px) {
  .container {
    box-shadow: none;
    border-radius: 0;
    min-width: 0;
    width: 100vw;
    height: 100vh;
    margin: 0;
  }
  .users {
    font-size: 15px;
    padding: 8px 2px;
  }
  h1 {
    font-size: 17px;
    flex-direction: row;
    align-items: center;
    gap: 4px;
  }
  .chat {
    padding: 4px 2px 2px 2px;
  }
  #messages li {
    font-size: 14px;
    padding: 6px 1px;
  }
  .msg-container {
    max-width: 98vw;
    padding: 4px 2px;
    gap: 6px;
  }
  .avatar {
    width: 22px;
    height: 22px;
    font-size: 12px;
    margin-right: 3px;
  }
  .msg-time {
    font-size: 11px;
    margin-left: 4px;
  }
  #emojiBar {
    font-size: 16px;
    gap: 2px;
    padding: 4px 0;
  }
}
@media (max-width: 420px) {
  h1, .users h2 {
    font-size: 15px;
    gap: 2px;
  }
  #messages li {
    font-size: 12px;
    padding: 4px 0;
  }
  .msg-container {
    max-width: 100vw;
    padding: 2px 0;
  }
  .avatar {
    width: 16px;
    height: 16px;
    font-size: 9px;
    margin-right: 2px;
  }
  .msg-time {
    font-size: 9px;
    margin-left: 2px;
  }
}
