body {
  font-family: sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f7f7f7;
  width: 100%;
  overflow-x: hidden; /* Prevent horizontal scroll */
  -webkit-text-size-adjust: 100%; /* Prevent iOS text size adjustment */
}

#app {
  max-width: 500px;
  margin: auto;
  padding: 1rem;
  background-color: white;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%; /* Full width on mobile */
  box-sizing: border-box;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.header-left h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-left h1 i {
  color: #fff;
  font-size: 1.3rem;
}

/* Auth Area Styles */
.auth-area {
  display: flex;
  align-items: center;
}

.login-btn {
  background: linear-gradient(135deg, #4285f4, #34a853);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 25px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(66, 133, 244, 0.3);
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(66, 133, 244, 0.4);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 25px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.user-avatar-container {
  position: relative;
}

.user-avatar {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.user-status-indicator {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  background: #4ade80;
  border: 2px solid white;
  border-radius: 50%;
  animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.user-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.user-id {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.logout-btn {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: none;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

#friends,
#chat {
  background: #ffffff;
  padding: 0;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  border: 1px solid #e0e0e0;
  overflow: hidden;
}

/* Chat Section Styles */
#chat {
  display: flex;
  flex-direction: column;
  height: 600px;
  min-height: 0; /* Allow shrinking */
  position: relative;
}

.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chat-friend-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.chat-friend-details h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.chat-friend-status {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.8);
}

.disappearing-status {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  padding: 6px 12px;
  border-radius: 15px;
  font-size: 0.8rem;
  backdrop-filter: blur(10px);
}

.disappearing-status i {
  color: #fbbf24;
  animation: clockTick 1s infinite;
}

@keyframes clockTick {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0; /* Allow shrinking */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.input-area {
  padding: 12px 16px;
  background: white;
  border-top: 1px solid #e0e0e0;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 100;
}

.message-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.disappear-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  padding: 6px 12px;
  border-radius: 20px;
  background: #f1f5f9;
  transition: all 0.3s ease;
  font-size: 0.85rem;
  border: 1px solid #e2e8f0;
}

.disappear-toggle:hover {
  background: #e2e8f0;
}

.disappear-toggle input[type="checkbox"] {
  display: none;
}

.toggle-slider {
  width: 30px;
  height: 16px;
  background: #cbd5e1;
  border-radius: 10px;
  position: relative;
  transition: all 0.3s ease;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: all 0.3s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.disappear-toggle input[type="checkbox"]:checked + .toggle-slider {
  background: #f59e0b;
}

.disappear-toggle input[type="checkbox"]:checked + .toggle-slider::after {
  transform: translateX(14px);
}

.disappear-icon {
  color: #64748b;
  transition: color 0.3s ease;
}

.disappear-toggle input[type="checkbox"]:checked ~ .disappear-icon {
  color: #f59e0b;
}

.toggle-text {
  color: #64748b;
  font-weight: 500;
  transition: color 0.3s ease;
}

.disappear-toggle input[type="checkbox"]:checked ~ .toggle-text {
  color: #f59e0b;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: nowrap; /* Prevent wrapping */
  width: 100%;
}

#messageInput {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 25px;
  font-size: 16px; /* Prevent zoom on iOS */
  outline: none;
  transition: all 0.3s ease;
  background: #f8fafc;
  min-height: 44px; /* Minimum touch target */
  box-sizing: border-box;
}

#messageInput:focus {
  border-color: #667eea;
  background: white;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  font-size: 1rem;
  flex-shrink: 0; /* Prevent shrinking */
  touch-action: manipulation; /* Improve touch response */
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
  user-select: none; /* Prevent text selection */
}

.input-btn.secondary {
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #e2e8f0;
}

.input-btn.secondary:hover {
  background: #e2e8f0;
  transform: scale(1.05);
}

.input-btn.primary {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
}

.input-btn.primary:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.input-btn.primary:active {
  transform: scale(0.95);
}

/* Enhanced Friends Section Styles - Modern Chat App UX */
#friends {
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  /* PREVENT ALL SCROLLING on Friends container */
  overflow: hidden !important;
  max-height: none !important;
  height: auto !important;
  display: flex;
  flex-direction: column;
  gap: 0;
  /* Smooth transitions for modern UX */
  transition: all 0.3s ease;
}

.friends-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #e0e0e0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px 12px 0 0; /* Round only top corners */
  /* Ensure header doesn't cause scrolling */
  flex-shrink: 0;
  position: relative;
  z-index: 5;
  margin: 0; /* Reset margins */
}

.friends-header h2 {
  margin: 0;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.friends-actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap; /* Keep buttons in one line */
  align-items: center;
}

