﻿.nw-livechat {
    position: fixed;
    z-index: 1085;
    right: 22px;
    bottom: 92px;
    font-family: inherit;
    direction: rtl;
    touch-action: none;
}

.nw-livechat * {
    box-sizing: border-box;
}

.nw-livechat.is-hidden {
    display: none;
}

.nw-livechat.is-intro-pending {
    opacity: 0;
    transform: translate3d(0, 24px, 0) scale(.96);
    pointer-events: none;
}

.nw-livechat.is-intro-active {
    animation: nwLiveChatEnter .72s cubic-bezier(.2, .9, .25, 1.18) both;
}

.nw-livechat.is-intro-active:not(.is-open) .nw-livechat-prompt {
    animation: nwLiveChatAttention 1.7s ease .72s 1;
}

@keyframes nwLiveChatEnter {
    0% {
        opacity: 0;
        transform: translate3d(0, 28px, 0) scale(.94);
    }
    72% {
        opacity: 1;
        transform: translate3d(0, -4px, 0) scale(1.01);
    }
    100% {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

@keyframes nwLiveChatAttention {
    0%, 100% {
        box-shadow: 0 14px 34px rgba(15, 23, 42, .14);
    }
    35% {
        box-shadow: 0 16px 38px rgba(15, 23, 42, .18), 0 0 0 10px rgba(17, 17, 17, .08);
    }
    65% {
        box-shadow: 0 16px 38px rgba(15, 23, 42, .18), 0 0 0 16px rgba(17, 17, 17, 0);
    }
}

.nw-livechat:not(.is-open).is-dragged {
    right: 22px !important;
    left: auto !important;
    top: auto !important;
    bottom: 92px !important;
}

.nw-livechat-prompt {
    position: relative;
    z-index: 1;
    isolation: isolate;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 218px;
    max-width: min(300px, calc(100vw - 36px));
    padding: 9px 10px;
    border: 1px solid rgba(17, 17, 17, .08);
    border-radius: 16px;
    background: #fff;
    color: #151515;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .14);
    cursor: pointer;
    user-select: none;
}

.nw-livechat-prompt:hover,
.nw-livechat-prompt:focus-visible {
    background: #fff !important;
    color: #151515 !important;
    border-color: rgba(17, 17, 17, .14) !important;
    box-shadow: 0 16px 36px rgba(15, 23, 42, .18) !important;
    opacity: 1;
    transform: translateY(-2px);
}

.nw-livechat-prompt:focus-visible {
    outline: 3px solid rgba(17, 17, 17, .16);
    outline-offset: 3px;
}

.nw-livechat-prompt-icon,
.nw-livechat-send,
.nw-livechat-close,
.nw-livechat-minimize,
.nw-livechat-dismiss {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    cursor: pointer;
}

.nw-livechat-prompt-icon {
    width: 38px;
    height: 38px;
    border-radius: 13px;
    background: #111;
    color: #fff;
    flex: 0 0 auto;
    font-weight: 900;
}

.nw-livechat-prompt-title {
    display: block;
    font-weight: 800;
    font-size: 13px;
}

.nw-livechat-prompt-text {
    display: block;
    margin-top: 2px;
    color: #666;
    font-size: 11px;
    line-height: 1.8;
}

.nw-livechat-prompt-copy {
    position: relative;
    z-index: 2;
    min-width: 0;
    text-align: right;
}

.nw-livechat.is-prompt-collapsed .nw-livechat-prompt {
    width: 54px;
    min-width: 54px;
    height: 54px;
    padding: 0;
    justify-content: center;
    border-radius: 18px;
}

.nw-livechat.is-prompt-collapsed .nw-livechat-prompt-copy,
.nw-livechat.is-prompt-collapsed .nw-livechat-dismiss {
    display: none !important;
}

.nw-livechat.is-prompt-collapsed .nw-livechat-prompt-icon {
    width: 54px;
    height: 54px;
    border-radius: 18px;
}

.nw-livechat-dismiss {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-inline-start: auto;
    border-radius: 50%;
    background: #f3f4f6;
    color: #555;
    font-size: 17px;
    font-weight: 800;
    line-height: 1;
}

.nw-livechat-panel {
    display: none;
    width: min(350px, calc(100vw - 28px));
    overflow: hidden;
    border: 1px solid rgba(17, 17, 17, .08);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 18px 45px rgba(15, 23, 42, .20);
}

.nw-livechat.is-open .nw-livechat-prompt {
    display: none;
}

.nw-livechat.is-open .nw-livechat-panel {
    display: block;
}

.nw-livechat-head {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px 10px 64px;
    min-height: 68px;
    background: #171717 !important;
    color: #fff !important;
    cursor: move;
    user-select: none;
}

.nw-livechat-head-copy {
    display: block !important;
    min-width: 0;
    color: #fff !important;
}

.nw-livechat-head strong {
    display: block;
    font-size: 14px;
}

.nw-livechat-head span {
    display: block;
    margin-top: 2px;
    color: rgba(255, 255, 255, .72);
    font-size: 11px;
    line-height: 1.7;
}

.nw-livechat-head span i {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-left: 4px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, .16);
}

.nw-livechat-head-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    position: absolute;
    left: 10px;
    top: 10px;
    z-index: 2;
}

