/* =====================================================================
   ChatBox — استایل مشترک ویجت سایت و کنسول چت پنل مدیریت
   پیشوند همه‌ی کلاس‌ها: cb-
   تم سایت  : .cb-theme-site  (نیلی-بنفش مثل app.css)
   تم ادمین : .cb-theme-admin (فیروزه‌ای-سرمه‌ای مثل AdminLayout)
   ===================================================================== */

.cb-theme-site {
    --cb-p1: #4f46e5;
    --cb-p2: #7c3aed;
    --cb-pd: #3730a3;
    --cb-soft: #eef2ff;
    --cb-soft2: #e0e7ff;
    --cb-ink: #1e1b4b;
    --cb-line: #e4e3f3;
    --cb-ring: rgba(99, 102, 241, .38);
    --cb-shadow: 0 24px 60px rgba(49, 46, 129, .28), 0 4px 14px rgba(49, 46, 129, .12);
}

.cb-theme-admin {
    --cb-p1: #0e7490;
    --cb-p2: #0b5f7a;
    --cb-pd: #053d67;
    --cb-soft: #ecfeff;
    --cb-soft2: #cffafe;
    --cb-ink: #0f2a43;
    --cb-line: #d6e6ee;
    --cb-ring: rgba(14, 116, 144, .35);
    --cb-shadow: 0 14px 40px rgba(0, 10, 30, .22);
}

.cb-root, .cb-admin {
    --cb-muted: #64748b;
    --cb-bg: #f7f8fc;
    --cb-card: #ffffff;
    --cb-ok: #10b981;
    --cb-danger: #dc2626;
    --cb-grad: linear-gradient(135deg, var(--cb-p1) 0%, var(--cb-p2) 100%);
    direction: rtl;
    text-align: right;
    color: var(--cb-ink);
    font-family: var(--font-main);
    font-size: .92rem;
    line-height: 1.7;
    color-scheme: light;
}

    .cb-root *, .cb-root *::before, .cb-root *::after,
    .cb-admin *, .cb-admin *::before, .cb-admin *::after {
        box-sizing: border-box;
    }

/* ریست‌ها با :where تا اولویت صفر داشته باشند و رنگ/فونت کلاس‌های خودمان را باطل نکنند */
:where(.cb-root, .cb-admin) :where(button, textarea, input) {
    font: inherit;
    color: inherit;
}

:where(.cb-root, .cb-admin) button {
    cursor: pointer;
}

    :where(.cb-root, .cb-admin) button:disabled {
        cursor: not-allowed;
    }

:where(.cb-root, .cb-admin) :focus-visible {
    outline: 2px solid var(--cb-p1);
    outline-offset: 2px;
}

/* هنگام باز بودن پنل در موبایل، صفحه‌ی زیرین اسکرول نمی‌شود (بدون جاوااسکریپت، با :has) */
@media (max-width: 560px) {
    html:has(.cb-root.is-open) {
        overflow: hidden;
    }
}

/* فقط برای صفحه‌خوان‌ها */
.cb-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- آیکن‌ها و دکمه‌های کوچک ---------- */
.cb-ico {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}

.cb-iconbtn {
    display: inline-grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border: 0;
    border-radius: 50%;
    background: transparent;
    transition: background var(--transition-fast, .15s ease), transform var(--transition-fast, .15s ease);
}

    .cb-iconbtn:hover {
        background: rgba(255, 255, 255, .18);
    }

    .cb-iconbtn:active {
        transform: scale(.92);
    }

.cb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 2.5rem;
    padding: .45rem 1.1rem;
    border-radius: 999px;
    border: 1.5px solid transparent;
    font-weight: 600;
    text-decoration: none;
    transition: background .15s ease, box-shadow .15s ease, transform .15s ease, color .15s ease;
}

.cb-btn--primary {
    background: var(--cb-grad);
    color: #fff;
    box-shadow: 0 6px 16px var(--cb-ring);
}

    .cb-btn--primary:hover {
        box-shadow: 0 8px 22px var(--cb-ring);
        transform: translateY(-1px);
    }

.cb-btn--ghost {
    background: #fff;
    color: var(--cb-p1);
    border-color: var(--cb-line);
}

    .cb-btn--ghost:hover {
        background: var(--cb-soft);
    }

