* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #d7e3ec;
  color: #17212b;
}

/* ==================== Авторизация ==================== */

#authPage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #d7e3ec;
}

.auth-box {
  width: 360px;
  padding: 35px 30px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px #0002;
  text-align: center;
}

.auth-box h1 {
  margin-top: 0;
  margin-bottom: 25px;
  color: #229ed9;
}

.auth-box input {
  width: 100%;
  padding: 13px;
  margin-bottom: 12px;
  border: 1px solid #d7dde3;
  border-radius: 8px;
  font-size: 15px;
  outline: none;
}

.auth-box input:focus {
  border-color: #229ed9;
}

.auth-box button {
  width: 100%;
  margin-bottom: 10px;
  padding: 13px;
  border: none;
  border-radius: 8px;
  background: #229ed9;
  color: white;
  font-size: 15px;
  cursor: pointer;
}

.auth-box button:hover {
  background: #168ac0;
}

#authError {
  min-height: 20px;
  color: #e53935;
}

/* ==================== Основное окно ==================== */

#chatPage {
  height: 100vh;
  display: flex;
  background: white;
}

/* Левая панель */

#chatPage aside.sidebar {
  width: 330px;
  height: 100vh;
  min-height: 0;
  display: flex !important;
  flex-direction: column !important;
  padding: 0;
  overflow: hidden;
  border-right: 1px solid #dfe5e9;
  background: #ffffff;
}

#chatPage aside.sidebar h2 {
  flex: 0 0 auto;
  margin: 0;
  padding: 20px;
  color: #229ed9;
  font-size: 22px;
  border-bottom: 1px solid #eef1f3;
}

#chatPage aside.sidebar #usersList {
  min-height: 0;
  flex: 1 1 auto !important;
  overflow-y: auto;
  padding: 8px;
}

/* Список пользователей */

.user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.user:hover {
  background: #f0f7fb;
}

.user-avatar {
  display: block;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: #dcecf5;
}

.user span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Нижняя панель кнопок */

.sidebar-bottom {
  flex: 0 0 auto;
  width: 100%;
  margin-top: auto !important;
  padding: 10px 12px;
  border-top: 1px solid #e1e8ed;
  background: #ffffff;
}

.sidebar-bottom button {
  display: block;
  width: 100%;
  margin: 6px 0;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: #eef5f8;
  color: #229ed9;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
}

.sidebar-bottom button:hover {
  background: #dcecf5;
}

aside > button {
  margin: 12px;
  padding: 11px;
  border: none;
  border-radius: 7px;
  background: #eef5f8;
  color: #229ed9;
  cursor: pointer;
}

aside > button:hover {
  background: #dcecf5;
}

/* Правая часть */

#chatPage main {
  min-width: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  background-color: #d7e3ec;
  background-image:
    radial-gradient(#ffffff55 1px, transparent 1px);
  background-size: 20px 20px;
}

#chatPage main header {
  padding: 18px 24px;
  background: #ffffff;
  border-bottom: 1px solid #dfe5e9;
  color: #17212b;
  font-size: 18px;
  font-weight: bold;
}

/* Шапка чата */

#chatHeader {
  display: flex;
  align-items: center;
  gap: 12px;
}

#backButton {
  display: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #eef5f8;
  color: #229ed9;
  font-size: 24px;
  cursor: pointer;
}

/* Сообщения */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 25px;
}

.message {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: 65%;
  margin-bottom: 8px;
  padding: 9px 13px;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 1px 2px #0002;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.message span {
  overflow-wrap: anywhere;
}

.my-message {
  margin-left: auto;
  background: #effdde;
}

.delete-message {
  display: none !important;
  padding: 5px 8px;
  margin-left: 8px;
  border: none;
  border-radius: 5px;
  background: #e53935;
  color: white;
  font-size: 11px;
  cursor: pointer;
}

.my-message:hover .delete-message {
  display: inline-block !important;
}

.delete-message:hover {
  background: #b71c1c;
}

/* Поле отправки */

#messageForm {
  display: flex;
  gap: 10px;
  padding: 12px 18px;
  background: #ffffff;
  border-top: 1px solid #dfe5e9;
}

#messageInput {
  flex: 1;
  padding: 13px 16px;
  border: 1px solid #d7dde3;
  border-radius: 22px;
  outline: none;
  font-size: 15px;
}

#messageInput:focus {
  border-color: #229ed9;
}

#messageForm button {
  padding: 0 20px;
  border: none;
  border-radius: 22px;
  background: #229ed9;
  color: white;
  cursor: pointer;
}

#messageForm button:hover {
  background: #168ac0;
}

/* ==================== Тёмная тема ==================== */

body.dark-mode {
  background: #17212b;
  color: #e6edf3;
}

body.dark-mode #authPage {
  background: #17212b;
}

body.dark-mode .auth-box {
  background: #202b36;
  color: #e6edf3;
}

body.dark-mode .auth-box h1 {
  color: #5eb5e6;
}