.nw-livechat-close,
.nw-livechat-minimize {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 22px !important;
    min-width: 22px !important;
    height: 22px !important;
    padding: 0 !important;
    border-radius: 50%;
    background: rgba(255, 255, 255, .14) !important;
    color: #fff !important;
    font-size: 13px;
    line-height: 1;
    box-shadow: none;
}

.nw-livechat-close:hover,
.nw-livechat-minimize:hover {
    background: rgba(255, 255, 255, .26) !important;
}

.nw-livechat-minimize {
    font-size: 12px;
}

.nw-livechat-body {
    height: min(260px, calc(100vh - 330px));
    min-height: 160px;
    padding: 12px;
    overflow-y: auto;
    background: #f7f7f8;
}

.nw-livechat-welcome {
    margin: 22px auto;
    padding: 14px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    background: #fff;
    color: #333;
    text-align: center;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .05);
}

.nw-livechat-welcome > span {
    display: block;
    margin-bottom: 5px;
    font-size: 22px;
}

.nw-livechat-welcome strong {
    display: block;
    font-size: 13px;
}

.nw-livechat-welcome p {
    margin: 4px 0 0;
    color: #667085;
    font-size: 11.5px;
    line-height: 1.8;
}

.nw-livechat.has-started .nw-livechat-welcome {
    display: none;
}

.nw-livechat-loadmore {
    display: block;
    margin: 0 auto 10px;
    padding: 5px 14px;
    border: 1px solid #e0e2e8;
    border-radius: 999px;
    background: #fff;
    color: #555;
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}

.nw-livechat-loadmore:hover {
    background: #f4f4f6;
    color: #111;
}

.nw-livechat-loadmore:disabled {
    opacity: .6;
    cursor: default;
}

.nw-livechat-message {
    width: fit-content;
    max-width: 82%;
    margin-bottom: 6px;
    padding: 7px 12px;
    border-radius: 14px;
    background: #fff;
    color: #171717;
    font-size: 12.5px;
    line-height: 1.9;
    direction: rtl;
    text-align: right;
    unicode-bidi: plain-text;
    overflow-wrap: anywhere;
    box-shadow: 0 4px 12px rgba(15, 23, 42, .05);
}

