.mx-chat-session {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: var(--mx-chat-session-height, 70vh);
    max-height: var(--mx-chat-session-height, 70vh);
    min-height: 0;
    overflow: hidden;
}

.mx-chat-session > * + * {
    margin-top: 0.75rem;
}

.mx-chat-header,
.mx-chat-stream,
.mx-chat-composer {
    border-radius: 16px;
}

.mx-chat-header-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem;
}

.mx-chat-header-identity {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.mx-chat-header-avatar-host {
    width: 40px;
    height: 40px;
}

.mx-chat-header-avatar {
    width: 100%;
    height: 100%;
    border-radius: 999px;
    object-fit: cover;
    border: 1px solid var(--mud-palette-lines-default);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.15);
}

.mx-chat-header-text {
    min-width: 0;
}

.mx-chat-header-subtitle {
    color: var(--mud-palette-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mx-chat-header-demographics {
    min-height: 1.25rem;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.mx-chat-header-action-wrap {
    display: inline-flex;
    align-items: center;
}

.mx-chat-header-menu-button {
    border: 1px solid color-mix(in srgb, var(--mud-palette-lines-default) 80%, transparent);
    border-radius: 999px;
    background-color: color-mix(in srgb, var(--mud-palette-surface) 92%, var(--mud-palette-background) 8%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
}

.mx-chat-stream-wrap {
    position: relative;
    min-height: 0;
}

.mx-chat-stream {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    background-color: var(--mud-palette-surface);
}

.mx-chat-scroll-bottom-btn {
    position: absolute;
    left: 50%;
    bottom: 0.9rem;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--mud-palette-lines-default);
    background-color: color-mix(in srgb, var(--mud-palette-surface) 84%, transparent);
    color: var(--mud-palette-text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.55;
    cursor: pointer;
    z-index: 3;
}

.mx-chat-scroll-bottom-btn:hover {
    opacity: 0.95;
}

.mx-chat-scroll-bottom-btn[hidden] {
    display: none;
}

.mx-chat-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--mud-palette-text-secondary);
}

.mx-chat-item {
    width: 100%;
    margin-bottom: 0.45rem;
}

.mx-chat-row {
    display: flex;
    width: 100%;
    align-items: flex-end;
    gap: 0.75rem;
}

.mx-chat-row-mine {
    justify-content: flex-end;
    padding-right: 0.25rem;
}

.mx-chat-row-theirs {
    justify-content: flex-start;
    padding-left: 0.15rem;
}

.mx-chat-avatar-wrap {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    align-self: flex-end;
}

.mx-chat-avatar {
    width: 100%;
    height: 100%;
    border-radius: 999px;
    object-fit: cover;
    border: 2px solid var(--mud-palette-background);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.mx-chat-bubble-wrap {
    display: inline-flex;
    flex: 0 0 auto;
    max-width: min(72ch, calc(100% - 56px));
    min-width: 0;
    position: relative;
}

.mx-chat-row-mine .mx-chat-bubble-wrap {
    max-width: min(70ch, calc(100% - 112px));
    margin-right: 0.35rem;
}

.mx-chat-row-theirs .mx-chat-bubble-wrap {
    max-width: min(72ch, calc(100% - 74px));
    margin-left: 0.2rem;
}

.mx-chat-bubble {
    max-width: 100%;
    border-radius: 18px;
    border: 2px solid var(--mud-palette-lines-default);
    position: relative;
    overflow: visible !important;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}

.mx-chat-bubble-mine {
    background-color: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text, #fff);
    border-color: var(--mud-palette-primary-darken);
    border-bottom-right-radius: 6px;
}

.mx-chat-bubble-theirs {
    background-color: var(--mud-palette-background-grey);
    color: var(--mud-palette-text-primary);
    border-color: var(--mud-palette-lines-default);
    border-bottom-left-radius: 6px;
}

.mx-chat-bubble-deleted {
    background-color: color-mix(in srgb, var(--mud-palette-surface) 88%, var(--mud-palette-lines-default) 12%);
    color: color-mix(in srgb, var(--mud-palette-text-secondary) 84%, var(--mud-palette-text-primary) 16%);
    border-color: color-mix(in srgb, var(--mud-palette-lines-default) 70%, transparent);
    box-shadow: none;
}

.mx-chat-message-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.45;
}

.mx-chat-message-text-deleted {
    font-style: italic;
    opacity: 0.88;
}

.mx-chat-indicator-bar {
    position: absolute;
    bottom: -0.02rem;
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    z-index: 2;
}

.mx-chat-indicator-bar-mine {
    right: 0.2rem;
}

.mx-chat-indicator-bar-theirs {
    left: 0.2rem;
}

.mx-chat-security-indicator,
.mx-chat-status-icon,
.mx-chat-reported-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mx-chat-security-indicator-encrypted {
    color: color-mix(in srgb, var(--mud-palette-success) 70%, var(--mud-palette-text-primary) 30%);
}

.mx-chat-security-indicator-fallback {
    color: color-mix(in srgb, var(--mud-palette-warning) 72%, var(--mud-palette-text-primary) 28%);
}

.mx-chat-security-indicator-deleted {
    color: color-mix(in srgb, var(--mud-palette-text-secondary) 82%, var(--mud-palette-text-primary) 18%);
}

.mx-chat-reported-indicator {
    color: color-mix(in srgb, var(--mud-palette-error) 74%, var(--mud-palette-text-primary) 26%);
}

.mx-chat-status-icon-mine {
    color: var(--mud-palette-primary-text, #fff);
}

.mx-chat-status-icon-unread {
    opacity: 0.7;
}

.mx-chat-row-action-wrap {
    width: 24px;
    flex: 0 0 24px;
    align-self: flex-end;
    display: inline-flex;
    justify-content: center;
    margin-bottom: 7px;
}

.mx-chat-message-menu-button,
.mx-chat-action-button {
    background-color: color-mix(in srgb, var(--mud-palette-surface) 92%, var(--mud-palette-lines-default) 8%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.mx-chat-message-menu-placeholder {
    width: 24px;
    height: 24px;
    display: inline-block;
    opacity: 0;
    pointer-events: none;
}

.mx-chat-action-bar {
    position: absolute;
    top: 50%;
    left: calc(100% + 8px);
    display: inline-flex;
    gap: 0.25rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
    z-index: 4;
    transform: translateY(-50%);
}

.mx-chat-item:hover .mx-chat-action-bar,
.mx-chat-item:focus-within .mx-chat-action-bar,
.mx-chat-action-bar-open {
    opacity: 1;
    pointer-events: auto;
}

.mx-chat-reaction-summaries {
    position: absolute;
    bottom: -6px;
    display: inline-flex;
    gap: 0.2rem;
    z-index: 3;
}

.mx-chat-reaction-summaries-mine {
    left: -6px;
}

.mx-chat-reaction-summaries-theirs {
    right: -6px;
}

.mx-chat-reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.12rem;
    font-size: 0.8rem;
}

.mx-chat-reaction-count {
    color: var(--mud-palette-text-secondary);
    font-size: 0.72rem;
}

.mx-chat-reaction-picker {
    position: absolute;
    top: 50%;
    left: calc(100% + 14px);
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.12rem;
    padding: 0.14rem 0.16rem;
    border-radius: 10px;
    background-color: color-mix(in srgb, var(--mud-palette-surface) 96%, var(--mud-palette-lines-default) 4%);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
    z-index: 6;
    transform: translateY(-50%);
}

.mx-chat-reaction-picker-button {
    width: 24px;
    height: 24px;
    min-width: 24px;
    padding: 0;
    border-radius: 50%;
}

.mx-chat-reaction-picker-button-selected {
    background-color: color-mix(in srgb, var(--mud-palette-primary) 14%, var(--mud-palette-surface) 86%);
}

.mx-chat-meta-row {
    width: 100%;
    display: flex;
    margin-top: 0.08rem;
}

.mx-chat-meta-row-mine {
    justify-content: flex-end;
    padding-right: 42px;
}

.mx-chat-meta-row-theirs {
    justify-content: flex-start;
    padding-left: 42px;
}

.mx-chat-meta {
    color: var(--mud-palette-text-secondary);
    opacity: 0.8;
}

.mx-chat-meta-time {
    font-size: 0.72rem;
    line-height: 1.2;
}

.mx-chat-composer-input-wrap {
    flex: 1 1 auto;
    min-width: 0;
}

.mx-chat-composer-main-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.mx-chat-composer-enter-hint,
.mx-chat-composer-char-count,
.mx-chat-composer-e2ee-status {
    font-size: 0.72rem;
    line-height: 1.2;
}

.mx-chat-composer-enter-hint,
.mx-chat-composer-char-count {
    color: color-mix(in srgb, var(--mud-palette-text-secondary) 82%, transparent);
}

.mx-chat-composer-e2ee-status-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.14rem;
}

.mx-chat-composer-e2ee-status-ready {
    color: color-mix(in srgb, var(--mud-palette-success) 70%, var(--mud-palette-text-secondary) 30%);
}

.mx-chat-composer-e2ee-status-warning {
    color: color-mix(in srgb, var(--mud-palette-warning) 70%, var(--mud-palette-text-secondary) 30%);
}

.mx-chat-composer-e2ee-status-error {
    color: color-mix(in srgb, var(--mud-palette-error) 78%, var(--mud-palette-text-secondary) 22%);
}

.mx-chat-composer-char-count {
    text-align: right;
}

.mx-chat-composer-char-count-over {
    color: var(--mud-palette-error);
}

.mx-chat-composer-send-button {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 12px;
}

@media (max-width: 760px) {
    .mx-chat-header-row {
        gap: 0.35rem;
    }

    .mx-chat-header-avatar-host {
        width: 32px;
        height: 32px;
    }

    .mx-chat-row-mine .mx-chat-bubble-wrap {
        max-width: calc(100% - 96px);
        margin-right: 0.2rem;
    }

    .mx-chat-row-theirs .mx-chat-bubble-wrap {
        max-width: calc(100% - 64px);
        margin-left: 0.1rem;
    }

    .mx-chat-avatar-wrap {
        width: 30px;
        height: 30px;
        flex-basis: 30px;
    }

    .mx-chat-meta-row-mine {
        padding-right: 38px;
    }

    .mx-chat-meta-row-theirs {
        padding-left: 38px;
    }
}
