/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  height: 100vh;
  overflow: hidden;
}

/* Utility Classes */
.hidden {
  display: none !important;
}

/* Visually Hidden (Screen Reader Only) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Authentication Styles */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.auth-box {
  background: white;
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.auth-header h1 {
  color: #333;
  margin-bottom: 10px;
  font-size: 2.5rem;
}

.auth-header h1 i {
  color: #667eea;
  margin-right: 10px;
}

.auth-header p {
  color: #666;
  margin-bottom: 30px;
}

.auth-form {
  text-align: left;
}

.auth-form h2 {
  color: #333;
  margin-bottom: 20px;
  text-align: center;
}

.input-group {
  position: relative;
  margin-bottom: 20px;
}

.input-group i {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  z-index: 1;
}

.input-group input {
  width: 100%;
  padding: 15px 15px 15px 45px;
  border: 2px solid #e1e5e9;
  border-radius: 10px;
  font-size: 16px;
  transition: all 0.3s ease;
  background: #f8f9fa;
}

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

.btn-primary {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 20px;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}

.auth-switch {
  text-align: center;
  color: #666;
}

.auth-switch a {
  color: #667eea;
  text-decoration: none;
  font-weight: 600;
}

.auth-switch a:hover {
  text-decoration: underline;
}

/* Main App Container */
.app-container {
  display: flex;
  height: 100vh;
  background: #f5f7fa;
}

/* Sidebar Styles */
.sidebar {
  width: 350px;
  background: white;
  border-right: 1px solid #e1e5e9;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

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

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

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

.user-details h3 {
  font-size: 16px;
  margin-bottom: 2px;
}

.user-details .status-online {
  font-size: 12px;
  color: #4ade80;
}

.btn-icon {
  background: none;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.3s ease;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Search Container */
.search-container {
  padding: 15px 20px;
  border-bottom: 1px solid #e1e5e9;
}

.search-box {
  position: relative;
}

.search-box i {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
}

.search-box input {
  width: 100%;
  padding: 12px 15px 12px 40px;
  border: 1px solid #e1e5e9;
  border-radius: 25px;
  font-size: 14px;
  background: #f8f9fa;
  transition: all 0.3s ease;
}

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

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  border-bottom: 1px solid #e1e5e9;
}

.nav-tab {
  flex: 1;
  padding: 15px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: #666;
  transition: all 0.3s ease;
  position: relative;
  min-height: 60px;
}

.nav-tab i {
  font-size: 18px;
}

.nav-tab span {
  font-size: 12px;
  font-weight: 500;
}

.nav-tab.active {
  color: #667eea;
  background: rgba(102, 126, 234, 0.1);
}

.nav-tab.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: #667eea;
}

.badge {
  background: #ef4444;
  color: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  position: absolute;
  top: 5px;
  right: 5px;
}

/* Sidebar Content */
.sidebar-content {
  flex: 1;
  overflow: hidden;
}

.content-area {
  display: none;
  height: 100%;
  flex-direction: column;
}

.content-area.active {
  display: flex;
}

.list-header {
  padding: 15px 20px;
  border-bottom: 1px solid #e1e5e9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8f9fa;
}

.list-header h3 {
  color: #333;
  font-size: 16px;
}

.list-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

/* Chat/Friend Item Styles */
.chat-item,
.friend-item,
.request-item {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-bottom: 1px solid #f1f3f4;
  min-height: 70px;
}

.chat-item:hover,
.friend-item:hover,
.request-item:hover {
  background: #f8f9fa;
}

.chat-item.active {
  background: rgba(102, 126, 234, 0.1);
  border-left: 3px solid #667eea;
}

.chat-item .avatar,
.friend-item .avatar,
.request-item .avatar {
  width: 45px;
  height: 45px;
  margin-right: 12px;
  flex-shrink: 0;
}

.chat-info,
.friend-info,
.request-info {
  flex: 1;
  min-width: 0;
}

.chat-info h4,
.friend-info h4,
.request-info h4 {
  color: #333;
  font-size: 14px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-info p,
.friend-info p,
.request-info p {
  color: #666;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-meta,
.friend-meta,
.request-meta {
  text-align: right;
  margin-left: 10px;
  flex-shrink: 0;
}

.chat-meta .time,
.friend-meta .status,
.request-meta .time {
  font-size: 11px;
  color: #999;
  margin-bottom: 4px;
}

.chat-meta .unread-count {
  background: #667eea;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  margin: 0 auto;
}

.request-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn-accept,
.btn-decline {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  min-height: 36px;
  min-width: 60px;
}

.btn-accept {
  background: #10b981;
  color: white;
}

.btn-decline {
  background: #ef4444;
  color: white;
}

.btn-accept:hover,
.btn-decline:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Main Chat Area */
.main-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
}

.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #666;
  padding: 20px;
}

.welcome-content i {
  font-size: 4rem;
  color: #667eea;
  margin-bottom: 20px;
}

.welcome-content h2 {
  font-size: 2rem;
  margin-bottom: 10px;
  color: #333;
}

/* Chat Interface */
.chat-interface {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 20px;
  border-bottom: 1px solid #e1e5e9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8f9fa;
}

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

.chat-user-details h3 {
  color: #333;
  font-size: 18px;
  margin-bottom: 2px;
}

.chat-actions {
  display: flex;
  gap: 10px;
}

/* Messages Container */
.messages-container {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: #f8f9fa;
}

.message {
  margin-bottom: 20px;
  display: flex;
  align-items: flex-end;
}

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

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

.message-content {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
}

.message.sent .message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.received .message-content {
  background: white;
  color: #333;
  border: 1px solid #e1e5e9;
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.7;
}

.message.sent .message-time {
  text-align: right;
}

/* Message Input */
.message-input-container {
  padding: 20px;
  border-top: 1px solid #e1e5e9;
  background: white;
  display: flex;
  align-items: center;
  gap: 10px;
}

.message-input-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8f9fa;
  border-radius: 25px;
  padding: 8px 16px;
  border: 1px solid #e1e5e9;
}

