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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #1a1a2e;
  color: #eee;
  height: 100vh;
  overflow: hidden;
}

/* Auth Screen */
.auth-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.auth-container {
  background: #0f3460;
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  width: 100%;
  max-width: 400px;
}

.auth-container h1 {
  text-align: center;
  color: #e94560;
  margin-bottom: 2rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-form h2 {
  color: #eee;
  margin-bottom: 0.5rem;
}

.auth-form input {
  padding: 0.8rem;
  border: 1px solid #16213e;
  border-radius: 6px;
  background: #16213e;
  color: #eee;
  font-size: 1rem;
}

.auth-form input:focus {
  outline: none;
  border-color: #e94560;
}

.auth-form button {
  padding: 0.8rem;
  background: #e94560;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s;
}

.auth-form button:hover {
  background: #d63650;
}

.toggle-auth {
  text-align: center;
  margin-top: 1rem;
  color: #aaa;
}

.toggle-auth a {
  color: #e94560;
  text-decoration: none;
}

.error-message {
  color: #ff6b6b;
  text-align: center;
  margin-top: 1rem;
  padding: 0.5rem;
  background: rgba(255, 107, 107, 0.1);
  border-radius: 6px;
  display: none;
}

.error-message.show {
  display: block;
}

/* reCAPTCHA container */
#recaptcha-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Hide reCAPTCHA badge globally - we'll show it only when needed via JS */
.grecaptcha-badge {
  visibility: hidden !important;
  opacity: 0 !important;
  transition: opacity 0.3s;
}

/* Show reCAPTCHA badge only on auth screen */
.auth-screen:not([style*="display: none"]) .grecaptcha-badge,
body:has(.auth-screen:not([style*="display: none"])) .grecaptcha-badge {
  visibility: visible !important;
  opacity: 1 !important;
}

/* Chat Screen */
.chat-screen {
  height: 100vh;
}

.chat-container {
  display: flex;
  height: 100%;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: #0f3460;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #16213e;
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid #16213e;
  background: #16213e;
}

.sidebar-header h2 {
  color: #e94560;
  margin-bottom: 1rem;
}

.user-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.user-info span {
  font-weight: 600;
  color: #eee;
}

.admin-link {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.4rem 0.8rem;
  background: #e94560;
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.9rem;
  text-align: center;
}

.admin-link:hover {
  background: #d63650;
}

.section {
  padding: 1rem;
  border-bottom: 1px solid #16213e;
}

.section h3 {
  color: #aaa;
  font-size: 0.9rem;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.list-item {
  padding: 0.6rem;
  background: #16213e;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.list-item:hover {
  background: #1a3a5c;
}

.list-item.active {
  background: #e94560;
}

.list-item .badge {
  background: #28a745;
  color: white;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
}

.friend-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.friend-actions input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid #16213e;
  border-radius: 4px;
  background: #16213e;
  color: #eee;
}

.btn-small {
  padding: 0.5rem 0.8rem;
  background: #e94560;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-small:hover {
  background: #d63650;
}

.btn-success {
  background: #28a745;
}

.btn-success:hover {
  background: #218838;
}

.btn-danger {
  background: #dc3545;
}

.btn-danger:hover {
  background: #c82333;
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #1a1a2e;
}

.chat-header {
  padding: 1.5rem;
  background: #0f3460;
  border-bottom: 1px solid #16213e;
}

.chat-header h2 {
  color: #eee;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.own {
  align-self: flex-end;
}

.message-header {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.3rem;
}

.message-username {
  font-weight: 600;
  color: #e94560;
}

.message.own .message-username {
  color: #4ecdc4;
}

.message-time {
  font-size: 0.75rem;
  color: #888;
}

.message-content {
  background: #0f3460;
  padding: 0.8rem;
  border-radius: 12px;
  word-wrap: break-word;
}

.message.own .message-content {
  background: #16213e;
}

.message-input-container {
  padding: 1.5rem;
  background: #0f3460;
  border-top: 1px solid #16213e;
  display: flex;
  gap: 1rem;
}

.message-input-container input {
  flex: 1;
  padding: 0.8rem;
  border: 1px solid #16213e;
  border-radius: 8px;
  background: #16213e;
  color: #eee;
  font-size: 1rem;
}

.message-input-container input:focus {
  outline: none;
  border-color: #e94560;
}

.message-input-container button {
  padding: 0.8rem 2rem;
  background: #e94560;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s;
}

.message-input-container button:hover {
  background: #d63650;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #0f3460;
}

::-webkit-scrollbar-thumb {
  background: #16213e;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #1a3a5c;
}

/* Modal */
.modal {
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background: #0f3460;
  padding: 2rem;
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-content h2 {
  color: #e94560;
  margin-bottom: 1.5rem;
}

.modal-content h3 {
  color: #eee;
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.close {
  position: absolute;
  right: 1.5rem;
  top: 1.5rem;
  color: #aaa;
  font-size: 2rem;
  font-weight: bold;
  cursor: pointer;
}

.close:hover {
  color: #e94560;
}

/* Settings */
.settings-section {
  margin-bottom: 2rem;
}

.settings-section form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.settings-section input {
  padding: 0.8rem;
  border: 1px solid #16213e;
  border-radius: 6px;
  background: #16213e;
  color: #eee;
  font-size: 1rem;
}

.settings-section input:focus {
  outline: none;
  border-color: #e94560;
}

.profile-picture-settings {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.profile-picture-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.settings-bio-edit {
  width: 100%;
  min-height: 120px;
  padding: 0.8rem;
  background: #16213e;
  border: 1px solid #1a3a5c;
  border-radius: 6px;
  color: #eee;
  font-size: 1rem;
  resize: vertical;
  font-family: inherit;
  margin-bottom: 0.5rem;
}

.settings-bio-edit:focus {
  outline: none;
  border-color: #e94560;
}

.btn-primary {
  padding: 0.8rem;
  background: #e94560;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s;
}

.btn-primary:hover {
  background: #d63650;
}

.btn-settings {
  background: #6c5ce7;
}

.btn-settings:hover {
  background: #5b4bc4;
}

.settings-message {
  margin-top: 1rem;
  padding: 0.8rem;
  border-radius: 6px;
  text-align: center;
  display: none;
}

.settings-message.success {
  background: rgba(40, 167, 69, 0.2);
  color: #28a745;
  display: block;
}

.settings-message.error {
  background: rgba(220, 53, 69, 0.2);
  color: #dc3545;
  display: block;
}

.user-info {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Channel Actions */
.channel-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

/* Channel Controls in Chat Header */
#channel-controls {
  display: none;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* Message Actions */
.message-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
}

.message-actions {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  left: auto;
  opacity: 0;
  transition: opacity 0.2s;
}

/* Position 3-dot menu on left for own messages */
.message.own .message-wrapper .message-actions {
  right: auto !important;
  left: 0.5rem !important;
}

.message-wrapper:hover .message-actions,
.message-actions:hover,
.message-actions:has(.emoji-picker.show),
.message-actions:has(.message-context-menu.show) {
  opacity: 1;
}

.message-menu-btn {
  background: #1a3a5c;
  color: #eee;
  border: none;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.message-menu-btn:hover {
  background: #2a4a6c;
}

.message-context-menu {
  position: absolute;
  top: 35px;
  right: 0;
  background: #0f3460;
  border: 1px solid #16213e;
  border-radius: 8px;
  padding: 0.5rem 0;
  min-width: 150px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: none;
}

.message-context-menu.show {
  display: block;
}

.context-menu-item {
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #eee;
}

.context-menu-item:hover {
  background: #1a3a5c;
}

.context-menu-item.danger {
  color: #ff6b6b;
}

.context-menu-item.danger:hover {
  background: rgba(220, 53, 69, 0.2);
}

/* Message Reactions */
.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.reaction {
  background: #1a3a5c;
  border: 1px solid #16213e;
  border-radius: 12px;
  padding: 0.2rem 0.5rem;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  transition: all 0.2s;
}

.reaction:hover {
  background: #2a4a6c;
  border-color: #e94560;
}

.reaction.user-reacted {
  background: #e94560;
  border-color: #e94560;
  color: white;
}

.reaction-count {
  font-size: 0.8rem;
  font-weight: 600;
}

/* Emoji Picker */
.emoji-picker {
  position: absolute;
  bottom: 100%;
  right: 0;
  background: #0f3460;
  border: 1px solid #16213e;
  border-radius: 8px;
  padding: 0.8rem;
  display: none;
  z-index: 101;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  max-width: 280px;
}

.emoji-picker.show {
  display: block;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.3rem;
}

.emoji-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  transition: background 0.2s;
}

.emoji-btn:hover {
  background: #1a3a5c;
}

/* Message Edit Mode */
.message-edit-container {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}

.message-edit-input {
  flex: 1;
  padding: 0.5rem;
  background: #16213e;
  border: 1px solid #1a3a5c;
  border-radius: 4px;
  color: #eee;
  font-size: 0.95rem;
}

.message-edit-input:focus {
  outline: none;
  border-color: #e94560;
}

.message-edited-tag {
  font-size: 0.7rem;
  color: #888;
  margin-left: 0.5rem;
}

/* Profile Pictures */
.profile-picture {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #16213e;
  cursor: pointer;
  transition: border-color 0.2s;
  margin-right: 0.5rem;
}

.profile-picture:hover {
  border-color: #e94560;
}

.profile-picture.large {
  width: 100px;
  height: 100px;
  border-width: 3px;
  margin-right: 0;
}

.profile-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e94560 0%, #0f3460 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 14px;
  margin-right: 0.5rem;
  cursor: pointer;
  border: 2px solid #16213e;
  transition: border-color 0.2s;
}

.profile-placeholder:hover {
  border-color: #e94560;
}

.profile-placeholder.large {
  width: 100px;
  height: 100px;
  font-size: 32px;
  border-width: 3px;
  margin-right: 0;
}

.message-header {
  display: flex;
  align-items: center;
}

/* Profile Modal */
.profile-modal {
  display: none;
  position: fixed;
  z-index: 1001;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
}

.profile-modal.show {
  display: flex;
  justify-content: center;
  align-items: center;
}

.profile-content {
  background: #0f3460;
  padding: 2rem;
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.5rem;
}

.profile-picture-section {
  position: relative;
  margin-bottom: 1rem;
}

.profile-upload-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  background: #e94560;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: white;
  transition: background 0.2s;
}

.profile-upload-btn:hover {
  background: #d63650;
}

.profile-username {
  font-size: 1.5rem;
  font-weight: 600;
  color: #e94560;
  margin-bottom: 0.3rem;
}

.profile-joined {
  font-size: 0.9rem;
  color: #888;
}

.profile-bio-section {
  background: #16213e;
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.profile-bio-section h3 {
  color: #e94560;
  margin-bottom: 0.8rem;
  font-size: 1.1rem;
}

.profile-bio {
  color: #eee;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.profile-bio.empty {
  color: #888;
  font-style: italic;
}

.profile-bio-edit {
  width: 100%;
  min-height: 100px;
  padding: 0.8rem;
  background: #0f3460;
  border: 1px solid #1a3a5c;
  border-radius: 6px;
  color: #eee;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

.profile-bio-edit:focus {
  outline: none;
  border-color: #e94560;
}

.profile-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.profile-badge {
  background: #6c5ce7;
  color: white;
  padding: 0.3rem 0.8rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-left: 0.5rem;
}

/* Channel Management */
.manage-section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #16213e;
}

.manage-section:last-child {
  border-bottom: none;
}

.invite-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.invite-form label {
  color: #aaa;
  font-size: 0.9rem;
  margin-bottom: -0.5rem;
}

.invite-form input {
  padding: 0.8rem;
  border: 1px solid #16213e;
  border-radius: 6px;
  background: #16213e;
  color: #eee;
  font-size: 1rem;
}

.invite-form input:focus {
  outline: none;
  border-color: #e94560;
}

.invite-result {
  margin-top: 1rem;
}

.invite-code-display {
  background: #16213e;
  padding: 1rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.invite-code-display code {
  background: #0f3460;
  padding: 0.5rem 0.8rem;
  border-radius: 4px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #4ecdc4;
  letter-spacing: 2px;
}

.invite-code-display strong {
  color: #eee;
}

/* Badge Variations */
.badge {
  background: #28a745;
  color: white;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  white-space: nowrap;
}

.badge.success {
  background: #28a745;
}

.badge.error {
  background: #dc3545;
}

/* Invites List */
#invites-list .list-item {
  cursor: default;
}

#invites-list code {
  background: #0f3460;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-weight: 600;
  color: #4ecdc4;
  margin-right: 0.5rem;
}

/* Members List */
#members-list .list-item {
  cursor: default;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1100;
  background: #e94560;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.8rem 1rem;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: background 0.3s;
}

.mobile-menu-toggle:hover {
  background: #d63650;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
  /* Prevent horizontal scrolling on mobile */
  body, html {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* Show mobile menu toggle */
  .mobile-menu-toggle {
    display: block;
  }

  /* Auth screen - better mobile padding */
  .auth-screen {
    padding: 1rem;
  }

  .auth-container {
    padding: 1.5rem;
    max-width: 100%;
  }

  .auth-container h1 {
    font-size: 1.5rem;
  }

  /* Chat screen - fix mobile viewport height */
  .chat-screen {
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for mobile browsers */
    position: relative;
  }

  /* Chat container - stack layout */
  .chat-container {
    position: relative;
    overflow-x: hidden;
    max-width: 100vw;
    height: 100%;
  }

  /* Sidebar - overlay on mobile */
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100vh;
    height: 100dvh;
    width: 85%;
    max-width: 320px;
    z-index: 1000;
    transition: left 0.3s ease-in-out;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.5);
  }

  .sidebar.mobile-open {
    left: 0;
  }

  /* Sidebar header adjustments */
  .sidebar-header {
    padding: 1rem;
  }

  .sidebar-header h2 {
    font-size: 1.3rem;
  }

  .user-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .user-info span {
    font-size: 0.95rem;
  }

  /* Chat area - full width on mobile with proper height */
  .chat-area {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  /* Chat header - better mobile layout */
  .chat-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    padding-right: 4rem;
    flex-shrink: 0;
  }

  .chat-header h2 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
  }

  #channel-controls {
    margin-top: 0.5rem;
    flex-wrap: wrap;
  }

  /* Messages container - adjust padding and ensure scrolling */
  .messages-container {
    padding: 1rem;
    flex: 1;
    min-height: 0; /* Important: allows flex child to shrink below content size */
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal scroll on mobile */
    max-width: 100vw;
  }

  /* Message input - keep at bottom */
  .message-input-container {
    flex-shrink: 0;
  }

  /* Messages - better mobile sizing */
  .message {
    max-width: 85%;
  }

  .message-content {
    padding: 0.6rem;
    font-size: 0.95rem;
  }

  .message-username {
    font-size: 0.9rem;
  }

  .message-time {
    font-size: 0.7rem;
  }

  /* Message input - better mobile layout */
  .message-input-container {
    padding: 1rem;
    gap: 0.5rem;
  }

  .message-input-container input {
    font-size: 16px; /* Prevent iOS zoom */
    padding: 0.7rem;
  }

  .message-input-container button {
    padding: 0.7rem 1.2rem;
    font-size: 0.95rem;
  }

  /* Sections - compact padding */
  .section {
    padding: 0.8rem;
  }

  .section h3 {
    font-size: 0.85rem;
  }

  /* Buttons - larger touch targets */
  .btn-small {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
  }

  /* Friend actions - stack on very small screens */
  .friend-actions {
    flex-direction: column;
  }

  .friend-actions input {
    width: 100%;
    font-size: 16px; /* Prevent iOS zoom */
  }

  /* Channel actions - wrap buttons */
  .channel-actions {
    flex-wrap: wrap;
  }

  /* Modals - full screen on mobile */
  .modal-content {
    padding: 1.5rem;
    width: 95%;
    max-width: 95%;
    margin: 1rem auto;
  }

  .modal-content h2 {
    font-size: 1.3rem;
    padding-right: 2rem;
  }

  .modal-content h3 {
    font-size: 1rem;
  }

  .close {
    position: fixed; /* Make it fixed so it stays visible while scrolling */
    right: 1rem;
    top: 1rem;
    font-size: 1.8rem;
    z-index: 1001; /* Higher z-index to stay above modal content */
    background: #0f3460;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    /* Better touch target on mobile */
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Ensure modal content doesn't overflow and hide close button */
  .modal-content {
    max-height: 90vh;
    overflow-y: auto;
    padding-top: 3rem; /* Space for close button */
  }

  /* Settings form inputs */
  .settings-section input,
  .invite-form input {
    font-size: 16px; /* Prevent iOS zoom */
  }

  /* List items - better touch targets */
  .list-item {
    padding: 0.8rem;
    font-size: 0.95rem;
  }

  /* Message actions - show on hover/tap on mobile */
  .message-actions {
    opacity: 0;
    transition: opacity 0.2s;
    /* Don't let this container constrain the fixed emoji picker */
    overflow: visible !important;
  }

  /* Show on hover or when parent message has active class */
  .message-wrapper:hover .message-actions,
  .message-wrapper:active .message-actions,
  .message-wrapper.show-actions .message-actions,
  .message-actions:hover,
  .message-actions:has(.emoji-picker.show),
  .message-actions:has(.message-context-menu.show) {
    opacity: 1;
  }

  /* Position 3-dot menu on left for own messages (mobile override) */
  .message.own .message-wrapper .message-actions {
    right: auto !important;
    left: 0.5rem !important;
  }

  /* Emoji picker positioning on mobile - prevent overflow */
  .emoji-picker,
  .emoji-picker.show {
    /* Use fixed positioning relative to viewport */
    position: fixed !important;
    /* Center horizontally on screen */
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    /* Position vertically centered */
    top: 50% !important;
    bottom: auto !important;
    margin-top: -100px !important;
    margin-bottom: 0 !important;
    /* Make it narrower on mobile */
    max-width: calc(100vw - 2rem) !important;
    width: 200px !important;
    padding: 0.5rem !important;
    /* Ensure it's above everything */
    z-index: 1000 !important;
    /* Force box sizing */
    box-sizing: border-box !important;
  }

  /* Make emoji grid smaller on mobile */
  .emoji-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.2rem;
  }

  .emoji-btn {
    font-size: 1.3rem;
    padding: 0.2rem;
  }

  /* Invite code display - stack on mobile */
  .invite-code-display {
    flex-direction: column;
    align-items: flex-start;
  }

  .invite-code-display code {
    font-size: 1rem;
    word-break: break-all;
  }

  /* Admin link - full width button */
  .admin-link {
    display: block;
    width: 100%;
  }

  /* Badge - slightly smaller */
  .badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .auth-container {
    padding: 1rem;
  }

  .auth-container h1 {
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
  }

  .sidebar {
    width: 90%;
  }

  .chat-header {
    padding: 0.8rem;
    padding-right: 3.5rem;
  }

  .chat-header h2 {
    font-size: 1.1rem;
  }

  .messages-container {
    padding: 0.8rem;
  }

  .message {
    max-width: 90%;
  }

  .message-content {
    font-size: 0.9rem;
  }

  .message-input-container {
    padding: 0.8rem;
  }

  .message-input-container button {
    padding: 0.7rem 1rem;
  }

  .modal-content {
    padding: 1rem;
  }

  .btn-small {
    font-size: 0.85rem;
    padding: 0.5rem 0.8rem;
  }
}

/* Reply Feature Styles */
.reply-preview {
  display: none;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(100, 100, 255, 0.1);
  border-left: 3px solid #6464ff;
  margin-bottom: 0.5rem;
  border-radius: 4px;
}

.reply-preview-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: #ddd;
}

.reply-indicator {
  font-size: 1rem;
}

.reply-cancel-btn {
  background: none;
  border: none;
  color: #ddd;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.reply-cancel-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.message-reply-info {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: rgba(100, 100, 255, 0.15);
  border-left: 2px solid #6464ff;
  margin: 0.5rem 0;
  border-radius: 4px;
  font-size: 0.85rem;
  color: #bbb;
}

.reply-to-username {
  font-weight: 600;
  color: #6464ff;
}

.reply-content {
  font-style: italic;
  opacity: 0.8;
}

/* DM Notification Badge */
.friend-name-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dm-notification-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #ff4444;
  border-radius: 50%;
  animation: pulse-notification 2s infinite;
}

@keyframes pulse-notification {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.1);
  }
}

/* Online Status Indicator */
.online-status-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.25rem;
  flex-shrink: 0;
}

.online-status-indicator.online {
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}

.online-status-indicator.offline {
  background: #6b7280;
  opacity: 0.5;
}