/* پیام کاربر: تیره، سمت راست (مثل پیام‌رسان‌های فارسی) */
.nw-livechat-message.visitor {
    margin-left: auto;
    margin-right: 0;
    background: #111;
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* پیام پشتیبان: روشن، سمت چپ */
.nw-livechat-message.operator {
    margin-right: auto;
    margin-left: 0;
    border: 1px solid #ececf1;
    border-bottom-left-radius: 4px;
}

.nw-livechat-message.system {
    margin-inline: auto;
    background: #eef7f2;
    color: #166534;
    text-align: center;
    box-shadow: none;
}

.nw-livechat-message.is-pending {
    opacity: .72;
}

.nw-livechat-message.is-failed {
    background: #fff1f2;
    color: #b42318;
    border: 1px solid #fecdd3;
    opacity: 1;
}

.nw-livechat-form {
    display: grid;
    gap: 7px;
    padding: 10px;
    background: #fff;
    border-top: 1px solid rgba(17, 17, 17, .08);
}

.nw-livechat-profile {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.nw-livechat.has-started .nw-livechat-profile {
    display: none;
}

.nw-livechat input,
.nw-livechat textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid #e4e7ec;
    border-radius: 11px;
    padding: 8px 10px;
    font: inherit;
    font-size: 12px;
    background: #fff;
    color: #111;
    outline: 0;
}

/* کامپوزر تک‌ردیفه مثل پیام‌رسان‌ها: فیلد کوچک + دکمه‌ی گرد ارسال کنارش */
.nw-livechat-composer {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.nw-livechat-composer textarea {
    flex: 1;
    min-height: 38px;
    height: 38px;
    max-height: 96px;
    padding: 8px 14px;
    border-radius: 19px;
    background: #f4f4f6;
    border-color: transparent;
    resize: none;
    line-height: 1.7;
    scrollbar-width: none;
}

.nw-livechat-composer textarea::-webkit-scrollbar {
    display: none;
}

.nw-livechat-composer textarea:focus {
    background: #fff;
    border-color: #d5d7de;
}

.nw-livechat-send {
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #111;
    color: #fff;
    padding: 0;
}

.nw-livechat-send:hover {
    opacity: .85;
}

.nw-livechat-status {
    color: #888;
    font-size: 11px;
    min-height: 14px;
    line-height: 1.3;
    padding-inline-start: 4px;
}

.nw-livechat-status:empty {
    display: none;
}

@media (max-width: 991.98px) {
    .nw-livechat {
        right: 12px;
        left: auto;
        bottom: calc(var(--mobile-toolbar-height, 68px) + var(--mobile-actionbar-height, 0px) + 12px);
        touch-action: auto;
    }

    .nw-livechat.is-dragged {
        left: auto !important;
        right: 12px !important;
        top: auto !important;
        bottom: calc(var(--mobile-toolbar-height, 68px) + var(--mobile-actionbar-height, 0px) + 12px) !important;
    }

    .nw-livechat.is-open.is-dragged {
        left: 12px !important;
        right: 12px !important;
        top: auto !important;
        bottom: calc(var(--mobile-toolbar-height, 68px) + 8px) !important;
    }

    .nw-livechat.is-open {
        right: 10px;
        left: 10px;
        bottom: calc(var(--mobile-toolbar-height, 68px) + 8px);
        z-index: 1040;
    }

    .nw-livechat-prompt {
        width: auto;
        min-width: 0;
        height: auto;
        max-width: min(286px, calc(100vw - 24px));
        padding: 8px 9px;
        justify-content: flex-start;
        border-radius: 17px;
        box-shadow: 0 12px 28px rgba(15, 23, 42, .18);
    }

    .nw-livechat-prompt-copy {
        display: block;
    }

    .nw-livechat-prompt-icon {
        width: 42px;
        height: 42px;
        border-radius: 14px;
        font-size: 17px;
    }

    .nw-livechat-panel {
        width: 100%;
        min-width: 0;
        max-width: none;
        max-height: calc(100dvh - var(--mobile-toolbar-height, 68px) - 28px);
        border-radius: 18px;
    }

    .nw-livechat-body {
        height: min(42dvh, 360px);
        min-height: 180px;
    }

    .nw-livechat-profile {
        grid-template-columns: 1fr;
    }

    .nw-livechat-composer textarea {
        min-height: 40px;
        height: 40px;
        max-height: 80px;
    }

    .nw-livechat-send {
        width: 40px;
        height: 40px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .nw-livechat.is-intro-pending {
        opacity: 1;
        transform: none;
        pointer-events: auto;
    }

    .nw-livechat.is-intro-active,
    .nw-livechat.is-intro-active:not(.is-open) .nw-livechat-prompt {
        animation: none;
    }
}