.message-input-wrapper:focus-within {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#file-upload-btn {
  background: none;
  border: none;
  font-size: 1.3em;
  cursor: pointer;
  margin-right: 8px;
  color: #667eea;
  display: flex;
  align-items: center;
  justify-content: center;
}

#file-upload-btn i {
  font-size: 1.3em;
  color: #667eea;
}

#file-upload-btn:hover {
  background: rgba(102, 126, 234, 0.1);
}

#message-input {
  flex: 1;
  border: none;
  background: #f8f9fa;
  padding: 12px 16px;
  font-size: 14px;
  outline: none;
  min-height: 36px;
  border-radius: 18px;
  transition: box-shadow 0.2s;
  box-shadow: 0 1px 2px rgba(102, 126, 234, 0.04);
}

#message-input:focus {
  background: white;
  box-shadow: 0 0 0 2px #667eea33;
}

#send-message-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 18px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  box-shadow: 0 1px 2px rgba(102, 126, 234, 0.08);
  margin-left: 4px;
}

#send-message-btn:hover {
  background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

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

.modal-content {
  background: white;
  border-radius: 15px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid #e1e5e9;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  color: #333;
  font-size: 18px;
}

.modal-body {
  padding: 20px;
}

/* Loading Spinner */
.loading-spinner {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Status Indicators */
.status-online {
  color: #10b981;
}

.status-offline {
  color: #6b7280;
}

.status-away {
  color: #f59e0b;
}

/* Mobile Header - Hidden by default on desktop */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-bottom: 1px solid #e1e5e9;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: 70px;
  box-sizing: border-box;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.3s ease;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

.mobile-menu-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

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

.mobile-user-info h3 {
  font-size: 16px;
  margin-bottom: 2px;
}

/* Profile and Group Modal Styles */
.profile-modal-avatar-preview,
.group-modal-avatar-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0 auto 16px auto;
}

.profile-modal-center,
.group-modal-center {
  text-align: center;
  margin-bottom: 16px;
}

#profile-avatar-input,
#group-avatar-input {
  display: none;
}

.profile-modal-btn,
.group-modal-btn {
  margin-top: 8px;
}

#save-profile-btn,
#save-group-btn {
  width: 100%;
  margin-top: 12px;
}

/* File Input Styles */
#file-input {
  display: none;
}

#file-upload-btn {
  background: none;
  border: none;
  font-size: 1.3em;
  cursor: pointer;
  margin-right: 8px;
  color: #667eea;
  display: flex;
  align-items: center;
  justify-content: center;
}

#file-upload-btn:hover {
  background: rgba(102, 126, 234, 0.1);
}

