#customerSupportWidget,
#customerSupportWidget * {
    box-sizing: border-box;
    font-family: 'IRANSans', 'Vazir', Tahoma, sans-serif;
}

#customerSupportWidget {
    --csw-navy: #0d2847;
    --csw-navy-light: #0f2d4a;
    --csw-gold: #c9a227;
    --csw-gold-light: #ffd86b;
    --csw-green: #10b981;
    --csw-ink: #1e293b;
    --csw-muted: #64748b;
    --csw-line: #e2e8f0;
    --csw-bg: #f1f5f9;
    color: var(--csw-ink);
    direction: rtl;
}

#customerSupportWidget [hidden] { display: none !important; }

.csw-launch {
    align-items: center;
    background: linear-gradient(150deg, var(--csw-navy-light), var(--csw-navy));
    border: 1px solid rgba(255, 216, 107, .3);
    border-radius: 999px;
    bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 10px 28px rgba(13, 40, 71, .4);
    color: #fff;
    cursor: pointer;
    direction: rtl;
    display: flex;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    gap: 11px;
    overflow: hidden;
    padding: 5px 5px 5px 15px;
    position: fixed;
    right: 22px;
    transition: box-shadow .2s ease, transform .2s ease;
    z-index: 999990;
}

.csw-launch:hover {
    box-shadow: 0 14px 34px rgba(13, 40, 71, .52);
    transform: translateY(-2px);
}

.csw-launch-avatar {
    flex: 0 0 auto;
    height: 54px;
    order: 1;
    position: relative;
    width: 54px;
}

.csw-launch-avatar img {
    border: 2px solid var(--csw-gold-light);
    border-radius: 50%;
    display: block;
    height: 100%;
    object-fit: cover;
    width: 100%;
}

.csw-launch-avatar i {
    background: #94a3b8;
    border: 2.5px solid var(--csw-navy);
    border-radius: 50%;
    bottom: 1px;
    height: 13px;
    position: absolute;
    right: 1px;
    width: 13px;
}

.csw-launch-unread {
    align-items: center;
    background: #ef4444;
    border: 2px solid #fff;
    border-radius: 999px;
    color: #fff;
    display: flex;
    font-size: 10px;
    font-weight: 800;
    height: 21px;
    justify-content: center;
    left: -1px;
    line-height: 1;
    min-width: 21px;
    padding: 0 4px;
    position: absolute;
    top: -1px;
    z-index: 3;
}

#customerSupportWidget.is-online .csw-launch-avatar i { background: var(--csw-green); }
.csw-launch-label {
    margin: 0 4px;
    max-width: 180px;
    opacity: 1;
    order: 2;
    overflow: hidden;
    transition: margin .28s ease, max-width .28s ease, opacity .2s ease;
    white-space: nowrap;
}
.csw-launch.collapsed { gap: 0; padding-left: 5px; }
.csw-launch.collapsed .csw-launch-label { margin: 0; max-width: 0; opacity: 0; }

#customerSupportWidget.is-chat-open .csw-launch,
#customerSupportWidget.is-chat-open .csw-teaser { display: none; }