.cb-btn--danger {
    background: #fff;
    color: var(--cb-danger);
    border-color: #fecaca;
}

    .cb-btn--danger:hover {
        background: var(--cb-danger);
        color: #fff;
        border-color: var(--cb-danger);
    }

.cb-btn--sm {
    min-height: 2.1rem;
    padding: .25rem .85rem;
    font-size: .84rem;
}

/* ---------- آواتار ---------- */
.cb-avatar {
    --h: 220;
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    flex-shrink: 0;
    border-radius: 50%;
    font-weight: 700;
    background: hsl(var(--h) 75% 92%);
    color: hsl(var(--h) 55% 30%);
    box-shadow: inset 0 0 0 1px hsl(var(--h) 60% 80%);
}

.cb-avatar--sm {
    width: 2.2rem;
    height: 2.2rem;
    font-size: .85rem;
}

.cb-avatar--lg {
    width: 3rem;
    height: 3rem;
    font-size: 1.1rem;
}

.cb-avatar--brand {
    background: rgba(255, 255, 255, .2);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}

.cb-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.cb-avatar-dot {
    position: absolute;
    bottom: 0;
    inset-inline-end: 0;
    width: .7rem;
    height: .7rem;
    border-radius: 50%;
    background: var(--cb-ok);
    border: 2px solid #fff;
}

/* =====================================================================
   لیست پیام‌ها
   ===================================================================== */
.cb-thread-wrap {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.cb-thread {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem .9rem .6rem;
    background: var(--cb-bg);
    scroll-behavior: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--cb-line) transparent;
    /* column-reverse: لیست همیشه از پایین شروع می‌شود و با آمدن پیام جدید پایین می‌ماند (بدون JS) */
    display: flex;
    flex-direction: column-reverse;
}

/* ظرف داخلی: وقتی پیام‌ها کم‌اند بالای لیست می‌نشیند، وقتی زیاد شدند اسکرول به پایین چسبیده است */
.cb-thread-inner {
    flex: 0 0 auto;
    margin-bottom: auto;
}

.cb-thread:focus,
.cb-thread:focus-visible {
    outline: none;
}

.cb-msgs {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.cb-day {
    align-self: center;
    margin: .9rem 0 .6rem;
}

    .cb-day span {
        display: inline-block;
        padding: .1rem .8rem;
        border-radius: 999px;
        background: #fff;
        border: 1px solid var(--cb-line);
        color: var(--cb-muted);
        font-size: .75rem;
    }

.cb-row {
    display: flex;
    margin-top: .18rem;
}

.cb-row--first {
    margin-top: .7rem;
}

.cb-row--mine {
    justify-content: flex-start;
}
/* RTL: شروع = سمت راست */
.cb-row--theirs {
    justify-content: flex-end;
}

.cb-bubble {
    max-width: min(82%, 30rem);
    padding: .5rem .8rem .35rem;
    border-radius: 1.1rem;
    word-break: break-word;
    overflow-wrap: anywhere;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
    animation: cb-in .22s ease-out both;
}

.cb-row--mine .cb-bubble {
    background: var(--cb-grad);
    color: #fff;
    border-end-start-radius: .3rem;
}

.cb-row--theirs .cb-bubble {
    background: #fff;
    color: var(--cb-ink);
    border: 1px solid var(--cb-line);
    border-end-end-radius: .3rem;
}

.cb-row--mine:not(.cb-row--last) .bubble-tail,
.cb-row--mine:not(.cb-row--last) .cb-bubble {
    border-end-start-radius: 1.1rem;
}

.cb-row--theirs:not(.cb-row--last) .cb-bubble {
    border-end-end-radius: 1.1rem;
}

.cb-text {
    margin: 0;
    white-space: pre-wrap;
    /* جهت هر پیام از خود متن تعیین می‌شود (dir=auto)؛ فارسی راست‌چین و انگلیسی چپ‌چین، بدون به‌هم‌ریختن علائم نگارشی */
    text-align: start;
    unicode-bidi: plaintext;
}

.cb-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .25rem;
    margin-top: .1rem;
    font-size: .68rem;
    line-height: 1.2;
    opacity: .78;
}

.cb-tick {
    width: .95rem;
    height: .95rem;
}

    .cb-tick.is-read {
        color: #67e8f9;
        opacity: 1;
    }