/* Responsive Design */
@media (max-width: 768px) {
  /* Auth Container */
  .auth-container {
    padding: 10px;
  }

  .auth-box {
    padding: 30px 20px;
    border-radius: 15px;
  }

  .auth-header h1 {
    font-size: 2rem;
  }

  /* Main App Layout */
  .app-container {
    flex-direction: column;
  }

  /* Show mobile header on mobile */
  .mobile-header {
    display: flex;
  }

  .mobile-menu-btn {
    display: flex;
  }

  /* Sidebar */
  .sidebar {
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Add backdrop when sidebar is open */
  .sidebar.open::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }

  /* Hide desktop sidebar header on mobile */
  .sidebar-header {
    display: none;
  }

  /* Main Chat Area */
  .main-chat {
    width: 100%;
    height: calc(100vh - 70px); /* Subtract mobile header height */
    margin-top: 70px; /* Add margin for mobile header */
  }

  /* Chat Header */
  .chat-header {
    padding: 15px 20px;
  }

  .chat-user-details h3 {
    font-size: 16px;
  }

  /* Messages */
  .messages-container {
    padding: 15px;
  }

  .message-content {
    max-width: 85%;
    padding: 10px 14px;
  }

  /* Message Input */
  .message-input-container {
    padding: 15px;
  }

  .message-input-wrapper {
    padding: 6px 12px;
  }

  /* Navigation Tabs */
  .nav-tab {
    padding: 12px 8px;
    min-height: 50px;
  }

  .nav-tab i {
    font-size: 16px;
  }

  .nav-tab span {
    font-size: 11px;
  }

  /* Chat/Friend Items */
  .chat-item,
  .friend-item,
  .request-item {
    padding: 12px 15px;
    min-height: 60px;
  }

  .chat-item .avatar,
  .friend-item .avatar,
  .request-item .avatar {
    width: 40px;
    height: 40px;
    margin-right: 10px;
  }

  /* Modal */
  .modal {
    padding: 10px;
  }

  .modal-content {
    border-radius: 10px;
  }

  .modal-header,
  .modal-body {
    padding: 15px;
  }

  /* Welcome Screen */
  .welcome-content i {
    font-size: 3rem;
  }

  .welcome-content h2 {
    font-size: 1.5rem;
  }

  /* Buttons */
  .btn-accept,
  .btn-decline {
    padding: 10px 20px;
    min-height: 40px;
    min-width: 70px;
    font-size: 14px;
  }

  /* Ensure proper touch targets */
  .btn-icon,
  .nav-tab,
  .mobile-menu-btn {
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
  }

  /* Improve scrolling on mobile */
  .messages-container,
  .list-container {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Prevent zoom on input focus */
  input[type="text"],
  input[type="email"],
  input[type="password"] {
    font-size: 16px;
  }

  /* Better spacing for mobile */
  .chat-item,
  .friend-item,
  .request-item {
    padding: 12px 15px;
  }

  /* Ensure modal is properly sized on mobile */
  .modal {
    padding: 10px;
  }

  .modal-content {
    max-width: 95%;
    margin: 0 auto;
  }
}

@media (max-width: 480px) {
  /* Auth */
  .auth-box {
    padding: 25px 15px;
  }

  .auth-header h1 {
    font-size: 1.8rem;
  }

  .input-group input {
    padding: 12px 12px 12px 40px;
    font-size: 16px; /* Prevents zoom on iOS */
  }

  /* Chat Header */
  .chat-header {
    padding: 12px 15px;
  }

  .chat-actions {
    gap: 5px;
  }

  /* Messages */
  .messages-container {
    padding: 10px;
  }

  .message-content {
    max-width: 90%;
    padding: 8px 12px;
  }

  /* Message Input */
  .message-input-container {
    padding: 12px;
  }

  /* Navigation */
  .nav-tab {
    padding: 10px 6px;
  }

  .nav-tab span {
    font-size: 10px;
  }

  /* Items */
  .chat-item,
  .friend-item,
  .request-item {
    padding: 10px 12px;
  }

  .chat-item .avatar,
  .friend-item .avatar,
  .request-item .avatar {
    width: 35px;
    height: 35px;
  }

  /* Modal */
  .modal-header,
  .modal-body {
    padding: 12px;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .btn-icon {
    min-width: 48px;
    min-height: 48px;
  }

  .nav-tab {
    min-height: 60px;
  }

  .chat-item,
  .friend-item,
  .request-item {
    min-height: 70px;
  }

  .btn-accept,
  .btn-decline {
    min-height: 44px;
    min-width: 80px;
  }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .auth-container {
    padding: 5px;
  }

  .auth-box {
    padding: 20px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .sidebar {
    width: 80%;
    max-width: 300px;
  }

  .main-chat {
    height: calc(100vh - 60px);
    margin-top: 60px;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .avatar {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Animation Classes */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

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

.slide-in {
  animation: slideIn 0.3s ease-out;
}

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

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

.empty-state p {
  font-size: 14px;
  margin-top: 10px;
}

#group-friend-list {
  max-height: 200px;
  overflow: auto;
  margin-bottom: 12px;
}