.action-btn {
  position: relative;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  white-space: nowrap;
  flex-shrink: 0; /* Prevent shrinking on larger screens */
  min-width: 36px; /* Minimum width for icon-only mode */
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.action-btn.active {
  background: rgba(255, 255, 255, 0.4);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.btn-text {
  display: inline; /* Show text by default on PC */
  transition: all 0.3s ease;
}

/* Mobile: Hide text and show only icons when screen is narrow */
@media (max-width: 768px) {
  .btn-text {
    display: none; /* Hide text on mobile/tablet */
  }
  
  .action-btn {
    padding: 8px; /* Reduce padding when text is hidden */
    gap: 0; /* Remove gap when no text */
    min-width: 40px; /* Slightly larger touch target */
  }
  
  .friends-actions {
    gap: 6px; /* Reduce gap between icon-only buttons */
  }
}

/* Very small mobile screens */
@media (max-width: 400px) {
  .action-btn {
    padding: 6px;
    min-width: 36px;
    font-size: 0.8rem;
  }
  
  .friends-actions {
    gap: 4px;
  }
}

/* Modern Loading States */
.loading-skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
  height: 60px;
  margin-bottom: 8px;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Modern section transitions */
.section-entering {
  animation: slideInFromTop 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.section-leaving {
  animation: slideOutToTop 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideOutToTop {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* Active section indicator */
.action-btn.active::before {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 1px;
  transition: all 0.3s ease;
}

/* Enhanced notification badge with pulse */
.notification-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: linear-gradient(135deg, #ff4757, #ff3742);
  color: white;
  border-radius: 50%;
  padding: 0;
  font-size: 0.7rem;
  font-weight: bold;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: badgePulse 2s infinite;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(255, 71, 87, 0.4);
  border: 2px solid white;
}

/* Modern content fade-in */
.content-fade-in {
  animation: contentFadeIn 0.4s ease-out forwards;
}

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

/* Header Center for View Toggle */
.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  margin: 0 20px;
}

.view-toggle-container {
  display: flex;
  align-items: center;
}

.view-toggle-btn {
  background: linear-gradient(135deg, #e0e7ff, #f0f4ff, #fbeffb, #ffe5ec);
  color: black;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
  font-weight: 500;
}

.view-toggle-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.view-toggle-btn.active {
  background: linear-gradient(135deg, #4facfe, #00f2fe);
}

@media (max-width: 768px) {
  
  .view-toggle-btn {
    padding: 8px 12px;
  }
}

/* Mobile Messenger Interface */
.mobile-view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: #ffffff;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
}

.mobile-view.slide-in {
  animation: slideInFromRight 0.3s ease-out forwards;
}

.mobile-view.slide-out {
  animation: slideOutToRight 0.3s ease-out forwards;
}

@keyframes slideInFromRight {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes slideOutToRight {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(100%);
  }
}

/* Mobile Messenger Header */
.mb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  background: #ffffff;
  border-bottom: 1px solid #e1e5e9;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.mb-header-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.mb-back-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #262626;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.mb-back-btn:hover {
  background: #f0f0f0;
}

.mb-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mb-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.mb-user-details {
  display: flex;
  flex-direction: column;
}

.mb-user-name {
  font-weight: 600;
  color: #262626;
  font-size: 1rem;
}

.mb-user-status {
  font-size: 0.8rem;
  color: #8e8e8e;
}

.mb-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mb-action-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #262626;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.mb-action-btn:hover {
  background: #f0f0f0;
}

/* Mobile Messenger Chat List */
.mb-chat-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mb-search-container {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 20px;
  background: #ffffff;
  border-bottom: 1px solid #e1e5e9;
}

.mb-search-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  background: #f0f2f5;
  border-radius: 20px;
  padding: 8px 15px;
  gap: 10px;
}

.mb-search-box i {
  color: #8e8e8e;
  font-size: 0.9rem;
}

.mb-search-box input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-size: 0.9rem;
  color: #262626;
}

.mb-search-box input::placeholder {
  color: #8e8e8e;
}

.mb-new-chat-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #262626;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.mb-new-chat-btn:hover {
  background: #f0f0f0;
}

.mb-chat-list-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.mb-friends-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mb-friends-list li {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.2s ease;
  border-bottom: 1px solid #f0f0f0;
}

.mb-friends-list li:hover {
  background: #f8f9fa;
}

.mb-friends-list li:last-child {
  border-bottom: none;
}

.mb-friend-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 15px;
}

.mb-friend-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mb-friend-name {
  font-weight: 600;
  color: #262626;
  font-size: 0.95rem;
}

.mb-friend-message {
  color: #8e8e8e;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.mb-friend-time {
  color: #8e8e8e;
  font-size: 0.8rem;
  white-space: nowrap;
}

.mb-friend-unread {
  width: 12px;
  height: 12px;
  background: #0095f6;
  border-radius: 50%;
  margin-left: 8px;
}

/* Mobile Messenger Empty State */
.mb-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  text-align: center;
  color: #8e8e8e;
}

.mb-empty-state i {
  font-size: 3rem;
  margin-bottom: 20px;
  color: #c7c7c7;
}

.mb-empty-state h3 {
  font-size: 1.3rem;
  color: #262626;
  margin-bottom: 10px;
}

.mb-empty-state p {
  font-size: 0.9rem;
  margin-bottom: 25px;
  line-height: 1.4;
}