@keyframes cb-in {
    from {
        opacity: 0;
        transform: translateY(6px) scale(.98);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* در حال نوشتن */
.cb-typing {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    margin: .7rem 0 .2rem;
    padding: .35rem .8rem;
    border-radius: 1.1rem;
    border-end-end-radius: .3rem;
    background: #fff;
    border: 1px solid var(--cb-line);
    color: var(--cb-muted);
    font-size: .75rem;
}

    .cb-typing i {
        display: inline-block;
        width: .35rem;
        height: .35rem;
        border-radius: 50%;
        background: var(--cb-p1);
        animation: cb-bounce 1.1s infinite ease-in-out;
    }

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

        .cb-typing i:nth-child(3) {
            animation-delay: .3s;
        }

@keyframes cb-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: .45;
    }

    30% {
        transform: translateY(-.28rem);
        opacity: 1;
    }
}

/* دکمه‌ی «پیام جدید» وقتی کاربر بالا اسکرول کرده */
.cb-jump {
    position: absolute;
    bottom: .7rem;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .3rem .9rem;
    border: 0;
    border-radius: 999px;
    background: var(--cb-grad);
    color: #fff;
    font-size: .8rem;
    font-weight: 600;
    box-shadow: 0 6px 18px var(--cb-ring);
    animation: cb-in .2s ease-out both;
}

/* ---------- حالت خالی / خوش‌آمد ---------- */
.cb-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    min-height: 100%;
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--cb-muted);
}

    .cb-empty h3 {
        margin: .3rem 0 0;
        font-size: 1.02rem;
        color: var(--cb-ink);
    }

    .cb-empty p {
        margin: 0;
        max-width: 18rem;
        font-size: .85rem;
    }

.cb-empty-ico {
    display: grid;
    place-items: center;
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    background: var(--cb-soft2);
    color: var(--cb-p1);
}

    .cb-empty-ico svg {
        width: 1.9rem;
        height: 1.9rem;
    }

.cb-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .45rem;
    margin-top: .9rem;
}

