* { box-sizing: border-box; }
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin:0; background:#0f172a; color:#e2e8f0; }
header { display:flex; justify-content:space-between; align-items:center; padding:12px 16px; background:#111827; border-bottom:1px solid #1f2937; }
h1 { font-size:18px; margin:0; }
#me { opacity:0.85; font-size:14px; }
.card { background:#111827; padding:16px; border:1px solid #1f2937; border-radius:8px; }
#auth { padding:16px; }
#chat { display:flex; height: calc(100vh - 60px); }
.hidden { display:none; }
aside { width:280px; border-right: 1px solid #1f2937; overflow-y:auto; padding:12px; }
aside h3 { margin-top:0; }
#users { display: none; list-style:none; padding:0; margin:0; }

#users.active {
    display: block;
}

#users li {
    padding: 8px;
    border: 1px solid #1f2937;
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    position: relative;
}

/* Имя пользователя */
#users li > span:first-child {
    flex-grow: 1; /* Занимает все доступное пространство */
    padding-right: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Контейнер для статуса и счетчика */
.user-status-container {
    display: flex;
    align-items: center;
    gap: 4px;
}

#users li.active {
  border-color:#3b82f6;
  background: none; }

#users li.active .user-content {
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
}

.badge {
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 999px;
    border: 1px solid #374151;
    background: none;
    margin-left: auto; /* Выравниваем по правому краю */
    flex-shrink: 0;
}



.badge.online {
    border-color: #22c55e;
}
main { flex:1; display:flex; flex-direction:column; }
#chat-header { padding:12px; border-bottom:1px solid #1f2937; display:flex; justify-content:space-between; align-items:center; }
#messages { flex:1; padding:12px; overflow-y:auto; display:flex; flex-direction:column; gap:8px;}
.msg { max-width:70%; padding:8px 12px; border:1px solid #1f2937; border-radius:12px; word-wrap: break-word; overflow-wrap: break-word; white-space: pre-wrap; word-break: break-word;}
.msg.me { align-self:flex-end; background:#0b1220; border-color:#3b82f6; }
.msg.other { align-self:flex-start; background:#0b1220; }
#composer { display:flex; gap:8px; padding:12px; border-top:1px solid #1f2937; }

/* Глобальные стили для input и button */
input, button {
  padding:10px;
  border-radius:8px;
  border:1px solid #374151;
  background:#0b1220;
  color:#e2e8f0;
}

button { cursor:pointer; }
button:disabled { opacity:0.5; cursor:not-allowed; }

/* Специфичные стили для страниц авторизации */
#auth .card h2 {
  text-align: center;
  margin-bottom: 20px;
}

#auth .card input {
  display: block;
  width: 100%;
  margin: 0 auto 12px;
  padding: 10px;
}

#auth .card button {
  display: block;
  margin-left: auto;
  margin-right: 0;
  margin-bottom: 12px;
}

#auth .auth-switch {
  margin-top: 16px;
  text-align: center;
}

/* Auth layout + user dropdown */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 32px;
  padding: 40px 20px; /* Уменьшим боковые отступы на мобильных */
  max-width: 400px; /* Увеличим максимальную ширину */
  min-width: 300px; /* Добавим минимальную ширину */
  width: 90%; /* Займёт 90% ширины экрана */
  margin: 40px auto;
}

/* Обновим стили для .card внутри контейнера */
.auth-container .card {
  width: 100%; /* Карточка займёт всю ширину контейнера */
  padding: 24px; /* Увеличим внутренние отступы */
}

/* Добавим медиа-запрос для очень широких экранов */
@media (min-width: 1200px) {
  .auth-container {
    max-width: 400px; /* Шире на больших экранах, но не слишком */
  }
}

