/* ===== BASE STYLES ===== */
:root {
  --primary-color: #4a7baa;
  --primary-hover: #3a6b9a;
  --online-color: #48bb78;
  --offline-color: #a0aec0;
  --text-dark: #2d3748;
  --text-light: #718096;
  --bg-light: #f7fafc;
  --border-color: #e1e5eb;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Nunito', sans-serif;
}

body {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background-color: var(--bg-light);
}

/* ===== HEADER & LOGOUT ===== */
header {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1000;
  padding: 15px;
}

.logout-container {
  display: flex;
  justify-content: flex-end;
}

.logout-btn {
  padding: 8px 16px;
  border-radius: 20px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.logout-btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-2px);
}

/* ===== APP LAYOUT ===== */
.chat-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 300px;
  height: 100vh;
  background: white;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.app-brand {
  display: flex;
  align-items: center;
  padding: 15px;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
}

.app-icon {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.search-container {
  padding: 15px;
  position: relative;
  border-bottom: 1px solid var(--border-color);
}

.search-container i {
  position: absolute;
  left: 25px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

#search-conversations {
  width: 100%;
  padding: 10px 15px 10px 35px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  font-size: 14px;
  transition: all 0.3s;
}

#search-conversations:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(74, 123, 170, 0.2);
}

.contacts-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 15px;
  border-bottom: 1px solid var(--border-color);
}

.contacts-section h3 {
  margin-bottom: 10px;
  color: var(--text-dark);
  font-size: 14px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}



.contacts-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 90px;
  margin-bottom: 0;
}




.contact-item {
  display: flex;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  margin: 2px 0;
  transition: background-color 0.2s;
}

.contact-item:hover {
  background-color: #ebf4ff;
}

.contact-item.active {
  background-color: #e2e8f0;
}

.contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #cbd5e0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  color: var(--text-dark);
  font-weight: bold;
}

.contact-info {
  flex: 1;
  min-width: 0;
}

.contact-name {
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-last-message {
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-left: auto;
}

.status-online {
  background-color: #48bb78;
  box-shadow: 0 0 0 2px white, 0 0 0 4px #48bb78;
  animation: pulse 1.5s infinite;
}

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

.status-offline {
  background-color: #a0aec0;
}

/* ===== CHAT AREA ===== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: var(--bg-light);
  position: relative;
}

.chat-header {
  padding: 15px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: white;
  position: sticky;
  top: 0;
  z-index: 5;
}

.user-info {
  display: flex;
  flex-direction: column;
}

#current-chat-name {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

#current-user {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

#chat-status {
  font-size: 12px;
  color: var(--text-light);
}

.messages-container {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  padding-bottom: 80px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-light);
  text-align: center;
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 15px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 16px;
  margin: 0;
  max-width: 300px;
  line-height: 1.5;
}

/* ===== MESSAGES ===== */
.message {
  margin-bottom: 15px;
  max-width: 75%;
  animation: fadeIn 0.3s ease-out;
}

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

.message-sent {
  margin-left: auto;
  text-align: right;
}

.message-received {
  margin-right: auto;
  text-align: left;
}

.message-content {
  display: inline-block;
  padding: 10px 15px;
  border-radius: 18px;
  font-size: 14px;
  word-break: break-word;
  line-height: 1.4;
}

.message-sent .message-content {
  background-color: var(--primary-color);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-received .message-content {
  background-color: #e2e8f0;
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-dark);
}

.message-sent .message-sender {
  color: #ebf8ff;
}

.message-time {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
  opacity: 0.8;
}

/* ===== MESSAGE INPUT ===== */
.message-input-container {
  position: fixed;
  bottom: 0;
  left: 300px;
  right: 0;
  padding: 15px;
  background-color: white;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  z-index: 10;
}

#message-input {
  flex: 1;
  padding: 12px 15px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  margin-right: 10px;
  font-size: 14px;
  transition: border-color 0.3s;
}

#message-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

#send-button {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

#send-button:hover {
  background-color: var(--primary-hover);
  transform: scale(1.05);
}

#send-button:disabled {
  background-color: var(--text-light);
  cursor: not-allowed;
}