.mb-send-message-btn {
  background: #0095f6;
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.mb-send-message-btn:hover {
  background: #007acc;
}

/* Mobile Messenger Chat View */
.mb-chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  height: 100vh;
  position: relative;
}

.mb-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  background: #ffffff;
  border-bottom: 1px solid #e1e5e9;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.mb-chat-header-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.mb-chat-friend-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.mb-chat-friend-info {
  display: flex;
  flex-direction: column;
}

.mb-chat-friend-info h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #262626;
}

.mb-friend-status {
  font-size: 0.8rem;
  color: #8e8e8e;
  margin: 0;
}

.mb-chat-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Mobile Messenger Messages */
.mb-messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #ffffff;
  margin-bottom: 80px; /* Reserve space for fixed input area */
}

.mb-message {
  display: flex;
  margin-bottom: 15px;
}

.mb-message.sent {
  justify-content: flex-end;
}

.mb-message.received {
  justify-content: flex-start;
}

.mb-message-content {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.mb-message.sent .mb-message-content {
  background: #0095f6;
  color: white;
  border-bottom-right-radius: 8px;
}

.mb-message.received .mb-message-content {
  background: #f0f0f0;
  color: #262626;
  border-bottom-left-radius: 8px;
}

.mb-message-time {
  font-size: 0.7rem;
  color: #8e8e8e;
  text-align: center;
  margin-top: 5px;
}

/* Mobile Messenger Input Area */
.mb-input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 15px 20px;
  background: #ffffff;
  border-top: 1px solid #e1e5e9;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.mb-input-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mb-media-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #262626;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.mb-media-btn:hover {
  background: #f0f0f0;
}

.mb-text-input-container {
  flex: 1;
  display: flex;
  align-items: center;
  background: #f0f2f5;
  border-radius: 20px;
  padding: 8px 15px;
  gap: 10px;
}

.mb-text-input-container input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-size: 0.9rem;
  color: #262626;
}

.mb-text-input-container input::placeholder {
  color: #8e8e8e;
}

.mb-emoji-btn {
  background: none;
  border: none;
  font-size: 1rem;
  color: #8e8e8e;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.mb-emoji-btn:hover {
  color: #262626;
}

.mb-send-btn, .mb-voice-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #0095f6;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.mb-send-btn:hover, .mb-voice-btn:hover {
  background: #f0f0f0;
}

/* Mobile Messenger Modal */
.mb-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
}

.mb-modal-content {
  background: #ffffff;
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  overflow: hidden;
  animation: modalSlideIn 0.3s ease-out;
}

.mb-modal-header {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px;
  border-bottom: 1px solid #e1e5e9;
}

.mb-modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #262626;
}

.mb-modal-body {
  padding: 20px;
}

.mb-search-users input {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid #e1e5e9;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.mb-search-users input:focus {
  border-color: #0095f6;
}

.mb-users-list {
  margin-top: 15px;
  max-height: 300px;
  overflow-y: auto;
}

.mb-users-list ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mb-users-list li {
  display: flex;
  align-items: center;
  padding: 12px 0;
  cursor: pointer;
  transition: background 0.2s ease;
  border-radius: 8px;
}

.mb-users-list li:hover {
  background: #f8f9fa;
}

/* Responsive Design for Mobile Messenger View */
@media (max-width: 768px) {
  .header-center {
    margin: 0 10px;
  }
  
  .view-toggle-btn {
    padding: 8px 12px;
  }
  
  .mb-header {
    padding: 12px 15px;
  }
  
  .mb-search-container {
    padding: 12px 15px;
  }
  
  .mb-friends-list li {
    padding: 12px 15px;
  }
  
  .mb-chat-header {
    padding: 12px 15px;
  }
  
  .mb-messages-container {
    padding: 15px;
    margin-bottom: 80px; /* Reserve space for fixed input area */
  }
  
  .mb-input-area {
    padding: 12px 15px;
  }
  
  .mb-message-content {
    max-width: 85%;
  }
  
  .mb-modal-content {
    width: 95%;
    max-height: 90vh;
  }
  
  .mb-user-details, .mb-chat-friend-info {
    display: flex;
    flex-direction: column;
  }
  
  .mb-friend-info {
    min-width: 0; /* Allow text truncation */
  }
  
  .mb-friend-message {
    max-width: 150px;
  }
}

@media (max-width: 480px) {
  .mb-header-right {
    gap: 5px;
  }
  
  .mb-action-btn {
    padding: 6px;
    font-size: 1rem;
  }
  
  .mb-friend-avatar {
    width: 48px;
    height: 48px;
  }
  
  .mb-chat-friend-avatar {
    width: 36px;
    height: 36px;
  }
  
  .mb-input-container {
    gap: 8px;
  }
  
  .mb-media-btn, .mb-send-btn, .mb-voice-btn {
    padding: 6px;
    font-size: 1rem;
  }
}

/* IMPORTANT: Prevent any scrolling on Friends container */
#friends {
  /* This container should NEVER scroll */
  overflow: hidden !important;
  max-height: none !important;
  height: auto !important;
}

