/* Окно онлайн-чата. Ширина и высота задаются переменными — их же меняет
   растягивание за края, а положение окна хранится в left/top. */

.ms-chat {
    --ms-chat-color: #5b38ed;
    --ms-chat-w: 380px;
    --ms-chat-h: 520px;
    --ms-chat-radius: 16px;

    position: fixed;
    z-index: 999998;
    inset-block-end: var( --ms-chat-offset-y, 24px );
    inset-inline-end: var( --ms-chat-offset-x, 24px );
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    color: #1d1f22;
}

.ms-chat.is-left { inset-inline-end: auto; inset-inline-start: var( --ms-chat-offset-x, 24px ); }

/* ---------- Кнопка ---------- */

.ms-chat-launcher {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-inline-start: auto;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.ms-chat-launcher-text {
    background: #fff;
    border-radius: 999px;
    box-shadow: 0 6px 24px rgba( 0, 0, 0, .14 );
    padding: 10px 16px;
    white-space: nowrap;
    font-size: 13px;
}

.ms-chat-launcher-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var( --ms-chat-color );
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 8px 28px rgba( 0, 0, 0, .22 );
    transition: transform .18s ease;
}

.ms-chat-launcher:hover .ms-chat-launcher-icon { transform: scale( 1.06 ); }
.ms-chat-launcher-icon svg { width: 26px; height: 26px; fill: currentColor; }

.ms-chat-badge {
    position: absolute;
    inset-block-start: -4px;
    inset-inline-end: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    background: #e02d3c;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    display: none;
    place-items: center;
    padding: 0 6px;
}

.ms-chat-launcher-icon { position: relative; }
.ms-chat.has-unread .ms-chat-badge { display: grid; }

/* ---------- Окно ---------- */

