/* ============================================================
   chatbot_widget.css — ⚚ v148 فاز ۳۸
   ویجت چت شناور (دستیار هوشمند + گفتگوی اپراتور فروش)
   مشترک بین: داشبورد همکار / صفحه فروشگاه / پنل اپراتور فروش
   همهٔ کلاس‌ها با cbt- پیشونددارند تا با CSS صفحات تداخل نکنند.
   ============================================================ */

.cbt-launcher {
    position: fixed;
    bottom: 22px;
    left: 22px; /* RTL: سمت چپ پایین — دور از دکمه چت فاکتور (سمت چپ وسط) */
    z-index: 1500;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 22px rgba(37, 99, 235, .45);
    transition: transform .18s ease, box-shadow .18s ease;
    animation: cbt-pop-in .25s ease;
}
.cbt-launcher:hover { transform: translateY(-3px) scale(1.05); box-shadow: 0 10px 28px rgba(37, 99, 235, .55); }
.cbt-launcher.cbt-expert-theme { background: linear-gradient(135deg, #8b5cf6, #6d28d9); box-shadow: 0 6px 22px rgba(139, 92, 246, .45); }
.cbt-launcher svg { width: 28px; height: 28px; }
.cbt-launcher .cbt-badge {
    position: absolute;
    top: -4px;
    left: -4px;
    min-width: 21px;
    height: 21px;
    padding: 0 5px;
    border-radius: 11px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-sizing: content-box;
    font-feature-settings: 'tnum';
}
.cbt-launcher .cbt-badge.cbt-show { display: flex; }

@keyframes cbt-pop-in { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- پنل اصلی ---------- */
.cbt-panel {
    position: fixed;
    bottom: 92px;
    left: 22px;
    z-index: 1600;
    width: 384px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 130px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 18px 60px rgba(15, 23, 42, .28);
    display: none;
    flex-direction: column;
    overflow: hidden;
    direction: rtl;
    font-family: Vazirmatn, Tahoma, sans-serif;
    animation: cbt-slide-up .22s ease;
    border: 1px solid #e2e8f0;
}
.cbt-panel.cbt-open { display: flex; }
@keyframes cbt-slide-up { from { transform: translateY(18px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- هدر ---------- */
.cbt-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    flex-shrink: 0;
}
.cbt-panel.cbt-expert-theme .cbt-header { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.cbt-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .2);
    display: flex; align-items: center; justify-content: center;
    font-size: 19px;
    flex-shrink: 0;
}
.cbt-header-titles { flex: 1; min-width: 0; }
.cbt-header-title { font-size: .95rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cbt-header-sub { font-size: .74rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cbt-icon-btn {
    width: 32px; height: 32px;
    border: none;
    border-radius: 9px;
    background: rgba(255, 255, 255, .16);
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
}
.cbt-icon-btn:hover { background: rgba(255, 255, 255, .3); }
.cbt-icon-btn svg { width: 17px; height: 17px; }
.cbt-icon-btn.cbt-hidden { display: none; }

/* ---------- نمای انتخاب (AI یا اپراتور) ---------- */
.cbt-views { flex: 1; min-height: 0; position: relative; }
.cbt-view { position: absolute; inset: 0; display: none; flex-direction: column; min-height: 0; }
.cbt-view.cbt-active { display: flex; }

.cbt-choice-list { padding: 18px 16px; overflow-y: auto; }
.cbt-choice-intro { font-size: .84rem; color: #64748b; text-align: center; margin-bottom: 16px; line-height: 1.9; }
.cbt-choice-card {
    width: 100%;
    border: 1.5px solid #e2e8f0;
    background: #fff;
    border-radius: 15px;
    padding: 15px 16px;
    display: flex;
    align-items: center;
    gap: 13px;
    cursor: pointer;
    text-align: right;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s, transform .15s;
    margin-bottom: 12px;
}
.cbt-choice-card:hover:not(:disabled) { border-color: #2563eb; box-shadow: 0 6px 18px rgba(37, 99, 235, .12); transform: translateY(-2px); }
.cbt-choice-card:disabled { opacity: .55; cursor: not-allowed; }
.cbt-choice-emoji {
    width: 48px; height: 48px;
    border-radius: 13px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    background: #eff6ff;
}
.cbt-choice-card.cbt-op .cbt-choice-emoji { background: #f5f3ff; }
.cbt-choice-title { font-size: .95rem; font-weight: 800; color: #0f172a; }
.cbt-choice-sub { font-size: .78rem; color: #64748b; margin-top: 3px; line-height: 1.7; }
.cbt-choice-tag {
    display: inline-block;
    margin-top: 6px;
    font-size: .68rem;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 20px;
    background: #f1f5f9;
    color: #64748b;
}
.cbt-choice-tag.cbt-on { background: #dcfce7; color: #166534; }
.cbt-choice-tag.cbt-off { background: #fef2f2; color: #b91c1c; }

/* ---------- پیام‌ها ---------- */
.cbt-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 13px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 9px;
}
.cbt-msg {
    max-width: 84%;
    padding: 9px 13px;
    border-radius: 15px;
    font-size: .86rem;
    line-height: 1.9;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}
/* خودم = سمت چپ (قرینهٔ RTL)، طرف مقابل = سمت راست */
.cbt-msg.cbt-mine { margin-inline-start: auto; background: #2563eb; color: #fff; border-bottom-left-radius: 5px; }
.cbt-msg.cbt-theirs { background: #fff; color: #1e293b; border: 1px solid #e2e8f0; border-bottom-right-radius: 5px; }
.cbt-msg.cbt-ai { background: #fff; color: #1e293b; border: 1px solid #e2e8f0; border-bottom-right-radius: 5px; }
.cbt-msg.cbt-ai.cbt-mine { background: #2563eb; border-color: #2563eb; color: #fff; }
.cbt-msg-time { display: block; font-size: .64rem; opacity: .65; margin-top: 4px; font-feature-settings: 'tnum'; }
.cbt-msg-error {
    align-self: center;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: .78rem;
    border-radius: 11px;
    padding: 7px 12px;
    max-width: 92%;
    text-align: center;
}
.cbt-typing { display: flex; gap: 4px; align-items: center; padding: 11px 15px; }
.cbt-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: cbt-blink 1.2s infinite;
}
.cbt-typing span:nth-child(2) { animation-delay: .2s; }
.cbt-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes cbt-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.cbt-msg.cbt-typing-bubble { background: #fff; border: 1px solid #e2e8f0; border-radius: 15px; }

/* چیپ‌های پیشنهادی سوال */
.cbt-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 13px 11px; background: #f8fafc; }
.cbt-chip {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    border-radius: 20px;
    padding: 5px 12px;
    font-size: .74rem;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s;
}
.cbt-chip:hover { background: #dbeafe; }

/* ---------- کارت سبد پیشنهادی ---------- */
.cbt-cart {
    max-width: 92%;
    background: #fff;
    border: 1.5px solid #bfdbfe;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(37, 99, 235, .10);
}
.cbt-cart-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 13px;
    background: #eff6ff;
    color: #1e3a8a;
    font-size: .82rem;
    font-weight: 800;
}
.cbt-cart-items { max-height: 240px; overflow-y: auto; }
.cbt-cart-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 13px;
    border-bottom: 1px solid #f1f5f9;
    font-size: .8rem;
}
.cbt-cart-row:last-child { border-bottom: none; }
.cbt-cart-img {
    width: 40px; height: 40px;
    border-radius: 9px;
    object-fit: cover;
    background: #f1f5f9;
    flex-shrink: 0;
}
.cbt-cart-img-placeholder {
    width: 40px; height: 40px;
    border-radius: 9px;
    background: #f1f5f9;
    display: flex; align-items: center; justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
}
.cbt-cart-info { flex: 1; min-width: 0; }
.cbt-cart-name { font-weight: 700; color: #0f172a; font-size: .8rem; line-height: 1.6; }
.cbt-cart-code { font-size: .68rem; color: #64748b; direction: ltr; text-align: right; font-feature-settings: 'tnum'; }
.cbt-cart-qty { font-size: .74rem; color: #475569; background: #f1f5f9; border-radius: 7px; padding: 2px 8px; white-space: nowrap; }
.cbt-cart-price { font-size: .78rem; font-weight: 800; color: #0f172a; white-space: nowrap; font-feature-settings: 'tnum'; }
.cbt-cart-stock-warn {
    display: inline-block;
    font-size: .64rem;
    color: #b91c1c;
    background: #fef2f2;
    border-radius: 6px;
    padding: 1px 6px;
    margin-top: 3px;
}
.cbt-cart-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 13px;
    background: #f8fafc;
    font-size: .84rem;
    color: #0f172a;
}
.cbt-cart-total strong { font-size: .95rem; color: #1d4ed8; font-feature-settings: 'tnum'; }

/* ---------- ناحیهٔ ورودی ---------- */
.cbt-input-area {
    display: flex;
    gap: 8px;
    padding: 11px 12px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}
.cbt-input-area textarea {
    flex: 1;
    resize: none;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    padding: 9px 13px;
    font-family: inherit;
    font-size: .87rem;
    line-height: 1.7;
    max-height: 96px;
    outline: none;
    transition: border-color .15s;
    background: #f8fafc;
}
.cbt-input-area textarea:focus { border-color: #2563eb; background: #fff; }
.cbt-send-btn {
    width: 44px;
    border: none;
    border-radius: 12px;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .15s;
}
.cbt-send-btn:hover { background: #1d4ed8; transform: scale(1.05); }
.cbt-send-btn:disabled { background: #94a3b8; cursor: not-allowed; transform: none; }
.cbt-send-btn svg { width: 19px; height: 19px; transform: scaleX(-1); }

/* ---------- پنل اپراتور: لیست تردها ---------- */
.cbt-panel.cbt-wide { width: 780px; height: 620px; }
.cbt-split { flex: 1; min-height: 0; display: flex; }

.cbt-threads-pane {
    width: 296px;
    flex-shrink: 0;
    border-inline-end: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #fff;
}
.cbt-threads-search { padding: 11px 12px; border-bottom: 1px solid #f1f5f9; display: flex; gap: 7px; }
.cbt-threads-search input {
    flex: 1;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 11px;
    font-family: inherit;
    font-size: .82rem;
    outline: none;
    background: #f8fafc;
}
.cbt-threads-search input:focus { border-color: #8b5cf6; background: #fff; }
.cbt-threads-search button {
    border: none;
    border-radius: 10px;
    background: #ede9fe;
    color: #6d28d9;
    font-family: inherit;
    font-size: .78rem;
    font-weight: 700;
    padding: 0 12px;
    cursor: pointer;
    white-space: nowrap;
}
.cbt-threads-list { flex: 1; overflow-y: auto; }
.cbt-thread-item {
    display: flex;
    gap: 10px;
    padding: 11px 13px;
    cursor: pointer;
    border-bottom: 1px solid #f8fafc;
    transition: background .13s;
    align-items: center;
}
.cbt-thread-item:hover { background: #f8fafc; }
.cbt-thread-item.cbt-selected { background: #ede9fe; }
.cbt-thread-avatar {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8b5cf6, #a78bfa);
    color: #fff;
    font-weight: 800;
    font-size: 1rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.cbt-thread-mid { flex: 1; min-width: 0; }
.cbt-thread-name { font-size: .84rem; font-weight: 700; color: #0f172a; display: flex; align-items: center; gap: 6px; }
.cbt-thread-name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cbt-thread-sub { font-size: .73rem; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.cbt-thread-sub.cbt-unread-text { color: #0f172a; font-weight: 700; }
.cbt-thread-side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.cbt-thread-time { font-size: .65rem; color: #94a3b8; font-feature-settings: 'tnum'; }
.cbt-thread-badge {
    min-width: 19px; height: 19px;
    padding: 0 5px;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: .68rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    font-feature-settings: 'tnum';
}
.cbt-thread-xfer {
    font-size: .62rem;
    color: #b45309;
    background: #fef3c7;
    border-radius: 6px;
    padding: 1px 6px;
}
.cbt-empty {
    padding: 34px 20px;
    text-align: center;
    color: #94a3b8;
    font-size: .82rem;
    line-height: 2;
}

/* نمای گفتگوی اپراتور با یک همکار */
.cbt-convo-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.cbt-convo-header {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 14px;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}
.cbt-convo-header .cbt-avatar { background: #ede9fe; color: #6d28d9; font-size: 16px; width: 36px; height: 36px; }
.cbt-back-btn {
    display: none;
    width: 34px; height: 34px;
    border: none;
    border-radius: 9px;
    background: #f1f5f9;
    color: #334155;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.cbt-back-btn svg { width: 17px; height: 17px; }
.cbt-convo-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: .85rem; }

/* ---------- نوار وضعیت کوچک ---------- */
.cbt-status-row {
    display: flex;
    justify-content: center;
    padding: 7px 10px;
    font-size: .72rem;
    color: #64748b;
    background: #fff;
    border-top: 1px dashed #e2e8f0;
    flex-shrink: 0;
}
.cbt-status-row a { color: #2563eb; text-decoration: none; font-weight: 700; }

/* ---------- موبایل ---------- */
@media (max-width: 640px) {
    .cbt-launcher { bottom: 16px; left: 16px; width: 54px; height: 54px; }
    .cbt-panel {
        left: 0; right: 0; bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 82vh;
        max-height: 82vh;
        border-radius: 18px 18px 0 0;
    }
    .cbt-panel.cbt-wide { width: 100%; }
    .cbt-split { position: relative; }
    .cbt-threads-pane {
        width: 100%;
        border-inline-end: none;
        position: absolute; inset: 0;
        z-index: 5;
        background: #fff;
    }
    .cbt-panel.cbt-convo-mode .cbt-threads-pane { display: none; }
    .cbt-back-btn { display: flex; }
}

/* حالت چاپ — ویجت هرگز چاپ نشود */
@media print { .cbt-launcher, .cbt-panel { display: none !important; } }