#friends * {
  /* Prevent any child elements from creating unwanted scroll except section-content */
  overscroll-behavior: contain;
}

/* Ensure only section content areas are scrollable */
.section-content {
  /* This is the ONLY scrollable area within Friends */
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

/* Prevent body scroll when interacting with Friends sections on mobile */
@media (max-width: 768px) {
  #friends {
    touch-action: manipulation; /* Improve touch response */
    -webkit-overflow-scrolling: auto; /* Disable momentum scrolling on container */
  }
  
  .section-content {
    -webkit-overflow-scrolling: touch; /* Enable momentum scrolling only on content */
    touch-action: pan-y; /* Allow only vertical scrolling */
  }
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.friends-section {
  border-bottom: 1px solid #e0e0e0;
  overflow: hidden;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-height: 0;
  /* Modern chat app transitions */
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(0);
  opacity: 1;
}

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

/* Hide sections by default with smooth animation */
.friends-section.hidden {
  display: none !important;
  opacity: 0;
  transform: translateY(-10px);
}

/* Show sections with smooth animation */
.friends-section.visible {
  display: flex !important;
  opacity: 1;
  transform: translateY(0);
}

.action-btn:hover {
  background: #3579bd6c;
  transform: translateY(-2px);
}

.action-btn.active {
  background: #28c54dc8;
}

.btn-text {
  display: none;
}

.notification-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #dc3545;
  color: white;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
  line-height: 1.2;
  animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.friends-section {
  background: #f8f9fa;
  border-radius: 12px;
  margin-bottom: 15px;
  border: 1px solid #e9ecef;
  overflow: hidden;
  transition: all 0.3s ease;
}

.section-header {
  background: #f8f9fa;
  color: #495057;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid #e0e0e0;
}

.section-header h3 {
  margin: 0;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.collapse-btn {
  background: none;
  border: none;
  color: #6c757d;
  font-size: 1rem;
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  transition: all 0.3s;
}

.collapse-btn:hover {
  background: #e9ecef;
  color: #495057;
}

.section-content {
  padding: 16px;
  background: #ffffff;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 350px; /* Increase height for better UX */
  min-height: 0;
  position: relative;
  /* Smooth content transitions */
  transition: all 0.3s ease;
}

/* Modern empty state with better positioning */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #6c757d;
  background: #f8f9fa;
  border-radius: 8px;
  margin: 10px;
  transition: all 0.3s ease;
}

.empty-state i {
  font-size: 3.5rem;
  color: #dee2e6;
  margin-bottom: 20px;
  display: block;
  opacity: 0.8;
}

.empty-state p {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
}

.search-container {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  flex-shrink: 0; /* Prevent search bar from shrinking */
}

.search-container input {
  flex: 1;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.95rem;
  transition: border-color 0.3s;
  background: #ffffff;
  color: #333;
}

.search-container input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-btn {
  background: #667eea;
  color: white;
  border: none;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.search-btn:hover {
  background: #5a6fd8;
}

.results-list, .friends-list, .requests-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 220px; /* Increase maximum height for better mobile scrolling */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; /* For Firefox */
  scrollbar-color: rgba(255, 255, 255, 0.4) rgba(255, 255, 255, 0.1); /* For Firefox */
}

/* Adjust height for sections with search containers */
.search-container + .results-list {
  max-height: 180px; /* Increase height to accommodate search bar */
}

/* Custom scrollbar styling for better UX */
.results-list::-webkit-scrollbar,
.friends-list::-webkit-scrollbar,
.requests-list::-webkit-scrollbar,
.section-content::-webkit-scrollbar {
  width: 6px;
}

.results-list::-webkit-scrollbar-track,
.friends-list::-webkit-scrollbar-track,
.requests-list::-webkit-scrollbar-track,
.section-content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.results-list::-webkit-scrollbar-thumb,
.friends-list::-webkit-scrollbar-thumb,
.requests-list::-webkit-scrollbar-thumb,
.section-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.4);
  border-radius: 3px;
}

.results-list::-webkit-scrollbar-thumb:hover,
.friends-list::-webkit-scrollbar-thumb:hover,
.requests-list::-webkit-scrollbar-thumb:hover,
.section-content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.6);
}

/* Scroll fade indicators */
.results-list,
.friends-list,
.requests-list {
  position: relative;
}

.results-list::after,
.friends-list::after,
.requests-list::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 6px; /* Account for scrollbar width */
  height: 20px;
  background: linear-gradient(transparent, rgba(255, 255, 255, 0.3));
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* Show fade when scrollable */
.results-list[data-scrollable="true"]::after,
.friends-list[data-scrollable="true"]::after,
.requests-list[data-scrollable="true"]::after {
  opacity: 1;
}

.results-list li, .friends-list li, .requests-list li {
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  min-height: 70px; /* Consistent height for 3-line layout */
}

.results-list li:hover, .friends-list li:hover {
  background: #f8f9fa;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border-color: #667eea;
}

.friends-list li {
  border-left: 3px solid transparent;
}

