/* =====================================================================
   گفتگوی پرونده — نسخه ساده و تمیز
   تم رنگی: فقط آبی و سفید (بدون بنفش / گرادیان رنگی)
   همه کلاس‌ها با پیشوند dc- تا با Tailwind تعارض نداشته باشد
   ===================================================================== */

.dc {
    --dc-blue: #2563eb;          /* آبی اصلی */
    --dc-blue-dark: #1d4ed8;
    --dc-blue-soft: #eff6ff;     /* آبی بسیار روشن */
    --dc-blue-line: #dbeafe;
    --dc-ink: #1e3a5f;           /* متن تیره مایل به آبی */
    --dc-ink-soft: #5b7796;
    --dc-green: #22c55e;

    /* لنگرگاه عناصر شناور (دکمه پرش به پایین) — قبلاً نبود و دکمه جابه‌جا می‌شد */
    position: relative;
    display: flex;
    flex-direction: column;
    height: var(--dc-h, 560px);
    background: #ffffff;
    border: 1px solid var(--dc-blue-line);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(37, 99, 235, .08);
    font-family: inherit;
    direction: rtl;
}

/* ===== سربرگ ===== */
.dc-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--dc-blue);
    color: #fff;
    flex: 0 0 auto;
}

.dc-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #fff;
    color: var(--dc-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 16px;
}

.dc-avatar.is-online::after {
    content: '';
    position: absolute;
    inset-inline-end: -1px;
    bottom: -1px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--dc-green);
    box-shadow: 0 0 0 2px var(--dc-blue);
}

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

.dc-peer-name {
    font-weight: 700;
    font-size: 14.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.dc-peer-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dc-peer-sub {
    font-size: 11.5px;
    opacity: .9;
    margin-top: 2px;
    height: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dc-peer-sub.is-typing { opacity: 1; font-weight: 700; }

.dc-head-actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }

.dc-icon-btn {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 9px;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}

.dc-icon-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .3); }
.dc-icon-btn:active:not(:disabled) { transform: scale(.94); }
.dc-icon-btn:disabled { opacity: .6; cursor: default; }

/* نشانگر قطع بودن اتصال */
.dc-offline-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: rgba(255, 255, 255, .22);
    color: #fff7ed;
    font-size: 12px;
}

.dc-badge {
    background: #fff;
    color: var(--dc-blue);
    font-size: 10.5px;
    font-weight: 800;
    border-radius: 99px;
    padding: 2px 8px;
    white-space: nowrap;
    flex: 0 0 auto;
}

/* ===== صحنه (بدنه + عناصر شناور) ===== */
.dc-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
}

/* ===== بدنه ===== */
.dc-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 16px 14px;
    background: #ffffff;
    /* اسکرول را جاوااسکریپت مدیریت می‌کند؛ smooth بودن هر پرش را کند می‌کرد */
    scroll-behavior: auto;
    /* گرادیان پس‌زمینه حذف شد: با هر اسکرول ری‌پینت اجباری می‌ساخت */
    contain: paint;
}

.dc-body::-webkit-scrollbar { width: 8px; }
.dc-body::-webkit-scrollbar-track { background: transparent; }
.dc-body::-webkit-scrollbar-thumb { background: var(--dc-blue-line); border-radius: 99px; }
.dc-body::-webkit-scrollbar-thumb:hover { background: #bfdbfe; }

/* ===== جداکننده روز ===== */
.dc-day { display: flex; align-items: center; justify-content: center; margin: 14px 0 16px; }

.dc-day span {
    background: var(--dc-blue-soft);
    color: var(--dc-blue);
    border: 1px solid var(--dc-blue-line);
    font-size: 11.5px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 99px;
}

.dc-unread-line {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--dc-blue);
    font-size: 11.5px;
    font-weight: 800;
    margin: 14px 0;
}

.dc-unread-line::before,
.dc-unread-line::after { content: ''; height: 1px; flex: 1; background: var(--dc-blue-line); }

/* ===== ردیف پیام ===== */
.dc-row {
    display: flex;
    margin-bottom: 4px;
    /* مرورگر حباب‌های بیرون کادر را لایوت/پینت نمی‌کند: اسکرول روان می‌ماند */
    content-visibility: auto;
    contain-intrinsic-size: auto 46px;
}
.dc-row.is-mine { justify-content: flex-end; }
.dc-row.is-peer { justify-content: flex-start; }
.dc-row.is-grouped { margin-top: 0; }
.dc-row:not(.is-grouped) { margin-top: 10px; }

