/* Вписываю загруженную картинку в аватар и наследую его скругление. */
.avatar img,
.initial img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.avatar:has(img),
.initial:has(img) {
  padding: 0 !important;
  overflow: hidden;
}

/* Задаю размер предпросмотра аватара в настройках профиля. */
.profile-avatar-preview {
  width: 76px;
  height: 76px;
  font-size: 2rem;
  border-radius: 22px;
  background: #563549;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.profile-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-upload-row {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin: 14px 0;
}

.avatar-upload-row p {
  font-size: 0.73rem;
  color: #b7aabb;
  line-height: 1.6;
  margin: 6px 0;
}

/* Размещаю чат конференции в отдельной колонке справа. */
.call-chat {
  min-width: 0;
  min-height: 0;
  padding: 18px 14px 10px;
  background: #19191f;
  border-left: 1px solid #35313d;
  display: flex;
  flex-direction: column;
  position: relative;
  grid-column: 4;
  grid-row: 2;
}

.call-chat > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  color: #c8bacf;
  font-size: 0.75rem;
  border-bottom: 1px solid #34303b;
  margin-bottom: 15px;
}

.call-chat > header button {
  background: #302733;
  border-radius: 8px;
  padding: 6px;
}

/* При открытом чате освобождаю место за счёт панели участников. */
.workspace.chat-open > .members {
  display: none;
}

.workspace.chat-open {
  grid-template-columns: 76px 248px minmax(0, 1fr) 360px;
}

#chat-pane {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.chat-heading {
  position: relative;
  flex-shrink: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid #35303d;
}

.chat-heading small {
  font-size: 0.64rem;
  line-height: 1.4;
}

.chat-heading h2 {
  padding-right: 0;
}

/* Оставляю место для кнопки личного звонка, только когда она видна. */
.chat-heading:has(#chat-call:not([hidden])) h2 {
  padding-right: 105px;
}

#chat-call {
  position: absolute;
  right: 0;
  top: 0;
  font-size: 0.7rem;
  padding: 7px;
  min-height: 34px;
}

#chat-call .icon {
  width: 16px;
  height: 16px;
}

/* Позволяю истории сжиматься и прокручиваться внутри панели звонка. */
.chat-messages {
  min-height: 0;
  max-height: none;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #675062 transparent;
}

.message p {
  line-height: 1.55;
}

.message-heading {
  gap: 5px 8px;
}

.call-chat .message-delete {
  font-size: 0.6rem;
}

.call-chat .message {
  gap: 8px;
}

.call-chat .message-heading time {
  font-size: 0.58rem;
}

.call-chat .message > .avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
}

.call-chat #chat-form {
  flex-wrap: wrap;
  gap: 7px;
}

.call-chat #chat-input {
  flex-basis: calc(100% - 45px);
}

.call-chat #chat-send {
  margin-left: auto;
  padding: 8px 14px;
  min-height: 34px;
  font-size: 0.73rem;
}

/* Ограничиваю высоту отдельного окна чата размерами экрана. */
.chat-dialog {
  height: min(740px, 90dvh);
  padding-top: 42px;
  overflow: hidden;
}

.chat-dialog #chat-dialog-slot {
  height: 100%;
}

.chat-dialog #chat-pane {
  height: 100%;
}

#chat-form {
  flex-shrink: 0;
  align-items: flex-end;
}

/* Оформляю кнопку выбора эмодзи рядом с полем сообщения. */
.emoji-toggle {
  background: #3a2b40;
  border-radius: 9px;
  width: 36px;
  min-width: 36px;
  height: 44px;
  padding: 7px;
  color: #eac4d7;
}

/* Открываю панель эмодзи над формой отправки, внутри области чата. */
#emoji-picker {
  position: absolute;
  bottom: 92px;
  left: 0;
  z-index: 5;
  background: #29212f;
  border: 1px solid #6c465f;
  border-radius: 12px;
  padding: 12px;
  width: min(320px, 100%);
  max-height: 330px;
  box-shadow: 0 10px 30px #0008;
  overflow-y: auto;
}

#emoji-search {
  font-size: 0.75rem;
  padding: 9px;
}

#emoji-options h4 {
  font-size: 0.66rem;
  color: #bca5c3;
  margin: 13px 0 6px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px;
}

.emoji-option {
  background: transparent;
  font-size: 1.4rem;
  border-radius: 6px;
  min-height: 36px;
  padding: 3px;
}

