/* Reval Chat layout fixes. Loaded after the active Element theme. */

html,
body,
#matrixchat {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

@supports (height: 100dvh) {
    html,
    body,
    #matrixchat {
        height: 100dvh;
        max-height: 100dvh;
    }
}

body {
    position: fixed;
    inset: 0;
}

.mx_MatrixChat,
.mx_MatrixChat_wrapper,
.mx_LeftPanel_panel.mx_RoomView_panel,
.mx_RoomView_wrapper,
.mx_RoomView,
.mx_MainSplit,
.mx_RoomView_body,
.mx_RoomView_timeline,
.mx_RoomView_messagePanel {
    box-sizing: border-box;
    min-width: 0;
    min-height: 0;
    max-width: 100%;
}

.mx_MatrixChat,
.mx_MatrixChat_wrapper,
.mx_LeftPanel_panel.mx_RoomView_panel,
.mx_RoomView_wrapper,
.mx_RoomView,
.mx_MainSplit,
.mx_RoomView_body {
    width: 100%;
    height: 100%;
}

/* The room panel inherited an 8px end padding, leaving chat short of full width. */
.mx_LeftPanel_panel.mx_RoomView_panel {
    padding-inline-end: 0 !important;
    overflow: hidden;
}

.mx_RoomHeader {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
}

.mx_RoomHeader > * {
    min-width: 0;
}

.mx_RoomView_messagePanel {
    flex: 1 1 auto;
    width: 100%;
    overscroll-behavior: contain;
}

.mx_RoomView_MessageList {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    padding-inline: clamp(12px, 2vw, 24px);
}

.mx_EventTile,
.mx_EventTile_line,
.mx_EventTile_content,
.mx_EventTile_body {
    min-width: 0;
    overflow-wrap: anywhere;
}

.mx_EventTile_content img,
.mx_EventTile_content video,
.mx_EventTile_content canvas,
.mx_EventTile_content iframe {
    max-width: 100%;
    height: auto;
}

.mx_EventTile_content pre,
.mx_EventTile_content table {
    max-width: 100%;
    overflow-x: auto;
}

/* Keep sent/read state inside an own-message bubble, immediately before time. */
.mx_EventTile_own:has(.mx_EventTile_content[data-event-layout="bubble"])
    > [data-testid="event-tile-slot-receipt"] {
    position: absolute !important;
    inset-inline-end: calc(var(--MessageTimestamp-width, 46px) - 2px) !important;
    inset-block-end: 3px !important;
    inset-inline-start: auto !important;
    inset-block-start: auto !important;
    width: max-content !important;
    min-width: 18px;
    max-width: 44px;
    height: 18px !important;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    overflow: visible;
    color: #61758a;
    z-index: 4;
}

.mx_EventTile_own:has(.mx_EventTile_content[data-event-layout="bubble"])
    > [data-testid="event-tile-slot-receipt"] .mx_ReadReceiptGroup,