#user-menu { position: relative; display: flex; align-items: center; gap: 8px; }
.dropdown { position: relative; }
.dropdown-content { position: absolute; right: 0; top: 100%; background: #111827; border: 1px solid #1f2937; border-radius: 8px; padding: 8px; display: flex; flex-direction: column; z-index: 1100;}
.dropdown-content.hidden { display: none; }
.dropdown-content button { border: none; background: none; color: #e2e8f0; padding: 8px; text-align: left; }
.dropdown-content button:hover { background: #1f2937; }

.auth-switch { margin-top: 12px; font-size: 14px; text-align: center; color: #94a3b8; }
.auth-switch a { color: #3b82f6; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

#remoteAudio {
  width: 100%;
  max-width: 300px;
  margin: 10px 0;
  background: #1e293b;
  border-radius: 8px;
  display: none;
}
.call-active #remoteAudio { display: block; }

/* Модальное окно */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7);
  display: none; justify-content: center; align-items: center; z-index: 1000;
}
.modal.show { display: flex; }
.modal-content { background: #1e293b; padding: 20px; border-radius: 8px; text-align: center; border: 1px solid #3b82f6; }
.call-buttons { display: flex; gap: 10px; margin-top: 15px; justify-content: center; }

/* Статус звонка */
#call-status {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: #1e293b; padding: 10px 20px; border-radius: 20px;
  display: none; align-items: center; gap: 10px; z-index: 999; border: 1px solid #3b82f6;
}
#call-status.show { display: flex; }

/* Кнопки звонка */
.call-controls { display: flex; gap: 10px; }
#btn-call { background: #10b981; }
#btn-hangup { background: #ef4444; display: none; }
#btn-call:hover { background: #059669; }
#btn-hangup:hover { background: #dc2626; }
.call-active #btn-call { display: none; }
.call-active #btn-hangup { display: block; }

.msg-time {
  font-size: 0.7em;
  opacity: 0.7;
  text-align: right;
}

.unread-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    background: transparent;
    color: #e2e8f0;
    font-size: 0.7em;
    flex-shrink: 0;
}

.badge-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto; /* Выравниваем по правому краю */
}

/* Profile settings modal */
.profile-preview {
  position: relative;
  margin-bottom: 20px;
  border: 1px solid #374151;
  border-radius: 8px;
  overflow: hidden;
}

.banner-preview {
  height: 150px;
  background: #1f2937;
  background-size: cover;
  background-position: center;
}

.avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #1f2937;
  border: 3px solid #111827;
  position: absolute;
  bottom: -32px;
  left: 20px;
  background-size: cover;
  background-position: center;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
}

.file-info {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 5px;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

/* Update user list items */
#users li {
  height: 80px; /* Увеличиваем высоту для баннеров */
  padding: 0;
  position: relative;
  overflow: hidden;
}

.user-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  align-items: center;
}

.user-banner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  z-index: -1;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 8px;
  background-size: cover;
  background-position: center;
  border: 1px solid #1f2937;
}

/* Добавим в конец файла */
#avatar-upload, #banner-upload {
  width: 100%;
  padding: 8px;
  border: 1px dashed #374151;
  border-radius: 8px;
  margin-bottom: 5px;
}

.profile-preview {
  height: 200px;
  margin-bottom: 20px;
}

.banner-preview {
  height: 120px;
  background-color: #1f2937;
  background-size: cover;
  background-position: center;
  border-radius: 8px 8px 0 0;
}

.avatar-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: #1f2937;
  border: 3px solid #111827;
  margin: -40px auto 0;
  position: relative;
  background-size: cover;
  background-position: center;
}

#chat-selector {
    display: flex;
    margin-bottom: 10px;
    border-bottom: 1px solid #374151;
    gap: 8px;
}

#chat-selector button {
  flex: 0 0 50px !important;   /* фиксируем ширину */
  width: 50px !important;
  height: 50px !important;     /* квадрат 60×60 */
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

#chat-selector button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

#chat-selector button.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

#chat-selector button:last-child {
    flex: 0 0 40px;
    font-size: 1.2em;
}

/* Группы */
#groups {
    display: none;
    list-style: none;
    padding: 0;
    margin: 0;
}

#groups.active {
    display: block;
}

#groups li {
    padding: 0;
    margin-bottom: 8px;
    border: 1px solid #1f2937;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    position: relative;
}

.group-banner {
    height: 80px;
    background-color: #1f2937;
    background-size: cover;
    background-position: center;
}

.group-content {
    padding: 8px;
}

.group-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #1f2937;
    border: 2px solid #111827;
    float: left;
    margin-right: 8px;
    background-size: cover;
    background-position: center;
}