.cb-chip {
    padding: .3rem .85rem;
    border-radius: 999px;
    border: 1px solid var(--cb-line);
    background: #fff;
    color: var(--cb-p1);
    font-size: .8rem;
    font-weight: 600;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

    .cb-chip:hover {
        background: var(--cb-soft);
        border-color: var(--cb-p1);
        transform: translateY(-1px);
    }

/* اسکلتون بارگذاری */
.cb-skel {
    display: flex;
    flex-direction: column;
    gap: .7rem;
    padding: 1rem .9rem;
}

    .cb-skel span {
        height: 2.4rem;
        width: 62%;
        border-radius: 1.1rem;
        background: linear-gradient(90deg, #eceef7 25%, #f6f7fc 50%, #eceef7 75%);
        background-size: 200% 100%;
        animation: cb-shimmer 1.3s infinite linear;
    }

        .cb-skel span:nth-child(even) {
            align-self: flex-end;
            width: 48%;
        }

        .cb-skel span:nth-child(3) {
            width: 72%;
            height: 3.4rem;
        }

@keyframes cb-shimmer {
    to {
        background-position: -200% 0;
    }
}

/* =====================================================================
   باکس ارسال پیام
   ===================================================================== */
.cb-composer {
    flex: 0 0 auto;
    padding: .65rem .8rem calc(.6rem + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-top: 1px solid var(--cb-line);
}

.cb-composer-box {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    padding-block: .3rem .3rem; padding-inline: .35rem .3rem;
    border: 1.5px solid var(--cb-line);
    border-radius: 1.4rem;
    background: var(--cb-bg);
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

    .cb-composer-box:focus-within {
        border-color: var(--cb-p1);
        background: #fff;
        box-shadow: 0 0 0 3px var(--cb-ring);
    }

.cb-input {
    flex: 1 1 auto;
    min-width: 0;
    max-height: 140px;
    padding: .45rem .7rem;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    line-height: 1.6;
}

    /* کادر مستطیلی داخل باکس پیام (outline فوکوس مرورگر/استایل‌های سراسری) حذف می‌شود؛
       حلقه‌ی فوکوس فقط روی خود .cb-composer-box (گرد) نمایش داده می‌شود */
    .cb-composer-box .cb-input,
    .cb-composer-box .cb-input:hover,
    .cb-composer-box .cb-input:focus,
    .cb-composer-box .cb-input:focus-visible,
    .cb-composer-box .cb-input:active {
        outline: none !important;
        outline-offset: 0 !important;
        box-shadow: none !important;
        border: 0 !important;
        -webkit-tap-highlight-color: transparent;
    }

    .cb-input::placeholder {
        color: #94a3b8;
    }

    .cb-input:disabled {
        cursor: not-allowed;
    }

.cb-send {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: 50%;
    background: var(--cb-grad);
    color: #fff;
    box-shadow: 0 4px 12px var(--cb-ring);
    transition: transform .15s ease, opacity .15s ease, box-shadow .15s ease;
}

    .cb-send svg {
        width: 1.2rem;
        height: 1.2rem;
        transform: scaleX(-1);
    }
    /* جهت فلش در RTL */
    .cb-send:hover:not(:disabled) {
        transform: translateY(-1px) scale(1.04);
    }

    .cb-send:active:not(:disabled) {
        transform: scale(.94);
    }

    .cb-send:disabled {
        opacity: .55;
        box-shadow: none;
    }

.cb-composer[data-empty="true"] .cb-send:not(.is-busy) {
    background: #cbd5e1;
    box-shadow: none;
}

.cb-spin {
    width: 1.1rem;
    height: 1.1rem;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cb-rot .7s linear infinite;
}

@keyframes cb-rot {
    to {
        transform: rotate(360deg);
    }
}

.cb-hint {
    display: flex;
    justify-content: space-between;
    gap: .5rem;
    margin-top: .3rem;
    padding-inline: .5rem;
    font-size: .7rem;
    color: var(--cb-muted);
}

.cb-count.is-warn {
    color: var(--cb-danger);
    font-weight: 600;
}

.cb-error {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: .5rem;
    padding: .4rem .75rem;
    border-radius: .75rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: .8rem;
}

.cb-banner {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .55rem;
    padding: .9rem 1rem calc(.9rem + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-top: 1px solid var(--cb-line);
    text-align: center;
    color: var(--cb-muted);
    font-size: .85rem;
}

    .cb-banner p {
        margin: 0;
    }

/* =====================================================================
   ویجت صفحه‌ی اصلی
   ===================================================================== */
.cb-root {
    position: fixed;
    right: 1.25rem; /* همیشه گوشه‌ی راست (مستقل از جهت rtl/ltr) */
    left: auto;
    bottom: 1.25rem;
    z-index: 970;
    animation: cb-root-in .5s ease-out both; /* ظاهر شدن نرم بعد از ۲ ثانیه */
}

/* فقط opacity: transform روی والد، position:fixed پنل موبایل را خراب می‌کند */
@keyframes cb-root-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.cb-fab {
    position: relative;
    display: grid;
    place-items: center;
    width: 3.7rem;
    height: 3.7rem;
    border: 0;
    border-radius: 50%;
    background: var(--cb-grad);
    color: #fff;
    box-shadow: var(--cb-shadow);
    transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s ease;
}

    .cb-fab:hover {
        transform: scale(1.08);
    }

    .cb-fab:active {
        transform: scale(.94);
    }

    .cb-fab svg {
        width: 1.7rem;
        height: 1.7rem;
        transition: transform .25s ease, opacity .2s ease;
    }

    .cb-fab:not(.is-open) {
        animation: cb-pulse 2.8s ease-out 1.2s 3;
    }

@keyframes cb-pulse {
    0% {
        box-shadow: var(--cb-shadow), 0 0 0 0 rgba(99, 102, 241, .5);
    }

    70%, 100% {
        box-shadow: var(--cb-shadow), 0 0 0 1.1rem rgba(99, 102, 241, 0);
    }
}

.cb-badge {
    position: absolute;
    top: -.15rem;
    inset-inline-start: -.15rem;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 .35rem;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: #ef4444;
    border: 2px solid #fff;
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    line-height: 1;
}

.cb-panel {
    position: absolute;
    right: 0;
    left: auto;
    bottom: 4.7rem;
    display: flex;
    flex-direction: column;
    width: 24.5rem;
    height: min(37.5rem, calc(100dvh - 7.5rem));
    border-radius: 1.4rem;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--cb-line);
    box-shadow: var(--cb-shadow);
    transform-origin: bottom right;
    animation: cb-pop .28s cubic-bezier(.34, 1.4, .64, 1) both;
}

@keyframes cb-pop {
    from {
        opacity: 0;
        transform: translateY(14px) scale(.94);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.cb-head {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .85rem .9rem;
    background: var(--cb-grad);
    color: #fff;
    overflow: hidden;
}

    .cb-head::after {
        content: "";
        position: absolute;
        width: 11rem;
        height: 11rem;
        top: -6rem;
        inset-inline-start: -3rem;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(255, 255, 255, .22), transparent 70%);
        pointer-events: none;
    }

.cb-head-info {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.cb-head-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.4;
}

.cb-head-sub {
    display: flex;
    align-items: center;
    gap: .35rem;
    font-size: .75rem;
    opacity: .92;
}

    .cb-head-sub::before {
        content: "";
        width: .5rem;
        height: .5rem;
        border-radius: 50%;
        background: #4ade80;
        box-shadow: 0 0 0 3px rgba(74, 222, 128, .3);
    }

.cb-head .cb-iconbtn {
    position: relative;
    z-index: 1;
    color: #fff;
}

.cb-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--cb-bg);
}

.cb-guest {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    flex: 1;
    padding: 2rem 1.5rem;
    text-align: center;
}

    .cb-guest h3 {
        margin: .4rem 0 0;
        font-size: 1.05rem;
    }

    .cb-guest p {
        margin: 0 0 .6rem;
        color: var(--cb-muted);
        font-size: .86rem;
    }

    .cb-guest .cb-btn {
        width: 100%;
        max-width: 15rem;
    }

/* موبایل: تمام‌صفحه */
@media (max-width: 560px) {
    .cb-root {
        right: 1rem;
        left: auto;
        bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }

        .cb-root.is-open {
            inset: 0;
        }

            .cb-root.is-open .cb-fab {
                display: none;
            }

    .cb-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        /* ارتفاع را عمداً از inset:0 می‌گیریم (نه 100dvh) تا با باز شدن کیبورد، پنل بالای کیبورد بماند */
        height: auto;
        border-radius: 0;
        border: 0;
        animation: cb-sheet .3s cubic-bezier(.22, 1, .36, 1) both;
    }

    .cb-head {
        padding-top: calc(.85rem + env(safe-area-inset-top, 0px));
    }

    .cb-iconbtn {
        width: 2.75rem;
        height: 2.75rem;
    }

    .cb-hint .cb-hint-keys {
        display: none;
    }

    /* وقتی کیبورد باز است هر پیکسل ارزش دارد: ردیف شمارنده فقط نزدیک سقف کاراکتر نمایش داده می‌شود */
    .cb-hint {
        display: none;
    }

    .cb-composer:has(.cb-count.is-warn) .cb-hint {
        display: flex;
    }

    .cb-input {
        font-size: 1rem;
    }
    /* جلوگیری از زوم خودکار iOS */
    .cb-bubble {
        max-width: 88%;
    }
}

@keyframes cb-sheet {
    from {
        transform: translateY(100%);
    }

    to {
        transform: none;
    }
}

/* =====================================================================
   کنسول ادمین
   ===================================================================== */
.cb-admin {
    display: grid;
    grid-template-columns: 21.5rem minmax(0, 1fr);
    height: calc(100dvh - 10.5rem);
    min-height: 32.5rem;
    border-radius: 1.2rem;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--cb-line);
    box-shadow: 0 10px 30px rgba(0, 20, 50, .12);
}

.cb-list-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-inline-end: 1px solid var(--cb-line);
    background: #fff;
}