.dc-bubble {
    max-width: 78%;
    min-width: 0;
    padding: 9px 13px 6px;
    border-radius: 14px;
    font-size: 13.6px;
    line-height: 1.85;
    position: relative;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* پیام طرف مقابل: سفید با حاشیه آبی */
.is-peer .dc-bubble {
    background: #ffffff;
    color: var(--dc-ink);
    border: 1px solid var(--dc-blue-line);
    border-start-start-radius: 4px;
}

/* پیام خودم: آبی توپر با متن سفید */
.is-mine .dc-bubble {
    background: var(--dc-blue);
    color: #ffffff;
    border: 1px solid var(--dc-blue);
    border-start-end-radius: 4px;
}

/* در حال ارسال / ناموفق */
.dc-bubble.is-pending { opacity: .62; }
.dc-bubble.is-failed { background: #b91c1c; border-color: #b91c1c; opacity: 1; }

.dc-sender { font-size: 11.5px; font-weight: 800; margin-bottom: 3px; }
.is-peer .dc-sender { color: var(--dc-blue); }
.is-mine .dc-sender { color: #dbeafe; }
.dc-role { opacity: .75; font-weight: 600; }

.dc-text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }

.dc-meta {
    display: flex;
    align-items: center;
    gap: 5px;
    justify-content: flex-end;
    font-size: 10.5px;
    margin-top: 3px;
    direction: ltr;
}

.is-mine .dc-meta { color: #dbeafe; }
.is-peer .dc-meta { color: var(--dc-ink-soft); }
.dc-tick-read { color: #ffffff; }

.dc-retry {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, .2);
    color: #fff;
    border: 0;
    border-radius: 99px;
    padding: 2px 8px;
    font-size: 10.5px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    direction: rtl;
}

.dc-retry:hover { background: rgba(255, 255, 255, .34); }

/* ===== در حال نوشتن (شناور، بیرون از لیست تا رندر لیست را دست نزند) ===== */
.dc-typing-float {
    position: absolute;
    inset-inline-start: 14px;
    bottom: 10px;
    pointer-events: none;
    z-index: 2;
}

.dc-typing {
    display: flex;
    gap: 4px;
    padding: 9px 13px;
    background: #ffffff;
    border: 1px solid var(--dc-blue-line);
    border-radius: 14px;
    box-shadow: 0 4px 14px rgba(37, 99, 235, .12);
}

.dc-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--dc-blue);
    animation: dc-blink 1.1s infinite ease-in-out;
}

.dc-typing i:nth-child(2) { animation-delay: .18s; }
.dc-typing i:nth-child(3) { animation-delay: .36s; }

@keyframes dc-blink {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* ===== دکمه پیام‌های قبلی ===== */
.dc-older { display: flex; justify-content: center; margin-bottom: 12px; }

.dc-older-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--dc-blue-soft);
    color: var(--dc-blue);
    border: 1px solid var(--dc-blue-line);
    border-radius: 99px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s ease;
}

.dc-older-btn:hover:not(:disabled) { background: #dbeafe; }
.dc-older-btn:disabled { opacity: .6; cursor: default; }

.dc-tail { height: 2px; }

/* ===== اسکلت بارگیری ===== */
.dc-skeleton {
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 37%, #f1f5f9 63%);
    background-size: 400% 100%;
    animation: dc-shimmer 1.3s ease-in-out infinite;
}

@keyframes dc-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
}

/* ===== حالت خالی ===== */
.dc-empty { text-align: center; color: var(--dc-ink-soft); padding: 48px 20px; width: 100%; }
.dc-empty i { font-size: 40px; color: #bfdbfe; margin-bottom: 12px; display: block; }
.dc-empty p { font-size: 13.5px; }

/* ===== دکمه پریدن به پایین ===== */
.dc-jump {
    position: absolute;
    inset-inline-start: 50%;
    transform: translateX(50%);
    bottom: 12px;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--dc-blue);
    color: #fff;
    border: 0;
    border-radius: 99px;
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 6px 16px rgba(37, 99, 235, .3);
}

.dc-jump span {
    background: #fff;
    color: var(--dc-blue);
    border-radius: 99px;
    padding: 0 6px;
    font-size: 11px;
}

/* ===== جعبه نوشتن (فقط متن) ===== */
.dc-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    background: #ffffff;
    border-top: 1px solid var(--dc-blue-line);
    flex: 0 0 auto;
}

.dc-input-wrap { flex: 1 1 auto; position: relative; min-width: 0; }

