/* ===========================================================================
   ویجتِ گفتگوی مشتری — فاز ۴۰، D37.

   هیچ کلاسِ بوت‌استرپ و هیچ متغیرِ پوسته‌ای استفاده نشده. پوستهٔ فروشگاه
   قرار است چند تا باشد ([D44])، و ویجتی که رنگش را از یک پوسته بگیرد در
   پوستهٔ بعدی یا نامرئی می‌شود یا زشت.

   همهٔ نام‌ها با `sw-` شروع می‌شوند تا با CSS پوسته تصادم نکنند.
   =========================================================================== */

.sw-root {
    position: fixed;
    inset-inline-end: 20px;
    inset-block-end: 20px;
    z-index: 9998;
    font-family: inherit;
    direction: rtl;
}

/* --- حباب --------------------------------------------------------------- */

.sw-bubble {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 0;
    background: #2563eb;
    color: #fff;
    box-shadow: 0 8px 24px rgba(37, 99, 235, .35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    transition: transform .15s;
}

.sw-bubble:hover { transform: scale(1.06); }

/* --- پنجره -------------------------------------------------------------- */

.sw-panel {
    position: absolute;
    inset-block-end: 74px;
    inset-inline-end: 0;
    width: 340px;
    max-width: calc(100vw - 40px);
    height: 460px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.sw-root.is-open .sw-panel { display: flex; }

.sw-header {
    background: #2563eb;
    color: #fff;
    padding: 14px 16px;
    position: relative;
}

.sw-title { font-weight: 700; font-size: 15px; }
.sw-header-status { font-size: 12px; opacity: .85; margin-top: 2px; }

.sw-close {
    position: absolute;
    inset-block-start: 10px;
    inset-inline-start: 12px;
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

/* --- انتخابِ بخش -------------------------------------------------------- */

.sw-picker {
    padding: 14px;
    overflow-y: auto;
    flex: 1 1 auto;
}

.sw-hint {
    font-size: 13px;
    color: #64748b;
    margin: 0 0 12px;
    line-height: 1.9;
}

.sw-desk {
    display: block;
    width: 100%;
    text-align: start;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.sw-desk:hover { border-color: #93c5fd; background: #eff6ff; }
.sw-desk-name { font-weight: 700; display: block; }
.sw-desk-desc { color: #64748b; display: block; margin-top: 2px; }

.sw-desk-closed {
    display: inline-block;
    margin-top: 4px;
    font-size: 11px;
    background: #fef3c7;
    color: #92400e;
    padding: 1px 8px;
    border-radius: 999px;
}

/* --- گفتگو -------------------------------------------------------------- */

.sw-chat {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sw-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sw-msg { max-width: 82%; }
.sw-msg.from-operator { align-self: flex-start; }
.sw-msg.from-visitor  { align-self: flex-end; }
.sw-msg.from-system   { align-self: center; max-width: 95%; }

.sw-bubble-msg {
    padding: 8px 12px;
    border-radius: 12px;
    background: #e2e8f0;
    font-size: 13px;
    line-height: 1.9;
    white-space: pre-wrap;
    word-break: break-word;
}

.from-visitor .sw-bubble-msg { background: #2563eb; color: #fff; }

.from-system .sw-bubble-msg {
    background: transparent;
    color: #64748b;
    font-size: 12px;
    text-align: center;
}

.sw-msg-meta { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.from-visitor .sw-msg-meta { text-align: start; }

.sw-attachment { font-size: 12px; display: block; margin-top: 3px; }

.sw-typing {
    font-size: 12px;
    color: #64748b;
    padding: 0 12px 4px;
    min-height: 18px;
}

.sw-composer {
    border-top: 1px solid #e2e8f0;
    padding: 8px;
    display: flex;
    gap: 6px;
    align-items: flex-end;
    background: #fff;
}

.sw-composer textarea {
    flex: 1 1 auto;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 10px;
    resize: none;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.9;
    max-height: 90px;
}

.sw-send {
    background: #2563eb;
    color: #fff;
    border: 0;
    border-radius: 10px;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .sw-root {
        inset-inline-end: 12px;
        inset-block-end: 12px;
    }

    .sw-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
    }
}