.cb-list-head {
    padding: 1rem 1rem .6rem;
}

.cb-list-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 .7rem;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--cb-pd);
}

.cb-pill {
    padding: .05rem .65rem;
    border-radius: 999px;
    background: var(--cb-soft2);
    color: var(--cb-p1);
    font-size: .75rem;
    font-weight: 700;
}

.cb-search {
    position: relative;
}

    .cb-search svg {
        position: absolute;
        top: 50%;
        inset-inline-start: .75rem;
        width: 1.05rem;
        height: 1.05rem;
        transform: translateY(-50%);
        color: var(--cb-muted);
        pointer-events: none;
    }

    .cb-search input {
        width: 100%;
        height: 2.5rem;
        padding-block: 0 0; padding-inline: 2.4rem .8rem;
        border: 1.5px solid var(--cb-line);
        border-radius: 999px;
        background: var(--cb-bg);
        outline: none;
        transition: border-color .15s ease, box-shadow .15s ease;
    }

        .cb-search input:focus {
            border-color: var(--cb-p1);
            background: #fff;
            box-shadow: 0 0 0 3px var(--cb-ring);
        }

.cb-tabs {
    display: flex;
    gap: .4rem;
    margin-top: .65rem;
}

.cb-tab {
    flex: 1;
    padding: .3rem .5rem;
    border: 1px solid var(--cb-line);
    border-radius: 999px;
    background: #fff;
    color: var(--cb-muted);
    font-size: .8rem;
    font-weight: 600;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}

    .cb-tab:hover {
        background: var(--cb-soft);
    }

    .cb-tab[aria-selected="true"] {
        background: var(--cb-grad);
        border-color: transparent;
        color: #fff;
    }

