/* Узкий iframe/телефон: Element 1.11 остаётся desktop-клиентом.
   Одноэкранный режим: без комнаты — список чатов на всю ширину,
   в комнате (html.abz-mobile-room из mobile-embed.js) — комната на всю ширину
   и кнопка «Назад» к списку. */
.abz-mobile-back {
  display: none;
}

/* UX-DR1: одна светлая тема. mobile-embed.js закрепляет её в mx_local_settings,
   переключатели темы убраны, чтобы выбор не сбрасывался при следующей загрузке. */
:root {
  color-scheme: only light;
}

.mx_UserMenu_contextMenu_themeButton,
.mx_QuickThemeSwitcher,
.mx_ThemeChoicePanel_ThemeSelectors {
  display: none !important;
}

/* Отдельным правилом: без :has() в старом WebView пропадёт только оно, а не список выше. */
.mx_SettingsSubsection:has(.mx_ThemeChoicePanel_ThemeSelectors) {
  display: none !important;
}

/* ScrollPanel Element измеряет offsetTop крайних плиток и якорей data-scroll-tokens.
   display:none обнуляет координаты скрытой плитки и ломает высоту/прокрутку истории.
   Оставляем пустой узел в потоке без высоты, но с корректной позицией. */
.mx_EventTile_info,
.mx_GenericEventListSummary,
.mx_EventTile:has(.mx_RedactedBody) {
  display: block !important;
  visibility: hidden !important;
  height: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
}