.friends-list li.has-unread {
  border-left: 3px solid #667eea;
  background: #f0f2ff;
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.15);
}

.friends-list li.has-unread .friend-item-avatar {
  border: 2px solid #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.friends-list li.has-unread .friend-item-name {
  color: #1a365d;
  font-weight: 700;
}

.friends-list li.has-unread .friend-item-status {
  color: #2d3748;
  font-weight: 500;
}

.friends-list li.has-unread .friend-item-time {
  color: #667eea;
  font-weight: 600;
}

.requests-list li {
  border-left: 3px solid #ffc107;
  background: rgba(255, 193, 7, 0.05);
}

.results-list li {
  border-left: 3px solid #28a745;
  background: rgba(40, 167, 69, 0.05);
}

.friend-item-avatar {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.friend-item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Allow text to truncate */
  gap: 2px; /* Small gap between lines */
}

.friend-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.friend-item-name {
  font-weight: 600;
  color: #333;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.friend-item-time {
  font-size: 0.75rem;
  color: #666;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: 8px;
}

.friend-item-status {
  font-size: 0.85rem;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  margin-top: 2px;
}

.unread-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 4px 8px;
  border-radius: 12px;
  min-width: 20px;
  text-align: center;
  line-height: 1;
  animation: unreadPulse 2s infinite;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

@keyframes unreadPulse {
  0%, 100% { 
    transform: scale(1); 
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
  }
  50% { 
    transform: scale(1.1); 
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.6);
  }
}

.friend-actions {
  display: flex;
  gap: 8px;
}

.friend-action-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.3s;
}

.request-btn {
  background: #28a745;
  color: white;
}

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

.accept-btn {
  background: #28a745;
  color: white;
}

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

.reject-btn {
  background: #dc3545;
  color: white;
}

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

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #666;
}

.empty-state i {
  font-size: 3rem;
  color: #ccc;
  margin-bottom: 15px;
  display: block;
}

.empty-state p {
  margin: 0;
  font-size: 0.95rem;
}

/* Legacy friend list styles - updated for new design */
#friendList {
  list-style: none;
  padding: 0;
}

#friendList li {
  margin-bottom: 0.5rem;
  background: white;
  padding: 0.5rem;
  border-radius: 0.25rem;
  /* Updated styles handled by .friends-list li */
}

/* Button styles */
button {
  cursor: pointer;
  transition: all 0.3s ease;
}

.message {
  padding: 12px 16px;
  border-radius: 18px;
  margin: 4px 0;
  max-width: 80%;
  display: flex;
  flex-direction: column;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
  animation: messageSlideIn 0.3s ease-out;
}

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

.message.sent {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  margin-left: auto;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.message.received {
  background: white;
  color: #1f2937;
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  margin-right: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 1px solid #e5e7eb;
}

.message.disappearing {
  border: 2px solid #f59e0b;
  animation: disappearingPulse 2s infinite;
}

@keyframes disappearingPulse {
  0%, 100% { 
    border-color: #f59e0b;
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
  }
  50% { 
    border-color: #fbbf24;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
  }
}

.message-sender {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.8;
}

.message-content {
  line-height: 1.4;
  margin-bottom: 4px;
}

.message-time {
  font-size: 0.7rem;
  opacity: 0.7;
  align-self: flex-end;
  margin-top: 4px;
}

.message.sent .message-time {
  color: rgba(255, 255, 255, 0.8);
}

.message.received .message-time {
  color: #6b7280;
}

.message-timer {
  font-size: 0.7rem;
  color: #ef4444;
  font-weight: 600;
  align-self: flex-end;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  background: rgba(239, 68, 68, 0.1);
  border-radius: 10px;
  animation: timerPulse 1s infinite;
}

@keyframes timerPulse {
  0%, 100% { 
    background: rgba(239, 68, 68, 0.1);
    transform: scale(1);
  }
  50% { 
    background: rgba(239, 68, 68, 0.2);
    transform: scale(1.05);
  }
}

.message-timer i {
  font-size: 0.6rem;
}

.disappearing-indicator {
  font-size: 0.7rem;
  color: #f59e0b;
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.disappearing-indicator i {
  animation: timerPulse 2s infinite;
}

/* Profile Section Styles */
#profileEditor {
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  border: 1px solid #e0e0e0;
}

.profile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #f0f0f0;
}

.profile-header h2 {
  margin: 0;
  color: #333;
  font-size: 1.4rem;
}

.profile-toggle-btn {
  background: #4a90e2;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.3s;
}

.profile-toggle-btn:hover {
  background: #357abd;
}

.profile-display {
  display: block;
}

.profile-card {
  display: flex;
  align-items: center;
  background: #f8f9fa;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  border: 1px solid #e9ecef;
}

.profile-avatar-container {
  margin-right: 20px;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #4a90e2;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.profile-info {
  flex: 1;
}

.profile-username {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  font-size: 1.2rem;
  font-weight: bold;
  color: #333;
}

.profile-username i {
  margin-right: 8px;
  color: #4a90e2;
}