.cb-list {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: .3rem .5rem .6rem;
    list-style: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.cb-item {
    display: flex;
    align-items: center;
    gap: .7rem;
    width: 100%;
    padding: .65rem .6rem;
    border: 1px solid transparent;
    border-radius: .95rem;
    background: transparent;
    text-align: start;
    transition: background .15s ease, border-color .15s ease;
}

    .cb-item:hover {
        background: var(--cb-soft);
    }

    .cb-item[aria-current="true"] {
        background: var(--cb-soft2);
        border-color: rgba(14, 116, 144, .25);
    }

.cb-item-main {
    flex: 1 1 auto;
    min-width: 0;
}

.cb-item-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .5rem;
}

.cb-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    font-size: .9rem;
}

.cb-item-time {
    flex-shrink: 0;
    font-size: .7rem;
    color: var(--cb-muted);
}

.cb-item-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}

.cb-item-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .8rem;
    color: var(--cb-muted);
}

.cb-item.has-unread .cb-item-preview {
    color: var(--cb-ink);
    font-weight: 600;
}

.cb-unread {
    flex-shrink: 0;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 .4rem;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: var(--cb-p1);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    line-height: 1;
}

.cb-no-results {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--cb-muted);
    font-size: .85rem;
}

.cb-main-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--cb-bg);
}

.cb-thread-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem 1rem;
    background: #fff;
    border-bottom: 1px solid var(--cb-line);
}

    .cb-thread-head .cb-iconbtn {
        color: var(--cb-pd);
    }

        .cb-thread-head .cb-iconbtn:hover {
            background: var(--cb-soft);
        }

.cb-peer {
    flex: 1 1 auto;
    min-width: 0;
}

.cb-peer-name {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.4;
}

.cb-peer-sub {
    display: flex;
    flex-wrap: wrap;
    gap: .15rem .8rem;
    min-width: 0;
    font-size: .76rem;
    color: var(--cb-muted);
}

    .cb-peer-sub bdi {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        unicode-bidi: isolate;
        direction: ltr;
    }

.cb-status {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .1rem .7rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
}

    .cb-status::before {
        content: "";
        width: .45rem;
        height: .45rem;
        border-radius: 50%;
        background: currentColor;
    }

.cb-status--open {
    background: #dcfce7;
    color: #15803d;
}

.cb-status--closed {
    background: #f1f5f9;
    color: #475569;
}

.cb-back {
    display: none;
}

.cb-actions {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex-shrink: 0;
}

.cb-main-empty {
    flex: 1;
    display: grid;
    place-items: center;
}

/* پاسخ‌های آماده */
.cb-canned-toggle {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    margin-bottom: .5rem;
    padding: .2rem .75rem;
    border: 1px solid var(--cb-line);
    border-radius: 999px;
    background: #fff;
    color: var(--cb-p1);
    font-size: .78rem;
    font-weight: 600;
}

    .cb-canned-toggle:hover {
        background: var(--cb-soft);
    }

.cb-canned {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: .55rem;
    animation: cb-in .18s ease-out both;
}

    .cb-canned button {
        max-width: 100%;
        padding: .3rem .8rem;
        border: 1px solid var(--cb-line);
        border-radius: .9rem;
        background: var(--cb-soft);
        color: var(--cb-ink);
        font-size: .8rem;
        text-align: start;
    }

        .cb-canned button:hover {
            border-color: var(--cb-p1);
            background: var(--cb-soft2);
        }

.cb-confirm {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    animation: cb-in .18s ease-out both;
}

/* نشان تعداد خوانده‌نشده در منوی کناری ادمین */
.cb-nav-badge {
    margin-inline-start:25px;
    flex: 0 0 auto;
    box-sizing: border-box;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0 .35rem;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: rgba(15, 23, 42, .55);
    border: 2px solid #ef4444;
    color: #fff;
    font-size: .8rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, .25);
}

