.mg-chat {
    position: fixed;
    right: var(--mg-spacing-lg, 24px);
    bottom: calc(var(--mg-spacing-lg, 24px) + 72px);
    z-index: 100150;
    display: flex;
    flex-direction: column;
    width: 370px;
    height: min(560px, calc(100dvh - 130px));
    overflow: hidden;
    border-radius: 18px;
    background: var(--mg-bg, #fff);
    color: var(--mg-text);
    box-shadow: 0 24px 60px -12px rgba(15, 23, 42, 0.32);
    direction: rtl;
}

.mg-chat[hidden],
.mg-chat [hidden] {
    display: none !important;
}

.mg-chat--left {
    right: auto;
    left: var(--mg-spacing-lg, 24px);
    bottom: calc(var(--mg-spacing-lg, 24px) + 134px);
    height: min(560px, calc(100dvh - 190px));
}

.mg-chat__head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--mg-gradient-primary, var(--mg-primary));
    color: #fff;
}

.mg-chat__info {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mg-chat__info strong {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.5;
}

.mg-chat__info span {
    font-size: 12px;
    line-height: 1.5;
    opacity: 0.85;
}

.mg-chat__close {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: inherit;
    cursor: pointer;
}

.mg-chat__close:hover {
    background: rgba(255, 255, 255, 0.16);
}

.mg-chat__list {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--mg-bg-secondary, #f6f7f9);
}

.mg-chat-msg {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 82%;
}

.mg-chat-msg--visitor {
    align-self: flex-start;
    align-items: flex-start;
}

.mg-chat-msg--admin {
    align-self: flex-end;
    align-items: flex-end;
}

.mg-chat-msg__text {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.8;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.mg-chat-msg--visitor .mg-chat-msg__text {
    border-start-start-radius: 4px;
    background: var(--mg-primary);
    color: #fff;
}

.mg-chat-msg--admin .mg-chat-msg__text {
    border-start-end-radius: 4px;
    background: var(--mg-bg, #fff);
    color: var(--mg-text);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.mg-chat-msg__time {
    padding-inline: 4px;
    font-size: 11px;
    line-height: 1.4;
    color: var(--mg-text-muted);
}

.mg-chat__ask {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #e8ebf0;
    font-size: 13px;
    line-height: 1.6;
}

.mg-chat__ask span {
    flex: 1 1 100%;
}

.mg-chat__yes,
.mg-chat__no {
    min-height: 34px;
    padding: 4px 14px;
    border: 0;
    border-radius: 10px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.mg-chat__yes {
    background: var(--mg-primary);
    color: #fff;
}

.mg-chat__no {
    background: #eef1f5;
    color: var(--mg-text);
}

.mg-chat__yes:hover,
.mg-chat__no:hover,
.mg-chat__send:hover {
    filter: brightness(0.94);
}

.mg-chat__error {
    flex: 0 0 auto;
    margin: 0;
    padding: 6px 14px;
    font-size: 13px;
    line-height: 1.6;
    color: #b91c1c;
    background: #fef2f2;
}

.mg-chat__form {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #e8ebf0;
    background: var(--mg-bg, #fff);
}

.mg-chat__who {
    display: flex;
    gap: 8px;
}

.mg-chat__who input,
.mg-chat__row textarea {
    width: 100%;
    min-width: 0;
    padding: 9px 12px;
    border: 1px solid #dfe3ea;
    border-radius: 12px;
    background: var(--mg-bg, #fff);
    color: var(--mg-text);
    font: inherit;
    font-size: 14px;
    line-height: 1.6;
}

.mg-chat__who input:focus,
.mg-chat__row textarea:focus {
    outline: none;
    border-color: var(--mg-primary);
}

.mg-chat__hp {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.mg-chat__row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.mg-chat__row textarea {
    flex: 1 1 auto;
    max-height: 110px;
    resize: none;
}

.mg-chat__send {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: var(--mg-primary);
    color: #fff;
    cursor: pointer;
}

.mg-chat__send svg {
    transform: scaleX(-1);
}

.mg-chat__send:disabled {
    opacity: 0.6;
    cursor: default;
}

.mg-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #dc2626;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

.mg-chat-note {
    align-self: center;
    max-width: 92%;
    padding: 6px 12px;
    border-radius: 10px;
    background: #eef1f5;
    font-size: 12.5px;
    line-height: 1.7;
    text-align: center;
    color: var(--mg-text-muted);
}

.mg-chat__who input.is-bad {
    border-color: #dc2626;
}

.mg-chat-teaser {
    position: fixed;
    right: var(--mg-spacing-lg, 24px);
    bottom: calc(var(--mg-spacing-lg, 24px) + 72px);
    z-index: 1001;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    width: 280px;
    max-width: calc(100vw - 32px);
    padding: 12px 14px;
    border: 0;
    border-radius: 14px;
    background: var(--mg-bg, #fff);
    color: var(--mg-text);
    box-shadow: 0 14px 34px -10px rgba(15, 23, 42, 0.35);
    font: inherit;
    text-align: right;
    cursor: pointer;
    direction: rtl;
}

.mg-chat-teaser--left {
    right: auto;
    left: var(--mg-spacing-lg, 24px);
    bottom: calc(var(--mg-spacing-lg, 24px) + 134px);
}

.mg-chat-teaser__text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mg-chat-teaser__text strong {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.6;
}

.mg-chat-teaser__text span {
    display: -webkit-box;
    overflow: hidden;
    font-size: 13px;
    line-height: 1.7;
    color: var(--mg-text-muted);
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

body.mg-sticky-atc-on .mg-chat-teaser {
    bottom: calc(var(--mg-spacing-lg, 24px) + 148px);
}

body.mg-sticky-atc-on .mg-chat-teaser--left {
    bottom: calc(var(--mg-spacing-lg, 24px) + 210px);
}

.mg-fab-item--chat {
    cursor: pointer;
}

@media (max-width: 767px) {
    html.mg-chat-open,
    html.mg-chat-open body {
        overflow: hidden;
    }

    .mg-chat,
    .mg-chat--left {
        inset: 0;
        width: 100%;
        height: 100dvh;
        border-radius: 0;
    }

    .mg-chat__who input,
    .mg-chat__row textarea {
        font-size: 16px;
    }
}