.profile-id {
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  color: #666;
}

.profile-id i {
  margin-right: 8px;
  color: #666;
}

.copy-btn {
  background: #28a745;
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 10px;
  font-size: 0.8rem;
  transition: background-color 0.3s;
}

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

.qr-section {
  text-align: center;
  background: #f8f9fa;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #e9ecef;
}

.qr-section h3 {
  margin: 0 0 15px 0;
  color: #333;
  font-size: 1.1rem;
}

.qr-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.profile-edit-form {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #e9ecef;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
  color: #333;
  font-size: 0.95rem;
}

.form-group label i {
  margin-right: 8px;
  color: #4a90e2;
}

.input-container {
  position: relative;
}

.form-group input {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.95rem;
  transition: border-color 0.3s;
  box-sizing: border-box;
}

.form-group input:focus {
  outline: none;
  border-color: #4a90e2;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.status-indicator {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  font-weight: bold;
}

.avatar-preview {
  margin-top: 10px;
  text-align: center;
}

.avatar-preview img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #e0e0e0;
}

/* Avatar Upload Options */
.avatar-upload-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-option {
  display: flex;
  justify-content: center;
}

.upload-avatar-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.upload-avatar-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.upload-divider {
  text-align: center;
  position: relative;
  margin: 8px 0;
}

.upload-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: #e0e0e0;
  z-index: 1;
}

.upload-divider span {
  background: white;
  padding: 0 12px;
  color: #888;
  font-size: 0.8rem;
  position: relative;
  z-index: 2;
}

.url-option input {
  width: 100%;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 25px;
}

.save-btn {
  background: #28a745;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: bold;
  flex: 1;
  transition: background-color 0.3s;
}

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

.cancel-btn {
  background: #6c757d;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: bold;
  flex: 1;
  transition: background-color 0.3s;
}

.cancel-btn:hover {
  background: #5a6268;
}

/* Ultra-mobile support for very small screens */
@media (max-width: 360px) {
  #app {
    padding: 0.25rem;
    gap: 0.25rem;
  }
  
  header {
    padding: 0.5rem 0.75rem;
    margin: 0 -0.25rem;
  }
  
  .header-left h1 {
    font-size: 1.1rem;
  }
  
  #friends, #chat, #profileEditor {
    margin: 0 -0.25rem;
    padding: 8px;
  }
  
  .friends-header h2 {
    font-size: 0.9rem;
  }
  
  .action-btn {
    padding: 4px 6px;
    min-width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }
  
  #chat {
    height: calc(100vh - 380px);
    min-height: 350px;
  }
  
  .input-btn {
    width: 36px;
    height: 36px;
    font-size: 0.8rem;
    min-width: 36px;
    flex-shrink: 0;
  }
  
  #messageInput {
    font-size: 16px !important;
    min-height: 36px;
    max-width: calc(100% - 160px); /* Adjust for smaller buttons */
    padding: 8px 12px;
  }
  
  .input-row {
    gap: 4px;
    min-height: 44px;
  }
  
  .friend-item-avatar {
    width: 32px;
    height: 32px;
  }
  
  .friend-item-name {
    font-size: 0.85rem;
  }
  
  .friend-item-status {
    font-size: 0.7rem;
  }
  
  .message {
    padding: 8px 10px;
    font-size: 0.85rem;
  }
}

