* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background-color: #e5e7eb;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: #f9fafb;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  margin-top: 16px;
}

h1 {
  margin: 0;
  margin-bottom: 12px;
  font-size: 24px;
  font-weight: 600;
  text-align: center;
}

h2 {
  margin: 0 0 12px 0;
  font-size: 20px;
  font-weight: 600;
}

label {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  margin-bottom: 12px;
}

textarea {
  resize: vertical;
  min-height: 60px;
  max-height: 160px;
}

button {
  padding: 10px 16px;
  font-size: 16px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  background-color: #1d4ed8;
  color: #ffffff;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: #1d4ed8;
  text-decoration: underline;
  cursor: pointer;
}

.link-button:focus {
  outline: none;
}

.muted {
  font-size: 13px;
  color: #6b7280;
}

.error {
  color: #b91c1c;
  font-size: 14px;
  margin-bottom: 8px;
}

.success {
  color: #166534;
  font-size: 14px;
  margin-bottom: 8px;
}

.hidden {
  display: none;
}

/* Кнопка-обёртка для большого аватара в шапке чата */

.avatar-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.avatar-button:focus {
  outline: none;
}

/* Шапка пользователя и кнопка Выйти */

.chat-header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

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

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: #d1d5db;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

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

.chat-user-name {
  font-weight: 600;
  font-size: 16px;
}

.logout-button {
  background-color: #4b5563;
  color: #ffffff;
  padding: 8px 16px;
  font-size: 15px;
  border-radius: 9999px;
  flex-shrink: 0;
}

/* Область чата */

.chat-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
}

.chat-messages {
  flex: 1;
  margin-top: 8px;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  overflow-y: auto;
}

.message-row {
  display: flex;
  align-items: flex-start;
  margin-bottom: 8px;
}

.message-row.own {
  justify-content: flex-end;
}

.message-row.other {
  justify-content: flex-start;
}

/* Мини-аватар в сообщениях (клик для звонка) */

.message-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-right: 8px;
  text-decoration: none;
  flex-shrink: 0;
  cursor: default; /* было pointer */
}

.message-avatar-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: #e5e7eb;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #374151;
}

.message-avatar-link {
  display: block;
  text-decoration: none;
  cursor: pointer; /* курсор-ладонь только на реальной ссылке tel: */
}

.message-bubble {
  max-width: 70%;
  border-radius: 16px;
  padding: 8px 12px;
  font-size: 15px;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message-bubble.own {
  background-color: #dbeafe;
  text-align: left;
}

.message-bubble.other {
  background-color: #f3f4f6;
  text-align: left;
}

.message-author {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
}

.message-time {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
  text-align: right;
}

/* Ввод сообщения */

.chat-input {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input textarea {
  margin-bottom: 0;
  flex: 1;
}

.chat-footer-note {
  font-size: 12px;
  color: #6b7280;
  text-align: right;
  margin-top: 4px;
}

/* Мобильная адаптация */

@media (max-width: 640px) {
  .chat-layout {
    height: auto;
  }

  .chat-messages {
    max-height: 60vh;
  }

  .chat-input {
    flex-direction: column;
    align-items: stretch;
  }

  #login-button,
  #change-password-button,
  #send-button {
    width: 100%;
  }

  #logout-button {
    width: auto;
    padding-left: 20px;
    padding-right: 20px;
    align-self: flex-end;
  }
}

/* Список участников */

.users-list {
  margin-top: 8px;
  border-top: 1px solid #e5e7eb;
}

.user-row {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #e5e7eb;
}

.user-avatar-small {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: #e5e7eb;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  flex-shrink: 0;
  margin-right: 8px;
}

.user-main {
  flex: 1;
}

.user-name {
  font-weight: 600;
  font-size: 15px;
}

.user-phone {
  font-size: 14px;
  margin-top: 2px;
}

.user-phone a {
  color: #1d4ed8;
  text-decoration: none;
}

.user-phone a:hover {
  text-decoration: underline;
}

.user-status {
  font-size: 12px;
  color: #6b7280;
  margin-left: 8px;
  white-space: nowrap;
}

.user-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  background-color: #9ca3af;
}

.user-status-dot.online {
  background-color: #16a34a;
}

.user-phone-link {
  color: #1d4ed8;
  text-decoration: underline;
  cursor: pointer;
}
