/* pm.css */
.pm-layout {
  display: flex;
  height: calc(100vh - 120px);
  border: 1px solid #000;
  background: #fff;
}

.pm-sidebar {
  width: 300px;
  border-right: 1px solid #000;
  display: flex;
  flex-direction: column;
  background: #f9f9f9;
}

.pm-sidebar-header {
  padding: 15px;
  border-bottom: 1px solid #000;
}

.new-message-btn {
  width: 100%;
  padding: 10px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
}

.new-message-btn:hover {
  background: #333;
}

.search-users-container {
  margin-top: 10px;
}

#userSearchInput {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #000;
  border-radius: 30px;
  font-size: 14px;
}

.search-results {
  position: absolute;
  width: 270px;
  max-height: 300px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #000;
  border-radius: 8px;
  margin-top: 5px;
  z-index: 100;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.search-result-item:hover {
  background: #f0f0f0;
}

.search-result-item img {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #000;
}

.search-result-item .avatar-placeholder {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  background: #000;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background 0.2s ease;
  position: relative;
}

.conversation-item:hover {
  background: #f0f0f0;
}

.conversation-item.active {
  background: #e3f2fd;
  border-left: 3px solid #000;
}

.conversation-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #000;
}

.conversation-avatar-placeholder {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #000;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  border: 1px solid #000;
}

.conversation-info {
  flex: 1;
  overflow: hidden;
}

.conversation-name {
  font-weight: 600;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-last-message {
  font-size: 0.85rem;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-time {
  font-size: 0.7rem;
  color: #999;
  position: absolute;
  top: 15px;
  right: 15px;
}

.unread-badge {
  position: absolute;
  bottom: 15px;
  right: 15px;
  background: #4caf50;
  color: #fff;
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
}

.pm-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.no-chat-selected {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 1.1rem;
}

#activeChat {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  padding: 15px 20px;
  border-bottom: 1px solid #000;
  background: #f9f9f9;
  display: flex;
  align-items: center;
  gap: 15px;
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #000;
}

.chat-header-info h3 {
  font-size: 1.2rem;
  font-weight: 500;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f5f5f5;
}

.message {
  max-width: 70%;
  padding: 10px 15px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
}

.message.own {
  align-self: flex-end;
  background: #e3f2fd;
  border-bottom-right-radius: 4px;
}

.message.other {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #ddd;
  border-bottom-left-radius: 4px;
}

.message-image {
  max-width: 300px;
  max-height: 200px;
  border-radius: 8px;
  margin: 5px 0;
  cursor: pointer;
  transition: transform 0.2s ease;
  border: 1px solid #ddd;
}

.message-image:hover {
  transform: scale(1.02);
}

.message-text {
  line-height: 1.5;
  white-space: pre-wrap;
}

.message-time {
  font-size: 0.7rem;
  color: #999;
  margin-top: 5px;
  text-align: right;
}

.message.edited::after {
  content: ' (ред.)';
  font-size: 0.7rem;
  color: #999;
  margin-left: 5px;
}

.message-input-area {
  display: flex;
  gap: 10px;
  padding: 15px;
  border-top: 1px solid #000;
  background: #fff;
  align-items: flex-end;
}

#messageInput {
  flex: 1;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 30px;
  resize: none;
  font-family: 'Geologica', sans-serif;
  font-size: 14px;
  min-height: 45px;
  max-height: 120px;
  overflow-y: auto;
}

#messageInput:focus {
  outline: none;
  border-color: #000;
}

.attach-btn, .send-btn {
  padding: 10px 5px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
  height: 45px;
  white-space: nowrap;
}

.attach-btn {
  background: #fff;
  color: #000;
  border: 1px solid #000;
  padding: 11px;
}

.attach-btn:hover {
  background: #000;
  color: #fff;
}

.send-btn:hover {
  background: #333;
}

.image-preview {
  padding: 10px 15px;
  background: #f0f0f0;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  gap: 10px;
}

.image-preview img {
  max-height: 60px;
  max-width: 60px;
  border-radius: 4px;
  border: 1px solid #000;
}

.remove-image {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #f44336;
  padding: 0 5px;
}

/* Модальное окно для фото */
.image-modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.9);
  align-items: center;
  justify-content: center;
}

.image-modal.show {
  display: flex;
}

.modal-content {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  border: 2px solid #fff;
  border-radius: 4px;
}

.close-modal {
  position: absolute;
  top: 20px;
  right: 30px;
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s ease;
}

.close-modal:hover {
  color: #ccc;
}

/* Контекстное меню */
.context-menu {
  position: absolute;
  background: #fff;
  border: 1px solid #000;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  z-index: 1000;
  min-width: 150px;
}

.context-menu ul {
  list-style: none;
  margin: 0;
  padding: 5px 0;
}

.context-menu li {
  padding: 10px 15px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.context-menu li:hover {
  background: #f0f0f0;
}

.context-menu li.delete:hover {
  color: #f44336;
}

/* Адаптация для мобильных */
@media (max-width: 768px) {
  .pm-layout {
    flex-direction: column;
    height: auto;
  }
  
  .pm-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #000;
    max-height: 250px;
  }
  
  .message {
    max-width: 85%;
  }
  
  .message-image {
    max-width: 200px;
    max-height: 150px;
  }
}

.no-messages {
  text-align: center;
  padding: 40px;
  color: #999;
  font-style: italic;
  background: #f9f9f9;
  border-radius: 8px;
  margin: 20px;
}

/* Адаптация для мобильных устройств */
@media (max-width: 768px) {
  .pm-layout {
    flex-direction: column;
    height: calc(100vh - 120px); /* Учитываем высоту header */
    min-height: 500px;
  }
}

@media (max-width: 480px) {
  .pm-layout {
    height: calc(100vh - 100px);
    min-height: 400px;
  }
}

@media (max-width: 360px) {
  .pm-layout {
    height: calc(100vh - 90px);
    min-height: 350px;
  }
}

/* Для ландшафтной ориентации */
@media (max-width: 768px) and (orientation: landscape) {
  .pm-layout {
    height: calc(100vh - 80px);
    min-height: 300px;
  }
}

.attach-btn svg {
  display: block;
}


.context-menu {
  position: absolute;
  background: #fff;
  border: 1px solid #000;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  z-index: 9999; /* Увеличиваем z-index */
  min-width: 180px;
  max-width: 250px;
  font-size: 14px;
}

.context-menu ul {
  list-style: none;
  margin: 0;
  padding: 5px 0;
}

.context-menu li {
  padding: 10px 15px;
  cursor: pointer;
  transition: background 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.context-menu li:hover {
  background: #f0f0f0;
}

.context-menu li.delete:hover {
  color: #f44336;
}

/* Для мобильных устройств */
@media (max-width: 768px) {
  .context-menu {
    min-width: 160px;
    font-size: 16px; /* Увеличиваем шрифт для touch */
    padding: 8px 0;
  }
  
  .context-menu li {
    padding: 15px 20px; /* Увеличиваем область касания */
  }
}

@media (max-width: 480px) {
  .context-menu {
    min-width: 150px;
    font-size: 15px;
  }
  
  .context-menu li {
    padding: 14px 18px;
  }
}