.emoji-option:hover {
  background: #5a354c;
}

/* Центрирую аватар и действия во входящем личном звонке. */
#call-dialog {
  text-align: center;
  width: min(370px, 92vw);
}

#call-peer-avatar {
  width: 80px;
  height: 80px;
  margin: 0 auto 15px;
  font-size: 2rem;
  border-radius: 25px;
}

#call-prompt-label {
  font-size: 0.8rem;
  color: #d5aec3;
}

#call-peer-name {
  overflow-wrap: anywhere;
}

.call-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 25px;
}

.call-actions button {
  border-radius: 12px;
  min-height: 44px;
  padding: 12px 20px;
}

#call-accept {
  background: #328054;
}

#call-decline {
  background: #bc3458;
}

.call-chat #chat-error {
  max-height: 48px;
  overflow-y: auto;
}

.call-chat #chat-input {
  resize: none;
}

.call-chat #chat-pane {
  flex: 1;
}

.call-chat .chat-heading small {
  display: none;
}

.call-chat .chat-heading h2 {
  font-size: 0.94rem;
}

.call-chat .chat-heading p {
  font-size: 0.66rem;
  margin-bottom: 0;
}

.call-chat .chat-messages {
  padding: 5px 0 10px;
}

/* Подстраиваю расположение и размеры элементов под указанную ширину экрана. */
@media (max-width: 1150px) {
  .workspace.chat-open {
    grid-template-columns: 76px 220px minmax(0, 1fr);
  }

  .call-chat {
    position: fixed;
    right: 12px;
    top: 104px;
    bottom: 130px;
    width: min(370px, calc(100vw - 92px));
    z-index: 4;
    border: 1px solid #604255;
    border-radius: 14px;
    box-shadow: 0 10px 35px #0008;
  }
}

/* Подстраиваю расположение и размеры элементов под указанную ширину экрана. */
@media (max-width: 760px) {
  .workspace.chat-open {
    grid-template-columns: 60px minmax(0, 1fr);
  }

  .call-chat {
    right: 5px;
    top: 96px;
    bottom: 120px;
    width: calc(100vw - 70px);
    padding: 12px 10px 8px;
  }

  .call-chat > header {
    margin-bottom: 9px;
    padding-bottom: 8px;
  }

  .chat-dialog {
    width: 96vw;
    padding: 40px 12px 10px;
  }

  .chat-dialog #chat-form {
    gap: 5px;
    flex-wrap: wrap;
  }

  .chat-dialog #chat-send {
    margin-left: auto;
    min-height: 35px;
  }

  .chat-dialog #chat-input {
    flex-basis: calc(100% - 45px);
  }

  .call-chat .message p {
    font-size: 0.8rem;
  }

  .call-chat .chat-heading:has(#chat-call:not([hidden])) h2 {
    padding-right: 85px;
  }

  #chat-call {
    font-size: 0.65rem;
  }
}

/* В горизонтальном режиме с небольшой высотой освобождаю место для демонстрации. */
@media (max-height: 500px) and (orientation: landscape) {
  .call-chat {
    top: 82px;
    bottom: 70px;
  }

  .call-chat > header {
    margin-bottom: 4px;
    padding-bottom: 3px;
  }

  .call-chat .chat-heading {
    padding-bottom: 4px;
  }

  .call-chat #chat-form {
    flex-wrap: nowrap;
  }

  .call-chat #chat-input {
    height: 42px;
    min-height: 42px;
  }

  .call-chat #chat-send {
    padding: 8px;
  }

  .call-chat .chat-heading p {
    display: none;
  }
}

/* Разрешаю содержимому чата сжиматься внутри Flex-контейнера. */
.call-chat #call-chat-content {
  display: flex;
  flex: 1;
  min-height: 0;
}

.call-chat #chat-pane {
  width: 100%;
}

.call-chat[hidden] {
  display: none !important;
}

.tile .initial {
  width: 76px;
}

.chat-heading h2 {
  overflow-wrap: anywhere;
}

/* Подстраиваю расположение и размеры элементов под указанную ширину экрана. */
@media (max-width: 760px) {
  .workspace.chat-open #call-controls {
    position: fixed;
    left: 68px;
    right: 8px;
    bottom: 12px;
    width: auto;
    margin: 0;
    z-index: 6;
    justify-content: center;
  }

  .workspace.chat-open #call-controls .control-item {
    min-width: 0;
  }
}