.mx_EventTile_own:has(.mx_EventTile_content[data-event-layout="bubble"])
    > [data-testid="event-tile-slot-receipt"] .mx_ReadReceiptGroup_button {
    width: auto;
    min-width: 18px;
    height: 18px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mx_EventTile_own:has(.mx_EventTile_content[data-event-layout="bubble"])
    > [data-testid="event-tile-slot-receipt"] .mx_ReadReceiptGroup_container,
.mx_EventTile_own:has(.mx_EventTile_content[data-event-layout="bubble"])
    > [data-testid="event-tile-slot-receipt"] svg {
    width: 14px;
    height: 14px;
}

.mx_MessageTimestamp {
    font-variant-numeric: tabular-nums;
}

.mx_MessageComposer {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    margin-inline: 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    flex: 0 0 auto;
}

.mx_BasicMessageComposer,
.mx_SendMessageComposer,
.mx_MessageComposer_input,
.mx_MessageComposer_input textarea,
.mx_SendMessageComposer .mx_BasicMessageComposer_input {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
}

.mx_BasicMessageComposer {
    flex: 1 1 auto;
}

.mx_SendMessageComposer {
    width: 100%;
}

/* The current MatrixRTC tombstone tile must be allowed to shrink on phones. */
.mx_RoomView_timeline .mx_EventTile_call {
    min-width: 0;
    max-width: 100%;
    overflow-x: clip;
    overscroll-behavior-x: none;
    touch-action: pan-y;
}

.mx_RoomView_timeline .mx_EventTile_call > .mx_EventTile_line {
    position: relative;
    display: block;
    width: min(292px, 100%);
    min-width: 0;
    max-width: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.mx_RoomView_timeline .mx_EventTile_call [data-testid="event-tile-slot-body"] {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 0;
    box-sizing: border-box;
    overflow-x: clip;
}

.mx_RoomView_timeline .mx_EventTile_call > [data-testid="event-tile-slot-receipt"] {
    display: none;
}

.mx_RoomView_timeline .mx_LegacyCallEvent_wrapper {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: clip;
    overscroll-behavior-x: none;
    touch-action: pan-y;
}

.mx_RoomView_timeline .mx_LegacyCallEvent,
.mx_RoomView_timeline .mx_LegacyCallEvent_info,
.mx_RoomView_timeline .mx_LegacyCallEvent_info_basic,
.mx_RoomView_timeline .mx_LegacyCallEvent_content {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.mx_RoomView_timeline .mx_LegacyCallEvent {
    height: 82px;
    min-height: 82px;
}

.mx_RoomView_timeline .mx_LegacyCallEvent_content {
    flex-wrap: nowrap;
    padding-inline-end: 54px;
    overflow-x: clip;
}

.mx_RoomView_timeline .mx_LegacyCallEvent_content > .mx_MessageTimestamp {
    position: absolute;
    z-index: 5;
    inset-block-start: auto;
    inset-block-end: 8px;
    inset-inline-start: 16px;
    inset-inline-end: auto;
    box-sizing: border-box;
    width: auto;
    max-width: 72px;
    padding: 0;
    background: transparent;
    color: #fff;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* MatrixRTC call events keep an opaque, stateful card in every selectable theme. */
.mx_RoomView_timeline .mx_EventTile_call .mx_CallEvent {
    border: 1px solid #8dc7d2;
    color: #102b3a;
    background: linear-gradient(135deg, #eff9fb 0%, #dff2f5 100%);
    box-shadow: 0 8px 22px rgb(24 69 86 / 14%);
}

.mx_RoomView_timeline .mx_EventTile_call .mx_CallEvent_active {
    border-color: #76cdb9;
    background: linear-gradient(135deg, #e9faf5 0%, #d8f3ea 100%);
}

.mx_RoomView_timeline .mx_EventTile_call .mx_CallEvent_inactive {
    border-color: #b8ccd5;
    background: linear-gradient(135deg, #f4f8fa 0%, #e5eef2 100%);
}

.mx_RoomView_timeline .mx_EventTile_call .mx_CallEvent_title {
    color: #102b3a;
}

body.cpd-theme-dark .mx_RoomView_timeline .mx_EventTile_call .mx_CallEvent {
    border-color: #3f7588;
    color: #ecf7fa;
    background: linear-gradient(135deg, #173848 0%, #102a38 100%);
    box-shadow: 0 10px 26px rgb(0 0 0 / 28%);
}

body.cpd-theme-dark .mx_RoomView_timeline .mx_EventTile_call .mx_CallEvent_active {
    border-color: #3c907c;
    background: linear-gradient(135deg, #184b43 0%, #123b37 100%);
}

body.cpd-theme-dark .mx_RoomView_timeline .mx_EventTile_call .mx_CallEvent_inactive {
    border-color: #455f6b;
    background: linear-gradient(135deg, #213640 0%, #182a33 100%);
}

body.cpd-theme-dark .mx_RoomView_timeline .mx_EventTile_call .mx_CallEvent_title {
    color: #ecf7fa;
}

@media (min-width: 769px) {
    .mx_RoomView_body[data-layout="bubble"] .mx_MessageComposer {
        max-width: 100%;
    }
}

@media (max-width: 768px), (max-height: 500px) and (max-width: 900px) {
    .mx_RoomView_MessageList {
        padding-block: 12px;
        padding-inline: max(16px, env(safe-area-inset-left, 0px))
            max(16px, env(safe-area-inset-right, 0px));
    }

    .mx_RoomHeader {
        padding-inline: max(6px, env(safe-area-inset-left, 0px))
            max(6px, env(safe-area-inset-right, 0px));
    }

    .mx_RoomHeader button,
    .mx_MessageComposer button {
        min-width: 40px;
        min-height: 40px;
    }

}

@media (max-width: 420px) {
    .mx_RoomView_MessageList {
        padding-inline: max(16px, env(safe-area-inset-left, 0px))
            max(16px, env(safe-area-inset-right, 0px));
    }

    .mx_EventTile_content[data-event-layout="bubble"] {
        max-width: min(82vw, 34rem);
    }

    .mx_SendMessageComposer {
        padding-inline-start: 44px;
        padding-inline-end: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mx_MatrixChat *,
    .mx_MatrixChat *::before,
    .mx_MatrixChat *::after {
        scroll-behavior: auto !important;
    }
}