/* ===== MODALS ===== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.3s ease-out;
}

.modal.show {
  display: flex;
}

.modal-content {
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background-color: white;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  transform: translateY(20px);
  transition: transform 0.3s ease-out;
}

.modal.show .modal-content {
  transform: translateY(0);
}

.modal-header {
  padding: 24px 24px 16px;
  position: relative;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}

.modal-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: var(--text-dark);
  text-align: center;
}

.close-modal {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.close-modal:hover {
  background: #e2e8f0;
  transform: rotate(90deg);
}

.close-modal::before {
  content: '×';
  font-size: 24px;
  color: var(--text-light);
}

.modal-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
}

.modal-option-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 18px 20px;
  border: none;
  border-radius: 12px;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  text-align: left;
  position: relative;
  overflow: hidden;
}

.modal-option-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary-color);
  transition: width 0.3s ease;
}

.modal-option-btn:hover {
  transform: translateX(4px);
  background: #f1f5f9;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.modal-option-btn:hover::before {
  width: 8px;
}

.modal-option-btn i {
  font-size: 24px;
  color: var(--primary-color);
  min-width: 24px;
  transition: transform 0.3s ease;
}

.modal-option-btn:hover i {
  transform: scale(1.1);
}

.modal-option-btn div {
  flex: 1;
}

.modal-option-btn h4 {
  margin: 0 0 4px 0;
  color: var(--text-dark);
  font-size: 16px;
  font-weight: 700;
}

.modal-option-btn p {
  margin: 0;
  color: var(--text-light);
  font-size: 14px;
  line-height: 1.4;
}

/* Add Users Modal Specific Styles */
#add-users-modal .modal-content {
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}

.search-users-container {
  position: relative;
  padding: 0 24px 16px;
}

.search-users-container i {
  position: absolute;
  left: 36px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  z-index: 1;
}

#search-users {
  width: 100%;
  padding: 14px 20px 14px 44px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  font-size: 14px;
  background: #f8fafc;
  transition: all 0.3s ease;
}

#search-users:focus {
  outline: none;
  border-color: var(--primary-color);
  background: white;
  box-shadow: 0 0 0 3px rgba(74, 123, 170, 0.2);
}

.user-selection {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px;
  margin: 8px 0;
}

.user-selection-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  transition: background 0.2s ease;
}

.user-selection-item:last-child {
  border-bottom: none;
}

.user-selection-item:hover {
  background: rgba(0,0,0,0.02);
}

.user-selection-item input[type="radio"],
.user-selection-item input[type="checkbox"] {
  margin-right: 12px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid rgba(0,0,0,0.1);
}

.modal-footer button {
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

#cancel-add-users {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-dark);
}

#cancel-add-users:hover {
  background: #f1f5f9;
}

#confirm-add-users {
  background: linear-gradient(135deg, var(--primary-color), #5d93c7);
  color: white;
  border: none;
  box-shadow: 0 2px 8px rgba(74, 123, 170, 0.3);
}

#confirm-add-users:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(74, 123, 170, 0.4);
}

/* New Chat Button Styling */
.new-chat-btn {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 40px);
  max-width: 260px;
  height: 56px;
  margin: 0;
  padding: 0 24px;
  background: linear-gradient(135deg, var(--primary-color), #5d93c7);
  color: white;
  border: none;
  border-radius: 28px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: 0 4px 16px rgba(74, 123, 170, 0.3);
  transition: all 0.3s ease;
  z-index: 100;
}

.new-chat-btn:hover {
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 0 6px 20px rgba(74, 123, 170, 0.4);
}

.new-chat-btn i {
  font-size: 20px;
  transition: transform 0.3s ease;
}

.new-chat-btn:hover i {
  transform: scale(1.1);
}

.contact-avatar-small {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: #cbd5e0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  color: var(--text-dark);
  font-weight: bold;
  font-size: 12px;
}

.contact-status-text {
  font-size: 12px;
  color: var(--text-light);
}

.no-contacts {
  padding: 20px;
  text-align: center;
  color: var(--text-light);
}

/* ===== SCROLLBARS ===== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

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

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

/* ===== RESPONSIVE DESIGN ===== */
@media screen and (max-width: 768px) {
  .chat-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .chat-area {
    height: calc(100vh - 300px); /* approximate sidebar height */
  }

  .message-input-container {
    left: 0;
    right: 0;
    width: 100%;
  }

  .new-chat-btn {
    position: fixed;
    left: 5%;
    bottom: 16px;
    width: 90%;
    max-width: none;
    transform: none;
  }
}

@media screen and (max-width: 480px) {
  .contact-avatar {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .contact-name {
    font-size: 14px;
  }

  .contact-last-message {
    font-size: 11px;
  }

  .modal-content {
    width: 95%;
    max-width: none;
  }
}