/* Responsive Design */
@media (max-width: 480px) {
  #app {
    padding: 0.5rem;
    gap: 0.5rem;
    max-width: 100%;
    margin: 0;
  }
  
  header {
    padding: 0.8rem 1rem;
    margin: 0.1px;
    border-radius: 20px;
  }
  
  .header-left h1 {
    font-size: 1.2rem;
  }
  
  .user-info {
    padding: 5px 8px;
  }
  
  .user-name {
    max-width: 80px;
  }
  
  .user-id {
    max-width: 80px;
  }

  /* Compact friends section like Instagram */
  #friends {
    padding: 12px;
    max-height: 250px;
    overflow-y: auto;
    margin: 0 -0.5rem;
    border-radius: 0;
  }

  .friends-header {
    margin-bottom: 8px;
    padding-bottom: 8px;
  }

  .friends-header h2 {
    font-size: 1rem;
  }

  .btn-text {
    display: none; /* Hide button text on mobile */
  }

  .action-btn {
    padding: 6px 8px;
    min-width: 36px;
    height: 36px;
  }
  
  #chat {
    height: calc(100vh - 420px);
    min-height: 400px;
    margin: 0 -0.5rem;
    border-radius: 0;
  }
  
  .chat-header {
    padding: 10px 12px;
    border-radius: 10px 10px 0 0;
  }

  .chat-friend-avatar {
    width: 32px;
    height: 32px;
  }
  
  .messages-container {
    padding: 8px 12px;
  }
  
  .input-area {
    padding: 10px 12px;
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid #e0e0e0;
    z-index: 10;
  }
  
  .message-controls {
    margin-bottom: 6px;
  }
  
  .disappear-toggle {
    font-size: 0.75rem;
    padding: 4px 8px;
  }

  .input-row {
    gap: 6px;
    padding: 0;
    min-height: 50px; /* Ensure adequate height */
    align-items: stretch; /* Make all elements same height */
  }

  .input-btn {
    width: 40px;
    height: 40px;
    font-size: 0.9rem;
    min-width: 40px; /* Prevent shrinking */
    flex-shrink: 0;
  }

  /* Prevent zoom on input focus - CRITICAL for mobile UX */
  #messageInput {
    font-size: 16px !important;
    min-height: 40px;
    flex: 1;
    max-width: calc(100% - 180px); /* Leave space for 4 buttons */
  }

  /* Compact friend list items like Instagram */
  .results-list li, .friends-list li, .requests-list li {
    padding: 8px 10px;
    min-height: 50px;
    gap: 10px;
  }

  .friend-item-avatar {
    width: 36px;
    height: 36px;
  }

  .friend-item-name {
    font-size: 0.9rem;
  }

  .friend-item-status {
    font-size: 0.75rem;
  }
  
  .message {
    max-width: 90%;
    padding: 10px 12px;
  }

  /* Modal adjustments */
  .modal-content {
    width: 95%;
    margin: 10px auto;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Mobile touch improvements */
  .input-btn:active {
    transform: scale(0.9);
    background-color: rgba(102, 126, 234, 0.8) !important;
    transition: all 0.1s ease;
  }

  .input-btn.secondary:active {
    background-color: rgba(226, 232, 240, 0.8) !important;
    transform: scale(0.9);
  }

  .input-btn.primary:active {
    background-color: rgba(102, 126, 234, 0.9) !important;
    transform: scale(0.9);
  }

  /* Better touch targets */
  .friends-list li, .results-list li, .requests-list li {
    min-height: 56px; /* Minimum touch target size */
  }

  .friend-actions button {
    min-width: 44px;
    min-height: 44px;
  }

  /* Optimize text sizing for mobile */
  .friend-item-info {
    line-height: 1.3;
  }

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

  /* Improve scrolling performance */
  .messages-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  #friends {
    -webkit-overflow-scrolling: touch;
  }
  
  #profileEditor {
    margin: 0 -0.5rem;
    border-radius: 0;
    padding: 12px;
  }
  
  .profile-card {
    flex-direction: column;
    text-align: center;
    padding: 15px;
  }
  
  .profile-avatar-container {
    margin-right: 0;
    margin-bottom: 15px;
  }
  
  .profile-id {
    justify-content: center;
  }
  
  .form-actions {
    flex-direction: column;
  }
  
  .profile-header {
    flex-direction: column;
    gap: 10px;
  }
  
  .link-buttons {
    flex-direction: column;
  }
  
  .modal-content {
    width: 95%;
    margin: 10px;
  }
  
  .friend-info-card {
    flex-direction: column;
    text-align: center;
  }
  
  .friend-avatar {
    margin-right: 0;
    margin-bottom: 10px;
  }
  
  .modal-actions {
    flex-direction: column;
  }
  
  /* Friends section responsive */
  .friends-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  
  .action-btn {
    flex: 1;
    min-width: 100px;
    justify-content: center;
  }
  
  .btn-text {
    display: inline;
  }
  
  .friends-header {
    flex-direction: column;
    gap: 15px;
  }
  
  .section-header {
    padding: 12px 15px;
  }
  
  .section-content {
    padding: 15px;
  }
  
  .search-container {
    flex-direction: column;
  }
  
  .friend-actions {
    flex-direction: column;
    width: 100%;
  }
  
  .results-list li, .friends-list li, .requests-list li {
    flex-direction: column;
    text-align: center;
    gap: 10px;
  }
  
  .friend-item-avatar {
    width: 40px;
    height: 40px;
  }
  
  .unread-badge {
    top: 8px;
    right: 8px;
    font-size: 0.65rem;
    padding: 3px 6px;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  #app {
    max-width: 600px;
    padding: 1rem;
  }
  
  .btn-text {
    display: inline;
  }
  
  .action-btn {
    padding: 10px 15px;
  }
  
  #chat {
    height: 600px;
  }
  
  .friends-header {
    flex-direction: row;
  }
  
  .friends-actions {
    flex-wrap: nowrap;
  }
}

/* Desktop responsive styles */
@media (min-width: 769px) {
  #app {
    max-width: 500px;
    padding: 1rem;
  }
  
  .btn-text {
    display: inline !important;
  }
  
  .action-btn {
    padding: 8px 12px;
  }
  
  #friends {
    max-height: 400px;
    padding: 16px;
  }
  
  #chat {
    height: 650px;
  }
  
  header {
    border-radius: 12px;
  }
  
  #friends, #chat, #profileEditor {
    border-radius: 12px;
  }
}

/* Animation for smooth transitions */
.profile-display, .profile-edit-form {
  transition: opacity 0.3s ease-in-out;
}