.dc-input {
    display: block;
    width: 100%;
    resize: none;
    /* هم‌تراز با سقف ۱۴۰ پیکسلی جاوااسکریپت (قبلاً ۱۳۰ بود و پرش می‌ساخت) */
    max-height: 140px;
    overflow-y: hidden;
    padding: 11px 14px;
    border: 1px solid var(--dc-blue-line);
    border-radius: 12px;
    background: var(--dc-blue-soft);
    color: var(--dc-ink);
    font-family: inherit;
    font-size: 13.6px;
    line-height: 1.8;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.dc-input::placeholder { color: #93a9c4; }

.dc-input:focus {
    border-color: var(--dc-blue);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.dc-send {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 12px;
    background: var(--dc-blue);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, transform .12s ease;
}

.dc-send:hover:not(:disabled) { background: var(--dc-blue-dark); }
.dc-send:active:not(:disabled) { transform: scale(.94); }
.dc-send:disabled { opacity: .45; cursor: not-allowed; }

/* ===== خطا ===== */
.dc-error {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 12px 8px;
    padding: 9px 12px;
    border-radius: 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 12.5px;
    overflow-wrap: anywhere;
}

.dc-error span { flex: 1 1 auto; min-width: 0; }

.dc-error-close {
    border: 0;
    background: transparent;
    color: #b91c1c;
    cursor: pointer;
    font-size: 12px;
    padding: 0 2px;
    flex: 0 0 auto;
}

/* موبایل */
@media (max-width: 767px) {
    /* 100vh/78vh در موبایل نوار آدرس را نمی‌بیند؛ dvh می‌بیند.
       و --dc-h را جاوااسکریپت هنگام باز شدن کیبورد می‌نشاند. */
    .dc {
        height: var(--dc-h, min(78dvh, 640px));
        border-radius: 14px;
    }

    .dc-bubble { max-width: 88%; font-size: 13.6px; }

    /* زیر ۱۶ پیکسل، iOS هنگام فوکوس کل صفحه را زوم می‌کرد */
    .dc-input { font-size: 16px; }

    /* دکمه ارسال و حاشیه امن (نوار خانه آیفون) */
    .dc-composer {
        gap: 8px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .dc-send { width: 46px; height: 46px; }
    .dc-icon-btn { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
    .dc-body { scroll-behavior: auto; }
    .dc-typing i { animation: none; }
    .dc-skeleton { animation: none; }
    .dc-bubble { transition: none; }
}

/* =====================================================================
   اعلان شناور (toast) — با رسیدن پیام جدید نمایش داده می‌شود
   ===================================================================== */
.daovi-toast-wrap {
    position: fixed;
    top: 18px;
    inset-inline-start: 18px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 340px;
    max-width: calc(100vw - 32px);
    direction: rtl;
    pointer-events: none;
}

.daovi-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 11px;
    background: rgba(255, 255, 255, .97);
    backdrop-filter: blur(10px);
    border: 1px solid #e5e7eb;
    border-inline-start: 4px solid #4f46e5;
    border-radius: 14px;
    padding: 12px 13px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, .16);
    opacity: 0;
    transform: translateY(-14px) scale(.97);
    transition: opacity .24s ease, transform .24s ease;
}

.daovi-toast.is-in { opacity: 1; transform: none; }
.daovi-toast.is-leaving { opacity: 0; transform: translateY(-10px) scale(.97); }
.daovi-toast.is-clickable { cursor: pointer; }
.daovi-toast.is-clickable:hover { box-shadow: 0 20px 48px rgba(15, 23, 42, .22); }
.daovi-toast.is-important { border-inline-start-color: #ef4444; }

.daovi-toast-icon {
    width: 36px;
    height: 36px;
    border-radius: 11px;
    background: #eef2ff;
    color: #4f46e5;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.daovi-toast.is-important .daovi-toast-icon { background: #fee2e2; color: #ef4444; }
.daovi-toast-body { flex: 1 1 auto; min-width: 0; max-width: 100%; }
/* متن اعلان هرگز از کادر بیرون نزند: لینک/کلمه طولانی هم شکسته می‌شود */
.daovi-toast-title {
    font-size: 13px; font-weight: 800; color: #1e293b; margin-bottom: 2px;
    overflow-wrap: anywhere; word-break: break-word;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.daovi-toast-text {
    font-size: 12px; color: #64748b; line-height: 1.7;
    overflow-wrap: anywhere; word-break: break-word; white-space: pre-wrap;
    display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.daovi-toast-close { border: 0; background: transparent; color: #94a3b8; cursor: pointer; font-size: 12px; padding: 2px; }
.daovi-toast-close:hover { color: #ef4444; }

/* زنگ ناوبار وقتی اعلان تازه می‌رسد */
@keyframes daovi-bell-ring {
    0%, 100% { transform: rotate(0); }
    15% { transform: rotate(14deg); }
    30% { transform: rotate(-12deg); }
    45% { transform: rotate(9deg); }
    60% { transform: rotate(-7deg); }
    75% { transform: rotate(4deg); }
}

.daovi-bell-ring { animation: daovi-bell-ring .9s ease-in-out 2; transform-origin: 50% 10%; }

@media (max-width: 640px) {
    .daovi-toast-wrap { inset-inline: 16px auto; width: calc(100vw - 32px); }
}


.daovi-toast-wrap { z-index: var(--z-toast); padding-top: env(safe-area-inset-top, 0px); }
.daovi-notify-controls { position: fixed; inset-inline-end: .75rem; bottom: max(.75rem, env(safe-area-inset-bottom, 0px)); z-index: var(--z-toast); display: flex; align-items: center; gap: .5rem; max-width: min(22rem, calc(100vw - 1.5rem)); }
.daovi-notify-controls button { border: 1px solid #cbd5e1; border-radius: .6rem; background: #fff; color: #334155; }
.daovi-notify-health { padding: .4rem .65rem; border-radius: .5rem; background: #fff7ed; color: #9a3412; font-size: .75rem; box-shadow: 0 2px 8px rgb(15 23 42 / .1); }
@media (max-width: 767px) { .daovi-notify-controls { inset-inline-start: .75rem; inset-inline-end: auto; } }
@media (prefers-reduced-motion: reduce) { .daovi-toast-wrap *, .daovi-notify-controls * { animation: none !important; transition: none !important; } }