.csw-teaser {
    background: #fff;
    border: 1px solid var(--csw-line);
    border-radius: 16px;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 16px 44px rgba(13,40,71,.24);
    cursor: pointer;
    max-width: calc(100vw - 36px);
    opacity: 0;
    padding: 14px 14px 13px;
    pointer-events: none;
    position: fixed;
    right: 22px;
    transform: translateY(12px);
    transition: opacity .3s ease, transform .3s ease;
    width: 300px;
    z-index: 999989;
}
.csw-teaser.show { opacity: 1; pointer-events: auto; transform: none; }
.csw-teaser::after {
    background: #fff;
    border-bottom: 1px solid var(--csw-line);
    border-left: 1px solid var(--csw-line);
    bottom: -7px;
    content: '';
    height: 14px;
    position: absolute;
    right: 30px;
    transform: rotate(-45deg);
    width: 14px;
}
.csw-teaser-close {
    align-items: center;
    background: var(--csw-bg);
    border: 0;
    border-radius: 50%;
    color: var(--csw-muted);
    cursor: pointer;
    display: flex;
    font: inherit;
    font-size: 21px;
    height: 26px;
    justify-content: center;
    left: 9px;
    line-height: 1;
    padding: 0;
    position: absolute;
    top: 9px;
    width: 26px;
}
.csw-teaser-head { align-items: center; display: flex; gap: 10px; }
.csw-teaser-head img {
    border: 2px solid #fef9e7;
    border-radius: 50%;
    flex: 0 0 auto;
    height: 40px;
    object-fit: cover;
    width: 40px;
}
.csw-teaser-head b { color: #0f172a; display: block; font-size: 13px; font-weight: 800; }
.csw-teaser-head small { color: var(--csw-muted); display: block; font-size: 10.5px; margin-top: 2px; }
.csw-teaser-text { color: var(--csw-ink); font-size: 12.5px; line-height: 1.9; margin: 10px 0 11px; }
.csw-teaser-cta {
    background: linear-gradient(135deg, var(--csw-gold), var(--csw-gold-light));
    border-radius: 10px;
    box-shadow: 0 6px 16px rgba(201,162,39,.3);
    color: var(--csw-navy);
    display: block;
    font-size: 13px;
    font-weight: 800;
    padding: 10px;
    text-align: center;
}

.csw-overlay {
    backdrop-filter: blur(3px);
    background: rgba(10, 31, 56, .6);
    inset: 0;
    position: fixed;
    z-index: 999998;
}

.csw-panel {
    background: var(--csw-bg);
    border-radius: 16px;
    bottom: 22px;
    box-shadow: 0 24px 60px rgba(10, 31, 56, .35);
    direction: rtl;
    max-height: min(680px, calc(100dvh - 24px));
    overflow: hidden;
    position: fixed;
    right: 22px;
    width: min(430px, calc(100vw - 24px));
    z-index: 999999;
}

.csw-panel.csw-auth-mode {
    display: flex;
    flex-direction: column;
    height: min(720px, calc(100dvh - 44px));
}
.csw-auth-mode .csw-welcome,
.csw-auth-mode #csw-chat,
.csw-auth-mode .csw-self { display: none; }

.csw-panel-head {
    align-items: center;
    background: linear-gradient(165deg, var(--csw-navy-light), var(--csw-navy));
    color: #fff;
    display: flex;
    gap: 11px;
    min-height: 76px;
    padding: 12px 16px 17px;
    position: relative;
}

.csw-panel-head::after {
    background: var(--csw-bg);
    border-radius: 14px 14px 0 0;
    bottom: -1px;
    content: '';
    height: 12px;
    left: 0;
    position: absolute;
    right: 0;
}

.csw-panel-head > img {
    border: 2px solid rgba(255, 216, 107, .55);
    border-radius: 50%;
    flex: 0 0 auto;
    height: 48px;
    object-fit: cover;
    width: 48px;
}

.csw-panel-head > span {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.csw-panel-head strong { font-size: 15px; font-weight: 800; }
.csw-panel-head small { align-items: center; color: rgba(255,255,255,.78); display: flex; font-size: 10.5px; gap: 6px; margin-top: 3px; }
.csw-panel-head small i { background: var(--csw-green); border-radius: 50%; height: 8px; width: 8px; }

.csw-close {
    align-items: center;
    background: rgba(255,255,255,.1);
    border: 0;
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    display: flex;
    flex: 0 0 auto;
    font: inherit;
    font-size: 24px;
    height: 36px;
    justify-content: center;
    line-height: 1;
    width: 36px;
}

.csw-close:hover { background: rgba(255,255,255,.2); }

.csw-panel-body {
    max-height: calc(100dvh - 112px);
    overflow-y: auto;
    padding: 18px;
}

.csw-auth-mode .csw-panel-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    isolation: isolate;
    justify-content: flex-start;
    position: relative;
}

.csw-auth-mode .csw-panel-body::before {
    background: url('/images/chat-back.jpg') center / cover no-repeat;
    content: '';
    filter: blur(1px) saturate(0%);
    inset: 0;
    position: absolute;
    transform: scale(1.06);
    z-index: -2;
}

.csw-auth-mode .csw-panel-body::after {
    background: rgba(248, 250, 252, .5);
    content: '';
    inset: 0;
    position: absolute;
    z-index: -1;
}

.csw-welcome {
    background: #fff;
    border: 1px solid var(--csw-line);
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 2px 8px rgba(13,40,71,.06);
    color: var(--csw-ink);
    font-size: 13px;
    line-height: 1.9;
    margin: 0 0 16px;
    padding: 12px 14px;
}

.csw-primary {
    background: linear-gradient(135deg, var(--csw-gold), var(--csw-gold-light));
    border: 0;
    border-radius: 10px;
    box-shadow: 0 6px 16px rgba(201, 162, 39, .25);
    color: var(--csw-navy) !important;
    cursor: pointer;
    display: block;
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    padding: 11px 14px;
    text-align: center;
    text-decoration: none;
    width: 100%;
}

.csw-primary:disabled { cursor: wait; opacity: .65; }

.csw-self {
    color: var(--csw-navy);
    display: block;
    font-size: 12.5px;
    font-weight: 700;
    margin-top: 6px;
    padding: 9px;
    text-align: center;
    text-decoration: none;
}

#csw-auth {
    background: #fff;
    border: 1px solid var(--csw-line);
    border-radius: 14px;
    display: grid;
    gap: 8px;
    margin: 14px auto 0;
    max-width: 340px;
    padding: 14px;
    width: 100%;
}

.csw-auth-prompt { display: none; }