@media (max-width: 767px) {
  html,
  body,
  #matrixchat,
  .mx_MatrixChat,
  .mx_MatrixChat_wrapper {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
  }

  html.abz-vv,
  html.abz-vv body,
  html.abz-vv #matrixchat,
  html.abz-vv .mx_MatrixChat,
  html.abz-vv .mx_MatrixChat_wrapper {
    height: var(--abz-vv-height, 100%) !important;
    max-height: var(--abz-vv-height, 100%) !important;
    overflow: hidden !important;
  }

  html.abz-vv body {
    position: fixed !important;
    top: var(--abz-vv-top, 0px) !important;
    right: 0 !important;
    left: 0 !important;
  }

  .mx_MatrixChat > .mx_ResizeHandle {
    display: none !important;
  }

  /* Верхний ряд кадра 48px, центр на 24px — по кнопке меню портала (40px, top 4px, left 8px).
     Левые 56px заняты этой кнопкой, пока html не получил abz-corner-free. */

  /* Сохраняем пользовательское меню Element слева над списком и убираем навигацию Spaces. */
  .mx_SpacePanel {
    position: absolute !important;
    top: 8px !important;
    left: 56px !important;
    right: auto !important;
    bottom: auto !important;
    z-index: 70 !important;
    width: 32px !important;
    height: 32px !important;
    overflow: visible !important;
    pointer-events: none !important;
    background: transparent !important;
  }

  .mx_SpacePanel > :not(.mx_UserMenu),
  .mx_SpacePanel .mx_SpacePanel_toggleCollapse {
    display: none !important;
  }

  /* У Element здесь margin 12px 14px 4px 18px, padding-bottom и черта: без сброса аватар уезжает на поиск. */
  .mx_SpacePanel > .mx_UserMenu {
    display: block !important;
    width: 32px !important;
    max-width: none !important;
    height: 32px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    pointer-events: auto !important;
  }

  .mx_LeftPanel_filterContainer {
    padding: 8px 0 7px 84px !important;
  }

  /* Подсказка «⌘ K» на телефоне без клавиатуры. */
  .mx_RoomSearch_shortcutPrompt {
    display: none !important;
  }

  html.abz-corner-free .mx_SpacePanel {
    left: 12px !important;
  }

  html.abz-corner-free .mx_LeftPanel_filterContainer {
    padding-left: 40px !important;
  }

  /* Список чатов: Resizer пишет inline-ширину, поэтому !important. */
  .mx_MatrixChat > .mx_LeftPanel_outerWrapper {
    flex: 1 1 auto !important;
    width: 100% !important;
    max-width: none !important;
  }

  .mx_LeftPanel_wrapper--user,
  .mx_LeftPanel_wrapper--user[data-collapsed] {
    flex: 1 1 auto !important;
    width: 100% !important;
    max-width: none !important;
  }

  html:not(.abz-mobile-room) .mx_MatrixChat > .mx_RoomView_wrapper {
    display: none !important;
  }

  /* Комната. */
  html.abz-mobile-room .mx_MatrixChat > .mx_LeftPanel_outerWrapper {
    display: none !important;
  }

  html.abz-mobile-room .mx_MatrixChat > .mx_RoomView_wrapper {
    flex: 1 1 auto !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .abz-mobile-back {
    display: none;
  }

  html.abz-mobile-room .abz-mobile-back {
    position: fixed;
    top: 4px;
    left: 52px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--cpd-color-icon-secondary, #656d77);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  html.abz-corner-free.abz-mobile-room .abz-mobile-back {
    left: 4px;
  }

  .mx_MatrixToolbar {
    display: none !important;
  }

  /* У Element height: 64px, поэтому прежний min-height не сжимал шапку и «Назад» стоял выше заголовка. */
  html.abz-mobile-room .mx_RoomHeader {
    gap: 8px !important;
    height: 48px !important;
    min-height: 48px !important;
    padding-block: 0 !important;
    padding-inline-start: 96px !important;
    padding-inline-end: 4px !important;
  }

  html.abz-corner-free.abz-mobile-room .mx_RoomHeader {
    padding-inline-start: 48px !important;
  }

  html.abz-mobile-room .mx_RoomHeader .mx_BaseAvatar {
    --cpd-avatar-size: 32px !important;
    width: 32px !important;
    height: 32px !important;
  }

  html.abz-mobile-room .mx_RoomHeader_heading {
    font: var(--cpd-font-body-lg-semibold) !important;
  }

  /* Лица участников дублируют «Сведения», отнимают ширину у названия и вылезают за правый край.
     className="mx_RoomHeader_members" в разметку 1.11.112 не попадает: прячем .mx_FacePile и её обёртку. */
  html.abz-mobile-room .mx_RoomHeader .mx_FacePile {
    display: none !important;
  }

  html.abz-mobile-room .mx_RoomHeader > :has(> .mx_FacePile) {
    display: none !important;
  }

  html.abz-mobile-room .abz-mobile-back:focus-visible {
    outline: 2px solid var(--cpd-color-border-focused, #0467dd);
    outline-offset: -2px;
  }

  /* До входа (#/room/… до логина) списка нет — «Назад» вести некуда.
     Правая панель комнаты (информация, участники, треды) открыта поверх со своей кнопкой закрытия. */
  html.abz-mobile-room.abz-mobile-right-panel .abz-mobile-back {
    display: none;
  }

  html.abz-mobile-room:not(.abz-corner-free) .mx_RightPanel .mx_BaseCard_header {
    padding-inline-start: 56px !important;
  }

  .mx_MainSplit {
    position: relative;
  }

  .mx_MainSplit > .mx_RightPanel_ResizeWrapper {
    position: absolute !important;
    inset: 0 !important;
    z-index: 60 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .mx_MainSplit > .mx_RightPanel_ResizeWrapper .mx_RightPanel {
    width: 100% !important;
    border-left: 0 !important;
  }

  .mx_MainSplit > .mx_RightPanel_ResizeWrapper .mx_ResizeHandle {
    display: none !important;
  }

  /* Лента: десктопные поля 64px под аватар и 80px под отметки прочтения съедают узкий экран. */
  .mx_RoomView {
    --RoomView_MessageList-padding: 8px;
  }

  .mx_EventTile[data-layout="group"] {
    --EventTile_group_line-spacing-inline-start: 52px;
    --EventTile_content-margin-inline-end: 0px;
  }

  .mx_EventTile[data-layout="group"] .mx_EventTile_e2eIcon {
    inset-inline-start: 34px !important;
  }

  .mx_EventTile[data-layout="group"] .mx_MessageTimestamp {
    width: 34px;
  }

  .mx_EventTile[data-layout="group"] > .mx_DisambiguatedProfile,
  .mx_EventTile[data-layout="group"] .mx_ThreadSummary,
  .mx_EventTile[data-layout="group"] .mx_ThreadSummary_icon {
    margin-left: 52px !important;
    max-width: calc(100% - 52px) !important;
  }

  .mx_RoomView_timeline_rr_enabled .mx_EventTile[data-layout="group"] .mx_EventTile_line,
  .mx_RoomView_timeline_rr_enabled .mx_EventTile[data-layout="group"] .mx_ThreadSummary,
  .mx_RoomView_timeline_rr_enabled .mx_EventTile[data-layout="group"] .mx_ThreadSummary_icon {
    margin-right: 36px !important;
  }

  .mx_EventTile[data-layout="group"] .mx_EventTile_msgOption {
    width: 32px !important;
    margin-inline-end: 4px !important;
  }

  .mx_GenericEventListSummary_spacer {
    margin-left: 52px !important;
  }

  .mx_EventTile_body,
  .mx_MTextBody,
  .mx_EventTile_content {
    word-break: break-word !important;
  }

  .mx_EventTile[data-layout='bubble'] .mx_EventTile_line {
    max-width: min(85%, 32rem);
  }

  /* Пузыри: Element держит справа 60px и выносит отметки прочтения на right: -78px за экран.
     12px справа гасят margin-right: -12px строки, отметки встают под пузырём. */
  .mx_EventTile[data-layout='bubble'] {
    margin-inline-end: 12px !important;
  }

  .mx_EventTile[data-layout='bubble'] .mx_EventTile_msgOption {
    display: flex !important;
    justify-content: flex-end;
  }

  .mx_EventTile[data-layout='bubble'] .mx_ReadReceiptGroup {
    position: static !important;
  }

  .mx_MessageComposer_wrapper {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  .mx_MessageComposer_input,
  .mx_SendMessageComposer .mx_BasicMessageComposer {
    min-height: 40px !important;
  }
}