.group-name {
    font-weight: bold;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#groups li.active {
    border-color: #3b82f6;
}

.msg.group-msg {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 75%;           /* не больше 75% контейнера */
    width: fit-content;
    margin-bottom: 4px;
    background: #1a243a;
    border: 1px solid #2d3748;
    border-radius: 12px;
    padding: 8px 12px;
    word-break: break-word;   /* перенос длинных слов */
    overflow-wrap: break-word;/* современный перенос слов */
}

.msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-color: #2d3748;
    flex-shrink: 0;
    margin-right: 2px;       /* уменьшенный отступ */
}

.msg-body {
    display: flex;
    flex-direction: column;
    flex: 0 1 auto;
    align-items: flex-start;
}

.msg-sender-name {
    font-weight: bold;
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: #cbd5e1;
}

.msg-content {
    font-size: 1rem;
    line-height: 1.4;
    margin-bottom: 4px;
    white-space: pre-wrap;     /* сохраняем переносы */
    word-wrap: break-word;     /* старый стандарт для переносов */
    overflow-wrap: break-word; /* современный стандарт для переносов */
}

.msg-time {
    font-size: 0.75rem;
    color: #94a3b8;
    align-self: flex-end;
    margin-top: 0;             /* убрали верхний margin */
}

/* ===================== */
/* Свои сообщения в группе*/
/* ===================== */

.msg.group-msg.me {
    margin-left: auto;
    background: #0b2d4e;
    border-color: #1e4a7e;
    justify-content: flex-end;
}

.msg.group-msg.me .msg-avatar,
.msg.group-msg.me .msg-sender-name {
    display: none; /* скрываем аватар и имя у себя */
}

.msg.group-msg.me .msg-body {
    align-items: flex-start;   /* текст внутри слева */
    text-align: left;
}

.search-container {
  position: relative;
  flex-grow: 1;
  max-width: 400px;
  margin: 0 20px;
}

#search-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 20px;
  background: #1f2937;
  border: 1px solid #374151;
  color: white;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 8px;
  margin-top: 5px;
  z-index: 1000;
  max-height: 0;
  overflow: hidden; /* Всегда hidden, даже при активном состоянии */
  opacity: 0;
  transform: translateY(-10px);
  transition:
    max-height 0.3s ease-in-out,
    opacity 0.2s ease-in-out,
    transform 0.2s ease-in-out;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.search-results.active {
  max-height: 300px;
  opacity: 1;
  transform: translateY(0);
}

.search-result-item {
  padding: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(-5px);
  transition:
    opacity 0.2s ease-in-out,
    transform 0.2s ease-in-out;
}

.search-results.active .search-result-item {
  opacity: 1;
  transform: translateY(0);
}

/* Добавим небольшую задержку для каждого элемента */
.search-results.active .search-result-item:nth-child(1) { transition-delay: 0.05s; }
.search-results.active .search-result-item:nth-child(2) { transition-delay: 0.1s; }
.search-results.active .search-result-item:nth-child(3) { transition-delay: 0.15s; }
.search-results.active .search-result-item:nth-child(4) { transition-delay: 0.2s; }
.search-results.active .search-result-item:nth-child(5) { transition-delay: 0.25s; }

.search-result-item:hover {
  background: #1f2937;
}

.search-result-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  background-color: #1f2937;
}

.search-result-info {
  flex-grow: 1;
}

.search-result-name {
  font-weight: bold;
}

.search-result-login {
  font-size: 0.8em;
  color: #94a3b8;
}

#users, #groups {
    transition:
        opacity 0.3s ease-in-out,
        transform 0.3s ease-in-out;
    will-change: opacity, transform;
}

/* Убедимся, что списки правильно позиционированы */
#users {
    position: relative;
    left: 0;
}

#groups {
    position: relative;
    left: 0;
}

/* Добавить в конец файла */
#btn-group-settings {
  background: none;
  border: none;
  padding: 0;
  margin-right: 8px;
}

#btn-group-settings img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.7;
  transition: opacity 0.2s;
}

#btn-group-settings:hover img {
  opacity: 1;
}