.csw-auth-mode .csw-auth-prompt {
    align-items: flex-end;
    direction: ltr;
    display: flex;
    gap: 8px;
    justify-content: flex-start;
    margin-bottom: 10px;
}

.csw-auth-prompt img {
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(13, 40, 71, .16);
    flex: 0 0 auto;
    height: 36px;
    object-fit: cover;
    width: 36px;
}

.csw-auth-prompt p {
    background: #fff;
    border: 1px solid rgba(203, 213, 225, .85);
    border-radius: 15px 15px 15px 5px;
    box-shadow: 0 2px 8px rgba(13, 40, 71, .08);
    color: var(--csw-ink);
    direction: rtl;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.9;
    margin: 0;
    max-width: 80%;
    padding: 9px 12px;
    text-align: right;
}

.csw-auth-mode #csw-auth {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    margin: 0 44px 0 0;
    max-width: calc(100% - 44px);
    padding: 0;
}
#csw-auth label { color: var(--csw-muted); font-size: 11px; font-weight: 700; }
#csw-auth input {
    background: #f8fafc;
    border: 1.5px solid var(--csw-line);
    border-radius: 10px;
    caret-color: #0f172a;
    color: #0f172a !important;
    direction: ltr;
    font: inherit;
    outline: none;
    padding: 10px 12px;
    text-align: left;
    -webkit-text-fill-color: #0f172a;
    width: 100%;
}
#csw-auth input::placeholder { color: #94a3b8; opacity: 1; -webkit-text-fill-color: #94a3b8; }
#csw-auth input:focus { background: #fff; border-color: var(--csw-gold); box-shadow: 0 0 0 3px rgba(201,162,39,.12); }
#csw-auth-reset { background: none; border: 0; color: var(--csw-navy); cursor: pointer; font: inherit; font-size: 11px; }
#csw-error { color: #dc2626; font-size: 12px; margin: 10px 0 0; }

/* نمای گفت‌وگو با همان زبان بصری ویجت قدیمی درخواست قطعه */
body.csw-theme .rsx-chat {
    border-radius: 16px;
    bottom: 22px;
    box-shadow: 0 24px 60px rgba(10,31,56,.35);
    height: min(720px, calc(100dvh - 44px));
    inset: auto 22px 22px auto;
    max-width: calc(100vw - 44px);
    width: 430px;
}

body.csw-theme .rsx-chat__head {
    background: linear-gradient(165deg, #0f2d4a, #0d2847);
    min-height: 76px;
    padding: 12px 14px;
}

body.csw-theme .rsx-chat__av {
    border: 2px solid rgba(255,216,107,.55);
    border-radius: 50%;
    height: 48px;
    width: 48px;
}

body.csw-theme .rsx-chat__hname { font-size: 14px; font-weight: 800; }
body.csw-theme .rsx-chat__hsub { color: rgba(255,255,255,.78); }
body.csw-theme .rsx-chat__hbtn { border-radius: 10px; height: 36px; order: 3; width: 36px; }
body.csw-theme .rsx-chat__bg::after { background: rgba(248,250,252,.5); }
body.csw-theme .rsx-chat__body { padding: 16px 14px 10px; }
body.csw-theme .rcm--me .rcm__bubble {
    background: linear-gradient(135deg, #1d4377 0%, #0d2847 100%);
    border-color: #0d2847;
    color: #fff;
}
body.csw-theme .rcm--them .rcm__bubble {
    background: #fff;
    border-color: #e4e8f0;
    color: #1a2a44;
}
body.csw-theme .rsx-chat__input:focus { border-color: #c9a227; box-shadow: 0 0 0 3px rgba(201,162,39,.12); }
body.csw-theme .rsx-chat__send { background: linear-gradient(150deg, #0f2d4a, #0d2847); }

@media (max-width: 540px) {
    .csw-launch {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        font-size: 13px;
        right: 16px;
    }
    .csw-launch.collapsed { padding-left: 5px; }
    .csw-launch-avatar { height: 50px; width: 50px; }
    .csw-teaser {
        bottom: calc(84px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }
    .csw-panel {
        border-radius: 20px 20px 0 0;
        bottom: 0;
        max-height: 94dvh;
        right: 0;
        width: 100%;
    }
    .csw-panel.csw-auth-mode { height: 94dvh; }
    .csw-panel-head { padding-top: 18px; }
    .csw-panel-head::before {
        background: rgba(255,255,255,.35);
        border-radius: 999px;
        content: '';
        height: 4px;
        left: 50%;
        position: absolute;
        top: 7px;
        transform: translateX(-50%);
        width: 42px;
    }
    body.csw-theme .rsx-chat {
        border-radius: 20px 20px 0 0;
        bottom: 0;
        height: 94dvh;
        inset: auto 0 0 0;
        max-width: 100%;
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .csw-launch { transition: none; }
}