.status-indicator {
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Enhanced button styles */
.copy-btn:active {
  transform: scale(0.95);
}

.save-btn:active, .cancel-btn:active, .profile-toggle-btn:active {
  transform: scale(0.98);
}

/* QR Code and Link Sharing Styles */
.qr-description {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 15px;
}

.share-link-container {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#friendLinkInput {
  width: 100%;
  padding: 10px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.85rem;
  background: #f8f9fa;
  box-sizing: border-box;
  text-align: center;
}

.link-buttons {
  display: flex;
  gap: 10px;
}

.copy-link-btn, .share-link-btn {
  flex: 1;
  padding: 10px 15px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: bold;
  transition: all 0.3s;
}

.copy-link-btn {
  background: #17a2b8;
  color: white;
}

.copy-link-btn:hover {
  background: #138496;
}

.share-link-btn {
  background: #28a745;
  color: white;
}

.share-link-btn:hover {
  background: #218838;
}

/* Add Friend Modal Styles */
.add-friend-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 0;
  max-width: 400px;
  width: 90%;
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 16px 16px 0 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.close-modal-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  transition: background 0.3s;
}

.close-modal-btn:hover {
  background: rgba(255,255,255,0.2);
}

.modal-body {
  padding: 20px;
}

.friend-info-card {
  display: flex;
  align-items: center;
  background: #f8f9fa;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  border: 1px solid #e9ecef;
}

.friend-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #4a90e2;
  margin-right: 15px;
}

.friend-details h3 {
  margin: 0 0 5px 0;
  color: #333;
  font-size: 1.1rem;
}

.friend-details p {
  margin: 0;
  color: #666;
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.add-friend-btn {
  background: #28a745;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: bold;
  flex: 1;
  transition: background-color 0.3s;
}

.add-friend-btn:hover {
  background: #218838;
}

.cancel-add-btn {
  background: #6c757d;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: bold;
  flex: 1;
  transition: background-color 0.3s;
}

.cancel-add-btn:hover {
  background: #5a6268;
}

/* Voice Recording Modal Styles */
.voice-recorder {
  text-align: center;
  padding: 20px;
}

.voice-status {
  font-size: 1.1rem;
  color: #333;
  margin-bottom: 15px;
  font-weight: 500;
}

.recording-time {
  font-size: 2rem;
  color: #dc3545;
  font-weight: bold;
  margin: 15px 0;
  font-family: 'Courier New', monospace;
}

.voice-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 20px 0;
}

.voice-control-btn {
  padding: 12px 20px;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.voice-control-btn.start {
  background: linear-gradient(135deg, #28a745, #20c997);
  color: white;
}

.voice-control-btn.start:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(40, 167, 69, 0.4);
}

.voice-control-btn.stop {
  background: linear-gradient(135deg, #dc3545, #c82333);
  color: white;
  animation: recordingPulse 1.5s infinite;
}

@keyframes recordingPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 2px 10px rgba(220, 53, 69, 0.3); }
  50% { transform: scale(1.05); box-shadow: 0 4px 20px rgba(220, 53, 69, 0.6); }
}

.voice-control-btn.play {
  background: linear-gradient(135deg, #007bff, #0056b3);
  color: white;
}

.voice-control-btn.play:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 123, 255, 0.4);
}

/* File Upload Progress Styles */
.upload-progress {
  text-align: center;
  padding: 20px;
}

.upload-file-name {
  font-size: 1.1rem;
  color: #333;
  margin-bottom: 20px;
  word-break: break-all;
}

.progress-bar {
  width: 100%;
  height: 10px;
  background: #e9ecef;
  border-radius: 5px;
  overflow: hidden;
  margin: 15px 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(135deg, #28a745, #20c997);
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 5px;
}

.upload-percentage {
  font-size: 1.2rem;
  font-weight: bold;
  color: #28a745;
}

/* Message type styles */
.message.voice {
  background: linear-gradient(135deg, #e3f2fd, #bbdefb);
}

.message.file {
  background: linear-gradient(135deg, #f3e5f5, #e1bee7);
}

.message.image {
  background: linear-gradient(135deg, #e8f5e8, #c8e6c9);
}

.message-content.voice {
  display: flex;
  align-items: center;
  gap: 10px;
}

.voice-player {
  width: 100%;
  max-width: 300px;
}

.file-attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  margin: 5px 0;
}

.file-icon {
  font-size: 2rem;
  color: #667eea;
}

.file-info {
  flex: 1;
}

.file-name {
  font-weight: 600;
  color: #333;
  margin-bottom: 2px;
}

.file-size {
  font-size: 0.8rem;
  color: #666;
}

.file-download {
  background: #667eea;
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.file-download:hover {
  background: #5a6fd8;
  transform: translateY(-1px);
}

.image-attachment {
  max-width: 300px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.image-attachment:hover {
  transform: scale(1.02);
}

/* Desktop responsive styles */
@media (min-width: 768px) {
  #app {
    max-width: 600px;
  }
  
  .btn-text {
    display: inline !important;
  }
  
  .action-btn {
    padding: 8px 12px;
  }
  
  #friends {
    max-height: 400px;
  }
  
  #chat {
    height: 650px;
  }
}