/* Обновим стили для элементов группы */
#groups li {
  height: 80px;
  padding: 0;
  position: relative;
  overflow: hidden;
}

.group-banner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  z-index: -1;
}

.group-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
}

.group-name {
  font-weight: bold;
  color: white;
  margin-bottom: 4px;
}

.group-tooltip {
  position: absolute;
  width: 204px;
  background: #111827;
  border: 1px solid #3b82f6;
  border-radius: 8px;
  padding: 12px;
  z-index: 1000;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 0.2s ease-in-out,
    transform 0.2s ease-in-out;
}

.group-tooltip.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.group-tooltip-banner {
  width: 180px;
  height: 120px;
  background-size: cover;
  background-position: center;
  border-radius: 4px;
  background-color: #1f2937;
  overflow: hidden; /* Добавляем это свойство */
}

.group-tooltip-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin: -30px auto 0;
  border: 3px solid #111827;
  background-size: cover;
  background-position: center;
  background-color: #1f2937;
  position: relative;
  z-index: 1;
}

.group-tooltip-desc {
  font-size: 0.8em;
  color: #94a3b8;
  text-align: center;
  margin-top: 8px;
}

.msg-media {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.msg-media-item {
    width: 100%;
    height: auto;
    max-height: 200px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #1f2937;
}

#btn-attach {
    background: none;
    border: none;
    padding: 10px;
    cursor: pointer;
    font-size: 1.2em;
    color: #94a3b8;
}

#btn-attach:hover {
    color: #e2e8f0;
}

.msg-media-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
  max-width: 100%; /* Ограничиваем максимальную ширину */
}

.msg-media-wrapper {
  position: relative;
  padding-bottom: 100%; /* Квадратное соотношение для контейнера */
  overflow: hidden;
  border-radius: 8px;
  background: #1f2937;
  width: 100%; /* Занимает всю ширину ячейки grid */
  height: 0; /* Для aspect ratio */
}

.msg-media-item {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover; /* Сохраняет соотношение сторон без обрезки */
  object-position: center;
}

.msg-media-container:has(.msg-media-wrapper:only-child) {
  grid-template-columns: 1fr; /* Одна колонка для одиночного изображения */
  max-width: 300px; /* Максимальная ширина для одиночного изображения */
}

/* Для двух изображений */
.msg-media-container:has(.msg-media-wrapper:nth-child(2):last-child) {
  grid-template-columns: repeat(2, 1fr);
  max-width: 250px;
}

/* Для трех и более изображений - стандартная grid */
.msg-media-container:has(.msg-media-wrapper:nth-child(3)) {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  max-width: 100%;
}

.msg-text {
    margin-top: 8px;
}

/* Стили для кнопки прикрепления */
.attach-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-btn:hover {
    color: #e2e8f0;
}

.attach-btn svg {
    width: 24px;
    height: 24px;
}

.format-menu {
    position: absolute;
    background: #1e293b;
    border: 1px solid #3b82f6;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    gap: 4px;
    z-index: 1100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.format-menu.hidden {
    display: none;
}

.format-menu button {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background: #0f172a;
    border: 1px solid #374151;
    color: #e2e8f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.format-menu button:hover {
    background: #1e293b;
    border-color: #3b82f6;
}

.format-menu button strong,
.format-menu button em,
.format-menu button u,
.format-menu button s {
    font-size: 14px;
    font-weight: normal;
    font-style: normal;
    text-decoration: none;
}

#msg-input[contenteditable="true"]:empty:before {
  content: attr(placeholder);
  color: gray;
}

#msg-input {
  flex: 1;                         /* занимает всю ширину в #composer */
  min-height: 40px;                /* минимальная высота */
  max-height: calc(1.4em * 8);     /* максимум примерно 8 строк */
  overflow-y: auto;                /* если больше 8 строк — скролл */
  padding: 10px 12px;
  border-radius: 20px;
  background: #1f2937;
  border: 1px solid #374151;
  color: #e2e8f0;
  outline: none;
  line-height: 1.4;
  font-size: 15px;
  white-space: pre-wrap;           /* сохраняем переносы */
  word-wrap: break-word;
}

#msg-input[contenteditable="true"]:empty:before {
  content: attr(placeholder);
  color: #94a3b8;
  pointer-events: none;
}