.ms-chat-panel {
    position: fixed;
    inset-block-end: calc( var( --ms-chat-offset-y, 24px ) + 72px );
    inset-inline-end: var( --ms-chat-offset-x, 24px );
    width: var( --ms-chat-w );
    height: var( --ms-chat-h );
    max-width: calc( 100vw - 32px );
    max-height: calc( 100vh - 120px );
    background: #fff;
    border-radius: var( --ms-chat-radius );
    box-shadow: 0 18px 60px rgba( 0, 0, 0, .24 );
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.ms-chat.is-left .ms-chat-panel { inset-inline-end: auto; inset-inline-start: var( --ms-chat-offset-x, 24px ); }

/* Окно перетащили — дальше положение задаём сами. */
.ms-chat-panel.is-moved {
    inset-block-end: auto;
    inset-inline-end: auto;
    inset-inline-start: auto;
}

.ms-chat.is-open .ms-chat-panel { display: flex; }
.ms-chat.is-open .ms-chat-launcher-text { display: none; }

.ms-chat-header {
    background: var( --ms-chat-color );
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.ms-chat-header.is-dragging { cursor: grabbing; }
.ms-chat-title { font-weight: 600; }
.ms-chat-subtitle { font-size: 12px; opacity: .85; }
.ms-chat-header-text { min-width: 0; }
.ms-chat-header-actions { margin-inline-start: auto; display: flex; gap: 4px; }

.ms-chat-icon-btn {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: rgba( 255, 255, 255, .16 );
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
}

.ms-chat-icon-btn:hover { background: rgba( 255, 255, 255, .28 ); }
.ms-chat-icon-btn svg { width: 16px; height: 16px; fill: currentColor; }

.ms-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f6f7f9;
    overscroll-behavior: contain;
}

.ms-chat-msg {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 1px 2px rgba( 0, 0, 0, .08 );
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.ms-chat-msg.is-visitor {
    align-self: flex-end;
    background: var( --ms-chat-color );
    color: #fff;
}

.ms-chat-msg.is-system {
    align-self: center;
    background: transparent;
    box-shadow: none;
    font-size: 12px;
    color: #6b7280;
}

.ms-chat-msg a { color: inherit; text-decoration: underline; }
.ms-chat-msg-name { font-size: 11px; opacity: .7; margin-bottom: 2px; }
.ms-chat-msg-time { font-size: 10px; opacity: .6; margin-top: 3px; text-align: end; }
.ms-chat-mark { margin-inline-start: 2px; }
.ms-chat-mark.is-read { opacity: 1; font-weight: 600; letter-spacing: -2px; }
.ms-chat-panel.is-dropping { outline: 2px dashed var( --ms-chat-color ); outline-offset: -6px; }

/* Вложения */
.ms-chat-photo { display: block; margin-top: 6px; }
.ms-chat-photo img { max-width: 100%; max-height: 220px; border-radius: 10px; display: block; }
.ms-chat-file-link { display: inline-block; margin-top: 4px; }

/* «Печатает…» */
.ms-chat-typing {
    align-self: flex-start;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba( 0, 0, 0, .08 );
    padding: 9px 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ms-chat-typing-dots { display: flex; gap: 4px; }
.ms-chat-typing-text { font-size: 12px; color: #6b7280; }

.ms-chat-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #b6bac2;
    animation: ms-chat-dot 1.2s infinite ease-in-out;
}

.ms-chat-typing i:nth-child( 2 ) { animation-delay: .15s; }
.ms-chat-typing i:nth-child( 3 ) { animation-delay: .3s; }

@keyframes ms-chat-dot {
    0%, 60%, 100% { opacity: .35; transform: translateY( 0 ); }
    30%           { opacity: 1; transform: translateY( -3px ); }
}

@media ( prefers-reduced-motion: reduce ) {
    .ms-chat-typing i { animation: none; }
}

/* Форма телефона — её открывает менеджер кнопкой в Telegram */
.ms-chat-phone {
    align-self: stretch;
    background: #fff;
    border: 1px solid var( --ms-chat-color );
    border-radius: 14px;
    padding: 12px 14px;
}

.ms-chat-phone-text { font-size: 13px; margin-bottom: 8px; }
.ms-chat-phone-row { display: flex; gap: 8px; }

.ms-chat-phone-input {
    flex: 1;
    min-width: 0;
    font: inherit;
    padding: 8px 10px;
    border: 1px solid #dcdde1;
    border-radius: 8px;
    outline: none;
}

.ms-chat-phone-input:focus { border-color: var( --ms-chat-color ); }

.ms-chat-phone-send {
    border: 0;
    border-radius: 8px;
    padding: 8px 14px;
    background: var( --ms-chat-color );
    color: #fff;
    font: inherit;
    cursor: pointer;
}

.ms-chat-phone-error { color: #e02d3c; font-size: 12px; min-height: 16px; margin-top: 4px; }

.ms-chat-consent {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-top: 10px;
    font-size: 12px;
    line-height: 1.4;
    color: #4b5563;
    cursor: pointer;
}

.ms-chat-consent input { margin-top: 2px; flex: 0 0 auto; }
.ms-chat-consent a { color: var( --ms-chat-color ); }

/* Ловушка для ботов: людям не видна и в фокус не попадает. */
.ms-chat-trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.ms-chat-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.ms-chat-quick button {
    border: 1px solid var( --ms-chat-color );
    background: #fff;
    color: var( --ms-chat-color );
    border-radius: 999px;
    padding: 7px 14px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.ms-chat-quick button:hover { background: var( --ms-chat-color ); color: #fff; }

/* Иконки, поле ввода и кнопка отправки стоят на одной линии: у всех
   одинаковая высота строки, поэтому ничего не «съезжает» вниз. */
.ms-chat-footer {
    border-top: 1px solid #ececef;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    position: relative;
}

.ms-chat-input {
    flex: 1;
    border: 0;
    resize: none;
    font: inherit;
    line-height: 20px;
    padding: 8px 6px;
    min-height: 36px;
    max-height: 96px;
    outline: none;
    background: transparent;
    color: inherit;
}

.ms-chat-send {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: var( --ms-chat-color );
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    flex: 0 0 auto;
}

.ms-chat-send[disabled] { opacity: .45; cursor: default; }
.ms-chat-send svg { width: 16px; height: 16px; fill: currentColor; }

.ms-chat-tools { display: flex; gap: 2px; }

.ms-chat-tool {
    width: 32px;
    height: 32px;
    border: 0;
    background: none;
    color: #8a8f98;
    cursor: pointer;
    border-radius: 8px;
    display: grid;
    place-items: center;
    padding: 0;
    font-size: 16px;
}

.ms-chat-tool:hover { background: #f1f2f4; color: #1d1f22; }
.ms-chat-tool svg { width: 18px; height: 18px; fill: currentColor; }

/* Всплывающие панели: эмодзи и меню. */
.ms-chat-popover {
    position: absolute;
    inset-block-end: 54px;
    inset-inline-start: 12px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 34px rgba( 0, 0, 0, .18 );
    padding: 10px;
    display: none;
    z-index: 2;
}

.ms-chat-popover.is-open { display: block; }
.ms-chat-emoji { display: grid; grid-template-columns: repeat( 6, 32px ); gap: 2px; }

.ms-chat-emoji button {
    width: 32px;
    height: 32px;
    border: 0;
    background: none;
    cursor: pointer;
    font-size: 19px;
    border-radius: 8px;
    padding: 0;
}

.ms-chat-emoji button:hover { background: #f1f2f4; }

.ms-chat-menu button {
    display: block;
    width: 100%;
    text-align: start;
    border: 0;
    background: none;
    font: inherit;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 8px;
    white-space: nowrap;
}

.ms-chat-menu button:hover { background: #f1f2f4; }

/* ---------- Растягивание ---------- */

.ms-chat-resize {
    position: absolute;
    z-index: 3;
    touch-action: none;
}

.ms-chat-resize-n { inset-block-start: -3px; inset-inline: 12px; height: 8px; cursor: ns-resize; }
.ms-chat-resize-w { inset-inline-start: -3px; inset-block: 12px; width: 8px; cursor: ew-resize; }
.ms-chat-resize-e { inset-inline-end: -3px; inset-block: 12px; width: 8px; cursor: ew-resize; }
.ms-chat-resize-nw { inset-block-start: -4px; inset-inline-start: -4px; width: 16px; height: 16px; cursor: nwse-resize; }
.ms-chat-resize-ne { inset-block-start: -4px; inset-inline-end: -4px; width: 16px; height: 16px; cursor: nesw-resize; }

/* ---------- Телефон ---------- */

@media ( max-width: 600px ) {
    .ms-chat { inset-block-end: var( --ms-chat-offset-y, 16px ); inset-inline-end: var( --ms-chat-offset-x, 16px ); }

    .ms-chat-panel,
    .ms-chat-panel.is-moved {
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: none;
        max-height: none;
        border-radius: 0;
    }

    .ms-chat-header { cursor: default; }
    .ms-chat-resize { display: none; }
    .ms-chat-launcher-text { display: none; }
}