body.dark-mode .auth-box input {
  background: #17212b;
  border-color: #405261;
  color: white;
}

body.dark-mode #chatPage aside.sidebar {
  background: #202b36;
  border-color: #405261;
}

body.dark-mode #chatPage aside.sidebar h2 {
  color: #5eb5e6;
  border-color: #405261;
}

body.dark-mode .user:hover {
  background: #2b3a48;
}

body.dark-mode .user-avatar {
  background: #34495a;
}

body.dark-mode .sidebar-bottom {
  border-color: #405261;
  background: #202b36;
}

body.dark-mode .sidebar-bottom button {
  background: #2b3a48;
  color: #8dcced;
}

body.dark-mode .sidebar-bottom button:hover {
  background: #34495a;
}

body.dark-mode aside > button,
body.dark-mode #themeButton {
  background: #2b3a48;
  color: #8dcced;
}

body.dark-mode aside > button:hover,
body.dark-mode #themeButton:hover {
  background: #34495a;
}

body.dark-mode #chatPage main {
  background-color: #17212b;
  background-image:
    radial-gradient(#ffffff12 1px, transparent 1px);
}

body.dark-mode #chatPage main header {
  background: #202b36;
  border-color: #405261;
  color: #e6edf3;
}

body.dark-mode #messageForm {
  background: #202b36;
  border-color: #405261;
}

body.dark-mode #messageInput {
  background: #17212b;
  border-color: #405261;
  color: white;
}

body.dark-mode #messageInput::placeholder {
  color: #9aa9b5;
}

body.dark-mode .message {
  background: #2b3a48;
  color: #e6edf3;
}

body.dark-mode .my-message {
  background: #2b7da8;
  color: white;
}

/* ==================== Окно настроек ==================== */

#settingsModal {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0008;
}

.settings-box {
  width: min(400px, 90%);
  padding: 25px;
  border-radius: 14px;
  background: white;
  box-shadow: 0 5px 30px #0005;
}

.settings-box h2 {
  margin-top: 0;
  color: #229ed9;
}

.settings-box label {
  display: block;
  margin: 12px 0 5px;
  color: #60717d;
}

.settings-box input {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccd6dc;
  border-radius: 8px;
  outline: none;
}

.settings-box button {
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: #229ed9;
  color: white;
  cursor: pointer;
}

.settings-box button:last-child {
  background: #eef5f8;
  color: #229ed9;
}

.avatar-preview {
  display: block;
  width: 90px;
  height: 90px;
  margin: 18px auto;
  border-radius: 50%;
  object-fit: cover;
  background: #dcecf5;
}

#settingsError {
  color: #e53935;
}

body.dark-mode .settings-box {
  background: #202b36;
  color: #e6edf3;
}

body.dark-mode .settings-box label {
  color: #aebdca;
}

body.dark-mode .settings-box input {
  background: #17212b;
  border-color: #405261;
  color: white;
}

body.dark-mode .settings-box button:last-child {
  background: #2b3a48;
  color: #8dcced;
}

/* ==================== Телефон ==================== */

@media (max-width: 700px) {
  body {
    overflow: hidden;
  }

  #chatPage aside.sidebar {
    width: 220px;
  }

  #chatPage aside.sidebar h2 {
    font-size: 18px;
    padding: 16px;
  }

  .user {
    padding-left: 12px;
    font-size: 14px;
  }

  #chatPage main header {
    padding: 16px;
    font-size: 16px;
  }

  #messages {
    padding: 15px;
  }

  .message {
    max-width: 85%;
  }

  #messageForm {
    padding: 8px;
  }

  #messageForm button {
    padding: 0 12px;
    font-size: 13px;
  }

  /* Мобильный чат */
  #chatPage aside.sidebar {
    width: 100%;
    height: 100vh;
  }

  #chatPage aside.sidebar h2 {
    padding: 17px;
    font-size: 20px;
  }

  #chatPage aside.sidebar .sidebar-bottom {
    padding: 8px 12px;
  }

  #chatPage aside.sidebar .sidebar-bottom button {
    padding: 13px;
    font-size: 15px;
  }

  #chatPage main {
    display: none;
    width: 100%;
    height: 100vh;
  }

  #chatPage.mobile-chat-open aside.sidebar {
    display: none !important;
  }

  #chatPage.mobile-chat-open main {
    display: flex !important;
  }

  #chatPage.mobile-chat-open #backButton {
    display: block;
  }

  #chatPage main header {
    min-height: 58px;
    padding: 10px 14px;
    font-size: 17px;
  }

  #messages {
    padding: 14px 10px;
  }

  .message {
    max-width: 88%;
    padding: 9px 11px;
    font-size: 15px;
  }

  #messageForm {
    gap: 7px;
    padding: 8px;
  }

  #messageInput {
    min-width: 0;
    padding: 12px;
    font-size: 16px;
  }

  #messageForm button {
    padding: 0 13px;
    white-space: nowrap;
  }

  .delete-message {
    padding: 5px;
    font-size: 10px;
  }
}