#media-preview-container {
  max-height: 300px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin: 15px 0;
}

#media-preview-container .msg-media-wrapper {
  max-width: 150px;
}

#media-caption {
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

#media-preview-container {
  max-height: 300px;
  overflow-y: auto;
}

#media-preview-container .msg-media-wrapper {
  max-width: 150px;
}

#media-caption.editable {
  min-height: 60px;
  max-height: 120px;
  overflow-y: auto;
  padding: 10px 12px;
  border-radius: 20px;
  background: #1f2937;
  border: 1px solid #374151;
  color: #e2e8f0;
  outline: none;
  line-height: 1.4;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#media-caption.editable:empty:before {
  content: attr(placeholder);
  color: #94a3b8;
  pointer-events: none;
}

.msg-media-grid {
  display: grid;
  gap: 4px;
  border-radius: 12px;
  overflow: hidden;
}

/* Ячейки */
.msg-media-cell {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
}

.msg-media-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Раскладки под количество фото */

/* 1 фото — большое */
.msg-media-grid.layout-1 {
  grid-template-columns: 1fr;
}
.msg-media-grid.layout-1 .msg-media-cell {
  aspect-ratio: 16/12;
}

/* 2 фото — два в ряд */
.msg-media-grid.layout-2 {
  grid-template-columns: repeat(2, 1fr);
}
.msg-media-grid.layout-2 .msg-media-cell {
  aspect-ratio: 4/5;
}

/* 3 фото — один сверху + два снизу */
.msg-media-grid.layout-3 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: auto auto;
}
.msg-media-grid.layout-3 .msg-media-cell:first-child {
  grid-column: span 2;
  aspect-ratio: 16/9;
}
.msg-media-grid.layout-3 .msg-media-cell:nth-child(n+2) {
  aspect-ratio: 1/1;
}

/* 4 фото — один сверху + три снизу */
.msg-media-grid.layout-4 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: auto auto;
}
.msg-media-grid.layout-4 .msg-media-cell:first-child {
  grid-column: span 2;
  aspect-ratio: 16/9;
}
.msg-media-grid.layout-4 .msg-media-cell:nth-child(n+2) {
  aspect-ratio: 1/1;
}

/* 5–9 фото — сетка 3×N */
.msg-media-grid.layout-5,
.msg-media-grid.layout-6,
.msg-media-grid.layout-7,
.msg-media-grid.layout-8,
.msg-media-grid.layout-9 {
  grid-template-columns: repeat(3, 1fr);
}
.msg-media-grid.layout-5 .msg-media-cell,
.msg-media-grid.layout-6 .msg-media-cell,
.msg-media-grid.layout-7 .msg-media-cell,
.msg-media-grid.layout-8 .msg-media-cell,
.msg-media-grid.layout-9 .msg-media-cell {
  aspect-ratio: 1/1;
}

/* ======================= */
/* Мобильная версия */
/* ======================= */
@media (orientation: portrait) {
  /* Контейнер чата вертикально */
  #chat {
    flex-direction: column;
  }

  /* aside занимает весь экран */
  aside {
    width: 100%;
    height: calc(100vh - 60px); /* 60px — высота header */
    border-right: none;
    position: absolute;
    top: 60px; /* сразу под header */
    left: 0;
    z-index: 1000;
    background: #0f172a;
    transition: transform 0.3s ease-in-out;
  }

  /* chat-selector — кнопки по центру */
  #chat-selector {
    justify-content: space-around;
    padding: 8px 0;
    margin-bottom: 10px;
    border-bottom: 1px solid #374151;
  }

  #chat-selector button {
    flex: 1;
    max-width: 80px;
  }

  /* main скрыт по умолчанию */
  main {
    display: none;
    width: 100%;
    height: calc(100vh - 60px); /* тоже под header */
  }

  /* header — без названия */
  header h1 {
    display: none;
  }
  header .search-container {
    margin: 0;
    flex: 1;
  }
  header #user-menu {
    margin-left: auto;
  }

  /* Когда открыт чат — aside скрываем, main показываем */
  body.chat-open aside {
    display: none;
  }
  body.chat-open main {
    display: flex;
  }
}