/* ═══════════════════════════════════════════════════════════════
   Chat Widget - Desktop - Modern Design
═══════════════════════════════════════════════════════════════ */

/* ── FAB Button ── */
.chat-widget-button {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00bcd4, #0097a7);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 9990;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 4px 20px rgba(0,188,212,.45);
    transition: transform .2s, box-shadow .2s;
}
.chat-widget-button:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,188,212,.55);
}
.chat-widget-button .badge {
    position: absolute;
    top: -4px; right: -4px;
    background: #e63950;
    color: #fff;
    border-radius: 50%;
    width: 20px; height: 20px;
    font-size: .65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ── Popup ── */
.chat-widget-popup {
    position: fixed;
    bottom: 92px;
    left: 24px;
    width: 360px;
    height: 580px;
    background: #1a1f2e;
    border-radius: 20px;
    box-shadow: 0 16px 60px rgba(0,0,0,.5);
    z-index: 10000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    direction: rtl;
    animation: cwSlideUp .28s cubic-bezier(.32,1,.23,1);
}
.chat-widget-popup.active { display: flex; }

@keyframes cwSlideUp {
    from { opacity:0; transform:translateY(20px) scale(.97); }
    to   { opacity:1; transform:translateY(0) scale(1); }
}

/* ── Header ── */
.chat-widget-header {
    background: linear-gradient(135deg, #00bcd4 0%, #0097a7 100%);
    padding: 16px 18px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}
.cw-header-avatars {
    width: 46px; height: 46px;
    flex-shrink: 0;
    position: relative;
}
.cw-header-avatars img,
.cw-header-avatars .cw-avatar-placeholder {
    width: 46px; height: 46px;
    border-radius: 50%;
    border: 2.5px solid rgba(255,255,255,.85);
    object-fit: cover;
    background: rgba(255,255,255,.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; font-weight: 800; color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
    transition: all .3s ease;
}
.cw-header-info { flex: 1; }
.cw-header-title {
    font-size: 1rem;
    font-weight: 800;
    color: #fff;
    margin: 0 0 2px;
    transition: opacity .3s;
}
.cw-header-sub {
    font-size: .72rem;
    color: rgba(255,255,255,.85);
    display: flex;
    align-items: center;
    gap: 5px;
    transition: opacity .3s;
}
.chat-widget-close {
    background: rgba(255,255,255,.2);
    border: none;
    color: #fff;
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: .85rem;
    transition: background .15s;
    flex-shrink: 0;
}
.chat-widget-close:hover { background: rgba(255,255,255,.35); }

/* ── Body (messages area) ── */
.chat-widget-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #1a1f2e;
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='300'%3E%3Ctext fill='rgba(0,188,212,0.07)' font-family='serif' font-size='11'%3E%3Ctspan x='10' y='20'%3Ex²+y²=r²%3C/tspan%3E%3Ctspan x='120' y='20'%3Esin²+cos²=1%3C/tspan%3E%3Ctspan x='260' y='20'%3Eπr²%3C/tspan%3E%3Ctspan x='10' y='50'%3Ef(x)=ax²+bx+c%3C/tspan%3E%3Ctspan x='200' y='50'%3E√(a²+b²)%3C/tspan%3E%3Ctspan x='320' y='50'%3Elogₐb%3C/tspan%3E%3Ctspan x='10' y='80'%3EΣn=n(n+1)/2%3C/tspan%3E%3Ctspan x='180' y='80'%3Etanx=sinx/cosx%3C/tspan%3E%3Ctspan x='10' y='110'%3Ee=mc²%3C/tspan%3E%3Ctspan x='90' y='110'%3E∫f(x)dx%3C/tspan%3E%3Ctspan x='200' y='110'%3Ea²+b²=c²%3C/tspan%3E%3Ctspan x='320' y='110'%3E2πr%3C/tspan%3E%3Ctspan x='10' y='140'%3Edy/dx%3C/tspan%3E%3Ctspan x='80' y='140'%3EΔy/Δx%3C/tspan%3E%3Ctspan x='160' y='140'%3Elim(x→∞)%3C/tspan%3E%3Ctspan x='280' y='140'%3E∞%3C/tspan%3E%3Ctspan x='10' y='170'%3Ex=(−b±√D)/2a%3C/tspan%3E%3Ctspan x='220' y='170'%3EV=πr²h%3C/tspan%3E%3Ctspan x='10' y='200'%3Ecos2x=1−2sin²x%3C/tspan%3E%3Ctspan x='240' y='200'%3E∀x∈ℝ%3C/tspan%3E%3Ctspan x='10' y='230'%3Exy=yx%3C/tspan%3E%3Ctspan x='90' y='230'%3E135+58%3C/tspan%3E%3Ctspan x='180' y='230'%3E√(2x)%3C/tspan%3E%3Ctspan x='260' y='230'%3Ef(x)=2ˣ+1%3C/tspan%3E%3Ctspan x='10' y='260'%3EcoSx−2/3=y%3C/tspan%3E%3Ctspan x='200' y='260'%3EΣ=n−1%3C/tspan%3E%3Ctspan x='10' y='290'%3Etg(−x)/2sinx%3C/tspan%3E%3Ctspan x='180' y='290'%3Er²√17%3C/tspan%3E%3Ctspan x='290' y='290'%3Ey=Δx/Δz%3C/tspan%3E%3C/text%3E%3C/svg%3E");
    background-size: 400px 300px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.chat-widget-body::-webkit-scrollbar { width: 4px; }
.chat-widget-body::-webkit-scrollbar-thumb { background: rgba(0,188,212,.3); border-radius: 4px; }

/* ── Login Form ── */
.chat-login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0;
}
.chat-login-form h6 {
    font-size: .88rem;
    font-weight: 700;
    color: rgba(255,255,255,.8);
    margin: 0 0 4px;
    text-align: center;
}
.chat-login-form input {
    width: 100%;
    height: 46px;
    border: 1.5px solid rgba(255,255,255,.12);
    border-radius: 12px;
    padding: 0 14px;
    font-size: 16px;
    font-family: inherit;
    color: #e2e8f0;
    background: #2a2f3e;
    outline: none;
    transition: border .15s;
    box-sizing: border-box;
}
.chat-login-form input::placeholder { color: rgba(255,255,255,.3); }
.chat-login-form input:focus { border-color: #00bcd4; }
.chat-login-form button {
    height: 48px;
    background: linear-gradient(135deg, #00bcd4, #0097a7);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: .92rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: opacity .2s;
    box-shadow: 0 4px 14px rgba(0,188,212,.35);
}
.chat-login-form button:hover { opacity: .9; }

/* ── Day label ── */
.cw-day-label {
    text-align: center;
    font-size: .65rem;
    color: rgba(255,255,255,.4);
    margin: 4px 0 8px;
    position: relative;
}
.cw-day-label::before, .cw-day-label::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: rgba(255,255,255,.15);
}
.cw-day-label::before { right: 0; }
.cw-day-label::after  { left: 0; }

/* ── Messages ── */
.chat-widget-messages {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 78%;
    margin-bottom: 6px;
}
.chat-message.customer {
    align-self: flex-end;
    align-items: flex-end;
}
.chat-message.admin {
    align-self: flex-start;
    align-items: flex-start;
}

/* admin sender info - فقط نام، بدون آواتار */
.cw-sender-info {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.cw-sender-name {
    font-size: .7rem;
    font-weight: 600;
    color: #00bcd4;
}

.chat-message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: .85rem;
    line-height: 1.55;
    word-break: break-word;
    max-width: 100%;
}
.chat-message.customer .chat-message-bubble {
    background: linear-gradient(135deg, #00bcd4, #0097a7);
    color: #fff;
    border-bottom-left-radius: 4px;
}
.chat-message.admin .chat-message-bubble {
    background: #2a2f3e;
    color: #e2e8f0;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.chat-message-bubble.auto-message {
    background: rgba(180,130,0,.25) !important;
    color: #fde68a !important;
    border: 1px solid rgba(253,230,138,.3);
    font-style: italic;
    text-align: center;
    font-size: .78rem;
    box-shadow: none !important;
}

.chat-message-footer {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
    padding: 0 4px;
}
.chat-message-time {
    font-size: .62rem;
    color: rgba(255,255,255,.4);
}
.chat-message-status {
    font-size: .65rem;
    color: rgba(255,255,255,.5);
}
.chat-message-status.read i { color: #00bcd4; }
.chat-message-status i { color: rgba(255,255,255,.5); }

/* ── Typing indicator ── */
#adminTypingIndicator {
    align-self: flex-start;
    margin-bottom: 6px;
}
#adminTypingIndicator .chat-message-bubble {
    background: #2a2f3e;
    padding: 10px 16px;
    display: flex;
    gap: 4px;
    align-items: center;
}
.cw-typing-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: rgba(0,188,212,.6);
    animation: cwDot 1.2s infinite;
}
.cw-typing-dot:nth-child(2) { animation-delay: .2s; }
.cw-typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes cwDot {
    0%,60%,100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* ── FAQ ── */
.chat-faq-section { margin-top: 12px; }
.chat-faq-title {
    font-size: .75rem;
    font-weight: 700;
    color: rgba(255,255,255,.5);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.chat-faq-item {
    background: #2a2f3e;
    border: 1.5px solid rgba(255,255,255,.08);
    border-radius: 12px;
    margin-bottom: 6px;
    overflow: hidden;
    cursor: pointer;
}
.chat-faq-question {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    font-size: .8rem;
    font-weight: 600;
    color: #e2e8f0;
}
.chat-faq-icon { transition: transform .2s; color: rgba(255,255,255,.3); font-size: .7rem; }
.chat-faq-item.active .chat-faq-question { color: #00bcd4; }
.chat-faq-item.active .chat-faq-icon { transform: rotate(180deg); color: #00bcd4; }
.chat-faq-answer {
    display: none;
    padding: 0 12px 10px;
    font-size: .78rem;
    color: rgba(255,255,255,.5);
    line-height: 1.7;
    border-top: 1px solid rgba(255,255,255,.06);
}
.chat-faq-item.active .chat-faq-answer { display: block; }

/* ── Input form ── */
.chat-widget-form {
    padding: 10px 14px 14px;
    background: #1a1f2e;
    border-top: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}
.cw-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #2a2f3e;
    border: 1.5px solid rgba(255,255,255,.1);
    border-radius: 16px;
    padding: 6px 8px 6px 10px;
    transition: border-color .15s;
}
.cw-input-row:focus-within { border-color: #00bcd4; }
.cw-input-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    align-items: center;
    padding-bottom: 2px;
}
.cw-input-action-btn {
    width: 30px; height: 30px;
    border: none;
    background: none;
    color: rgba(255,255,255,.4);
    cursor: pointer;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem;
    transition: color .15s, background .15s;
}
.cw-input-action-btn:hover { color: #00bcd4; background: rgba(0,188,212,.1); }
.chat-widget-textarea {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    color: #e2e8f0;
    line-height: 1.5;
    max-height: 90px;
    overflow-y: auto;
    padding: 4px 0;
    direction: rtl;
}
.chat-widget-textarea::placeholder { color: rgba(255,255,255,.3); }
.chat-widget-send-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00bcd4, #0097a7);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,188,212,.4);
    transition: transform .15s, opacity .15s;
}
.chat-widget-send-btn:hover { transform: scale(1.08); }
.chat-widget-send-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ── Responsive ── */
@media (max-width: 480px) {
    .chat-widget-popup {
        width: calc(100vw - 32px);
        left: 16px;
        bottom: 84px;
        height: calc(100vh - 110px);
        max-height: none;
    }
}