/* تبلت و موبایل: یک پنل در هر لحظه */
@media (max-width: 860px) {
    .cb-admin {
        grid-template-columns: minmax(0, 1fr);
        height: calc(100dvh - 12.5rem);
        min-height: 30rem;
        border-radius: 1rem;
    }

        .cb-admin .cb-main-pane {
            display: none;
        }

        .cb-admin.is-thread .cb-list-pane {
            display: none;
        }

        .cb-admin.is-thread .cb-main-pane {
            display: flex;
        }

    .cb-list-pane {
        border-inline-end: 0;
    }

    .cb-back {
        display: inline-grid;
    }

    .cb-peer-sub .cb-peer-phone {
        display: none;
    }

    .cb-hint .cb-hint-keys {
        display: none;
    }

    .cb-input {
        font-size: 1rem;
    }

    .cb-btn-label {
        display: none;
    }

    /* موبایل/تبلت: وقتی ادمین داخل یک گفتگو است، چت دقیقاً مثل پنل کاربران تمام‌صفحه می‌شود
       تا بیشترین فضای ممکن به پیام‌ها برسد (بالای هدر/منوی ادمین، z-index کمتر از مودال‌ها که 1050 است) */
    .cb-admin.is-thread {
        position: fixed;
        inset: 0;
        z-index: 1045;
        grid-template-rows: minmax(0, 1fr);
        /* ارتفاع را عمداً از inset:0 می‌گیریم (نه 100dvh) تا با باز شدن کیبورد، چت بالای کیبورد بماند */
        height: auto;
        min-height: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        overscroll-behavior: contain;
    }

        .cb-admin.is-thread .cb-thread-head {
            padding-top: calc(.6rem + env(safe-area-inset-top, 0px));
        }

        /* وقتی کیبورد باز است هر پیکسل ارزش دارد: ردیف راهنما فقط نزدیک سقف کاراکتر نمایش داده می‌شود */
        .cb-admin.is-thread .cb-hint {
            display: none;
        }

        .cb-admin.is-thread .cb-composer:has(.cb-count.is-warn) .cb-hint {
            display: flex;
        }

        /* در حال تایپ (کیبورد باز): دکمه و فهرست پاسخ‌های آماده مخفی می‌شود تا پیام‌ها بیشترین ارتفاع را داشته باشند */
        .cb-admin.is-thread.is-composing .cb-canned-toggle,
        .cb-admin.is-thread.is-composing .cb-canned {
            display: none;
        }
}

@media (max-width: 560px) {
    .cb-thread-head {
        gap: .5rem;
        padding: .6rem .6rem;
    }

        .cb-thread-head .cb-avatar--lg {
            width: 2.4rem;
            height: 2.4rem;
            font-size: .95rem;
        }

    .cb-status {
        padding: .05rem .55rem;
        font-size: .7rem;
    }

    .cb-thread-head .cb-btn--sm {
        padding: .25rem .6rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cb-root *, .cb-admin * {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

/* آیکن ارسال در حالت راست‌به‌چپ برعکس می‌شود؛ در چپ‌به‌راست باید حالت عادی داشته باشد */
:root[dir="ltr"] .cb-send svg {
    transform: none;
}

/* ===== تاریخ و ساعت زیر هر پیام (ChatThread با StampBelow) ===== */
.cb-msg--stamped {
    display: flex;
    flex-direction: column;
    max-width: min(82%, 30rem);
    min-width: 0;
}

.cb-row--mine .cb-msg--stamped {
    align-items: flex-start;
}

.cb-row--theirs .cb-msg--stamped {
    align-items: flex-end;
}

.cb-msg--stamped .cb-bubble {
    max-width: 100%;
    padding-bottom: .5rem;
}

.cb-stamp {
    display: flex;
    align-items: center;
    gap: .3rem;
    margin-top: .2rem;
    padding-inline: .35rem;
    font-size: .7rem;
    line-height: 1.2;
    color: var(--cb-muted, #64748b);
    white-space: nowrap;
}

    .cb-stamp .cb-tick.is-read {
        color: #0891b2;
    }

/* دکمه‌ی ✕ بستن پنل گفتگو */
.cb-dismiss {
    flex-shrink: 0;
    margin-inline-start: .1rem;
}

    .cb-dismiss svg {
        width: 1.15rem;
        height: 1.15rem;
    }
